summaryrefslogtreecommitdiff
path: root/src/resolve/resolvconf-compat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/resolve/resolvconf-compat.c')
-rw-r--r--src/resolve/resolvconf-compat.c88
1 files changed, 40 insertions, 48 deletions
diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c
index d7e68003e6..383d0b819b 100644
--- a/src/resolve/resolvconf-compat.c
+++ b/src/resolve/resolvconf-compat.c
@@ -9,13 +9,22 @@
#include "extract-word.h"
#include "fileio.h"
#include "parse-util.h"
+#include "pretty-print.h"
#include "resolvconf-compat.h"
#include "resolvectl.h"
#include "resolved-def.h"
#include "string-util.h"
#include "strv.h"
+#include "terminal-util.h"
+
+static int resolvconf_help(void) {
+ _cleanup_free_ char *link = NULL;
+ int r;
+
+ r = terminal_urlify_man("resolvectl", "1", &link);
+ if (r < 0)
+ return log_oom();
-static void resolvconf_help(void) {
printf("%1$s -a INTERFACE < FILE\n"
"%1$s -d INTERFACE\n"
"\n"
@@ -34,7 +43,12 @@ static void resolvconf_help(void) {
"implementations are not supported and will cause the invocation to fail: -u,\n"
"-I, -i, -l, -R, -r, -v, -V, --enable-updates, --disable-updates,\n"
"--updates-are-enabled.\n"
- , program_invocation_short_name);
+ "\nSee the %2$s for details.\n"
+ , program_invocation_short_name
+ , link
+ );
+
+ return 0;
}
static int parse_nameserver(const char *string) {
@@ -53,6 +67,8 @@ static int parse_nameserver(const char *string) {
if (strv_push(&arg_set_dns, word) < 0)
return log_oom();
+
+ word = NULL;
}
return 0;
@@ -107,7 +123,6 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
TYPE_EXCLUSIVE, /* -x */
} type = TYPE_REGULAR;
- const char *dot, *iface;
int c, r;
assert(argc >= 0);
@@ -125,8 +140,7 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
switch(c) {
case 'h':
- resolvconf_help();
- return 0; /* done */;
+ return resolvconf_help();
case ARG_VERSION:
return version();
@@ -169,19 +183,19 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
case 'r':
case 'v':
case 'V':
- log_error("Switch -%c not supported.", c);
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch -%c not supported.", c);
/* The Debian resolvconf commands we don't support. */
case ARG_ENABLE_UPDATES:
- log_error("Switch --enable-updates not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --enable-updates not supported.");
case ARG_DISABLE_UPDATES:
- log_error("Switch --disable-updates not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --disable-updates not supported.");
case ARG_UPDATES_ARE_ENABLED:
- log_error("Switch --updates-are-enabled not supported.");
- return -EINVAL;
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Switch --updates-are-enabled not supported.");
case '?':
return -EINVAL;
@@ -190,40 +204,19 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
- if (arg_mode == _MODE_INVALID) {
- log_error("Expected either -a or -d on the command line.");
- return -EINVAL;
- }
+ if (arg_mode == _MODE_INVALID)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected either -a or -d on the command line.");
- if (optind+1 != argc) {
- log_error("Expected interface name as argument.");
- return -EINVAL;
- }
-
- dot = strchr(argv[optind], '.');
- if (dot) {
- iface = strndupa(argv[optind], dot - argv[optind]);
- log_debug("Ignoring protocol specifier '%s'.", dot + 1);
- } else
- iface = argv[optind];
- optind++;
+ if (optind+1 != argc)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "Expected interface name as argument.");
- if (parse_ifindex(iface, &arg_ifindex) < 0) {
- int ifi;
+ r = ifname_mangle(argv[optind]);
+ if (r <= 0)
+ return r;
- ifi = if_nametoindex(iface);
- if (ifi <= 0) {
- if (errno == ENODEV && arg_ifindex_permissive) {
- log_debug("Interface '%s' not found, but -f specified, ignoring.", iface);
- return 0; /* done */
- }
-
- return log_error_errno(errno, "Unknown interface '%s': %m", iface);
- }
-
- arg_ifindex = ifi;
- arg_ifname = iface;
- }
+ optind++;
if (arg_mode == MODE_SET_LINK) {
unsigned n = 0;
@@ -273,10 +266,9 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
} else if (type == TYPE_PRIVATE)
log_debug("Private DNS server data not supported, ignoring.");
- if (!arg_set_dns) {
- log_error("No DNS servers specified, refusing operation.");
- return -EINVAL;
- }
+ if (!arg_set_dns)
+ return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
+ "No DNS servers specified, refusing operation.");
}
return 1; /* work to do */