coccinelle: make use of SYNTHETIC_ERRNO

Ideally, coccinelle would strip unnecessary braces too. But I do not see any
option in coccinelle for this, so instead, I edited the patch text using
search&replace to remove the braces. Unfortunately this is not fully automatic,
in particular it didn't deal well with if-else-if-else blocks and ifdefs, so
there is an increased likelikehood be some bugs in such spots.

I also removed part of the patch that coccinelle generated for udev, where we
returns -1 for failure. This should be fixed independently.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2018-11-20 23:40:44 +01:00
parent 52d86690d6
commit baaa35ad70
129 changed files with 1932 additions and 2311 deletions

View file

@ -0,0 +1,35 @@
@@
expression e;
expression list args;
@@
- log_debug(args);
- return -e;
+ return log_debug_errno(SYNTHETIC_ERRNO(e), args);
@@
expression e;
expression list args;
@@
- log_info(args);
- return -e;
+ return log_info_errno(SYNTHETIC_ERRNO(e), args);
@@
expression e;
expression list args;
@@
- log_notice(args);
- return -e;
+ return log_notice_errno(SYNTHETIC_ERRNO(e), args);
@@
expression e;
expression list args;
@@
- log_error(args);
- return -e;
+ return log_error_errno(SYNTHETIC_ERRNO(e), args);
@@
expression e;
expression list args;
@@
- log_emergency(args);
- return -e;
+ return log_emergency_errno(SYNTHETIC_ERRNO(e), args);

View file

@ -56,10 +56,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind < argc) { if (optind < argc)
log_error("%s takes no arguments.", program_invocation_short_name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s takes no arguments.",
} program_invocation_short_name);
return 1; return 1;
} }

View file

@ -122,10 +122,9 @@ static int exec_process(const char* name, char **argv, char **env, int start_fd,
char **s; char **s;
int r; int r;
if (arg_inetd && n_fds != 1) { if (arg_inetd && n_fds != 1)
log_error("--inetd only supported for single file descriptors."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--inetd only supported for single file descriptors.");
}
length = strv_length(arg_setenv); length = strv_length(arg_setenv);
@ -384,19 +383,17 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'd': case 'd':
if (arg_socket_type == SOCK_SEQPACKET) { if (arg_socket_type == SOCK_SEQPACKET)
log_error("--datagram may not be combined with --seqpacket."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--datagram may not be combined with --seqpacket.");
}
arg_socket_type = SOCK_DGRAM; arg_socket_type = SOCK_DGRAM;
break; break;
case ARG_SEQPACKET: case ARG_SEQPACKET:
if (arg_socket_type == SOCK_DGRAM) { if (arg_socket_type == SOCK_DGRAM)
log_error("--seqpacket may not be combined with --datagram."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--seqpacket may not be combined with --datagram.");
}
arg_socket_type = SOCK_SEQPACKET; arg_socket_type = SOCK_SEQPACKET;
break; break;
@ -448,17 +445,15 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind == argc) { if (optind == argc)
log_error("%s: command to execute is missing.", return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
program_invocation_short_name); "%s: command to execute is missing.",
return -EINVAL; program_invocation_short_name);
}
if (arg_socket_type == SOCK_DGRAM && arg_accept) { if (arg_socket_type == SOCK_DGRAM && arg_accept)
log_error("Datagram sockets do not accept connections. " return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"The --datagram and --accept options may not be combined."); "Datagram sockets do not accept connections. "
return -EINVAL; "The --datagram and --accept options may not be combined.");
}
arg_args = argv + optind; arg_args = argv + optind;

View file

@ -1360,10 +1360,10 @@ static int cat_config(int argc, char *argv[], void *userdata) {
break; break;
} }
if (!t) { if (!t)
log_error("Path %s does not start with any known prefix.", *arg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path %s does not start with any known prefix.",
} *arg);
} else } else
t = *arg; t = *arg;
@ -1638,10 +1638,9 @@ static int dump_syscall_filters(int argc, char *argv[], void *userdata) {
} }
#else #else
static int dump_syscall_filters(int argc, char *argv[], void *userdata) { static int dump_syscall_filters(int argc, char *argv[], void *userdata)
log_error("Not compiled with syscall filters, sorry."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Not compiled with syscall filters, sorry.");
}
#endif #endif
static int dump_timespan(int argc, char *argv[], void *userdata) { static int dump_timespan(int argc, char *argv[], void *userdata) {
@ -1948,10 +1947,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_MAN: case ARG_MAN:
if (optarg) { if (optarg) {
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("Failed to parse --man= argument."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --man= argument.");
}
arg_man = r; arg_man = r;
} else } else
@ -1962,10 +1960,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_GENERATORS: case ARG_GENERATORS:
if (optarg) { if (optarg) {
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("Failed to parse --generators= argument."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --generators= argument.");
}
arg_generators = r; arg_generators = r;
} else } else
@ -1981,15 +1978,13 @@ static int parse_argv(int argc, char *argv[]) {
} }
if (arg_scope == UNIT_FILE_GLOBAL && if (arg_scope == UNIT_FILE_GLOBAL &&
!STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify")) { !STR_IN_SET(argv[optind] ?: "time", "dot", "unit-paths", "verify"))
log_error("Option --global only makes sense with verbs dot, unit-paths, verify."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --global only makes sense with verbs dot, unit-paths, verify.");
}
if (arg_root && !streq_ptr(argv[optind], "cat-config")) { if (arg_root && !streq_ptr(argv[optind], "cat-config"))
log_error("Option --root is only supported for cat-config right now."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --root is only supported for cat-config right now.");
}
return 1; /* work to do */ return 1; /* work to do */
} }

View file

@ -102,10 +102,10 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_TIMEOUT: case ARG_TIMEOUT:
if (parse_sec(optarg, &arg_timeout) < 0) { if (parse_sec(optarg, &arg_timeout) < 0)
log_error("Failed to parse --timeout parameter %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --timeout parameter %s",
} optarg);
break; break;
case ARG_ECHO: case ARG_ECHO:

View file

@ -2545,11 +2545,10 @@ static int cg_unified_update(void) {
unified_cache = CGROUP_UNIFIED_NONE; unified_cache = CGROUP_UNIFIED_NONE;
} }
} }
} else { } else
log_debug("Unknown filesystem type %llx mounted on /sys/fs/cgroup.", return log_debug_errno(SYNTHETIC_ERRNO(ENOMEDIUM),
(unsigned long long) fs.f_type); "Unknown filesystem type %llx mounted on /sys/fs/cgroup.",
return -ENOMEDIUM; (unsigned long long)fs.f_type);
}
return 0; return 0;
} }

View file

@ -638,16 +638,18 @@ static int check_utf8ness_and_warn(
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
p = utf8_escape_invalid(key); p = utf8_escape_invalid(key);
log_error("%s:%u: invalid UTF-8 in key '%s', ignoring.", strna(filename), line, p); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s:%u: invalid UTF-8 in key '%s', ignoring.",
strna(filename), line, p);
} }
if (value && !utf8_is_valid(value)) { if (value && !utf8_is_valid(value)) {
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
p = utf8_escape_invalid(value); p = utf8_escape_invalid(value);
log_error("%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.", strna(filename), line, key, p); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s:%u: invalid UTF-8 value for key %s: '%s', ignoring.",
strna(filename), line, key, p);
} }
return 0; return 0;

View file

@ -202,10 +202,10 @@ void log_assert_failed_return_realm(
#define log_full_errno_realm(realm, level, error, ...) \ #define log_full_errno_realm(realm, level, error, ...) \
({ \ ({ \
int _level = (level), _e = (error), _realm = (realm); \ int _level = (level), _e = (error), _realm = (realm); \
(log_get_max_level_realm(_realm) >= LOG_PRI(_level)) \ (log_get_max_level_realm(_realm) >= LOG_PRI(_level)) \
? log_internal_realm(LOG_REALM_PLUS_LEVEL(_realm, _level), _e, \ ? log_internal_realm(LOG_REALM_PLUS_LEVEL(_realm, _level), _e, \
__FILE__, __LINE__, __func__, __VA_ARGS__) \ __FILE__, __LINE__, __func__, __VA_ARGS__) \
: -abs(_e); \ : -ERRNO_VALUE(_e); \
}) })
#define log_full_errno(level, error, ...) \ #define log_full_errno(level, error, ...) \

View file

@ -1227,8 +1227,7 @@ int must_be_root(void) {
if (geteuid() == 0) if (geteuid() == 0)
return 0; return 0;
log_error("Need to be root."); return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Need to be root.");
return -EPERM;
} }
int safe_fork_full( int safe_fork_full(

View file

@ -168,10 +168,10 @@ int rm_rf(const char *path, RemoveFlags flags) {
/* We refuse to clean the root file system with this /* We refuse to clean the root file system with this
* call. This is extra paranoia to never cause a really * call. This is extra paranoia to never cause a really
* seriously broken system. */ * seriously broken system. */
if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW)) { if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW))
log_error("Attempted to remove entire root file system (\"%s\"), and we can't allow that.", path); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Attempted to remove entire root file system (\"%s\"), and we can't allow that.",
} path);
if (FLAGS_SET(flags, REMOVE_SUBVOLUME | REMOVE_ROOT | REMOVE_PHYSICAL)) { if (FLAGS_SET(flags, REMOVE_SUBVOLUME | REMOVE_ROOT | REMOVE_PHYSICAL)) {
/* Try to remove as subvolume first */ /* Try to remove as subvolume first */
@ -194,10 +194,10 @@ int rm_rf(const char *path, RemoveFlags flags) {
if (statfs(path, &s) < 0) if (statfs(path, &s) < 0)
return -errno; return -errno;
if (is_physical_fs(&s)) { if (is_physical_fs(&s))
log_error("Attempted to remove files from a disk file system under \"%s\", refusing.", path); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Attempted to remove files from a disk file system under \"%s\", refusing.",
} path);
} }
if ((flags & REMOVE_ROOT) && !(flags & REMOVE_ONLY_DIRECTORIES)) if ((flags & REMOVE_ROOT) && !(flags & REMOVE_ONLY_DIRECTORIES))

View file

@ -39,10 +39,9 @@ static int delete_rule(const char *rule) {
e = strchrnul(x+1, x[0]); e = strchrnul(x+1, x[0]);
*e = 0; *e = 0;
if (!filename_is_valid(x + 1)) { if (!filename_is_valid(x + 1))
log_error("Rule file name '%s' is not valid, refusing.", x+1); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Rule file name '%s' is not valid, refusing.", x + 1);
}
fn = strappend("/proc/sys/fs/binfmt_misc/", x+1); fn = strappend("/proc/sys/fs/binfmt_misc/", x+1);
if (!fn) if (!fn)
@ -170,10 +169,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_cat_config && argc > optind) { if (arg_cat_config && argc > optind)
log_error("Positional arguments are not allowed with --cat-config"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Positional arguments are not allowed with --cat-config");
}
return 1; return 1;
} }

View file

@ -121,10 +121,10 @@ static int parse_counter(
e++; e++;
k = strspn(e, DIGITS); k = strspn(e, DIGITS);
if (k == 0) { if (k == 0)
log_error("Can't parse empty 'tries left' counter from LoaderBootCountPath: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
} path);
z = strndupa(e, k); z = strndupa(e, k);
r = safe_atou64(z, &left); r = safe_atou64(z, &left);
@ -137,10 +137,10 @@ static int parse_counter(
e++; e++;
k = strspn(e, DIGITS); k = strspn(e, DIGITS);
if (k == 0) { /* If there's a "-" there also needs to be at least one digit */ if (k == 0) /* If there's a "-" there also needs to be at least one digit */
log_error("Can't parse empty 'tries done' counter from LoaderBootCountPath: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
} path);
z = strndupa(e, k); z = strndupa(e, k);
r = safe_atou64(z, &done); r = safe_atou64(z, &done);
@ -185,22 +185,22 @@ static int acquire_boot_count_path(
efi_tilt_backslashes(path); efi_tilt_backslashes(path);
if (!path_is_normalized(path)) { if (!path_is_normalized(path))
log_error("Path read from LoaderBootCountPath is not normalized, refusing: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path read from LoaderBootCountPath is not normalized, refusing: %s",
} path);
if (!path_is_absolute(path)) { if (!path_is_absolute(path))
log_error("Path read from LoaderBootCountPath is not absolute, refusing: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path read from LoaderBootCountPath is not absolute, refusing: %s",
} path);
last = last_path_component(path); last = last_path_component(path);
e = strrchr(last, '+'); e = strrchr(last, '+');
if (!e) { if (!e)
log_error("Path read from LoaderBootCountPath does not contain a counter, refusing: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path read from LoaderBootCountPath does not contain a counter, refusing: %s",
} path);
if (ret_prefix) { if (ret_prefix) {
prefix = strndup(path, e - path); prefix = strndup(path, e - path);
@ -458,15 +458,13 @@ static int run(int argc, char *argv[]) {
if (r <= 0) if (r <= 0)
return r; return r;
if (detect_container() > 0) { if (detect_container() > 0)
log_error("Marking a boot is not supported in containers."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Marking a boot is not supported in containers.");
}
if (!is_efi_boot()) { if (!is_efi_boot())
log_error("Marking a boot is only supported on EFI systems."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Marking a boot is only supported on EFI systems.");
}
return dispatch_verb(argc, argv, verbs, NULL); return dispatch_verb(argc, argv, verbs, NULL);
} }

View file

@ -372,18 +372,18 @@ static int version_check(int fd_from, const char *from, int fd_to, const char *t
r = get_file_version(fd_from, &a); r = get_file_version(fd_from, &a);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0) { if (r == 0)
log_error("Source file \"%s\" does not carry version information!", from); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Source file \"%s\" does not carry version information!",
} from);
r = get_file_version(fd_to, &b); r = get_file_version(fd_to, &b);
if (r < 0) if (r < 0)
return r; return r;
if (r == 0 || compare_product(a, b) != 0) { if (r == 0 || compare_product(a, b) != 0)
log_notice("Skipping \"%s\", since it's owned by another boot loader.", to); return log_notice_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Skipping \"%s\", since it's owned by another boot loader.",
} to);
if (compare_version(a, b) < 0) { if (compare_version(a, b) < 0) {
log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to); log_warning("Skipping \"%s\", since a newer boot loader version exists already.", to);
@ -1193,10 +1193,9 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
const char *name; const char *name;
int r; int r;
if (!is_efi_boot()) { if (!is_efi_boot())
log_error("Not booted with UEFI."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Not booted with UEFI.");
}
if (access("/sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK) < 0) { if (access("/sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK) < 0) {
if (errno == ENOENT) { if (errno == ENOENT) {
@ -1207,15 +1206,15 @@ static int verb_set_default(int argc, char *argv[], void *userdata) {
return log_error_errno(errno, "Failed to detect whether boot loader supports '%s' operation: %m", argv[0]); return log_error_errno(errno, "Failed to detect whether boot loader supports '%s' operation: %m", argv[0]);
} }
if (detect_container() > 0) { if (detect_container() > 0)
log_error("'%s' operation not supported in a container.", argv[0]); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "'%s' operation not supported in a container.",
} argv[0]);
if (!arg_touch_variables) { if (!arg_touch_variables)
log_error("'%s' operation cannot be combined with --touch-variables=no.", argv[0]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "'%s' operation cannot be combined with --touch-variables=no.",
} argv[0]);
name = streq(argv[0], "set-default") ? "LoaderEntryDefault" : "LoaderEntryOneShot"; name = streq(argv[0], "set-default") ? "LoaderEntryDefault" : "LoaderEntryOneShot";

View file

@ -67,10 +67,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
return t; return t;
} }
if (t == XML_END) { if (t == XML_END)
log_error("Premature end of XML data."); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Premature end of XML data.");
}
switch (state) { switch (state) {
@ -84,10 +83,10 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
else if (streq_ptr(name, "value")) else if (streq_ptr(name, "value"))
state = STATE_VALUE; state = STATE_VALUE;
else { else
log_error("Unexpected <annotation> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <annotation> attribute %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "annotation"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "annotation"))) {
@ -116,10 +115,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
return 0; return 0;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <annotation>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <annotation>. (1)");
}
break; break;
@ -129,10 +127,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(field, name); free_and_replace(field, name);
state = STATE_ANNOTATION; state = STATE_ANNOTATION;
} else { } else
log_error("Unexpected token in <annotation>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <annotation>. (2)");
}
break; break;
@ -142,10 +139,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(value, name); free_and_replace(value, name);
state = STATE_ANNOTATION; state = STATE_ANNOTATION;
} else { } else
log_error("Unexpected token in <annotation>. (3)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <annotation>. (3)");
}
break; break;
@ -187,10 +183,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
assert(context); assert(context);
assert(prefix); assert(prefix);
if (n_depth > NODE_DEPTH_MAX) { if (n_depth > NODE_DEPTH_MAX)
log_error("<node> depth too high."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "<node> depth too high.");
return -EINVAL;
}
for (;;) { for (;;) {
_cleanup_free_ char *name = NULL; _cleanup_free_ char *name = NULL;
@ -202,10 +196,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
return t; return t;
} }
if (t == XML_END) { if (t == XML_END)
log_error("Premature end of XML data."); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Premature end of XML data.");
return -EBADMSG;
}
switch (state) { switch (state) {
@ -214,10 +206,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (streq_ptr(name, "name")) if (streq_ptr(name, "name"))
state = STATE_NODE_NAME; state = STATE_NODE_NAME;
else { else
log_error("Unexpected <node> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <node> attribute %s.", name);
}
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
@ -228,10 +219,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_node(context, np, n_depth+1); r = parse_xml_node(context, np, n_depth+1);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected <node> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <node> tag %s.", name);
}
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "node"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "node"))) {
@ -244,10 +234,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
return 0; return 0;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <node>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <node>. (1)");
}
break; break;
@ -271,10 +260,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
np = node_path; np = node_path;
state = STATE_NODE; state = STATE_NODE;
} else { } else
log_error("Unexpected token in <node>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <node>. (2)");
}
break; break;
@ -283,10 +271,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) { if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name")) if (streq_ptr(name, "name"))
state = STATE_INTERFACE_NAME; state = STATE_INTERFACE_NAME;
else { else
log_error("Unexpected <interface> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <interface> attribute %s.",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "method")) if (streq_ptr(name, "method"))
@ -300,10 +288,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->interface_flags); r = parse_xml_annotation(context, &context->interface_flags);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected <interface> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected <interface> tag %s.", name);
}
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "interface"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "interface"))) {
@ -319,10 +306,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_NODE; state = STATE_NODE;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <interface>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <interface>. (1)");
}
break; break;
@ -333,10 +319,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->interface_name, name); free_and_replace(context->interface_name, name);
state = STATE_INTERFACE; state = STATE_INTERFACE;
} else { } else
log_error("Unexpected token in <interface>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <interface>. (2)");
}
break; break;
@ -345,10 +330,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) { if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name")) if (streq_ptr(name, "name"))
state = STATE_METHOD_NAME; state = STATE_METHOD_NAME;
else { else
log_error("Unexpected <method> attribute %s", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <method> attribute %s",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "arg")) if (streq_ptr(name, "arg"))
state = STATE_METHOD_ARG; state = STATE_METHOD_ARG;
@ -356,10 +341,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->member_flags); r = parse_xml_annotation(context, &context->member_flags);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected <method> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected <method> tag %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "method"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "method"))) {
@ -375,10 +360,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE; state = STATE_INTERFACE;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <method> (1)."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <method> (1).");
}
break; break;
@ -389,10 +373,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name); free_and_replace(context->member_name, name);
state = STATE_METHOD; state = STATE_METHOD;
} else { } else
log_error("Unexpected token in <method> (2)."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <method> (2).");
}
break; break;
@ -405,19 +388,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_METHOD_ARG_TYPE; state = STATE_METHOD_ARG_TYPE;
else if (streq_ptr(name, "direction")) else if (streq_ptr(name, "direction"))
state = STATE_METHOD_ARG_DIRECTION; state = STATE_METHOD_ARG_DIRECTION;
else { else
log_error("Unexpected method <arg> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected method <arg> attribute %s.",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) { if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL); r = parse_xml_annotation(context, NULL);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected method <arg> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected method <arg> tag %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) {
@ -439,10 +422,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
} }
state = STATE_METHOD; state = STATE_METHOD;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in method <arg>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in method <arg>. (1)");
}
break; break;
@ -450,10 +432,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE) if (t == XML_ATTRIBUTE_VALUE)
state = STATE_METHOD_ARG; state = STATE_METHOD_ARG;
else { else
log_error("Unexpected token in method <arg>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in method <arg>. (2)");
}
break; break;
@ -463,10 +444,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name); free_and_replace(argument_type, name);
state = STATE_METHOD_ARG; state = STATE_METHOD_ARG;
} else { } else
log_error("Unexpected token in method <arg>. (3)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in method <arg>. (3)");
}
break; break;
@ -476,10 +456,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name); free_and_replace(argument_direction, name);
state = STATE_METHOD_ARG; state = STATE_METHOD_ARG;
} else { } else
log_error("Unexpected token in method <arg>. (4)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in method <arg>. (4)");
}
break; break;
@ -488,10 +467,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) { if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name")) if (streq_ptr(name, "name"))
state = STATE_SIGNAL_NAME; state = STATE_SIGNAL_NAME;
else { else
log_error("Unexpected <signal> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <signal> attribute %s.",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "arg")) if (streq_ptr(name, "arg"))
state = STATE_SIGNAL_ARG; state = STATE_SIGNAL_ARG;
@ -499,10 +478,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
r = parse_xml_annotation(context, &context->member_flags); r = parse_xml_annotation(context, &context->member_flags);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected <signal> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected <signal> tag %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "signal"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "signal"))) {
@ -518,10 +497,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE; state = STATE_INTERFACE;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <signal>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <signal>. (1)");
}
break; break;
@ -532,10 +510,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name); free_and_replace(context->member_name, name);
state = STATE_SIGNAL; state = STATE_SIGNAL;
} else { } else
log_error("Unexpected token in <signal>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <signal>. (2)");
}
break; break;
@ -548,19 +525,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_SIGNAL_ARG_TYPE; state = STATE_SIGNAL_ARG_TYPE;
else if (streq_ptr(name, "direction")) else if (streq_ptr(name, "direction"))
state = STATE_SIGNAL_ARG_DIRECTION; state = STATE_SIGNAL_ARG_DIRECTION;
else { else
log_error("Unexpected signal <arg> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected signal <arg> attribute %s.",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) { if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL); r = parse_xml_annotation(context, NULL);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected signal <arg> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected signal <arg> tag %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "arg"))) {
@ -575,10 +552,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
} }
state = STATE_SIGNAL; state = STATE_SIGNAL;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in signal <arg> (1)."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in signal <arg> (1).");
}
break; break;
@ -586,10 +562,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE) if (t == XML_ATTRIBUTE_VALUE)
state = STATE_SIGNAL_ARG; state = STATE_SIGNAL_ARG;
else { else
log_error("Unexpected token in signal <arg> (2)."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in signal <arg> (2).");
}
break; break;
@ -599,10 +574,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name); free_and_replace(argument_type, name);
state = STATE_SIGNAL_ARG; state = STATE_SIGNAL_ARG;
} else { } else
log_error("Unexpected token in signal <arg> (3)."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in signal <arg> (3).");
}
break; break;
@ -612,10 +586,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name); free_and_replace(argument_direction, name);
state = STATE_SIGNAL_ARG; state = STATE_SIGNAL_ARG;
} else { } else
log_error("Unexpected token in signal <arg>. (4)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in signal <arg>. (4)");
}
break; break;
@ -628,20 +601,20 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_PROPERTY_TYPE; state = STATE_PROPERTY_TYPE;
else if (streq_ptr(name, "access")) else if (streq_ptr(name, "access"))
state = STATE_PROPERTY_ACCESS; state = STATE_PROPERTY_ACCESS;
else { else
log_error("Unexpected <property> attribute %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Unexpected <property> attribute %s.",
} name);
} else if (t == XML_TAG_OPEN) { } else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) { if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, &context->member_flags); r = parse_xml_annotation(context, &context->member_flags);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("Unexpected <property> tag %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected <property> tag %s.",
} name);
} else if (t == XML_TAG_CLOSE_EMPTY || } else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "property"))) { (t == XML_TAG_CLOSE && streq_ptr(name, "property"))) {
@ -658,10 +631,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_INTERFACE; state = STATE_INTERFACE;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) { } else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
log_error("Unexpected token in <property>. (1)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <property>. (1)");
}
break; break;
@ -672,10 +644,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_name, name); free_and_replace(context->member_name, name);
state = STATE_PROPERTY; state = STATE_PROPERTY;
} else { } else
log_error("Unexpected token in <property>. (2)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <property>. (2)");
}
break; break;
@ -686,10 +657,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(context->member_signature, name); free_and_replace(context->member_signature, name);
state = STATE_PROPERTY; state = STATE_PROPERTY;
} else { } else
log_error("Unexpected token in <property>. (3)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <property>. (3)");
}
break; break;
@ -701,10 +671,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
context->member_writable = true; context->member_writable = true;
state = STATE_PROPERTY; state = STATE_PROPERTY;
} else { } else
log_error("Unexpected token in <property>. (4)"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unexpected token in <property>. (4)");
}
break; break;
} }

View file

@ -1257,10 +1257,9 @@ static int verb_monitor(int argc, char **argv, void *userdata) {
static int verb_capture(int argc, char **argv, void *userdata) { static int verb_capture(int argc, char **argv, void *userdata) {
int r; int r;
if (isatty(fileno(stdout)) > 0) { if (isatty(fileno(stdout)) > 0)
log_error("Refusing to write message data to console, please redirect output to a file."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Refusing to write message data to console, please redirect output to a file.");
}
bus_pcap_header(arg_snaplen, stdout); bus_pcap_header(arg_snaplen, stdout);
@ -1346,10 +1345,9 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
if (t == 0) if (t == 0)
break; break;
if (!v) { if (!v)
log_error("Too few parameters for signature."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too few parameters for signature.");
}
signature++; signature++;
p++; p++;
@ -1539,12 +1537,12 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
} }
case SD_BUS_TYPE_UNIX_FD: case SD_BUS_TYPE_UNIX_FD:
log_error("UNIX file descriptor not supported as type."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "UNIX file descriptor not supported as type.");
default: default:
log_error("Unknown signature type %c.", t); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown signature type %c.", t);
} }
if (r < 0) if (r < 0)
@ -2291,10 +2289,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse size '%s': %m", optarg); return log_error_errno(r, "Failed to parse size '%s': %m", optarg);
if ((uint64_t) (size_t) sz != sz) { if ((uint64_t) (size_t) sz != sz)
log_error("Size out of range."); return log_error_errno(SYNTHETIC_ERRNO(E2BIG),
return -E2BIG; "Size out of range.");
}
arg_snaplen = (size_t) sz; arg_snaplen = (size_t) sz;
break; break;
@ -2385,10 +2382,10 @@ static int parse_argv(int argc, char *argv[]) {
fputs("short\n" fputs("short\n"
"pretty\n", stdout); "pretty\n", stdout);
return 0; return 0;
} else { } else
log_error("Unknown JSON out mode: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown JSON out mode: %s",
} optarg);
break; break;

View file

@ -146,10 +146,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_machine && arg_show_unit != SHOW_UNIT_NONE) { if (arg_machine && arg_show_unit != SHOW_UNIT_NONE)
log_error("Cannot combine --unit or --user-unit with --machine=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot combine --unit or --user-unit with --machine=.");
}
return 1; return 1;
} }

View file

@ -779,10 +779,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_cpu_type = CPU_TIME; arg_cpu_type = CPU_TIME;
else if (streq(optarg, "percentage")) else if (streq(optarg, "percentage"))
arg_cpu_type = CPU_PERCENT; arg_cpu_type = CPU_PERCENT;
else { else
log_error("Unknown argument to --cpu=: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown argument to --cpu=: %s",
} optarg);
} else } else
arg_cpu_type = CPU_TIME; arg_cpu_type = CPU_TIME;
@ -799,10 +799,10 @@ static int parse_argv(int argc, char *argv[]) {
r = parse_sec(optarg, &arg_delay); r = parse_sec(optarg, &arg_delay);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse delay parameter '%s': %m", optarg); return log_error_errno(r, "Failed to parse delay parameter '%s': %m", optarg);
if (arg_delay <= 0) { if (arg_delay <= 0)
log_error("Invalid delay parameter '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid delay parameter '%s'",
} optarg);
break; break;
@ -856,10 +856,10 @@ static int parse_argv(int argc, char *argv[]) {
arg_order = ORDER_MEMORY; arg_order = ORDER_MEMORY;
else if (streq(optarg, "io")) else if (streq(optarg, "io"))
arg_order = ORDER_IO; arg_order = ORDER_IO;
else { else
log_error("Invalid argument to --order=: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid argument to --order=: %s",
} optarg);
break; break;
case 'k': case 'k':
@ -892,10 +892,9 @@ static int parse_argv(int argc, char *argv[]) {
if (optind == argc - 1) if (optind == argc - 1)
arg_root = argv[optind]; arg_root = argv[optind];
else if (optind < argc) { else if (optind < argc)
log_error("Too many arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many arguments.");
}
return 1; return 1;
} }

View file

@ -994,10 +994,9 @@ int bus_init_private(Manager *m) {
const char *e, *joined; const char *e, *joined;
e = secure_getenv("XDG_RUNTIME_DIR"); e = secure_getenv("XDG_RUNTIME_DIR");
if (!e) { if (!e)
log_error("XDG_RUNTIME_DIR is not set, refusing."); return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
return -EHOSTDOWN; "XDG_RUNTIME_DIR is not set, refusing.");
}
joined = strjoina(e, "/systemd/private"); joined = strjoina(e, "/systemd/private");
salen = sockaddr_un_set_path(&sa.un, joined); salen = sockaddr_un_set_path(&sa.un, joined);

View file

@ -244,10 +244,10 @@ int job_install_deserialized(Job *j) {
assert(!j->installed); assert(!j->installed);
if (j->type < 0 || j->type >= _JOB_TYPE_MAX_IN_TRANSACTION) { if (j->type < 0 || j->type >= _JOB_TYPE_MAX_IN_TRANSACTION)
log_debug("Invalid job type %s in deserialization.", strna(job_type_to_string(j->type))); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid job type %s in deserialization.",
} strna(job_type_to_string(j->type)));
pj = (j->type == JOB_NOP) ? &j->unit->nop_job : &j->unit->job; pj = (j->type == JOB_NOP) ? &j->unit->nop_job : &j->unit->job;
if (*pj) { if (*pj) {

View file

@ -200,10 +200,10 @@ int machine_id_commit(const char *root) {
r = fd_is_temporary_fs(fd); r = fd_is_temporary_fs(fd);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to determine whether %s is on a temporary file system: %m", etc_machine_id); return log_error_errno(r, "Failed to determine whether %s is on a temporary file system: %m", etc_machine_id);
if (r == 0) { if (r == 0)
log_error("%s is not on a temporary file system.", etc_machine_id); return log_error_errno(SYNTHETIC_ERRNO(EROFS),
return -EROFS; "%s is not on a temporary file system.",
} etc_machine_id);
r = id128_read_fd(fd, ID128_PLAIN, &id); r = id128_read_fd(fd, ID128_PLAIN, &id);
if (r < 0) if (r < 0)

View file

@ -1031,10 +1031,10 @@ static int parse_argv(int argc, char *argv[]) {
r = safe_atoi(optarg, &fd); r = safe_atoi(optarg, &fd);
if (r < 0) if (r < 0)
log_error_errno(r, "Failed to parse deserialize option \"%s\": %m", optarg); log_error_errno(r, "Failed to parse deserialize option \"%s\": %m", optarg);
if (fd < 0) { if (fd < 0)
log_error("Invalid deserialize fd: %d", fd); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid deserialize fd: %d",
} fd);
(void) fd_cloexec(fd, true); (void) fd_cloexec(fd, true);
@ -1088,8 +1088,8 @@ static int parse_argv(int argc, char *argv[]) {
/* Hmm, when we aren't run as init system /* Hmm, when we aren't run as init system
* let's complain about excess arguments */ * let's complain about excess arguments */
log_error("Excess arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Excess arguments.");
} }
return 0; return 0;
@ -2149,50 +2149,43 @@ static int load_configuration(int argc, char **argv, const char **ret_error_mess
static int safety_checks(void) { static int safety_checks(void) {
if (getpid_cached() == 1 && if (getpid_cached() == 1 &&
arg_action != ACTION_RUN) { arg_action != ACTION_RUN)
log_error("Unsupported execution mode while PID 1."); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Unsupported execution mode while PID 1.");
}
if (getpid_cached() == 1 && if (getpid_cached() == 1 &&
!arg_system) { !arg_system)
log_error("Can't run --user mode as PID 1."); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Can't run --user mode as PID 1.");
}
if (arg_action == ACTION_RUN && if (arg_action == ACTION_RUN &&
arg_system && arg_system &&
getpid_cached() != 1) { getpid_cached() != 1)
log_error("Can't run system mode unless PID 1."); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Can't run system mode unless PID 1.");
}
if (arg_action == ACTION_TEST && if (arg_action == ACTION_TEST &&
geteuid() == 0) { geteuid() == 0)
log_error("Don't run test mode as root."); return log_error_errno(SYNTHETIC_ERRNO(EPERM),
return -EPERM; "Don't run test mode as root.");
}
if (!arg_system && if (!arg_system &&
arg_action == ACTION_RUN && arg_action == ACTION_RUN &&
sd_booted() <= 0) { sd_booted() <= 0)
log_error("Trying to run as user instance, but the system has not been booted with systemd."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Trying to run as user instance, but the system has not been booted with systemd.");
}
if (!arg_system && if (!arg_system &&
arg_action == ACTION_RUN && arg_action == ACTION_RUN &&
!getenv("XDG_RUNTIME_DIR")) { !getenv("XDG_RUNTIME_DIR"))
log_error("Trying to run as user instance, but $XDG_RUNTIME_DIR is not set."); return log_error_errno(SYNTHETIC_ERRNO(EUNATCH),
return -EUNATCH; "Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.");
}
if (arg_system && if (arg_system &&
arg_action == ACTION_RUN && arg_action == ACTION_RUN &&
running_in_chroot() > 0) { running_in_chroot() > 0)
log_error("Cannot be run in a chroot() environment."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Cannot be run in a chroot() environment.");
}
return 0; return 0;
} }

View file

@ -235,10 +235,9 @@ static int append_access_mounts(MountEntry **p, char **strv, MountMode mode, boo
needs_prefix = true; needs_prefix = true;
} }
if (!path_is_absolute(e)) { if (!path_is_absolute(e))
log_debug("Path is not absolute: %s", e); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path is not absolute: %s", e);
}
*((*p)++) = (MountEntry) { *((*p)++) = (MountEntry) {
.path_const = e, .path_const = e,
@ -306,10 +305,10 @@ static int append_tmpfs_mounts(MountEntry **p, const TemporaryFileSystem *tmpfs,
unsigned long flags; unsigned long flags;
bool ro = false; bool ro = false;
if (!path_is_absolute(t->path)) { if (!path_is_absolute(t->path))
log_debug("Path is not absolute: %s", t->path); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path is not absolute: %s",
} t->path);
str = strjoin("mode=0755,", t->options); str = strjoin("mode=0755,", t->options);
if (!str) if (!str)
@ -575,10 +574,10 @@ static int clone_device_node(
} }
if (!S_ISBLK(st.st_mode) && if (!S_ISBLK(st.st_mode) &&
!S_ISCHR(st.st_mode)) { !S_ISCHR(st.st_mode))
log_debug("Device node '%s' to clone is not a device node, ignoring.", d); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Device node '%s' to clone is not a device node, ignoring.",
} d);
dn = strjoina(temporary_mount, d); dn = strjoina(temporary_mount, d);
@ -855,10 +854,10 @@ static int follow_symlink(
if (r > 0) /* Reached the end, nothing more to resolve */ if (r > 0) /* Reached the end, nothing more to resolve */
return 1; return 1;
if (m->n_followed >= CHASE_SYMLINKS_MAX) { /* put a boundary on things */ if (m->n_followed >= CHASE_SYMLINKS_MAX) /* put a boundary on things */
log_debug("Symlink loop on '%s'.", mount_entry_path(m)); return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
return -ELOOP; "Symlink loop on '%s'.",
} mount_entry_path(m));
log_debug("Followed mount entry path symlink %s → %s.", mount_entry_path(m), target); log_debug("Followed mount entry path symlink %s → %s.", mount_entry_path(m), target);
@ -900,10 +899,9 @@ static int apply_mount(
} }
what = mode_to_inaccessible_node(target.st_mode); what = mode_to_inaccessible_node(target.st_mode);
if (!what) { if (!what)
log_debug("File type not supported for inaccessible mounts. Note that symlinks are not allowed"); return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
return -ELOOP; "File type not supported for inaccessible mounts. Note that symlinks are not allowed");
}
break; break;
} }

View file

@ -146,10 +146,9 @@ int path_spec_fd_event(PathSpec *s, uint32_t revents) {
ssize_t l; ssize_t l;
int r = 0; int r = 0;
if (revents != EPOLLIN) { if (revents != EPOLLIN)
log_error("Got invalid poll event on inotify."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Got invalid poll event on inotify.");
}
l = read(s->inotify_fd, &buffer, sizeof(buffer)); l = read(s->inotify_fd, &buffer, sizeof(buffer));
if (l < 0) { if (l < 0) {

View file

@ -137,10 +137,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option code."); assert_not_reached("Unhandled option code.");
} }
if (!arg_verb) { if (!arg_verb)
log_error("Verb argument missing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Verb argument missing.");
}
return 0; return 0;
} }

View file

@ -372,10 +372,10 @@ static int swap_setup_unit(
if (u && if (u &&
SWAP(u)->from_proc_swaps && SWAP(u)->from_proc_swaps &&
!path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps)) { !path_equal(SWAP(u)->parameters_proc_swaps.what, what_proc_swaps))
log_error("Swap %s appeared twice with different device paths %s and %s", e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "Swap %s appeared twice with different device paths %s and %s",
} e, SWAP(u)->parameters_proc_swaps.what, what_proc_swaps);
if (!u) { if (!u) {
delete = true; delete = true;

View file

@ -351,16 +351,15 @@ static int save_external_coredump(
/* Is coredumping disabled? Then don't bother saving/processing the coredump. /* Is coredumping disabled? Then don't bother saving/processing the coredump.
* Anything below PAGE_SIZE cannot give a readable coredump (the kernel uses * Anything below PAGE_SIZE cannot give a readable coredump (the kernel uses
* ELF_EXEC_PAGESIZE which is not easily accessible, but is usually the same as PAGE_SIZE. */ * ELF_EXEC_PAGESIZE which is not easily accessible, but is usually the same as PAGE_SIZE. */
log_info("Resource limits disable core dumping for process %s (%s).", return log_info_errno(SYNTHETIC_ERRNO(EBADSLT),
context[CONTEXT_PID], context[CONTEXT_COMM]); "Resource limits disable core dumping for process %s (%s).",
return -EBADSLT; context[CONTEXT_PID], context[CONTEXT_COMM]);
} }
process_limit = MAX(arg_process_size_max, storage_size_max()); process_limit = MAX(arg_process_size_max, storage_size_max());
if (process_limit == 0) { if (process_limit == 0)
log_debug("Limits for coredump processing and storage are both 0, not dumping core."); return log_debug_errno(SYNTHETIC_ERRNO(EBADSLT),
return -EBADSLT; "Limits for coredump processing and storage are both 0, not dumping core.");
}
/* Never store more than the process configured, or than we actually shall keep or process */ /* Never store more than the process configured, or than we actually shall keep or process */
max_size = MIN(rlimit, process_limit); max_size = MIN(rlimit, process_limit);
@ -484,10 +483,9 @@ static int allocate_journal_field(int fd, size_t size, char **ret, size_t *ret_s
n = read(fd, field + 9, size); n = read(fd, field + 9, size);
if (n < 0) if (n < 0)
return log_error_errno((int) n, "Failed to read core data: %m"); return log_error_errno((int) n, "Failed to read core data: %m");
if ((size_t) n < size) { if ((size_t) n < size)
log_error("Core data too short."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Core data too short.");
}
*ret = TAKE_PTR(field); *ret = TAKE_PTR(field);
*ret_size = size + 9; *ret_size = size + 9;
@ -1236,10 +1234,10 @@ static int process_kernel(int argc, char* argv[]) {
log_debug("Processing coredump received from the kernel..."); log_debug("Processing coredump received from the kernel...");
if (argc < CONTEXT_COMM + 1) { if (argc < CONTEXT_COMM + 1)
log_error("Not enough arguments passed by the kernel (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not enough arguments passed by the kernel (%i, expected %i).",
} argc - 1, CONTEXT_COMM + 1 - 1);
context[CONTEXT_PID] = argv[1 + CONTEXT_PID]; context[CONTEXT_PID] = argv[1 + CONTEXT_PID];
context[CONTEXT_UID] = argv[1 + CONTEXT_UID]; context[CONTEXT_UID] = argv[1 + CONTEXT_UID];
@ -1293,10 +1291,10 @@ static int process_backtrace(int argc, char *argv[]) {
log_debug("Processing backtrace on stdin..."); log_debug("Processing backtrace on stdin...");
if (argc < CONTEXT_COMM + 1) { if (argc < CONTEXT_COMM + 1)
log_error("Not enough arguments passed (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not enough arguments passed (%i, expected %i).",
} argc - 1, CONTEXT_COMM + 1 - 1);
context[CONTEXT_PID] = argv[2 + CONTEXT_PID]; context[CONTEXT_PID] = argv[2 + CONTEXT_PID];
context[CONTEXT_UID] = argv[2 + CONTEXT_UID]; context[CONTEXT_UID] = argv[2 + CONTEXT_UID];
@ -1407,8 +1405,8 @@ static int run(int argc, char *argv[]) {
} else if (r == 1) } else if (r == 1)
return process_socket(SD_LISTEN_FDS_START); return process_socket(SD_LISTEN_FDS_START);
log_error("Received unexpected number of file descriptors."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Received unexpected number of file descriptors.");
} }
DEFINE_MAIN_FUNCTION(run); DEFINE_MAIN_FUNCTION(run);

View file

@ -225,10 +225,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'o': case 'o':
if (arg_output) { if (arg_output)
log_error("Cannot set output more than once."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot set output more than once.");
}
arg_output = optarg; arg_output = optarg;
break; break;
@ -246,10 +245,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'F': case 'F':
if (arg_field) { if (arg_field)
log_error("Cannot use --field/-F more than once."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot use --field/-F more than once.");
}
arg_field = optarg; arg_field = optarg;
break; break;
@ -277,10 +275,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
if (arg_since != USEC_INFINITY && arg_until != USEC_INFINITY && if (arg_since != USEC_INFINITY && arg_until != USEC_INFINITY &&
arg_since > arg_until) { arg_since > arg_until)
log_error("--since= must be before --until=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--since= must be before --until=.");
}
return 1; return 1;
} }
@ -628,10 +625,9 @@ static int focus(sd_journal *j) {
r = sd_journal_previous(j); r = sd_journal_previous(j);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to search journal: %m"); return log_error_errno(r, "Failed to search journal: %m");
if (r == 0) { if (r == 0)
log_error("No match found."); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "No match found.");
}
return r; return r;
} }

View file

@ -123,10 +123,10 @@ static int create_disk(
swap = fstab_test_option(options, "swap\0"); swap = fstab_test_option(options, "swap\0");
netdev = fstab_test_option(options, "_netdev\0"); netdev = fstab_test_option(options, "_netdev\0");
if (tmp && swap) { if (tmp && swap)
log_error("Device '%s' cannot be both 'tmp' and 'swap'. Ignoring.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Device '%s' cannot be both 'tmp' and 'swap'. Ignoring.",
} name);
name_escaped = specifier_escape(name); name_escaped = specifier_escape(name);
if (!name_escaped) if (!name_escaped)
@ -158,10 +158,9 @@ static int create_disk(
return log_oom(); return log_oom();
} }
if (keydev && !password) { if (keydev && !password)
log_error("Key device is specified, but path to the password file is missing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Key device is specified, but path to the password file is missing.");
}
r = generator_open_unit_file(arg_dest, NULL, n, &f); r = generator_open_unit_file(arg_dest, NULL, n, &f);
if (r < 0) if (r < 0)

View file

@ -173,15 +173,13 @@ static int parse_one_option(const char *option) {
} else if ((val = startswith(option, "header="))) { } else if ((val = startswith(option, "header="))) {
arg_type = ANY_LUKS; arg_type = ANY_LUKS;
if (!path_is_absolute(val)) { if (!path_is_absolute(val))
log_error("Header path \"%s\" is not absolute, refusing.", val); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Header path \"%s\" is not absolute, refusing.", val);
}
if (arg_header) { if (arg_header)
log_error("Duplicate header= option, refusing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Duplicate header= option, refusing.");
}
arg_header = strdup(val); arg_header = strdup(val);
if (!arg_header) if (!arg_header)
@ -216,8 +214,8 @@ static int parse_one_option(const char *option) {
arg_type = CRYPT_TCRYPT; arg_type = CRYPT_TCRYPT;
arg_tcrypt_veracrypt = true; arg_tcrypt_veracrypt = true;
#else #else
log_error("This version of cryptsetup does not support tcrypt-veracrypt; refusing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This version of cryptsetup does not support tcrypt-veracrypt; refusing.");
#endif #endif
} else if (STR_IN_SET(option, "plain", "swap", "tmp")) } else if (STR_IN_SET(option, "plain", "swap", "tmp"))
arg_type = CRYPT_PLAIN; arg_type = CRYPT_PLAIN;
@ -463,10 +461,10 @@ static int attach_tcrypt(
r = crypt_load(cd, CRYPT_TCRYPT, &params); r = crypt_load(cd, CRYPT_TCRYPT, &params);
if (r < 0) { if (r < 0) {
if (key_file && r == -EPERM) { if (key_file && r == -EPERM)
log_error("Failed to activate using password file '%s'.", key_file); return log_error_errno(SYNTHETIC_ERRNO(EAGAIN),
return -EAGAIN; "Failed to activate using password file '%s'.",
} key_file);
return r; return r;
} }

View file

@ -145,10 +145,9 @@ static int generate_wants_symlinks(void) {
static int run(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
int r, q; int r, q;
if (argc > 1 && argc != 4) { if (argc > 1 && argc != 4)
log_error("This program takes three or no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes three or no arguments.");
}
if (argc > 1) if (argc > 1)
arg_dest = argv[2]; arg_dest = argv[2];

View file

@ -513,8 +513,8 @@ static int process_suffix_chop(const char *arg) {
} }
} }
log_error("Invalid suffix specification %s.", arg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid suffix specification %s.", arg);
} }
static int help(void) { static int help(void) {
@ -604,10 +604,9 @@ static int parse_argv(int argc, char *argv[]) {
case 't': { case 't': {
int f; int f;
f = parse_flags(optarg, arg_flags); f = parse_flags(optarg, arg_flags);
if (f < 0) { if (f < 0)
log_error("Failed to parse flags field."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse flags field.");
}
arg_flags = f; arg_flags = f;
break; break;
} }
@ -619,10 +618,9 @@ static int parse_argv(int argc, char *argv[]) {
int b; int b;
b = parse_boolean(optarg); b = parse_boolean(optarg);
if (b < 0) { if (b < 0)
log_error("Failed to parse diff boolean."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse diff boolean.");
}
arg_diff = b; arg_diff = b;
} }

View file

@ -113,10 +113,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind < argc) { if (optind < argc)
log_error("%s takes no arguments.", program_invocation_short_name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s takes no arguments.",
} program_invocation_short_name);
return 1; return 1;
} }

View file

@ -94,10 +94,10 @@ static int parse_argv(int argc, char *argv[]) {
flags = DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD; flags = DISSECT_IMAGE_DISCARD_ON_LOOP | DISSECT_IMAGE_DISCARD;
else if (streq(optarg, "crypt")) else if (streq(optarg, "crypt"))
flags = DISSECT_IMAGE_DISCARD_ANY; flags = DISSECT_IMAGE_DISCARD_ANY;
else { else
log_error("Unknown --discard= parameter: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown --discard= parameter: %s",
} optarg);
arg_flags = (arg_flags & ~DISSECT_IMAGE_DISCARD_ANY) | flags; arg_flags = (arg_flags & ~DISSECT_IMAGE_DISCARD_ANY) | flags;
break; break;
@ -134,20 +134,18 @@ static int parse_argv(int argc, char *argv[]) {
switch (arg_action) { switch (arg_action) {
case ACTION_DISSECT: case ACTION_DISSECT:
if (optind + 1 != argc) { if (optind + 1 != argc)
log_error("Expected a file path as only argument."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Expected a file path as only argument.");
}
arg_image = argv[optind]; arg_image = argv[optind];
arg_flags |= DISSECT_IMAGE_READ_ONLY; arg_flags |= DISSECT_IMAGE_READ_ONLY;
break; break;
case ACTION_MOUNT: case ACTION_MOUNT:
if (optind + 2 != argc) { if (optind + 2 != argc)
log_error("Expected a file path and mount point path as only arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Expected a file path and mount point path as only arguments.");
}
arg_image = argv[optind]; arg_image = argv[optind];
arg_path = argv[optind + 1]; arg_path = argv[optind + 1];

View file

@ -85,20 +85,18 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_SUFFIX: case ARG_SUFFIX:
if (unit_type_from_string(optarg) < 0) { if (unit_type_from_string(optarg) < 0)
log_error("Invalid unit suffix type %s.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid unit suffix type %s.", optarg);
}
arg_suffix = optarg; arg_suffix = optarg;
break; break;
case ARG_TEMPLATE: case ARG_TEMPLATE:
if (!unit_name_is_valid(optarg, UNIT_NAME_TEMPLATE)) { if (!unit_name_is_valid(optarg, UNIT_NAME_TEMPLATE))
log_error("Template name %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Template name %s is not valid.", optarg);
}
arg_template = optarg; arg_template = optarg;
break; break;
@ -126,40 +124,33 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind >= argc) { if (optind >= argc)
log_error("Not enough arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not enough arguments.");
}
if (arg_template && arg_suffix) { if (arg_template && arg_suffix)
log_error("--suffix= and --template= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--suffix= and --template= may not be combined.");
}
if ((arg_template || arg_suffix) && arg_action == ACTION_MANGLE) { if ((arg_template || arg_suffix) && arg_action == ACTION_MANGLE)
log_error("--suffix= and --template= are not compatible with --mangle."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--suffix= and --template= are not compatible with --mangle.");
}
if (arg_suffix && arg_action == ACTION_UNESCAPE) { if (arg_suffix && arg_action == ACTION_UNESCAPE)
log_error("--suffix is not compatible with --unescape."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--suffix is not compatible with --unescape.");
}
if (arg_path && !IN_SET(arg_action, ACTION_ESCAPE, ACTION_UNESCAPE)) { if (arg_path && !IN_SET(arg_action, ACTION_ESCAPE, ACTION_UNESCAPE))
log_error("--path may not be combined with --mangle."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--path may not be combined with --mangle.");
}
if (arg_instance && arg_action != ACTION_UNESCAPE) { if (arg_instance && arg_action != ACTION_UNESCAPE)
log_error("--instance must be used in conjunction with --unescape."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--instance must be used in conjunction with --unescape.");
}
if (arg_instance && arg_template) { if (arg_instance && arg_template)
log_error("--instance may not be combined with --template."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--instance may not be combined with --template.");
}
return 1; return 1;
} }

View file

@ -806,10 +806,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_LOCALE: case ARG_LOCALE:
if (!locale_is_valid(optarg)) { if (!locale_is_valid(optarg))
log_error("Locale %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Locale %s is not valid.", optarg);
}
r = free_and_strdup(&arg_locale, optarg); r = free_and_strdup(&arg_locale, optarg);
if (r < 0) if (r < 0)
@ -818,10 +817,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_LOCALE_MESSAGES: case ARG_LOCALE_MESSAGES:
if (!locale_is_valid(optarg)) { if (!locale_is_valid(optarg))
log_error("Locale %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Locale %s is not valid.", optarg);
}
r = free_and_strdup(&arg_locale_messages, optarg); r = free_and_strdup(&arg_locale_messages, optarg);
if (r < 0) if (r < 0)
@ -830,10 +828,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_KEYMAP: case ARG_KEYMAP:
if (!keymap_is_valid(optarg)) { if (!keymap_is_valid(optarg))
log_error("Keymap %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Keymap %s is not valid.", optarg);
}
r = free_and_strdup(&arg_keymap, optarg); r = free_and_strdup(&arg_keymap, optarg);
if (r < 0) if (r < 0)
@ -842,10 +839,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_TIMEZONE: case ARG_TIMEZONE:
if (!timezone_is_valid(optarg, LOG_ERR)) { if (!timezone_is_valid(optarg, LOG_ERR))
log_error("Timezone %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Timezone %s is not valid.", optarg);
}
r = free_and_strdup(&arg_timezone, optarg); r = free_and_strdup(&arg_timezone, optarg);
if (r < 0) if (r < 0)
@ -869,10 +865,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_HOSTNAME: case ARG_HOSTNAME:
if (!hostname_is_valid(optarg, true)) { if (!hostname_is_valid(optarg, true))
log_error("Host name %s is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Host name %s is not valid.", optarg);
}
hostname_cleanup(optarg); hostname_cleanup(optarg);
r = free_and_strdup(&arg_hostname, optarg); r = free_and_strdup(&arg_hostname, optarg);
@ -882,10 +877,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_MACHINE_ID: case ARG_MACHINE_ID:
if (sd_id128_from_string(optarg, &arg_machine_id) < 0) { if (sd_id128_from_string(optarg, &arg_machine_id) < 0)
log_error("Failed to parse machine id %s.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse machine id %s.", optarg);
}
break; break;

View file

@ -870,10 +870,9 @@ static int determine_root(void) {
static int run(int argc, char *argv[]) { static int run(int argc, char *argv[]) {
int r; int r;
if (argc > 1 && argc != 4) { if (argc > 1 && argc != 4)
log_error("This program takes three or no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes three or no arguments.");
}
if (argc > 1) if (argc > 1)
arg_dest = argv[1]; arg_dest = argv[1];

View file

@ -74,10 +74,9 @@ static int run(int argc, char *argv[]) {
log_setup_generator(); log_setup_generator();
if (argc > 1 && argc != 4) { if (argc > 1 && argc != 4)
log_error("This program takes three or no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes three or no arguments.");
}
if (argc > 1) if (argc > 1)
arg_dest = argv[1]; arg_dest = argv[1];

View file

@ -41,10 +41,9 @@ static int curl_glue_on_io(sd_event_source *s, int fd, uint32_t revents, void *u
else else
action = 0; action = 0;
if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK) { if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK)
log_debug("Failed to propagate IO event."); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to propagate IO event.");
}
curl_glue_check_finished(g); curl_glue_check_finished(g);
return 0; return 0;
@ -151,10 +150,9 @@ static int curl_glue_on_timer(sd_event_source *s, uint64_t usec, void *userdata)
assert(s); assert(s);
assert(g); assert(g);
if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK) { if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK)
log_debug("Failed to propagate timeout."); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to propagate timeout.");
}
curl_glue_check_finished(g); curl_glue_check_finished(g);
return 0; return 0;

View file

@ -253,10 +253,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_compress = IMPORT_COMPRESS_GZIP; arg_compress = IMPORT_COMPRESS_GZIP;
else if (streq(optarg, "bzip2")) else if (streq(optarg, "bzip2"))
arg_compress = IMPORT_COMPRESS_BZIP2; arg_compress = IMPORT_COMPRESS_BZIP2;
else { else
log_error("Unknown format: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown format: %s", optarg);
}
break; break;
case '?': case '?':

View file

@ -338,10 +338,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
if (!filename_is_valid(fn)) { if (!filename_is_valid(fn))
log_error("Cannot verify checksum, could not determine server-side file name."); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Cannot verify checksum, could not determine server-side file name.");
}
line = strjoina(job->checksum, " *", fn, "\n"); line = strjoina(job->checksum, " *", fn, "\n");
@ -359,10 +358,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
strlen(line)); strlen(line));
} }
if (!p || (p != (char*) checksum_job->payload && p[-1] != '\n')) { if (!p || (p != (char*) checksum_job->payload && p[-1] != '\n'))
log_error("DOWNLOAD INVALID: Checksum of %s file did not checkout, file has been tampered with.", fn); return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "DOWNLOAD INVALID: Checksum of %s file did not checkout, file has been tampered with.", fn);
}
log_info("SHA256 checksum of %s is valid.", job->url); log_info("SHA256 checksum of %s is valid.", job->url);
return 1; return 1;

View file

@ -214,15 +214,13 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
if (sz <= 0) if (sz <= 0)
return 0; return 0;
if (j->written_uncompressed + sz < j->written_uncompressed) { if (j->written_uncompressed + sz < j->written_uncompressed)
log_error("File too large, overflow"); return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW),
return -EOVERFLOW; "File too large, overflow");
}
if (j->written_uncompressed + sz > j->uncompressed_max) { if (j->written_uncompressed + sz > j->uncompressed_max)
log_error("File overly large, refusing"); return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
return -EFBIG; "File overly large, refusing");
}
if (j->disk_fd >= 0) { if (j->disk_fd >= 0) {
@ -240,10 +238,8 @@ static int pull_job_write_uncompressed(const void *p, size_t sz, void *userdata)
} }
if (n < 0) if (n < 0)
return log_error_errno((int) n, "Failed to write file: %m"); return log_error_errno((int) n, "Failed to write file: %m");
if ((size_t) n < sz) { if ((size_t) n < sz)
log_error("Short write"); return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write");
return -EIO;
}
} else { } else {
if (!GREEDY_REALLOC(j->payload, j->payload_allocated, j->payload_size + sz)) if (!GREEDY_REALLOC(j->payload, j->payload_allocated, j->payload_size + sz))
@ -268,21 +264,16 @@ static int pull_job_write_compressed(PullJob *j, void *p, size_t sz) {
if (sz <= 0) if (sz <= 0)
return 0; return 0;
if (j->written_compressed + sz < j->written_compressed) { if (j->written_compressed + sz < j->written_compressed)
log_error("File too large, overflow"); return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW), "File too large, overflow");
return -EOVERFLOW;
}
if (j->written_compressed + sz > j->compressed_max) { if (j->written_compressed + sz > j->compressed_max)
log_error("File overly large, refusing."); return log_error_errno(SYNTHETIC_ERRNO(EFBIG), "File overly large, refusing.");
return -EFBIG;
}
if (j->content_length != (uint64_t) -1 && if (j->content_length != (uint64_t) -1 &&
j->written_compressed + sz > j->content_length) { j->written_compressed + sz > j->content_length)
log_error("Content length incorrect."); return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
return -EFBIG; "Content length incorrect.");
}
if (j->checksum_context) if (j->checksum_context)
gcry_md_write(j->checksum_context, p, sz); gcry_md_write(j->checksum_context, p, sz);
@ -323,10 +314,9 @@ static int pull_job_open_disk(PullJob *j) {
if (j->calc_checksum) { if (j->calc_checksum) {
initialize_libgcrypt(false); initialize_libgcrypt(false);
if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0) { if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0)
log_error("Failed to initialize hash context."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Failed to initialize hash context.");
}
} }
return 0; return 0;

View file

@ -271,10 +271,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_VERIFY: case ARG_VERIFY:
arg_verify = import_verify_from_string(optarg); arg_verify = import_verify_from_string(optarg);
if (arg_verify < 0) { if (arg_verify < 0)
log_error("Invalid verification setting '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid verification setting '%s'", optarg);
}
break; break;

View file

@ -322,10 +322,9 @@ static int process_event(Server *s, struct epoll_event *ev) {
assert(s); assert(s);
if (!(ev->events & EPOLLIN)) { if (!(ev->events & EPOLLIN))
log_info("Got invalid event from epoll. (3)"); return log_info_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Got invalid event from epoll. (3)");
}
f = (Fifo*) ev->data.ptr; f = (Fifo*) ev->data.ptr;
r = fifo_process(f); r = fifo_process(f);

View file

@ -921,10 +921,9 @@ static int parse_argv(int argc, char *argv[]) {
return version(); return version();
case ARG_KEY: case ARG_KEY:
if (arg_key_pem) { if (arg_key_pem)
log_error("Key file specified twice"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Key file specified twice");
}
r = read_full_file(optarg, &arg_key_pem, NULL); r = read_full_file(optarg, &arg_key_pem, NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read key file: %m"); return log_error_errno(r, "Failed to read key file: %m");
@ -932,10 +931,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_CERT: case ARG_CERT:
if (arg_cert_pem) { if (arg_cert_pem)
log_error("Certificate file specified twice"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Certificate file specified twice");
}
r = read_full_file(optarg, &arg_cert_pem, NULL); r = read_full_file(optarg, &arg_cert_pem, NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read certificate file: %m"); return log_error_errno(r, "Failed to read certificate file: %m");
@ -944,18 +942,17 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_TRUST: case ARG_TRUST:
#if HAVE_GNUTLS #if HAVE_GNUTLS
if (arg_trust_pem) { if (arg_trust_pem)
log_error("CA certificate file specified twice"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "CA certificate file specified twice");
}
r = read_full_file(optarg, &arg_trust_pem, NULL); r = read_full_file(optarg, &arg_trust_pem, NULL);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read CA certificate file: %m"); return log_error_errno(r, "Failed to read CA certificate file: %m");
assert(arg_trust_pem); assert(arg_trust_pem);
break; break;
#else #else
log_error("Option --trust is not available."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --trust is not available.");
#endif #endif
case 'D': case 'D':
arg_directory = optarg; arg_directory = optarg;
@ -968,20 +965,17 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind < argc) { if (optind < argc)
log_error("This program does not take arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program does not take arguments.");
}
if (!!arg_key_pem != !!arg_cert_pem) { if (!!arg_key_pem != !!arg_cert_pem)
log_error("Certificate and key files must be specified together"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Certificate and key files must be specified together");
}
if (arg_trust_pem && !arg_key_pem) { if (arg_trust_pem && !arg_key_pem)
log_error("CA certificate can only be used with certificate file"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "CA certificate can only be used with certificate file");
}
return 1; return 1;
} }

View file

@ -494,11 +494,10 @@ static int dispatch_http_event(sd_event_source *event,
assert(d); assert(d);
r = MHD_run(d->daemon); r = MHD_run(d->daemon);
if (r == MHD_NO) { if (r == MHD_NO)
log_error("MHD_run failed!"); // FIXME: unregister daemon
// XXX: unregister daemon return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "MHD_run failed!");
}
if (MHD_get_timeout(d->daemon, &timeout) == MHD_NO) if (MHD_get_timeout(d->daemon, &timeout) == MHD_NO)
timeout = ULONG_LONG_MAX; timeout = ULONG_LONG_MAX;
@ -570,10 +569,9 @@ static int create_remoteserver(
else else
log_debug("Received %d descriptors", n); log_debug("Received %d descriptors", n);
if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n) { if (MAX(http_socket, https_socket) >= SD_LISTEN_FDS_START + n)
log_error("Received fewer sockets than expected"); return log_error_errno(SYNTHETIC_ERRNO(EBADFD),
return -EBADFD; "Received fewer sockets than expected");
}
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
if (sd_is_socket(fd, AF_UNSPEC, 0, true)) { if (sd_is_socket(fd, AF_UNSPEC, 0, true)) {
@ -595,15 +593,12 @@ static int create_remoteserver(
log_debug("Received a connection socket (fd:%d) from %s", fd, hostname); log_debug("Received a connection socket (fd:%d) from %s", fd, hostname);
r = journal_remote_add_source(s, fd, hostname, true); r = journal_remote_add_source(s, fd, hostname, true);
} else { } else
log_error("Unknown socket passed on fd:%d", fd); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown socket passed on fd:%d", fd);
return -EINVAL;
}
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to register socket (fd:%d): %m", return log_error_errno(r, "Failed to register socket (fd:%d): %m", fd);
fd);
} }
if (arg_getter) { if (arg_getter) {
@ -692,10 +687,9 @@ static int create_remoteserver(
return r; return r;
} }
if (s->active == 0) { if (s->active == 0)
log_error("Zero sources specified"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Zero sources specified");
}
if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE) { if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE) {
/* In this case we know what the writer will be /* In this case we know what the writer will be
@ -830,37 +824,33 @@ static int parse_argv(int argc, char *argv[]) {
return version(); return version();
case ARG_URL: case ARG_URL:
if (arg_url) { if (arg_url)
log_error("cannot currently set more than one --url"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot currently set more than one --url");
}
arg_url = optarg; arg_url = optarg;
break; break;
case ARG_GETTER: case ARG_GETTER:
if (arg_getter) { if (arg_getter)
log_error("cannot currently use --getter more than once"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot currently use --getter more than once");
}
arg_getter = optarg; arg_getter = optarg;
break; break;
case ARG_LISTEN_RAW: case ARG_LISTEN_RAW:
if (arg_listen_raw) { if (arg_listen_raw)
log_error("cannot currently use --listen-raw more than once"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot currently use --listen-raw more than once");
}
arg_listen_raw = optarg; arg_listen_raw = optarg;
break; break;
case ARG_LISTEN_HTTP: case ARG_LISTEN_HTTP:
if (arg_listen_http || http_socket >= 0) { if (arg_listen_http || http_socket >= 0)
log_error("cannot currently use --listen-http more than once"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot currently use --listen-http more than once");
}
r = negative_fd(optarg); r = negative_fd(optarg);
if (r >= 0) if (r >= 0)
@ -870,10 +860,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_LISTEN_HTTPS: case ARG_LISTEN_HTTPS:
if (arg_listen_https || https_socket >= 0) { if (arg_listen_https || https_socket >= 0)
log_error("cannot currently use --listen-https more than once"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot currently use --listen-https more than once");
}
r = negative_fd(optarg); r = negative_fd(optarg);
if (r >= 0) if (r >= 0)
@ -884,10 +873,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_KEY: case ARG_KEY:
if (arg_key) { if (arg_key)
log_error("Key file specified twice"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Key file specified twice");
}
arg_key = strdup(optarg); arg_key = strdup(optarg);
if (!arg_key) if (!arg_key)
@ -896,10 +884,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_CERT: case ARG_CERT:
if (arg_cert) { if (arg_cert)
log_error("Certificate file specified twice"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Certificate file specified twice");
}
arg_cert = strdup(optarg); arg_cert = strdup(optarg);
if (!arg_cert) if (!arg_cert)
@ -908,10 +895,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_TRUST: case ARG_TRUST:
if (arg_trust || arg_trust_all) { if (arg_trust || arg_trust_all)
log_error("Confusing trusted CA configuration"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Confusing trusted CA configuration");
}
if (streq(optarg, "all")) if (streq(optarg, "all"))
arg_trust_all = true; arg_trust_all = true;
@ -921,37 +907,34 @@ static int parse_argv(int argc, char *argv[]) {
if (!arg_trust) if (!arg_trust)
return log_oom(); return log_oom();
#else #else
log_error("Option --trust is not available."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --trust is not available.");
#endif #endif
} }
break; break;
case 'o': case 'o':
if (arg_output) { if (arg_output)
log_error("cannot use --output/-o more than once"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use --output/-o more than once");
}
arg_output = optarg; arg_output = optarg;
break; break;
case ARG_SPLIT_MODE: case ARG_SPLIT_MODE:
arg_split_mode = journal_write_split_mode_from_string(optarg); arg_split_mode = journal_write_split_mode_from_string(optarg);
if (arg_split_mode == _JOURNAL_WRITE_SPLIT_INVALID) { if (arg_split_mode == _JOURNAL_WRITE_SPLIT_INVALID)
log_error("Invalid split mode: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid split mode: %s", optarg);
}
break; break;
case ARG_COMPRESS: case ARG_COMPRESS:
if (optarg) { if (optarg) {
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("Failed to parse --compress= parameter."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --compress= parameter.");
}
arg_compress = !!r; arg_compress = !!r;
} else } else
@ -962,10 +945,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_SEAL: case ARG_SEAL:
if (optarg) { if (optarg) {
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("Failed to parse --seal= parameter."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --seal= parameter.");
}
arg_seal = !!r; arg_seal = !!r;
} else } else
@ -982,7 +964,6 @@ static int parse_argv(int argc, char *argv[]) {
r = extract_first_word(&p, &word, ",", 0); r = extract_first_word(&p, &word, ",", 0);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse --gnutls-log= argument: %m"); return log_error_errno(r, "Failed to parse --gnutls-log= argument: %m");
if (r == 0) if (r == 0)
break; break;
@ -993,8 +974,8 @@ static int parse_argv(int argc, char *argv[]) {
} }
break; break;
#else #else
log_error("Option --gnutls-log is not available."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --gnutls-log is not available.");
#endif #endif
} }
@ -1013,21 +994,18 @@ static int parse_argv(int argc, char *argv[]) {
|| arg_listen_raw || arg_listen_raw
|| arg_listen_http || arg_listen_https || arg_listen_http || arg_listen_https
|| sd_listen_fds(false) > 0; || sd_listen_fds(false) > 0;
if (type_a && type_b) { if (type_a && type_b)
log_error("Cannot use file input or --getter with " return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--arg-listen-... or socket activation."); "Cannot use file input or --getter with "
return -EINVAL; "--arg-listen-... or socket activation.");
}
if (type_a) { if (type_a) {
if (!arg_output) { if (!arg_output)
log_error("Option --output must be specified with file input or --getter."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --output must be specified with file input or --getter.");
}
if (!IN_SET(arg_split_mode, JOURNAL_WRITE_SPLIT_NONE, _JOURNAL_WRITE_SPLIT_INVALID)) { if (!IN_SET(arg_split_mode, JOURNAL_WRITE_SPLIT_NONE, _JOURNAL_WRITE_SPLIT_INVALID))
log_error("For active sources, only --split-mode=none is allowed."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "For active sources, only --split-mode=none is allowed.");
}
arg_split_mode = JOURNAL_WRITE_SPLIT_NONE; arg_split_mode = JOURNAL_WRITE_SPLIT_NONE;
} }
@ -1036,21 +1014,18 @@ static int parse_argv(int argc, char *argv[]) {
arg_split_mode = JOURNAL_WRITE_SPLIT_HOST; arg_split_mode = JOURNAL_WRITE_SPLIT_HOST;
if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE && arg_output) { if (arg_split_mode == JOURNAL_WRITE_SPLIT_NONE && arg_output) {
if (is_dir(arg_output, true) > 0) { if (is_dir(arg_output, true) > 0)
log_error("For SplitMode=none, output must be a file."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "For SplitMode=none, output must be a file.");
} if (!endswith(arg_output, ".journal"))
if (!endswith(arg_output, ".journal")) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
log_error("For SplitMode=none, output file name must end with .journal."); "For SplitMode=none, output file name must end with .journal.");
return -EINVAL;
}
} }
if (arg_split_mode == JOURNAL_WRITE_SPLIT_HOST if (arg_split_mode == JOURNAL_WRITE_SPLIT_HOST
&& arg_output && is_dir(arg_output, true) <= 0) { && arg_output && is_dir(arg_output, true) <= 0)
log_error("For SplitMode=host, output must be a directory."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "For SplitMode=host, output must be a directory.");
}
log_debug("Full config: SplitMode=%s Key=%s Cert=%s Trust=%s", log_debug("Full config: SplitMode=%s Key=%s Cert=%s Trust=%s",
journal_write_split_mode_to_string(arg_split_mode), journal_write_split_mode_to_string(arg_split_mode),
@ -1083,10 +1058,9 @@ static int load_certificates(char **key, char **cert, char **trust) {
arg_trust ?: TRUST_FILE); arg_trust ?: TRUST_FILE);
} }
if ((arg_listen_raw || arg_listen_http) && *trust) { if ((arg_listen_raw || arg_listen_http) && *trust)
log_error("Option --trust makes all non-HTTPS connections untrusted."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Option --trust makes all non-HTTPS connections untrusted.");
}
return 0; return 0;
} }

View file

@ -184,10 +184,9 @@ static ssize_t write_entry(char *buf, size_t size, Uploader *u) {
size_t len; size_t len;
c = memchr(u->field_data, '=', u->field_length); c = memchr(u->field_data, '=', u->field_length);
if (!c || c == u->field_data) { if (!c || c == u->field_data)
log_error("Invalid field."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid field.");
}
len = c - (const char*)u->field_data; len = c - (const char*)u->field_data;

View file

@ -198,10 +198,9 @@ int start_upload(Uploader *u,
CURL *curl; CURL *curl;
curl = curl_easy_init(); curl = curl_easy_init();
if (!curl) { if (!curl)
log_error("Call to curl_easy_init failed."); return log_error_errno(SYNTHETIC_ERRNO(ENOSR),
return -ENOSR; "Call to curl_easy_init failed.");
}
/* tell it to POST to the URL */ /* tell it to POST to the URL */
easy_setopt(curl, CURLOPT_POST, 1L, easy_setopt(curl, CURLOPT_POST, 1L,
@ -265,11 +264,10 @@ int start_upload(Uploader *u,
/* upload to this place */ /* upload to this place */
code = curl_easy_setopt(u->easy, CURLOPT_URL, u->url); code = curl_easy_setopt(u->easy, CURLOPT_URL, u->url);
if (code) { if (code)
log_error("curl_easy_setopt CURLOPT_URL failed: %s", return log_error_errno(SYNTHETIC_ERRNO(EXFULL),
curl_easy_strerror(code)); "curl_easy_setopt CURLOPT_URL failed: %s",
return -EXFULL; curl_easy_strerror(code));
}
u->uploading = true; u->uploading = true;
@ -488,21 +486,20 @@ static int perform_upload(Uploader *u) {
} }
code = curl_easy_getinfo(u->easy, CURLINFO_RESPONSE_CODE, &status); code = curl_easy_getinfo(u->easy, CURLINFO_RESPONSE_CODE, &status);
if (code) { if (code)
log_error("Failed to retrieve response code: %s", return log_error_errno(SYNTHETIC_ERRNO(EUCLEAN),
curl_easy_strerror(code)); "Failed to retrieve response code: %s",
return -EUCLEAN; curl_easy_strerror(code));
}
if (status >= 300) { if (status >= 300)
log_error("Upload to %s failed with code %ld: %s", return log_error_errno(SYNTHETIC_ERRNO(EIO),
u->url, status, strna(u->answer)); "Upload to %s failed with code %ld: %s",
return -EIO; u->url, status, strna(u->answer));
} else if (status < 200) { else if (status < 200)
log_error("Upload to %s finished with unexpected code %ld: %s", return log_error_errno(SYNTHETIC_ERRNO(EIO),
u->url, status, strna(u->answer)); "Upload to %s finished with unexpected code %ld: %s",
return -EIO; u->url, status, strna(u->answer));
} else else
log_debug("Upload finished successfully with code %ld: %s", log_debug("Upload finished successfully with code %ld: %s",
status, strna(u->answer)); status, strna(u->answer));
@ -615,37 +612,33 @@ static int parse_argv(int argc, char *argv[]) {
return version(); return version();
case 'u': case 'u':
if (arg_url) { if (arg_url)
log_error("cannot use more than one --url"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --url");
}
arg_url = optarg; arg_url = optarg;
break; break;
case ARG_KEY: case ARG_KEY:
if (arg_key) { if (arg_key)
log_error("cannot use more than one --key"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --key");
}
arg_key = optarg; arg_key = optarg;
break; break;
case ARG_CERT: case ARG_CERT:
if (arg_cert) { if (arg_cert)
log_error("cannot use more than one --cert"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --cert");
}
arg_cert = optarg; arg_cert = optarg;
break; break;
case ARG_TRUST: case ARG_TRUST:
if (arg_trust) { if (arg_trust)
log_error("cannot use more than one --trust"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --trust");
}
arg_trust = optarg; arg_trust = optarg;
break; break;
@ -663,19 +656,17 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'M': case 'M':
if (arg_machine) { if (arg_machine)
log_error("cannot use more than one --machine/-M"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --machine/-M");
}
arg_machine = optarg; arg_machine = optarg;
break; break;
case 'D': case 'D':
if (arg_directory) { if (arg_directory)
log_error("cannot use more than one --directory/-D"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --directory/-D");
}
arg_directory = optarg; arg_directory = optarg;
break; break;
@ -687,19 +678,17 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_CURSOR: case ARG_CURSOR:
if (arg_cursor) { if (arg_cursor)
log_error("cannot use more than one --cursor/--after-cursor"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --cursor/--after-cursor");
}
arg_cursor = optarg; arg_cursor = optarg;
break; break;
case ARG_AFTER_CURSOR: case ARG_AFTER_CURSOR:
if (arg_cursor) { if (arg_cursor)
log_error("cannot use more than one --cursor/--after-cursor"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "cannot use more than one --cursor/--after-cursor");
}
arg_cursor = optarg; arg_cursor = optarg;
arg_after_cursor = true; arg_after_cursor = true;
@ -708,10 +697,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_FOLLOW: case ARG_FOLLOW:
if (optarg) { if (optarg) {
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("Failed to parse --follow= parameter."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --follow= parameter.");
}
arg_follow = !!r; arg_follow = !!r;
} else } else
@ -724,31 +712,30 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case '?': case '?':
log_error("Unknown option %s.", argv[optind-1]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown option %s.",
argv[optind - 1]);
case ':': case ':':
log_error("Missing argument to %s.", argv[optind-1]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Missing argument to %s.",
argv[optind - 1]);
default: default:
assert_not_reached("Unhandled option code."); assert_not_reached("Unhandled option code.");
} }
if (!arg_url) { if (!arg_url)
log_error("Required --url/-u option missing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Required --url/-u option missing.");
}
if (!!arg_key != !!arg_cert) { if (!!arg_key != !!arg_cert)
log_error("Options --key and --cert must be used together."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Options --key and --cert must be used together.");
}
if (optind < argc && (arg_directory || arg_file || arg_machine || arg_journal_type)) { if (optind < argc && (arg_directory || arg_file || arg_machine || arg_journal_type))
log_error("Input arguments make no sense with journal input."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Input arguments make no sense with journal input.");
}
return 1; return 1;
} }

View file

@ -153,8 +153,7 @@ static int log_enable_gnutls_category(const char *cat) {
log_reset_gnutls_level(); log_reset_gnutls_level();
return 0; return 0;
} }
log_error("No such log category: %s", cat); return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No such log category: %s", cat);
return -EINVAL;
} }
int setup_gnutls_logger(char **categories) { int setup_gnutls_logger(char **categories) {
@ -206,10 +205,9 @@ static int get_client_cert(gnutls_session_t session, gnutls_x509_crt_t *client_c
assert(client_cert); assert(client_cert);
pcert = gnutls_certificate_get_peers(session, &listsize); pcert = gnutls_certificate_get_peers(session, &listsize);
if (!pcert || !listsize) { if (!pcert || !listsize)
log_error("Failed to retrieve certificate chain"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to retrieve certificate chain");
}
r = gnutls_x509_crt_init(&cert); r = gnutls_x509_crt_init(&cert);
if (r < 0) { if (r < 0) {

View file

@ -86,10 +86,9 @@ static int parse_argv(int argc, char *argv[]) {
case 'p': case 'p':
arg_priority = log_level_from_string(optarg); arg_priority = log_level_from_string(optarg);
if (arg_priority < 0) { if (arg_priority < 0)
log_error("Failed to parse priority value."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse priority value.");
}
break; break;
case ARG_LEVEL_PREFIX: { case ARG_LEVEL_PREFIX: {

View file

@ -217,14 +217,14 @@ static int catalog_entry_lang(const char* filename, int line,
size_t c; size_t c;
c = strlen(t); c = strlen(t);
if (c == 0) { if (c == 0)
log_error("[%s:%u] Language too short.", filename, line); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "[%s:%u] Language too short.",
} filename, line);
if (c > 31) { if (c > 31)
log_error("[%s:%u] language too long.", filename, line); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "[%s:%u] language too long.", filename,
} line);
if (deflang) { if (deflang) {
if (streq(t, deflang)) { if (streq(t, deflang)) {
@ -304,10 +304,11 @@ int catalog_import_file(Hashmap *h, const char *path) {
if (sd_id128_from_string(line + 2 + 1, &jd) >= 0) { if (sd_id128_from_string(line + 2 + 1, &jd) >= 0) {
if (got_id) { if (got_id) {
if (payload_size == 0) { if (payload_size == 0)
log_error("[%s:%u] No payload text.", path, n); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "[%s:%u] No payload text.",
} path,
n);
r = finish_item(h, id, lang ?: deflang, payload, payload_size); r = finish_item(h, id, lang ?: deflang, payload, payload_size);
if (r < 0) if (r < 0)
@ -335,10 +336,10 @@ int catalog_import_file(Hashmap *h, const char *path) {
} }
/* Payload */ /* Payload */
if (!got_id) { if (!got_id)
log_error("[%s:%u] Got payload before ID.", path, n); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "[%s:%u] Got payload before ID.",
} path, n);
line_len = strlen(line); line_len = strlen(line);
if (!GREEDY_REALLOC(payload, payload_allocated, if (!GREEDY_REALLOC(payload, payload_allocated,
@ -356,10 +357,10 @@ int catalog_import_file(Hashmap *h, const char *path) {
} }
if (got_id) { if (got_id) {
if (payload_size == 0) { if (payload_size == 0)
log_error("[%s:%u] No payload text.", path, n); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "[%s:%u] No payload text.",
} path, n);
r = finish_item(h, id, lang ?: deflang, payload, payload_size); r = finish_item(h, id, lang ?: deflang, payload, payload_size);
if (r < 0) if (r < 0)

View file

@ -566,13 +566,14 @@ static int journal_file_verify_header(JournalFile *f) {
if (state == STATE_ARCHIVED) if (state == STATE_ARCHIVED)
return -ESHUTDOWN; /* Already archived */ return -ESHUTDOWN; /* Already archived */
else if (state == STATE_ONLINE) { else if (state == STATE_ONLINE)
log_debug("Journal file %s is already online. Assuming unclean closing.", f->path); return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
return -EBUSY; "Journal file %s is already online. Assuming unclean closing.",
} else if (state != STATE_OFFLINE) { f->path);
log_debug("Journal file %s has unknown state %i.", f->path, state); else if (state != STATE_OFFLINE)
return -EBUSY; return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
} "Journal file %s has unknown state %i.",
f->path, state);
if (f->header->field_hash_table_size == 0 || f->header->data_hash_table_size == 0) if (f->header->field_hash_table_size == 0 || f->header->data_hash_table_size == 0)
return -EBADMSG; return -EBADMSG;
@ -580,10 +581,10 @@ static int journal_file_verify_header(JournalFile *f) {
/* Don't permit appending to files from the future. Because otherwise the realtime timestamps wouldn't /* Don't permit appending to files from the future. Because otherwise the realtime timestamps wouldn't
* be strictly ordered in the entries in the file anymore, and we can't have that since it breaks * be strictly ordered in the entries in the file anymore, and we can't have that since it breaks
* bisection. */ * bisection. */
if (le64toh(f->header->tail_entry_realtime) > now(CLOCK_REALTIME)) { if (le64toh(f->header->tail_entry_realtime) > now(CLOCK_REALTIME))
log_debug("Journal file %s is from the future, refusing to append new data to it that'd be older.", f->path); return log_debug_errno(SYNTHETIC_ERRNO(ETXTBSY),
return -ETXTBSY; "Journal file %s is from the future, refusing to append new data to it that'd be older.",
} f->path);
} }
f->compress_xz = JOURNAL_HEADER_COMPRESSED_XZ(f->header); f->compress_xz = JOURNAL_HEADER_COMPRESSED_XZ(f->header);
@ -747,153 +748,124 @@ static int journal_file_check_object(JournalFile *f, uint64_t offset, Object *o)
switch (o->object.type) { switch (o->object.type) {
case OBJECT_DATA: { case OBJECT_DATA: {
if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0)) { if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0))
log_debug("Bad n_entries: %"PRIu64": %"PRIu64, return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
le64toh(o->data.n_entries), offset); "Bad n_entries: %" PRIu64 ": %" PRIu64,
return -EBADMSG; le64toh(o->data.n_entries),
} offset);
if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0) { if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0)
log_debug("Bad object size (<= %zu): %"PRIu64": %"PRIu64, return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
offsetof(DataObject, payload), "Bad object size (<= %zu): %" PRIu64 ": %" PRIu64,
le64toh(o->object.size), offsetof(DataObject, payload),
offset); le64toh(o->object.size),
return -EBADMSG; offset);
}
if (!VALID64(le64toh(o->data.next_hash_offset)) || if (!VALID64(le64toh(o->data.next_hash_offset)) ||
!VALID64(le64toh(o->data.next_field_offset)) || !VALID64(le64toh(o->data.next_field_offset)) ||
!VALID64(le64toh(o->data.entry_offset)) || !VALID64(le64toh(o->data.entry_offset)) ||
!VALID64(le64toh(o->data.entry_array_offset))) { !VALID64(le64toh(o->data.entry_array_offset)))
log_debug("Invalid offset, next_hash_offset="OFSfmt", next_field_offset="OFSfmt return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
", entry_offset="OFSfmt", entry_array_offset="OFSfmt": %"PRIu64, "Invalid offset, next_hash_offset=" OFSfmt ", next_field_offset=" OFSfmt ", entry_offset=" OFSfmt ", entry_array_offset=" OFSfmt ": %" PRIu64,
le64toh(o->data.next_hash_offset), le64toh(o->data.next_hash_offset),
le64toh(o->data.next_field_offset), le64toh(o->data.next_field_offset),
le64toh(o->data.entry_offset), le64toh(o->data.entry_offset),
le64toh(o->data.entry_array_offset), le64toh(o->data.entry_array_offset),
offset); offset);
return -EBADMSG;
}
break; break;
} }
case OBJECT_FIELD: case OBJECT_FIELD:
if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0) { if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad field size (<= %zu): %"PRIu64": %"PRIu64, "Bad field size (<= %zu): %" PRIu64 ": %" PRIu64,
offsetof(FieldObject, payload), offsetof(FieldObject, payload),
le64toh(o->object.size), le64toh(o->object.size),
offset); offset);
return -EBADMSG;
}
if (!VALID64(le64toh(o->field.next_hash_offset)) || if (!VALID64(le64toh(o->field.next_hash_offset)) ||
!VALID64(le64toh(o->field.head_data_offset))) { !VALID64(le64toh(o->field.head_data_offset)))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid offset, next_hash_offset="OFSfmt "Invalid offset, next_hash_offset=" OFSfmt ", head_data_offset=" OFSfmt ": %" PRIu64,
", head_data_offset="OFSfmt": %"PRIu64, le64toh(o->field.next_hash_offset),
le64toh(o->field.next_hash_offset), le64toh(o->field.head_data_offset),
le64toh(o->field.head_data_offset), offset);
offset);
return -EBADMSG;
}
break; break;
case OBJECT_ENTRY: case OBJECT_ENTRY:
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0) { if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad entry size (<= %zu): %"PRIu64": %"PRIu64, "Bad entry size (<= %zu): %" PRIu64 ": %" PRIu64,
offsetof(EntryObject, items), offsetof(EntryObject, items),
le64toh(o->object.size), le64toh(o->object.size),
offset); offset);
return -EBADMSG;
}
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0) { if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid number items in entry: %"PRIu64": %"PRIu64, "Invalid number items in entry: %" PRIu64 ": %" PRIu64,
(le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem), (le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem),
offset); offset);
return -EBADMSG;
}
if (le64toh(o->entry.seqnum) <= 0) { if (le64toh(o->entry.seqnum) <= 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry seqnum: %"PRIx64": %"PRIu64, "Invalid entry seqnum: %" PRIx64 ": %" PRIu64,
le64toh(o->entry.seqnum), le64toh(o->entry.seqnum),
offset); offset);
return -EBADMSG;
}
if (!VALID_REALTIME(le64toh(o->entry.realtime))) { if (!VALID_REALTIME(le64toh(o->entry.realtime)))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry realtime timestamp: %"PRIu64": %"PRIu64, "Invalid entry realtime timestamp: %" PRIu64 ": %" PRIu64,
le64toh(o->entry.realtime), le64toh(o->entry.realtime),
offset); offset);
return -EBADMSG;
}
if (!VALID_MONOTONIC(le64toh(o->entry.monotonic))) { if (!VALID_MONOTONIC(le64toh(o->entry.monotonic)))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry monotonic timestamp: %"PRIu64": %"PRIu64, "Invalid entry monotonic timestamp: %" PRIu64 ": %" PRIu64,
le64toh(o->entry.monotonic), le64toh(o->entry.monotonic),
offset); offset);
return -EBADMSG;
}
break; break;
case OBJECT_DATA_HASH_TABLE: case OBJECT_DATA_HASH_TABLE:
case OBJECT_FIELD_HASH_TABLE: case OBJECT_FIELD_HASH_TABLE:
if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) % sizeof(HashItem) != 0 || if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) % sizeof(HashItem) != 0 ||
(le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0) { (le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid %s hash table size: %"PRIu64": %"PRIu64, "Invalid %s hash table size: %" PRIu64 ": %" PRIu64,
o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field", o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field",
le64toh(o->object.size), le64toh(o->object.size),
offset); offset);
return -EBADMSG;
}
break; break;
case OBJECT_ENTRY_ARRAY: case OBJECT_ENTRY_ARRAY:
if ((le64toh(o->object.size) - offsetof(EntryArrayObject, items)) % sizeof(le64_t) != 0 || if ((le64toh(o->object.size) - offsetof(EntryArrayObject, items)) % sizeof(le64_t) != 0 ||
(le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0) { (le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0)
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object entry array size: %"PRIu64": %"PRIu64, "Invalid object entry array size: %" PRIu64 ": %" PRIu64,
le64toh(o->object.size), le64toh(o->object.size),
offset); offset);
return -EBADMSG;
}
if (!VALID64(le64toh(o->entry_array.next_entry_array_offset))) { if (!VALID64(le64toh(o->entry_array.next_entry_array_offset)))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object entry array next_entry_array_offset: "OFSfmt": %"PRIu64, "Invalid object entry array next_entry_array_offset: " OFSfmt ": %" PRIu64,
le64toh(o->entry_array.next_entry_array_offset), le64toh(o->entry_array.next_entry_array_offset),
offset); offset);
return -EBADMSG;
}
break; break;
case OBJECT_TAG: case OBJECT_TAG:
if (le64toh(o->object.size) != sizeof(TagObject)) { if (le64toh(o->object.size) != sizeof(TagObject))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object tag size: %"PRIu64": %"PRIu64, "Invalid object tag size: %" PRIu64 ": %" PRIu64,
le64toh(o->object.size), le64toh(o->object.size),
offset); offset);
return -EBADMSG;
}
if (!VALID_EPOCH(le64toh(o->tag.epoch))) { if (!VALID_EPOCH(le64toh(o->tag.epoch)))
log_debug( return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object tag epoch: %"PRIu64": %"PRIu64, "Invalid object tag epoch: %" PRIu64 ": %" PRIu64,
le64toh(o->tag.epoch), le64toh(o->tag.epoch), offset);
offset);
return -EBADMSG;
}
break; break;
} }
@ -912,16 +884,16 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
assert(ret); assert(ret);
/* Objects may only be located at multiple of 64 bit */ /* Objects may only be located at multiple of 64 bit */
if (!VALID64(offset)) { if (!VALID64(offset))
log_debug("Attempt to move to object at non-64bit boundary: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to object at non-64bit boundary: %" PRIu64,
} offset);
/* Object may not be located in the file header */ /* Object may not be located in the file header */
if (offset < le64toh(f->header->header_size)) { if (offset < le64toh(f->header->header_size))
log_debug("Attempt to move to object located in file header: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to object located in file header: %" PRIu64,
} offset);
r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t, &tsize); r = journal_file_move_to(f, type, false, offset, sizeof(ObjectHeader), &t, &tsize);
if (r < 0) if (r < 0)
@ -930,29 +902,29 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
o = (Object*) t; o = (Object*) t;
s = le64toh(o->object.size); s = le64toh(o->object.size);
if (s == 0) { if (s == 0)
log_debug("Attempt to move to uninitialized object: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to uninitialized object: %" PRIu64,
} offset);
if (s < sizeof(ObjectHeader)) { if (s < sizeof(ObjectHeader))
log_debug("Attempt to move to overly short object: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to overly short object: %" PRIu64,
} offset);
if (o->object.type <= OBJECT_UNUSED) { if (o->object.type <= OBJECT_UNUSED)
log_debug("Attempt to move to object with invalid type: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to object with invalid type: %" PRIu64,
} offset);
if (s < minimum_header_size(o)) { if (s < minimum_header_size(o))
log_debug("Attempt to move to truncated object: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to truncated object: %" PRIu64,
} offset);
if (type > OBJECT_UNUSED && o->object.type != type) { if (type > OBJECT_UNUSED && o->object.type != type)
log_debug("Attempt to move to object of unexpected type: %" PRIu64, offset); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Attempt to move to object of unexpected type: %" PRIu64,
} offset);
if (s > tsize) { if (s > tsize) {
r = journal_file_move_to(f, type, false, offset, s, &t, NULL); r = journal_file_move_to(f, type, false, offset, s, &t, NULL);
@ -1953,14 +1925,14 @@ int journal_file_append_entry(
assert(iovec || n_iovec == 0); assert(iovec || n_iovec == 0);
if (ts) { if (ts) {
if (!VALID_REALTIME(ts->realtime)) { if (!VALID_REALTIME(ts->realtime))
log_debug("Invalid realtime timestamp %"PRIu64", refusing entry.", ts->realtime); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Invalid realtime timestamp %" PRIu64 ", refusing entry.",
} ts->realtime);
if (!VALID_MONOTONIC(ts->monotonic)) { if (!VALID_MONOTONIC(ts->monotonic))
log_debug("Invalid monotomic timestamp %"PRIu64", refusing entry.", ts->monotonic); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Invalid monotomic timestamp %" PRIu64 ", refusing entry.",
} ts->monotonic);
} else { } else {
dual_timestamp_get(&_ts); dual_timestamp_get(&_ts);
ts = &_ts; ts = &_ts;
@ -2744,10 +2716,10 @@ int journal_file_next_entry(
} }
/* Ensure our array is properly ordered. */ /* Ensure our array is properly ordered. */
if (p > 0 && !check_properly_ordered(ofs, p, direction)) { if (p > 0 && !check_properly_ordered(ofs, p, direction))
log_debug("%s: entry array not properly ordered at entry %" PRIu64, f->path, i); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "%s: entry array not properly ordered at entry %" PRIu64,
} f->path, i);
if (offset) if (offset)
*offset = ofs; *offset = ofs;
@ -2820,10 +2792,10 @@ int journal_file_next_entry_for_data(
} }
/* Ensure our array is properly ordered. */ /* Ensure our array is properly ordered. */
if (p > 0 && check_properly_ordered(ofs, p, direction)) { if (p > 0 && check_properly_ordered(ofs, p, direction))
log_debug("%s data entry array not properly ordered at entry %" PRIu64, f->path, i); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "%s data entry array not properly ordered at entry %" PRIu64,
} f->path, i);
if (offset) if (offset)
*offset = ofs; *offset = ofs;

View file

@ -85,10 +85,9 @@ static int pattern_compile(const char *pattern, unsigned flags, pcre2_code **out
r = pcre2_get_error_message(errorcode, buf, sizeof buf); r = pcre2_get_error_message(errorcode, buf, sizeof buf);
log_error("Bad pattern \"%s\": %s", return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
pattern, "Bad pattern \"%s\": %s", pattern,
r < 0 ? "unknown error" : (char*) buf); r < 0 ? "unknown error" : (char *)buf);
return -EINVAL;
} }
*out = p; *out = p;
@ -1070,10 +1069,10 @@ static int add_matches(sd_journal *j, char **args) {
r = add_matches_for_device(j, p); r = add_matches_for_device(j, p);
if (r < 0) if (r < 0)
return r; return r;
} else { } else
log_error("File is neither a device node, nor regular file, nor executable: %s", *i); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "File is neither a device node, nor regular file, nor executable: %s",
} *i);
have_term = true; have_term = true;
} else { } else {
@ -1085,10 +1084,9 @@ static int add_matches(sd_journal *j, char **args) {
return log_error_errno(r, "Failed to add match '%s': %m", *i); return log_error_errno(r, "Failed to add match '%s': %m", *i);
} }
if (!strv_isempty(args) && !have_term) { if (!strv_isempty(args) && !have_term)
log_error("\"+\" can only be used between terms"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "\"+\" can only be used between terms");
}
return 0; return 0;
} }
@ -1179,10 +1177,9 @@ static int discover_next_boot(sd_journal *j,
r = sd_journal_previous(j); r = sd_journal_previous(j);
if (r < 0) if (r < 0)
return r; return r;
else if (r == 0) { else if (r == 0)
log_debug("Whoopsie! We found a boot ID but can't read its last entry."); return log_debug_errno(SYNTHETIC_ERRNO(ENODATA),
return -ENODATA; /* This shouldn't happen. We just came from this very boot ID. */ "Whoopsie! We found a boot ID but can't read its last entry."); /* This shouldn't happen. We just came from this very boot ID. */
}
r = sd_journal_get_realtime_usec(j, &next_boot->last); r = sd_journal_get_realtime_usec(j, &next_boot->last);
if (r < 0) if (r < 0)
@ -1833,8 +1830,8 @@ finish:
return r; return r;
#else #else
log_error("Forward-secure sealing not available."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Forward-secure sealing not available.");
#endif #endif
} }
@ -2066,10 +2063,9 @@ static int wait_for_change(sd_journal *j, int poll_fd) {
return log_error_errno(errno, "Couldn't wait for journal event: %m"); return log_error_errno(errno, "Couldn't wait for journal event: %m");
} }
if (pollfds[1].revents & (POLLHUP|POLLERR)) { /* STDOUT has been closed? */ if (pollfds[1].revents & (POLLHUP|POLLERR)) /* STDOUT has been closed? */
log_debug("Standard output has been closed."); return log_debug_errno(SYNTHETIC_ERRNO(ECANCELED),
return -ECANCELED; "Standard output has been closed.");
}
r = sd_journal_process(j); r = sd_journal_process(j);
if (r < 0) if (r < 0)

View file

@ -1247,10 +1247,10 @@ int server_process_datagram(sd_event_source *es, int fd, uint32_t revents, void
assert(s); assert(s);
assert(fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd); assert(fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd);
if (revents != EPOLLIN) { if (revents != EPOLLIN)
log_error("Got invalid event from epoll for datagram fd: %"PRIx32, revents); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Got invalid event from epoll for datagram fd: %" PRIx32,
} revents);
/* Try to get the right size, if we can. (Not all sockets support SIOCINQ, hence we just try, but don't rely on /* Try to get the right size, if we can. (Not all sockets support SIOCINQ, hence we just try, but don't rely on
* it.) */ * it.) */
@ -1884,38 +1884,34 @@ int server_init(Server *s) {
if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/socket", 0) > 0) { if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/socket", 0) > 0) {
if (s->native_fd >= 0) { if (s->native_fd >= 0)
log_error("Too many native sockets passed."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many native sockets passed.");
}
s->native_fd = fd; s->native_fd = fd;
} else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) { } else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) {
if (s->stdout_fd >= 0) { if (s->stdout_fd >= 0)
log_error("Too many stdout sockets passed."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many stdout sockets passed.");
}
s->stdout_fd = fd; s->stdout_fd = fd;
} else if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/dev/log", 0) > 0 || } else if (sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/dev/log", 0) > 0 ||
sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/dev-log", 0) > 0) { sd_is_socket_unix(fd, SOCK_DGRAM, -1, "/run/systemd/journal/dev-log", 0) > 0) {
if (s->syslog_fd >= 0) { if (s->syslog_fd >= 0)
log_error("Too many /dev/log sockets passed."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many /dev/log sockets passed.");
}
s->syslog_fd = fd; s->syslog_fd = fd;
} else if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) { } else if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
if (s->audit_fd >= 0) { if (s->audit_fd >= 0)
log_error("Too many audit sockets passed."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many audit sockets passed.");
}
s->audit_fd = fd; s->audit_fd = fd;

View file

@ -596,10 +596,10 @@ static int stdout_stream_new(sd_event_source *es, int listen_fd, uint32_t revent
assert(s); assert(s);
if (revents != EPOLLIN) { if (revents != EPOLLIN)
log_error("Got invalid event from epoll for stdout server fd: %"PRIx32, revents); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Got invalid event from epoll for stdout server fd: %" PRIx32,
} revents);
fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC); fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (fd < 0) { if (fd < 0) {

View file

@ -2825,31 +2825,30 @@ _public_ int sd_journal_enumerate_unique(sd_journal *j, const void **data, size_
return r; return r;
/* Let's do the type check by hand, since we used 0 context above. */ /* Let's do the type check by hand, since we used 0 context above. */
if (o->object.type != OBJECT_DATA) { if (o->object.type != OBJECT_DATA)
log_debug("%s:offset " OFSfmt ": object has type %d, expected %d", return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
j->unique_file->path, j->unique_offset, "%s:offset " OFSfmt ": object has type %d, expected %d",
o->object.type, OBJECT_DATA); j->unique_file->path,
return -EBADMSG; j->unique_offset,
} o->object.type, OBJECT_DATA);
r = return_data(j, j->unique_file, o, &odata, &ol); r = return_data(j, j->unique_file, o, &odata, &ol);
if (r < 0) if (r < 0)
return r; return r;
/* Check if we have at least the field name and "=". */ /* Check if we have at least the field name and "=". */
if (ol <= k) { if (ol <= k)
log_debug("%s:offset " OFSfmt ": object has size %zu, expected at least %zu", return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
j->unique_file->path, j->unique_offset, "%s:offset " OFSfmt ": object has size %zu, expected at least %zu",
ol, k + 1); j->unique_file->path,
return -EBADMSG; j->unique_offset, ol, k + 1);
}
if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=') { if (memcmp(odata, j->unique_field, k) || ((const char*) odata)[k] != '=')
log_debug("%s:offset " OFSfmt ": object does not start with \"%s=\"", return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
j->unique_file->path, j->unique_offset, "%s:offset " OFSfmt ": object does not start with \"%s=\"",
j->unique_field); j->unique_file->path,
return -EBADMSG; j->unique_offset,
} j->unique_field);
/* OK, now let's see if we already returned this data /* OK, now let's see if we already returned this data
* object by checking if it exists in the earlier * object by checking if it exists in the earlier
@ -2980,10 +2979,11 @@ _public_ int sd_journal_enumerate_fields(sd_journal *j, const char **field) {
return r; return r;
/* Because we used OBJECT_UNUSED above, we need to do our type check manually */ /* Because we used OBJECT_UNUSED above, we need to do our type check manually */
if (o->object.type != OBJECT_FIELD) { if (o->object.type != OBJECT_FIELD)
log_debug("%s:offset " OFSfmt ": object has type %i, expected %i", f->path, j->fields_offset, o->object.type, OBJECT_FIELD); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "%s:offset " OFSfmt ": object has type %i, expected %i",
} f->path, j->fields_offset,
o->object.type, OBJECT_FIELD);
sz = le64toh(o->object.size) - offsetof(Object, field.payload); sz = le64toh(o->object.size) - offsetof(Object, field.payload);

View file

@ -106,70 +106,62 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, ui
/* IP */ /* IP */
if (packet->ip.version != IPVERSION) { if (packet->ip.version != IPVERSION)
log_debug("ignoring packet: not IPv4"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "ignoring packet: not IPv4");
}
if (packet->ip.ihl < 5) { if (packet->ip.ihl < 5)
log_debug("ignoring packet: IPv4 IHL (%u words) invalid", return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
packet->ip.ihl); "ignoring packet: IPv4 IHL (%u words) invalid",
return -EINVAL; packet->ip.ihl);
}
hdrlen = packet->ip.ihl * 4; hdrlen = packet->ip.ihl * 4;
if (hdrlen < 20) { if (hdrlen < 20)
log_debug("ignoring packet: IPv4 IHL (%zu bytes) " return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"smaller than minimum (20 bytes)", hdrlen); "ignoring packet: IPv4 IHL (%zu bytes) "
return -EINVAL; "smaller than minimum (20 bytes)",
} hdrlen);
if (len < hdrlen) { if (len < hdrlen)
log_debug("ignoring packet: packet (%zu bytes) " return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"smaller than expected (%zu) by IP header", len, "ignoring packet: packet (%zu bytes) "
hdrlen); "smaller than expected (%zu) by IP header",
return -EINVAL; len, hdrlen);
}
/* UDP */ /* UDP */
if (packet->ip.protocol != IPPROTO_UDP) { if (packet->ip.protocol != IPPROTO_UDP)
log_debug("ignoring packet: not UDP"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "ignoring packet: not UDP");
}
if (len < hdrlen + be16toh(packet->udp.len)) { if (len < hdrlen + be16toh(packet->udp.len))
log_debug("ignoring packet: packet (%zu bytes) " return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"smaller than expected (%zu) by UDP header", len, "ignoring packet: packet (%zu bytes) "
hdrlen + be16toh(packet->udp.len)); "smaller than expected (%zu) by UDP header",
return -EINVAL; len, hdrlen + be16toh(packet->udp.len));
}
if (be16toh(packet->udp.dest) != port) { if (be16toh(packet->udp.dest) != port)
log_debug("ignoring packet: to port %u, which " return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"is not the DHCP client port (%u)", "ignoring packet: to port %u, which "
be16toh(packet->udp.dest), port); "is not the DHCP client port (%u)",
return -EINVAL; be16toh(packet->udp.dest), port);
}
/* checksums - computing these is relatively expensive, so only do it /* checksums - computing these is relatively expensive, so only do it
if all the other checks have passed if all the other checks have passed
*/ */
if (dhcp_packet_checksum((uint8_t*)&packet->ip, hdrlen)) { if (dhcp_packet_checksum((uint8_t*)&packet->ip, hdrlen))
log_debug("ignoring packet: invalid IP checksum"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "ignoring packet: invalid IP checksum");
}
if (checksum && packet->udp.check) { if (checksum && packet->udp.check) {
packet->ip.check = packet->udp.len; packet->ip.check = packet->udp.len;
packet->ip.ttl = 0; packet->ip.ttl = 0;
if (dhcp_packet_checksum((uint8_t*)&packet->ip.ttl, if (dhcp_packet_checksum((uint8_t*)&packet->ip.ttl,
be16toh(packet->udp.len) + 12)) { be16toh(packet->udp.len) + 12))
log_debug("ignoring packet: invalid UDP checksum"); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "ignoring packet: invalid UDP checksum");
}
} }
return 0; return 0;

View file

@ -3832,11 +3832,13 @@ static int build_struct_offsets(
x = size - (n_variable * sz); x = size - (n_variable * sz);
offset = m->rindex + x; offset = m->rindex + x;
if (offset < start) { if (offset < start)
log_debug("For type %s with alignment %zu, message specifies offset %zu which is smaller than previous end %zu + alignment = %zu", return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
t, align, offset, previous, start); "For type %s with alignment %zu, message specifies offset %zu which is smaller than previous end %zu + alignment = %zu",
return -EBADMSG; t, align,
} offset,
previous,
start);
} else } else
/* Fixed size */ /* Fixed size */
offset = start + k; offset = start + k;

View file

@ -137,10 +137,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
assert(_syspath); assert(_syspath);
/* must be a subdirectory of /sys */ /* must be a subdirectory of /sys */
if (!path_startswith(_syspath, "/sys/")) { if (!path_startswith(_syspath, "/sys/"))
log_debug("sd-device: Syspath '%s' is not a subdirectory of /sys", _syspath); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "sd-device: Syspath '%s' is not a subdirectory of /sys",
} _syspath);
if (verify) { if (verify) {
r = chase_symlinks(_syspath, NULL, 0, &syspath); r = chase_symlinks(_syspath, NULL, 0, &syspath);
@ -159,10 +159,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
return log_debug_errno(r, "sd-device: Failed to chase symlink /sys: %m"); return log_debug_errno(r, "sd-device: Failed to chase symlink /sys: %m");
p = path_startswith(syspath, real_sys); p = path_startswith(syspath, real_sys);
if (!p) { if (!p)
log_debug("sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'", syspath, real_sys); return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
return -ENODEV; "sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'",
} syspath, real_sys);
new_syspath = strjoin("/sys/", p); new_syspath = strjoin("/sys/", p);
if (!new_syspath) if (!new_syspath)

View file

@ -224,10 +224,10 @@ int sd_netlink_send(sd_netlink *nl,
int rtnl_rqueue_make_room(sd_netlink *rtnl) { int rtnl_rqueue_make_room(sd_netlink *rtnl) {
assert(rtnl); assert(rtnl);
if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX) { if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX)
log_debug("rtnl: exhausted the read queue size (%d)", RTNL_RQUEUE_MAX); return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
return -ENOBUFS; "rtnl: exhausted the read queue size (%d)",
} RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue, rtnl->rqueue_allocated, rtnl->rqueue_size + 1)) if (!GREEDY_REALLOC(rtnl->rqueue, rtnl->rqueue_allocated, rtnl->rqueue_size + 1))
return -ENOMEM; return -ENOMEM;
@ -238,10 +238,10 @@ int rtnl_rqueue_make_room(sd_netlink *rtnl) {
int rtnl_rqueue_partial_make_room(sd_netlink *rtnl) { int rtnl_rqueue_partial_make_room(sd_netlink *rtnl) {
assert(rtnl); assert(rtnl);
if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX) { if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX)
log_debug("rtnl: exhausted the partial read queue size (%d)", RTNL_RQUEUE_MAX); return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
return -ENOBUFS; "rtnl: exhausted the partial read queue size (%d)",
} RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue_partial, rtnl->rqueue_partial_allocated, if (!GREEDY_REALLOC(rtnl->rqueue_partial, rtnl->rqueue_partial_allocated,
rtnl->rqueue_partial_size + 1)) rtnl->rqueue_partial_size + 1))

View file

@ -363,10 +363,9 @@ static int list_x11_keymaps(int argc, char **argv, void *userdata) {
return log_oom(); return log_oom();
} }
if (strv_isempty(list)) { if (strv_isempty(list))
log_error("Couldn't find any entries."); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "Couldn't find any entries.");
}
strv_sort(list); strv_sort(list);
strv_uniq(list); strv_uniq(list);

View file

@ -259,10 +259,9 @@ static int parse_argv(int argc, char *argv[]) {
if (arg_action == ACTION_INHIBIT && optind == argc) if (arg_action == ACTION_INHIBIT && optind == argc)
arg_action = ACTION_LIST; arg_action = ACTION_LIST;
else if (arg_action == ACTION_INHIBIT && optind >= argc) { else if (arg_action == ACTION_INHIBIT && optind >= argc)
log_error("Missing command line to execute."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Missing command line to execute.");
}
return 1; return 1;
} }

View file

@ -763,10 +763,10 @@ static int print_property(const char *name, const char *expected_value, sd_bus_m
if (r < 0) if (r < 0)
return bus_log_parse_error(r); return bus_log_parse_error(r);
if (!uid_is_valid(uid)) { if (!uid_is_valid(uid))
log_error("Invalid user ID: " UID_FMT, uid); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid user ID: " UID_FMT,
} uid);
bus_print_property_value(name, expected_value, value, UID_FMT, uid); bus_print_property_value(name, expected_value, value, UID_FMT, uid);
return 1; return 1;
@ -1419,10 +1419,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'n': case 'n':
if (safe_atou(optarg, &arg_lines) < 0) { if (safe_atou(optarg, &arg_lines) < 0)
log_error("Failed to parse lines '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse lines '%s'", optarg);
}
break; break;
case 'o': case 'o':
@ -1432,10 +1431,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_output = output_mode_from_string(optarg); arg_output = output_mode_from_string(optarg);
if (arg_output < 0) { if (arg_output < 0)
log_error("Unknown output '%s'.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown output '%s'.", optarg);
}
break; break;
case ARG_NO_PAGER: case ARG_NO_PAGER:
@ -1461,10 +1459,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_signal = signal_from_string(optarg); arg_signal = signal_from_string(optarg);
if (arg_signal < 0) { if (arg_signal < 0)
log_error("Failed to parse signal string %s.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse signal string %s.", optarg);
}
break; break;
case 'H': case 'H':

View file

@ -329,10 +329,10 @@ int button_open(Button *b) {
r = button_suitable(b); r = button_suitable(b);
if (r < 0) if (r < 0)
return log_warning_errno(r, "Failed to determine whether input device is relevant to us: %m"); return log_warning_errno(r, "Failed to determine whether input device is relevant to us: %m");
if (r == 0) { if (r == 0)
log_debug("Device %s does not expose keys or switches relevant to us, ignoring.", p); return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
return -EADDRNOTAVAIL; "Device %s does not expose keys or switches relevant to us, ignoring.",
} p);
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) { if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
r = log_error_errno(errno, "Failed to get input name: %m"); r = log_error_errno(errno, "Failed to get input name: %m");

View file

@ -1660,10 +1660,10 @@ int bus_manager_shutdown_or_sleep_now_or_later(
if (r < 0) if (r < 0)
return r; return r;
if (!streq(load_state, "loaded")) { if (!streq(load_state, "loaded"))
log_notice("Unit %s is %s, refusing operation.", unit_name, load_state); return log_notice_errno(SYNTHETIC_ERRNO(EACCES),
return -EACCES; "Unit %s is %s, refusing operation.",
} unit_name, load_state);
/* Tell everybody to prepare for shutdown/sleep */ /* Tell everybody to prepare for shutdown/sleep */
(void) send_prepare_for(m, w, true); (void) send_prepare_for(m, w, true);

View file

@ -175,10 +175,9 @@ static int session_device_start(SessionDevice *sd) {
switch (sd->type) { switch (sd->type) {
case DEVICE_TYPE_DRM: case DEVICE_TYPE_DRM:
if (sd->fd < 0) { if (sd->fd < 0)
log_error("Failed to re-activate DRM fd, as the fd was lost (maybe logind restart went wrong?)"); return log_error_errno(SYNTHETIC_ERRNO(EBADF),
return -EBADF; "Failed to re-activate DRM fd, as the fd was lost (maybe logind restart went wrong?)");
}
/* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we /* Device is kept open. Simply call drmSetMaster() and hope there is no-one else. In case it fails, we
* keep the device paused. Maybe at some point we have a drmStealMaster(). */ * keep the device paused. Maybe at some point we have a drmStealMaster(). */

View file

@ -441,10 +441,10 @@ int session_load(Session *s) {
uid_t u; uid_t u;
User *user; User *user;
if (!uid) { if (!uid)
log_error("UID not specified for session %s", s->id); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "UID not specified for session %s",
} s->id);
r = parse_uid(uid, &u); r = parse_uid(uid, &u);
if (r < 0) { if (r < 0) {
@ -453,10 +453,10 @@ int session_load(Session *s) {
} }
user = hashmap_get(s->manager->users, UID_TO_PTR(u)); user = hashmap_get(s->manager->users, UID_TO_PTR(u));
if (!user) { if (!user)
log_error("User of session %s not known.", s->id); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "User of session %s not known.",
} s->id);
session_set_user(s, user); session_set_user(s, user);
} }

View file

@ -824,10 +824,10 @@ static int manager_connect_console(Manager *m) {
* release events immediately. * release events immediately.
*/ */
if (SIGRTMIN + 1 > SIGRTMAX) { if (SIGRTMIN + 1 > SIGRTMAX)
log_error("Not enough real-time signals available: %u-%u", SIGRTMIN, SIGRTMAX); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not enough real-time signals available: %u-%u",
} SIGRTMIN, SIGRTMAX);
assert_se(ignore_signals(SIGRTMIN + 1, -1) >= 0); assert_se(ignore_signals(SIGRTMIN + 1, -1) >= 0);
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGRTMIN, -1) >= 0); assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGRTMIN, -1) >= 0);

View file

@ -175,14 +175,12 @@ static int run(int argc, char *argv[]) {
log_parse_environment(); log_parse_environment();
log_open(); log_open();
if (argc != 3) { if (argc != 3)
log_error("This program takes two arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes two arguments.");
} if (!STR_IN_SET(argv[1], "start", "stop"))
if (!STR_IN_SET(argv[1], "start", "stop")) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
log_error("First argument must be either \"start\" or \"stop\"."); "First argument must be either \"start\" or \"stop\".");
return -EINVAL;
}
r = mac_selinux_init(); r = mac_selinux_init();
if (r < 0) if (r < 0)

View file

@ -97,10 +97,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind < argc) { if (optind < argc)
log_error("Extraneous arguments"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Extraneous arguments");
}
return 1; return 1;
} }

View file

@ -1710,10 +1710,9 @@ static int make_service_name(const char *name, char **ret) {
assert(name); assert(name);
assert(ret); assert(ret);
if (!machine_name_is_valid(name)) { if (!machine_name_is_valid(name))
log_error("Invalid machine name %s.", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid machine name %s.", name);
}
r = unit_name_build("systemd-nspawn", name, ".service", ret); r = unit_name_build("systemd-nspawn", name, ".service", ret);
if (r < 0) if (r < 0)
@ -2837,10 +2836,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'n': case 'n':
if (safe_atou(optarg, &arg_lines) < 0) { if (safe_atou(optarg, &arg_lines) < 0)
log_error("Failed to parse lines '%s'", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse lines '%s'", optarg);
}
break; break;
case 'o': case 'o':
@ -2850,10 +2848,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_output = output_mode_from_string(optarg); arg_output = output_mode_from_string(optarg);
if (arg_output < 0) { if (arg_output < 0)
log_error("Unknown output '%s'.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown output '%s'.", optarg);
}
break; break;
case ARG_NO_PAGER: case ARG_NO_PAGER:
@ -2875,10 +2872,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_signal = signal_from_string(optarg); arg_signal = signal_from_string(optarg);
if (arg_signal < 0) { if (arg_signal < 0)
log_error("Failed to parse signal string %s.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse signal string %s.", optarg);
}
break; break;
case ARG_NO_ASK_PASSWORD: case ARG_NO_ASK_PASSWORD:
@ -2914,10 +2910,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_verify = import_verify_from_string(optarg); arg_verify = import_verify_from_string(optarg);
if (arg_verify < 0) { if (arg_verify < 0)
log_error("Failed to parse --verify= setting: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --verify= setting: %s", optarg);
}
break; break;
case ARG_FORCE: case ARG_FORCE:
@ -2925,10 +2920,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_FORMAT: case ARG_FORMAT:
if (!STR_IN_SET(optarg, "uncompressed", "xz", "gzip", "bzip2")) { if (!STR_IN_SET(optarg, "uncompressed", "xz", "gzip", "bzip2"))
log_error("Unknown format: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown format: %s", optarg);
}
arg_format = optarg; arg_format = optarg;
break; break;
@ -2938,10 +2932,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'E': case 'E':
if (!env_assignment_is_valid(optarg)) { if (!env_assignment_is_valid(optarg))
log_error("Environment assignment invalid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Environment assignment invalid: %s", optarg);
}
r = strv_extend(&arg_setenv, optarg); r = strv_extend(&arg_setenv, optarg);
if (r < 0) if (r < 0)
@ -2951,13 +2944,12 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NUMBER_IPS: case ARG_NUMBER_IPS:
if (streq(optarg, "all")) if (streq(optarg, "all"))
arg_addrs = ALL_IP_ADDRESSES; arg_addrs = ALL_IP_ADDRESSES;
else if (safe_atoi(optarg, &arg_addrs) < 0) { else if (safe_atoi(optarg, &arg_addrs) < 0)
log_error("Invalid number of IPs"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid number of IPs");
} else if (arg_addrs < 0) { else if (arg_addrs < 0)
log_error("Number of IPs cannot be negative"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Number of IPs cannot be negative");
}
break; break;
case '?': case '?':

View file

@ -309,46 +309,39 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Execution in user context is not supported on non-local systems."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Execution in user context is not supported on non-local systems.");
}
if (arg_action == ACTION_LIST) { if (arg_action == ACTION_LIST) {
if (optind < argc) { if (optind < argc)
log_error("Too many arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Too many arguments.");
}
if (arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Listing devices only supported locally."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Listing devices only supported locally.");
}
} else if (arg_action == ACTION_UMOUNT) { } else if (arg_action == ACTION_UMOUNT) {
if (optind >= argc) { if (optind >= argc)
log_error("At least one argument required."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "At least one argument required.");
}
if (arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_transport != BUS_TRANSPORT_LOCAL) {
int i; int i;
for (i = optind; i < argc; i++) for (i = optind; i < argc; i++)
if (!path_is_absolute(argv[i]) ) { if (!path_is_absolute(argv[i]) )
log_error("Only absolute path is supported: %s", argv[i]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Only absolute path is supported: %s", argv[i]);
}
} }
} else { } else {
if (optind >= argc) { if (optind >= argc)
log_error("At least one argument required."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "At least one argument required.");
}
if (argc > optind+2) { if (argc > optind+2)
log_error("At most two arguments required."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "At most two arguments required.");
}
if (arg_mount_type && (fstype_is_api_vfs(arg_mount_type) || fstype_is_network(arg_mount_type))) { if (arg_mount_type && (fstype_is_api_vfs(arg_mount_type) || fstype_is_network(arg_mount_type))) {
arg_mount_what = strdup(argv[optind]); arg_mount_what = strdup(argv[optind]);
@ -372,10 +365,9 @@ static int parse_argv(int argc, char *argv[]) {
path_simplify(arg_mount_what, false); path_simplify(arg_mount_what, false);
if (!path_is_absolute(arg_mount_what)) { if (!path_is_absolute(arg_mount_what))
log_error("Only absolute path is supported: %s", arg_mount_what); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Only absolute path is supported: %s", arg_mount_what);
}
} }
if (argc > optind+1) { if (argc > optind+1) {
@ -390,18 +382,16 @@ static int parse_argv(int argc, char *argv[]) {
path_simplify(arg_mount_where, false); path_simplify(arg_mount_where, false);
if (!path_is_absolute(arg_mount_where)) { if (!path_is_absolute(arg_mount_where))
log_error("Only absolute path is supported: %s", arg_mount_where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Only absolute path is supported: %s", arg_mount_where);
}
} }
} else } else
arg_discover = true; arg_discover = true;
if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_discover && arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Automatic mount location discovery is only supported locally."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Automatic mount location discovery is only supported locally.");
}
} }
return 1; return 1;
@ -909,15 +899,13 @@ static int stop_mounts(
int r; int r;
if (path_equal(where, "/")) { if (path_equal(where, "/"))
log_error("Refusing to operate on root directory: %s", where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Refusing to operate on root directory: %s", where);
}
if (!path_is_normalized(where)) { if (!path_is_normalized(where))
log_error("Path contains non-normalized components: %s", where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path contains non-normalized components: %s", where);
}
r = stop_mount(bus, where, ".mount"); r = stop_mount(bus, where, ".mount");
if (r < 0) if (r < 0)
@ -1164,13 +1152,14 @@ static int acquire_mount_where_for_loop_dev(const char *loop_dev) {
r = find_mount_points(loop_dev, &list); r = find_mount_points(loop_dev, &list);
if (r < 0) if (r < 0)
return r; return r;
else if (r == 0) { else if (r == 0)
log_error("Can't find mount point of %s. It is expected that %s is already mounted on a place.", loop_dev, loop_dev); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Can't find mount point of %s. It is expected that %s is already mounted on a place.",
} else if (r >= 2) { loop_dev, loop_dev);
log_error("%s is mounted on %d places. It is expected that %s is mounted on a place.", loop_dev, r, loop_dev); else if (r >= 2)
return -EINVAL; return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
} "%s is mounted on %d places. It is expected that %s is mounted on a place.",
loop_dev, r, loop_dev);
arg_mount_where = strdup(list[0]); arg_mount_where = strdup(list[0]);
if (!arg_mount_where) if (!arg_mount_where)

View file

@ -96,10 +96,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PID: case ARG_PID:
if (optarg) { if (optarg) {
if (parse_pid(optarg, &arg_pid) < 0) { if (parse_pid(optarg, &arg_pid) < 0)
log_error("Failed to parse PID %s.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse PID %s.", optarg);
}
} else } else
arg_pid = getppid(); arg_pid = getppid();
@ -208,10 +207,9 @@ static int run(int argc, char* argv[]) {
r = sd_pid_notify(arg_pid ? arg_pid : getppid(), false, n); r = sd_pid_notify(arg_pid ? arg_pid : getppid(), false, n);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to notify init system: %m"); return log_error_errno(r, "Failed to notify init system: %m");
if (r == 0) { if (r == 0)
log_error("No status data could be sent: $NOTIFY_SOCKET was not set"); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "No status data could be sent: $NOTIFY_SOCKET was not set");
}
return 0; return 0;
} }

View file

@ -525,8 +525,8 @@ static int mount_unified_cgroups(const char *dest) {
if (errno != ENOENT) if (errno != ENOENT)
return log_error_errno(errno, "Failed to determine if mount point %s contains the unified cgroup hierarchy: %m", p); return log_error_errno(errno, "Failed to determine if mount point %s contains the unified cgroup hierarchy: %m", p);
log_error("%s is already mounted but not a unified cgroup hierarchy. Refusing.", p); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s is already mounted but not a unified cgroup hierarchy. Refusing.", p);
} }
return mount_verbose(LOG_ERR, "cgroup", p, "cgroup2", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL); return mount_verbose(LOG_ERR, "cgroup", p, "cgroup2", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL);

View file

@ -678,15 +678,15 @@ static int mount_bind(const char *dest, CustomMount *m) {
if (stat(where, &dest_st) < 0) if (stat(where, &dest_st) < 0)
return log_error_errno(errno, "Failed to stat %s: %m", where); return log_error_errno(errno, "Failed to stat %s: %m", where);
if (S_ISDIR(source_st.st_mode) && !S_ISDIR(dest_st.st_mode)) { if (S_ISDIR(source_st.st_mode) && !S_ISDIR(dest_st.st_mode))
log_error("Cannot bind mount directory %s on file %s.", m->source, where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot bind mount directory %s on file %s.",
} m->source, where);
if (!S_ISDIR(source_st.st_mode) && S_ISDIR(dest_st.st_mode)) { if (!S_ISDIR(source_st.st_mode) && S_ISDIR(dest_st.st_mode))
log_error("Cannot bind mount file %s on directory %s.", m->source, where); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot bind mount file %s on directory %s.",
} m->source, where);
} else { /* Path doesn't exist yet? */ } else { /* Path doesn't exist yet? */
r = mkdir_parents_label(where, 0755); r = mkdir_parents_label(where, 0755);

View file

@ -94,69 +94,60 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1; fd = -1;
r = read_line(f, LONG_LINE_MAX, &line); r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) { if (r == 0)
log_error("Failed to resolve user %s.", user); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "Failed to resolve user %s.", user);
}
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m"); return log_error_errno(r, "Failed to read from getent: %m");
(void) wait_for_terminate_and_check("getent passwd", pid, WAIT_LOG); (void) wait_for_terminate_and_check("getent passwd", pid, WAIT_LOG);
x = strchr(line, ':'); x = strchr(line, ':');
if (!x) { if (!x)
log_error("/etc/passwd entry has invalid user field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid user field.");
}
u = strchr(x+1, ':'); u = strchr(x+1, ':');
if (!u) { if (!u)
log_error("/etc/passwd entry has invalid password field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid password field.");
}
u++; u++;
g = strchr(u, ':'); g = strchr(u, ':');
if (!g) { if (!g)
log_error("/etc/passwd entry has invalid UID field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid UID field.");
}
*g = 0; *g = 0;
g++; g++;
x = strchr(g, ':'); x = strchr(g, ':');
if (!x) { if (!x)
log_error("/etc/passwd entry has invalid GID field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid GID field.");
}
*x = 0; *x = 0;
h = strchr(x+1, ':'); h = strchr(x+1, ':');
if (!h) { if (!h)
log_error("/etc/passwd entry has invalid GECOS field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid GECOS field.");
}
h++; h++;
x = strchr(h, ':'); x = strchr(h, ':');
if (!x) { if (!x)
log_error("/etc/passwd entry has invalid home directory field."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "/etc/passwd entry has invalid home directory field.");
}
*x = 0; *x = 0;
r = parse_uid(u, &uid); r = parse_uid(u, &uid);
if (r < 0) { if (r < 0)
log_error("Failed to parse UID of user."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Failed to parse UID of user.");
}
r = parse_gid(g, &gid); r = parse_gid(g, &gid);
if (r < 0) { if (r < 0)
log_error("Failed to parse GID of user."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Failed to parse GID of user.");
}
home = strdup(h); home = strdup(h);
if (!home) if (!home)
@ -176,10 +167,9 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1; fd = -1;
r = read_line(f, LONG_LINE_MAX, &line); r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) { if (r == 0)
log_error("Failed to resolve user %s.", user); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "Failed to resolve user %s.", user);
}
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m"); return log_error_errno(r, "Failed to read from getent: %m");

View file

@ -321,14 +321,12 @@ static int custom_mount_check_all(void) {
CustomMount *m = &arg_custom_mounts[i]; CustomMount *m = &arg_custom_mounts[i];
if (path_equal(m->destination, "/") && arg_userns_mode != USER_NAMESPACE_NO) { if (path_equal(m->destination, "/") && arg_userns_mode != USER_NAMESPACE_NO) {
if (arg_userns_chown)
if (arg_userns_chown) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
log_error("--private-users-chown may not be combined with custom root mounts."); "--private-users-chown may not be combined with custom root mounts.");
return -EINVAL; else if (arg_uid_shift == UID_INVALID)
} else if (arg_uid_shift == UID_INVALID) { return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
log_error("--private-users with automatic UID shift may not be combined with custom root mounts."); "--private-users with automatic UID shift may not be combined with custom root mounts.");
return -EINVAL;
}
} }
} }
@ -609,10 +607,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_BRIDGE: case ARG_NETWORK_BRIDGE:
if (!ifname_valid(optarg)) { if (!ifname_valid(optarg))
log_error("Bridge interface name not valid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Bridge interface name not valid: %s", optarg);
}
r = free_and_strdup(&arg_network_bridge, optarg); r = free_and_strdup(&arg_network_bridge, optarg);
if (r < 0) if (r < 0)
@ -635,10 +632,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_NETWORK_INTERFACE: case ARG_NETWORK_INTERFACE:
if (!ifname_valid(optarg)) { if (!ifname_valid(optarg))
log_error("Network interface name not valid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Network interface name not valid: %s", optarg);
}
if (strv_extend(&arg_network_interfaces, optarg) < 0) if (strv_extend(&arg_network_interfaces, optarg) < 0)
return log_oom(); return log_oom();
@ -649,10 +645,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_MACVLAN: case ARG_NETWORK_MACVLAN:
if (!ifname_valid(optarg)) { if (!ifname_valid(optarg))
log_error("MACVLAN network interface name not valid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "MACVLAN network interface name not valid: %s", optarg);
}
if (strv_extend(&arg_network_macvlan, optarg) < 0) if (strv_extend(&arg_network_macvlan, optarg) < 0)
return log_oom(); return log_oom();
@ -663,10 +658,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_IPVLAN: case ARG_NETWORK_IPVLAN:
if (!ifname_valid(optarg)) { if (!ifname_valid(optarg))
log_error("IPVLAN network interface name not valid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "IPVLAN network interface name not valid: %s", optarg);
}
if (strv_extend(&arg_network_ipvlan, optarg) < 0) if (strv_extend(&arg_network_ipvlan, optarg) < 0)
return log_oom(); return log_oom();
@ -685,20 +679,18 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case 'b': case 'b':
if (arg_start_mode == START_PID2) { if (arg_start_mode == START_PID2)
log_error("--boot and --as-pid2 may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--boot and --as-pid2 may not be combined.");
}
arg_start_mode = START_BOOT; arg_start_mode = START_BOOT;
arg_settings_mask |= SETTING_START_MODE; arg_settings_mask |= SETTING_START_MODE;
break; break;
case 'a': case 'a':
if (arg_start_mode == START_BOOT) { if (arg_start_mode == START_BOOT)
log_error("--boot and --as-pid2 may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--boot and --as-pid2 may not be combined.");
}
arg_start_mode = START_PID2; arg_start_mode = START_PID2;
arg_settings_mask |= SETTING_START_MODE; arg_settings_mask |= SETTING_START_MODE;
@ -709,10 +701,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0) if (r < 0)
return log_error_errno(r, "Invalid UUID: %s", optarg); return log_error_errno(r, "Invalid UUID: %s", optarg);
if (sd_id128_is_null(arg_uuid)) { if (sd_id128_is_null(arg_uuid))
log_error("Machine UUID may not be all zeroes."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Machine UUID may not be all zeroes.");
}
arg_settings_mask |= SETTING_MACHINE_ID; arg_settings_mask |= SETTING_MACHINE_ID;
break; break;
@ -725,10 +716,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg)) if (isempty(optarg))
arg_machine = mfree(arg_machine); arg_machine = mfree(arg_machine);
else { else {
if (!machine_name_is_valid(optarg)) { if (!machine_name_is_valid(optarg))
log_error("Invalid machine name: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid machine name: %s", optarg);
}
r = free_and_strdup(&arg_machine, optarg); r = free_and_strdup(&arg_machine, optarg);
if (r < 0) if (r < 0)
@ -740,10 +730,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg)) if (isempty(optarg))
arg_hostname = mfree(arg_hostname); arg_hostname = mfree(arg_hostname);
else { else {
if (!hostname_is_valid(optarg, false)) { if (!hostname_is_valid(optarg, false))
log_error("Invalid hostname: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid hostname: %s", optarg);
}
r = free_and_strdup(&arg_hostname, optarg); r = free_and_strdup(&arg_hostname, optarg);
if (r < 0) if (r < 0)
@ -788,10 +777,9 @@ static int parse_argv(int argc, char *argv[]) {
int cap; int cap;
cap = capability_from_name(t); cap = capability_from_name(t);
if (cap < 0) { if (cap < 0)
log_error("Failed to parse capability %s.", t); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse capability %s.", t);
}
if (c == ARG_CAPABILITY) if (c == ARG_CAPABILITY)
plus |= 1ULL << (uint64_t) cap; plus |= 1ULL << (uint64_t) cap;
@ -860,10 +848,9 @@ static int parse_argv(int argc, char *argv[]) {
case 'E': { case 'E': {
char **n; char **n;
if (!env_assignment_is_valid(optarg)) { if (!env_assignment_is_valid(optarg))
log_error("Environment variable assignment '%s' is not valid.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Environment variable assignment '%s' is not valid.", optarg);
}
n = strv_env_set(arg_setenv, optarg); n = strv_env_set(arg_setenv, optarg);
if (!n) if (!n)
@ -902,10 +889,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PERSONALITY: case ARG_PERSONALITY:
arg_personality = personality_from_string(optarg); arg_personality = personality_from_string(optarg);
if (arg_personality == PERSONALITY_INVALID) { if (arg_personality == PERSONALITY_INVALID)
log_error("Unknown or unsupported personality '%s'.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown or unsupported personality '%s'.", optarg);
}
arg_settings_mask |= SETTING_PERSONALITY; arg_settings_mask |= SETTING_PERSONALITY;
break; break;
@ -921,10 +907,10 @@ static int parse_argv(int argc, char *argv[]) {
VolatileMode m; VolatileMode m;
m = volatile_mode_from_string(optarg); m = volatile_mode_from_string(optarg);
if (m < 0) { if (m < 0)
log_error("Failed to parse --volatile= argument: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --volatile= argument: %s", optarg);
} else else
arg_volatile_mode = m; arg_volatile_mode = m;
} }
@ -998,10 +984,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_userns_mode = USER_NAMESPACE_FIXED; arg_userns_mode = USER_NAMESPACE_FIXED;
} }
if (arg_uid_range <= 0) { if (arg_uid_range <= 0)
log_error("UID range cannot be 0."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "UID range cannot be 0.");
}
arg_settings_mask |= SETTING_USERNS; arg_settings_mask |= SETTING_USERNS;
break; break;
@ -1031,10 +1016,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_kill_signal = signal_from_string(optarg); arg_kill_signal = signal_from_string(optarg);
if (arg_kill_signal < 0) { if (arg_kill_signal < 0)
log_error("Cannot parse signal: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot parse signal: %s", optarg);
}
arg_settings_mask |= SETTING_KILL_SIGNAL; arg_settings_mask |= SETTING_KILL_SIGNAL;
break; break;
@ -1075,10 +1059,9 @@ static int parse_argv(int argc, char *argv[]) {
break; break;
case ARG_CHDIR: case ARG_CHDIR:
if (!path_is_absolute(optarg)) { if (!path_is_absolute(optarg))
log_error("Working directory %s is not an absolute path.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Working directory %s is not an absolute path.", optarg);
}
r = free_and_strdup(&arg_chdir, optarg); r = free_and_strdup(&arg_chdir, optarg);
if (r < 0) if (r < 0)
@ -1097,10 +1080,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NOTIFY_READY: case ARG_NOTIFY_READY:
r = parse_boolean(optarg); r = parse_boolean(optarg);
if (r < 0) { if (r < 0)
log_error("%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg);
}
arg_notify_ready = r; arg_notify_ready = r;
arg_settings_mask |= SETTING_NOTIFY_READY; arg_settings_mask |= SETTING_NOTIFY_READY;
break; break;
@ -1165,20 +1147,18 @@ static int parse_argv(int argc, char *argv[]) {
} }
eq = strchr(optarg, '='); eq = strchr(optarg, '=');
if (!eq) { if (!eq)
log_error("--rlimit= expects an '=' assignment."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--rlimit= expects an '=' assignment.");
}
name = strndup(optarg, eq - optarg); name = strndup(optarg, eq - optarg);
if (!name) if (!name)
return log_oom(); return log_oom();
rl = rlimit_from_string_harder(name); rl = rlimit_from_string_harder(name);
if (rl < 0) { if (rl < 0)
log_error("Unknown resource limit: %s", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown resource limit: %s", name);
}
if (!arg_rlimit[rl]) { if (!arg_rlimit[rl]) {
arg_rlimit[rl] = new0(struct rlimit, 1); arg_rlimit[rl] = new0(struct rlimit, 1);
@ -1226,10 +1206,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_resolv_conf = resolv_conf_mode_from_string(optarg); arg_resolv_conf = resolv_conf_mode_from_string(optarg);
if (arg_resolv_conf < 0) { if (arg_resolv_conf < 0)
log_error("Failed to parse /etc/resolv.conf mode: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse /etc/resolv.conf mode: %s", optarg);
}
arg_settings_mask |= SETTING_RESOLV_CONF; arg_settings_mask |= SETTING_RESOLV_CONF;
break; break;
@ -1241,10 +1220,9 @@ static int parse_argv(int argc, char *argv[]) {
} }
arg_timezone = timezone_mode_from_string(optarg); arg_timezone = timezone_mode_from_string(optarg);
if (arg_timezone < 0) { if (arg_timezone < 0)
log_error("Failed to parse /etc/localtime mode: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse /etc/localtime mode: %s", optarg);
}
arg_settings_mask |= SETTING_TIMEZONE; arg_settings_mask |= SETTING_TIMEZONE;
break; break;
@ -1262,10 +1240,9 @@ static int parse_argv(int argc, char *argv[]) {
(arg_network_interfaces || arg_network_macvlan || (arg_network_interfaces || arg_network_macvlan ||
arg_network_ipvlan || arg_network_veth_extra || arg_network_ipvlan || arg_network_veth_extra ||
arg_network_bridge || arg_network_zone || arg_network_bridge || arg_network_zone ||
arg_network_veth || arg_private_network)) { arg_network_veth || arg_private_network))
log_error("--network-namespace-path cannot be combined with other network options."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--network-namespace-path cannot be combined with other network options.");
}
parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_IPC", CLONE_NEWIPC); parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_IPC", CLONE_NEWIPC);
parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_PID", CLONE_NEWPID); parse_share_ns_env("SYSTEMD_NSPAWN_SHARE_NS_PID", CLONE_NEWPID);
@ -1283,31 +1260,27 @@ static int parse_argv(int argc, char *argv[]) {
if (!(arg_clone_ns_flags & CLONE_NEWPID) || if (!(arg_clone_ns_flags & CLONE_NEWPID) ||
!(arg_clone_ns_flags & CLONE_NEWUTS)) { !(arg_clone_ns_flags & CLONE_NEWUTS)) {
arg_register = false; arg_register = false;
if (arg_start_mode != START_PID1) { if (arg_start_mode != START_PID1)
log_error("--boot cannot be used without namespacing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--boot cannot be used without namespacing.");
}
} }
if (arg_userns_mode == USER_NAMESPACE_PICK) if (arg_userns_mode == USER_NAMESPACE_PICK)
arg_userns_chown = true; arg_userns_chown = true;
if (arg_keep_unit && arg_register && cg_pid_get_owner_uid(0, NULL) >= 0) { if (arg_keep_unit && arg_register && cg_pid_get_owner_uid(0, NULL) >= 0)
/* Save the user from accidentally registering either user-$SESSION.scope or user@.service. /* Save the user from accidentally registering either user-$SESSION.scope or user@.service.
* The latter is not technically a user session, but we don't need to labour the point. */ * The latter is not technically a user session, but we don't need to labour the point. */
log_error("--keep-unit --register=yes may not be used when invoked from a user session."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--keep-unit --register=yes may not be used when invoked from a user session.");
}
if (arg_directory && arg_image) { if (arg_directory && arg_image)
log_error("--directory= and --image= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--directory= and --image= may not be combined.");
}
if (arg_template && arg_image) { if (arg_template && arg_image)
log_error("--template= and --image= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--template= and --image= may not be combined.");
}
if (arg_ephemeral && arg_template && !arg_directory) { if (arg_ephemeral && arg_template && !arg_directory) {
/* User asked for ephemeral execution but specified --template= instead of --directory=. Semantically /* User asked for ephemeral execution but specified --template= instead of --directory=. Semantically
@ -1318,35 +1291,29 @@ static int parse_argv(int argc, char *argv[]) {
arg_directory = TAKE_PTR(arg_template); arg_directory = TAKE_PTR(arg_template);
} }
if (arg_template && !(arg_directory || arg_machine)) { if (arg_template && !(arg_directory || arg_machine))
log_error("--template= needs --directory= or --machine=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--template= needs --directory= or --machine=.");
}
if (arg_ephemeral && arg_template) { if (arg_ephemeral && arg_template)
log_error("--ephemeral and --template= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--ephemeral and --template= may not be combined.");
}
if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO)) { if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO))
log_error("--ephemeral and --link-journal= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--ephemeral and --link-journal= may not be combined.");
}
if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported()) { if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported())
log_error("--private-users= is not supported, kernel compiled without user namespace support."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "--private-users= is not supported, kernel compiled without user namespace support.");
}
if (arg_userns_chown && arg_read_only) { if (arg_userns_chown && arg_read_only)
log_error("--read-only and --private-users-chown may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--read-only and --private-users-chown may not be combined.");
}
if (arg_network_bridge && arg_network_zone) { if (arg_network_bridge && arg_network_zone)
log_error("--network-bridge= and --network-zone= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--network-bridge= and --network-zone= may not be combined.");
}
if (argc > optind) { if (argc > optind) {
arg_parameters = strv_copy(argv + optind); arg_parameters = strv_copy(argv + optind);
@ -1388,31 +1355,26 @@ static int parse_argv(int argc, char *argv[]) {
} }
static int verify_arguments(void) { static int verify_arguments(void) {
if (arg_userns_mode != USER_NAMESPACE_NO && (arg_mount_settings & MOUNT_APPLY_APIVFS_NETNS) && !arg_private_network) { if (arg_userns_mode != USER_NAMESPACE_NO && (arg_mount_settings & MOUNT_APPLY_APIVFS_NETNS) && !arg_private_network)
log_error("Invalid namespacing settings. Mounting sysfs with --private-users requires --private-network."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid namespacing settings. Mounting sysfs with --private-users requires --private-network.");
}
if (arg_userns_mode != USER_NAMESPACE_NO && !(arg_mount_settings & MOUNT_APPLY_APIVFS_RO)) { if (arg_userns_mode != USER_NAMESPACE_NO && !(arg_mount_settings & MOUNT_APPLY_APIVFS_RO))
log_error("Cannot combine --private-users with read-write mounts."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot combine --private-users with read-write mounts.");
}
if (arg_volatile_mode != VOLATILE_NO && arg_read_only) { if (arg_volatile_mode != VOLATILE_NO && arg_read_only)
log_error("Cannot combine --read-only with --volatile. Note that --volatile already implies a read-only base hierarchy."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot combine --read-only with --volatile. Note that --volatile already implies a read-only base hierarchy.");
}
if (arg_expose_ports && !arg_private_network) { if (arg_expose_ports && !arg_private_network)
log_error("Cannot use --port= without private networking."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Cannot use --port= without private networking.");
}
#if ! HAVE_LIBIPTC #if ! HAVE_LIBIPTC
if (arg_expose_ports) { if (arg_expose_ports)
log_error("--port= is not supported, compiled without libiptc support."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "--port= is not supported, compiled without libiptc support.");
}
#endif #endif
if (arg_start_mode == START_BOOT && arg_kill_signal <= 0) if (arg_start_mode == START_BOOT && arg_kill_signal <= 0)
@ -1804,12 +1766,10 @@ static int copy_devnodes(const char *dest) {
if (errno != ENOENT) if (errno != ENOENT)
return log_error_errno(errno, "Failed to stat %s: %m", from); return log_error_errno(errno, "Failed to stat %s: %m", from);
} else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) { } else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
log_error("%s is not a char or block device, cannot copy.", from); "%s is not a char or block device, cannot copy.", from);
return -EIO; else {
} else {
_cleanup_free_ char *sl = NULL, *prefixed = NULL, *dn = NULL, *t = NULL; _cleanup_free_ char *sl = NULL, *prefixed = NULL, *dn = NULL, *t = NULL;
if (mknod(to, st.st_mode, st.st_rdev) < 0) { if (mknod(to, st.st_mode, st.st_rdev) < 0) {
@ -2071,16 +2031,16 @@ static int setup_journal(const char *directory) {
if (try) if (try)
return 0; return 0;
log_error("%s: already a mount point, refusing to use for journal", p); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "%s: already a mount point, refusing to use for journal", p);
} }
if (path_is_mount_point(q, NULL, 0) > 0) { if (path_is_mount_point(q, NULL, 0) > 0) {
if (try) if (try)
return 0; return 0;
log_error("%s: already a mount point, refusing to use for journal", q); return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
return -EEXIST; "%s: already a mount point, refusing to use for journal", q);
} }
r = readlink_and_make_absolute(p, &d); r = readlink_and_make_absolute(p, &d);
@ -2252,10 +2212,9 @@ static int setup_machine_id(const char *directory) {
return log_error_errno(r, "Failed to acquire randomized machine UUID: %m"); return log_error_errno(r, "Failed to acquire randomized machine UUID: %m");
} }
} else { } else {
if (sd_id128_is_null(id)) { if (sd_id128_is_null(id))
log_error("Machine ID in container image is zero, refusing."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Machine ID in container image is zero, refusing.");
}
arg_uuid = id; arg_uuid = id;
} }
@ -2336,12 +2295,12 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
_fallthrough_; _fallthrough_;
case CLD_DUMPED: case CLD_DUMPED:
log_error("Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status)); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status));
default: default:
log_error("Container %s failed due to unknown reason.", arg_machine); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Container %s failed due to unknown reason.", arg_machine);
} }
} }
@ -2531,18 +2490,16 @@ static int determine_uid_shift(const char *directory) {
arg_uid_shift = st.st_uid & UINT32_C(0xffff0000); arg_uid_shift = st.st_uid & UINT32_C(0xffff0000);
if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000))) { if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000)))
log_error("UID and GID base of %s don't match.", directory); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "UID and GID base of %s don't match.", directory);
}
arg_uid_range = UINT32_C(0x10000); arg_uid_range = UINT32_C(0x10000);
} }
if (arg_uid_shift > (uid_t) -1 - arg_uid_range) { if (arg_uid_shift > (uid_t) -1 - arg_uid_range)
log_error("UID base too high for UID range."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "UID base too high for UID range.");
}
return 0; return 0;
} }
@ -2595,10 +2552,9 @@ static int inner_child(
(void) barrier_place(barrier); /* #1 */ (void) barrier_place(barrier); /* #1 */
/* Wait until the parent wrote the UID map */ /* Wait until the parent wrote the UID map */
if (!barrier_place_and_sync(barrier)) { /* #2 */ if (!barrier_place_and_sync(barrier)) /* #2 */
log_error("Parent died too early"); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "Parent died too early");
}
} }
r = reset_uid_gid(); r = reset_uid_gid();
@ -2627,10 +2583,9 @@ static int inner_child(
/* Wait until we are cgroup-ified, so that we /* Wait until we are cgroup-ified, so that we
* can mount the right cgroup path writable */ * can mount the right cgroup path writable */
if (!barrier_place_and_sync(barrier)) { /* #4 */ if (!barrier_place_and_sync(barrier)) /* #4 */
log_error("Parent died too early"); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "Parent died too early");
}
if (arg_use_cgns && cg_ns_supported()) { if (arg_use_cgns && cg_ns_supported()) {
r = unshare(CLONE_NEWCGROUP); r = unshare(CLONE_NEWCGROUP);
@ -2750,10 +2705,9 @@ static int inner_child(
/* Let the parent know that we are ready and /* Let the parent know that we are ready and
* wait until the parent is ready with the * wait until the parent is ready with the
* setup, too... */ * setup, too... */
if (!barrier_place_and_sync(barrier)) { /* #5 */ if (!barrier_place_and_sync(barrier)) /* #5 */
log_error("Parent died too early"); return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
return -ESRCH; "Parent died too early");
}
if (arg_chdir) if (arg_chdir)
if (chdir(arg_chdir) < 0) if (chdir(arg_chdir) < 0)
@ -2941,10 +2895,9 @@ static int outer_child(
l = send(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), MSG_NOSIGNAL); l = send(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), MSG_NOSIGNAL);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to send UID shift: %m"); return log_error_errno(errno, "Failed to send UID shift: %m");
if (l != sizeof(arg_uid_shift)) { if (l != sizeof(arg_uid_shift))
log_error("Short write while sending UID shift."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Short write while sending UID shift.");
}
if (arg_userns_mode == USER_NAMESPACE_PICK) { if (arg_userns_mode == USER_NAMESPACE_PICK) {
/* When we are supposed to pick the UID shift, the parent will check now whether the UID shift /* When we are supposed to pick the UID shift, the parent will check now whether the UID shift
@ -2954,10 +2907,9 @@ static int outer_child(
l = recv(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), 0); l = recv(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), 0);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to recv UID shift: %m"); return log_error_errno(errno, "Failed to recv UID shift: %m");
if (l != sizeof(arg_uid_shift)) { if (l != sizeof(arg_uid_shift))
log_error("Short read while receiving UID shift."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Short read while receiving UID shift.");
}
} }
log_full(arg_quiet ? LOG_DEBUG : LOG_INFO, log_full(arg_quiet ? LOG_DEBUG : LOG_INFO,
@ -2982,10 +2934,9 @@ static int outer_child(
l = send(unified_cgroup_hierarchy_socket, &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), MSG_NOSIGNAL); l = send(unified_cgroup_hierarchy_socket, &arg_unified_cgroup_hierarchy, sizeof(arg_unified_cgroup_hierarchy), MSG_NOSIGNAL);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to send cgroup mode: %m"); return log_error_errno(errno, "Failed to send cgroup mode: %m");
if (l != sizeof(arg_unified_cgroup_hierarchy)) { if (l != sizeof(arg_unified_cgroup_hierarchy))
log_error("Short write while sending cgroup mode."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Short write while sending cgroup mode.");
}
unified_cgroup_hierarchy_socket = safe_close(unified_cgroup_hierarchy_socket); unified_cgroup_hierarchy_socket = safe_close(unified_cgroup_hierarchy_socket);
} }
@ -3162,18 +3113,16 @@ static int outer_child(
l = send(pid_socket, &pid, sizeof(pid), MSG_NOSIGNAL); l = send(pid_socket, &pid, sizeof(pid), MSG_NOSIGNAL);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to send PID: %m"); return log_error_errno(errno, "Failed to send PID: %m");
if (l != sizeof(pid)) { if (l != sizeof(pid))
log_error("Short write while sending PID."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Short write while sending PID.");
}
l = send(uuid_socket, &arg_uuid, sizeof(arg_uuid), MSG_NOSIGNAL); l = send(uuid_socket, &arg_uuid, sizeof(arg_uuid), MSG_NOSIGNAL);
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to send machine ID: %m"); return log_error_errno(errno, "Failed to send machine ID: %m");
if (l != sizeof(arg_uuid)) { if (l != sizeof(arg_uuid))
log_error("Short write while sending machine ID."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Short write while sending machine ID.");
}
l = send_one_fd(notify_socket, fd, 0); l = send_one_fd(notify_socket, fd, 0);
if (l < 0) if (l < 0)

View file

@ -211,11 +211,10 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (optind + 1 != argc) { if (optind + 1 != argc)
log_error("%s excepts exactly one argument (the mount point).", return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
program_invocation_short_name); "%s excepts exactly one argument (the mount point).",
return -EINVAL; program_invocation_short_name);
}
arg_target = argv[optind]; arg_target = argv[optind];

View file

@ -51,10 +51,9 @@ static int run(int argc, char *argv[]) {
log_setup_service(); log_setup_service();
if (argc != 3) { if (argc != 3)
log_error("This program expects two arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program expects two arguments.");
}
type = argv[1]; type = argv[1];
device = argv[2]; device = argv[2];

View file

@ -100,8 +100,8 @@ static int print_home(const char *n) {
} }
} }
log_error("Path %s not known.", n); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Path %s not known.", n);
} }
static int help(void) { static int help(void) {

View file

@ -62,10 +62,9 @@ static int determine_image(const char *image, bool permit_non_existing, char **r
return 0; return 0;
} }
if (arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Operations on images by path not supported when connecting to remote systems."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Operations on images by path not supported when connecting to remote systems.");
}
r = chase_symlinks(image, NULL, CHASE_TRAIL_SLASH | (permit_non_existing ? CHASE_NONEXISTENT : 0), ret); r = chase_symlinks(image, NULL, CHASE_TRAIL_SLASH | (permit_non_existing ? CHASE_NONEXISTENT : 0), ret);
if (r < 0) if (r < 0)
@ -135,10 +134,9 @@ static int determine_matches(const char *image, char **l, bool allow_any, char *
} else if (strv_equal(l, STRV_MAKE("-"))) { } else if (strv_equal(l, STRV_MAKE("-"))) {
if (!allow_any) { if (!allow_any)
log_error("Refusing all unit file match."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Refusing all unit file match.");
}
if (!arg_quiet) if (!arg_quiet)
log_info("(Matching all unit files.)"); log_info("(Matching all unit files.)");
@ -896,10 +894,9 @@ static int parse_argv(int argc, char *argv[]) {
if (streq(optarg, "help")) if (streq(optarg, "help"))
return dump_profiles(); return dump_profiles();
if (!filename_is_valid(optarg)) { if (!filename_is_valid(optarg))
log_error("Unit profile name not valid: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unit profile name not valid: %s", optarg);
}
arg_profile = optarg; arg_profile = optarg;
break; break;
@ -914,10 +911,9 @@ static int parse_argv(int argc, char *argv[]) {
"copy\n" "copy\n"
"symlink"); "symlink");
return 0; return 0;
} else { } else
log_error("Failed to parse --copy= argument: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse --copy= argument: %s", optarg);
}
break; break;

View file

@ -58,10 +58,9 @@ static int run(int argc, char *argv[]) {
log_setup_service(); log_setup_service();
if (argc > 1) { if (argc > 1)
log_error("This program takes no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes no arguments.");
}
umask(0022); umask(0022);

View file

@ -32,10 +32,9 @@ static int run(int argc, char *argv[]) {
log_setup_service(); log_setup_service();
if (argc != 2) { if (argc != 2)
log_error("This program requires one argument."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program requires one argument.");
}
umask(0022); umask(0022);
@ -104,10 +103,9 @@ static int run(int argc, char *argv[]) {
read_seed_file = false; read_seed_file = false;
write_seed_file = true; write_seed_file = true;
} else { } else
log_error("Unknown verb '%s'.", argv[1]); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown verb '%s'.", argv[1]);
}
if (fstat(seed_fd, &st) < 0) if (fstat(seed_fd, &st) < 0)
return log_error_errno(errno, "Failed to stat() seed file " RANDOM_SEED ": %m"); return log_error_errno(errno, "Failed to stat() seed file " RANDOM_SEED ": %m");
@ -164,10 +162,9 @@ static int run(int argc, char *argv[]) {
k = loop_read(random_fd, buf, buf_size, false); k = loop_read(random_fd, buf, buf_size, false);
if (k < 0) if (k < 0)
return log_error_errno(k, "Failed to read new seed from /dev/urandom: %m"); return log_error_errno(k, "Failed to read new seed from /dev/urandom: %m");
if (k == 0) { if (k == 0)
log_error("Got EOF while reading from /dev/urandom."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Got EOF while reading from /dev/urandom.");
}
r = loop_write(seed_fd, buf, (size_t) k, false); r = loop_write(seed_fd, buf, (size_t) k, false);
if (r < 0) if (r < 0)

View file

@ -31,10 +31,9 @@ static int run(int argc, char *argv[]) {
log_setup_service(); log_setup_service();
if (argc > 1) { if (argc > 1)
log_error("This program takes no arguments."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "This program takes no arguments.");
}
umask(0022); umask(0022);

View file

@ -183,19 +183,19 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
case 'r': case 'r':
case 'v': case 'v':
case 'V': case 'V':
log_error("Switch -%c not supported.", c); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Switch -%c not supported.", c);
/* The Debian resolvconf commands we don't support. */ /* The Debian resolvconf commands we don't support. */
case ARG_ENABLE_UPDATES: case ARG_ENABLE_UPDATES:
log_error("Switch --enable-updates not supported."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Switch --enable-updates not supported.");
case ARG_DISABLE_UPDATES: case ARG_DISABLE_UPDATES:
log_error("Switch --disable-updates not supported."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Switch --disable-updates not supported.");
case ARG_UPDATES_ARE_ENABLED: case ARG_UPDATES_ARE_ENABLED:
log_error("Switch --updates-are-enabled not supported."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Switch --updates-are-enabled not supported.");
case '?': case '?':
return -EINVAL; return -EINVAL;
@ -204,15 +204,13 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_mode == _MODE_INVALID) { if (arg_mode == _MODE_INVALID)
log_error("Expected either -a or -d on the command line."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Expected either -a or -d on the command line.");
}
if (optind+1 != argc) { if (optind+1 != argc)
log_error("Expected interface name as argument."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Expected interface name as argument.");
}
r = ifname_mangle(argv[optind], false); r = ifname_mangle(argv[optind], false);
if (r <= 0) if (r <= 0)
@ -268,10 +266,9 @@ int resolvconf_parse_argv(int argc, char *argv[]) {
} else if (type == TYPE_PRIVATE) } else if (type == TYPE_PRIVATE)
log_debug("Private DNS server data not supported, ignoring."); log_debug("Private DNS server data not supported, ignoring.");
if (!arg_set_dns) { if (!arg_set_dns)
log_error("No DNS servers specified, refusing operation."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "No DNS servers specified, refusing operation.");
}
} }
return 1; /* work to do */ return 1; /* work to do */

View file

@ -91,10 +91,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
if (arg_ifname) { if (arg_ifname) {
assert(arg_ifindex >= 0); assert(arg_ifindex >= 0);
if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX) { if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX)
log_error("Interface can't be the loopback interface (lo). Sorry."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Interface can't be the loopback interface (lo). Sorry.");
}
return 1; return 1;
} }
@ -124,10 +123,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
} }
} }
if (!allow_loopback && r == LOOPBACK_IFINDEX) { if (!allow_loopback && r == LOOPBACK_IFINDEX)
log_error("Interface can't be the loopback interface (lo). Sorry."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Interface can't be the loopback interface (lo). Sorry.");
}
arg_ifindex = r; arg_ifindex = r;
arg_ifname = TAKE_PTR(iface); arg_ifname = TAKE_PTR(iface);
@ -579,10 +577,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL; _cleanup_free_ char *t = NULL;
const char *e; const char *e;
if (class != 0) { if (class != 0)
log_error("DNS class specified twice."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "DNS class specified twice.");
}
e = strchrnul(f, ';'); e = strchrnul(f, ';');
t = strndup(f, e - f); t = strndup(f, e - f);
@ -590,10 +587,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom(); return log_oom();
r = dns_class_from_string(t); r = dns_class_from_string(t);
if (r < 0) { if (r < 0)
log_error("Unknown DNS class %s.", t); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown DNS class %s.", t);
}
class = r; class = r;
@ -610,10 +606,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL; _cleanup_free_ char *t = NULL;
const char *e; const char *e;
if (type != 0) { if (type != 0)
log_error("DNS type specified twice."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "DNS type specified twice.");
}
e = strchrnul(f, ';'); e = strchrnul(f, ';');
t = strndup(f, e - f); t = strndup(f, e - f);
@ -621,10 +616,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom(); return log_oom();
r = dns_type_from_string(t); r = dns_type_from_string(t);
if (r < 0) { if (r < 0)
log_error("Unknown DNS type %s.", t); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown DNS type %s.", t);
}
type = r; type = r;
@ -649,8 +643,8 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return resolve_record(bus, n, class, type, true); return resolve_record(bus, n, class, type, true);
invalid: invalid:
log_error("Invalid DNS URI: %s", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid DNS URI: %s", name);
} }
static int verb_query(int argc, char **argv, void *userdata) { static int verb_query(int argc, char **argv, void *userdata) {
@ -897,13 +891,12 @@ static int resolve_openpgp(sd_bus *bus, const char *address) {
assert(address); assert(address);
domain = strrchr(address, '@'); domain = strrchr(address, '@');
if (!domain) { if (!domain)
log_error("Address does not contain '@': \"%s\"", address); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Address does not contain '@': \"%s\"", address);
} else if (domain == address || domain[1] == '\0') { if (domain == address || domain[1] == '\0')
log_error("Address starts or ends with '@': \"%s\"", address); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Address starts or ends with '@': \"%s\"", address);
}
domain++; domain++;
r = string_hashsum_sha256(address, domain - 1 - address, &hashed); r = string_hashsum_sha256(address, domain - 1 - address, &hashed);
@ -2566,10 +2559,9 @@ static int compat_parse_argv(int argc, char *argv[]) {
arg_flags |= SD_RESOLVED_MDNS_IPV4; arg_flags |= SD_RESOLVED_MDNS_IPV4;
else if (streq(optarg, "mdns-ipv6")) else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6; arg_flags |= SD_RESOLVED_MDNS_IPV6;
else { else
log_error("Unknown protocol specifier: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown protocol specifier: %s", optarg);
}
break; break;
@ -2585,26 +2577,24 @@ static int compat_parse_argv(int argc, char *argv[]) {
arg_mode = MODE_RESOLVE_TLSA; arg_mode = MODE_RESOLVE_TLSA;
if (!optarg || service_family_is_valid(optarg)) if (!optarg || service_family_is_valid(optarg))
arg_service_family = optarg; arg_service_family = optarg;
else { else
log_error("Unknown service family \"%s\".", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown service family \"%s\".", optarg);
}
break; break;
case ARG_RAW: case ARG_RAW:
if (on_tty()) { if (on_tty())
log_error("Refusing to write binary data to tty."); return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
return -ENOTTY; "Refusing to write binary data to tty.");
}
if (optarg == NULL || streq(optarg, "payload")) if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD; arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet")) else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET; arg_raw = RAW_PACKET;
else { else
log_error("Unknown --raw specifier \"%s\".", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown --raw specifier \"%s\".",
} optarg);
arg_legend = false; arg_legend = false;
break; break;
@ -2716,15 +2706,13 @@ static int compat_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_type == 0 && arg_class != 0) { if (arg_type == 0 && arg_class != 0)
log_error("--class= may only be used in conjunction with --type=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--class= may only be used in conjunction with --type=.");
}
if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE) { if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE)
log_error("--service and --type= may not be combined."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--service and --type= may not be combined.");
}
if (arg_type != 0 && arg_class == 0) if (arg_type != 0 && arg_class == 0)
arg_class = DNS_CLASS_IN; arg_class = DNS_CLASS_IN;
@ -2734,15 +2722,13 @@ static int compat_parse_argv(int argc, char *argv[]) {
if (IN_SET(arg_mode, MODE_SET_LINK, MODE_REVERT_LINK)) { if (IN_SET(arg_mode, MODE_SET_LINK, MODE_REVERT_LINK)) {
if (arg_ifindex <= 0) { if (arg_ifindex <= 0)
log_error("--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=.");
}
if (arg_ifindex == LOOPBACK_IFINDEX) { if (arg_ifindex == LOOPBACK_IFINDEX)
log_error("Interface can't be the loopback interface (lo). Sorry."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Interface can't be the loopback interface (lo). Sorry.");
}
} }
return 1 /* work to do */; return 1 /* work to do */;
@ -2864,27 +2850,26 @@ static int native_parse_argv(int argc, char *argv[]) {
arg_flags |= SD_RESOLVED_MDNS_IPV4; arg_flags |= SD_RESOLVED_MDNS_IPV4;
else if (streq(optarg, "mdns-ipv6")) else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6; arg_flags |= SD_RESOLVED_MDNS_IPV6;
else { else
log_error("Unknown protocol specifier: %s", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown protocol specifier: %s",
} optarg);
break; break;
case ARG_RAW: case ARG_RAW:
if (on_tty()) { if (on_tty())
log_error("Refusing to write binary data to tty."); return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
return -ENOTTY; "Refusing to write binary data to tty.");
}
if (optarg == NULL || streq(optarg, "payload")) if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD; arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet")) else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET; arg_raw = RAW_PACKET;
else { else
log_error("Unknown --raw specifier \"%s\".", optarg); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown --raw specifier \"%s\".",
} optarg);
arg_legend = false; arg_legend = false;
break; break;
@ -2928,10 +2913,9 @@ static int native_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option"); assert_not_reached("Unhandled option");
} }
if (arg_type == 0 && arg_class != 0) { if (arg_type == 0 && arg_class != 0)
log_error("--class= may only be used in conjunction with --type=."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--class= may only be used in conjunction with --type=.");
}
if (arg_type != 0 && arg_class == 0) if (arg_type != 0 && arg_class == 0)
arg_class = DNS_CLASS_IN; arg_class = DNS_CLASS_IN;

View file

@ -1272,10 +1272,10 @@ int dnssec_nsec3_hash(DnsResourceRecord *nsec3, const char *name, void *ret) {
if (nsec3->key->type != DNS_TYPE_NSEC3) if (nsec3->key->type != DNS_TYPE_NSEC3)
return -EINVAL; return -EINVAL;
if (nsec3->nsec3.iterations > NSEC3_ITERATIONS_MAX) { if (nsec3->nsec3.iterations > NSEC3_ITERATIONS_MAX)
log_debug("Ignoring NSEC3 RR %s with excessive number of iterations.", dns_resource_record_to_string(nsec3)); return log_debug_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Ignoring NSEC3 RR %s with excessive number of iterations.",
} dns_resource_record_to_string(nsec3));
algorithm = nsec3_hash_to_gcrypt_md(nsec3->nsec3.algorithm); algorithm = nsec3_hash_to_gcrypt_md(nsec3->nsec3.algorithm);
if (algorithm < 0) if (algorithm < 0)

View file

@ -48,10 +48,10 @@ int dns_packet_new(
/* The caller may not check what is going to be truly allocated, so do not allow to /* The caller may not check what is going to be truly allocated, so do not allow to
* allocate a DNS packet bigger than DNS_PACKET_SIZE_MAX. * allocate a DNS packet bigger than DNS_PACKET_SIZE_MAX.
*/ */
if (min_alloc_dsize > DNS_PACKET_SIZE_MAX) { if (min_alloc_dsize > DNS_PACKET_SIZE_MAX)
log_error("Requested packet data size too big: %zu", min_alloc_dsize); return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
return -EFBIG; "Requested packet data size too big: %zu",
} min_alloc_dsize);
/* When dns_packet_new() is called with min_alloc_dsize == 0, allocate more than the /* When dns_packet_new() is called with min_alloc_dsize == 0, allocate more than the
* absolute minimum (which is the dns packet header size), to avoid * absolute minimum (which is the dns packet header size), to avoid

View file

@ -1816,13 +1816,12 @@ static int dns_transaction_add_dnssec_transaction(DnsTransaction *t, DnsResource
if (r > 0) { if (r > 0) {
char s[DNS_RESOURCE_KEY_STRING_MAX], saux[DNS_RESOURCE_KEY_STRING_MAX]; char s[DNS_RESOURCE_KEY_STRING_MAX], saux[DNS_RESOURCE_KEY_STRING_MAX];
log_debug("Potential cyclic dependency, refusing to add transaction %" PRIu16 " (%s) as dependency for %" PRIu16 " (%s).", return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
aux->id, "Potential cyclic dependency, refusing to add transaction %" PRIu16 " (%s) as dependency for %" PRIu16 " (%s).",
dns_resource_key_to_string(t->key, s, sizeof s), aux->id,
t->id, dns_resource_key_to_string(t->key, s, sizeof s),
dns_resource_key_to_string(aux->key, saux, sizeof saux)); t->id,
dns_resource_key_to_string(aux->key, saux, sizeof saux));
return -ELOOP;
} }
} }
@ -2445,8 +2444,8 @@ static int dns_transaction_requires_rrsig(DnsTransaction *t, DnsResourceRecord *
return true; return true;
/* A CNAME/DNAME without a parent? That's sooo weird. */ /* A CNAME/DNAME without a parent? That's sooo weird. */
log_debug("Transaction %" PRIu16 " claims CNAME/DNAME at root. Refusing.", t->id); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
return -EBADMSG; "Transaction %" PRIu16 " claims CNAME/DNAME at root. Refusing.", t->id);
} }
} }

View file

@ -175,10 +175,10 @@ int dnssd_render_instance_name(DnssdService *s, char **ret_name) {
if (r < 0) if (r < 0)
return log_debug_errno(r, "Failed to replace specifiers: %m"); return log_debug_errno(r, "Failed to replace specifiers: %m");
if (!dns_service_name_is_valid(name)) { if (!dns_service_name_is_valid(name))
log_debug("Service instance name '%s' is invalid.", name); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Service instance name '%s' is invalid.",
} name);
*ret_name = TAKE_PTR(name); *ret_name = TAKE_PTR(name);

View file

@ -155,8 +155,9 @@ ssize_t dnstls_stream_write(DnsStream *stream, const char *buf, size_t count) {
case GNUTLS_E_AGAIN: case GNUTLS_E_AGAIN:
return -EAGAIN; return -EAGAIN;
default: default:
log_debug("Failed to invoke gnutls_record_send: %s", gnutls_strerror(ss)); return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
return -EPIPE; "Failed to invoke gnutls_record_send: %s",
gnutls_strerror(ss));
} }
return ss; return ss;
@ -178,8 +179,9 @@ ssize_t dnstls_stream_read(DnsStream *stream, void *buf, size_t count) {
case GNUTLS_E_AGAIN: case GNUTLS_E_AGAIN:
return -EAGAIN; return -EAGAIN;
default: default:
log_debug("Failed to invoke gnutls_record_recv: %s", gnutls_strerror(ss)); return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
return -EPIPE; "Failed to invoke gnutls_record_recv: %s",
gnutls_strerror(ss));
} }
return ss; return ss;

View file

@ -174,8 +174,9 @@ int dnstls_stream_on_io(DnsStream *stream, uint32_t revents) {
char errbuf[256]; char errbuf[256];
ERR_error_string_n(error, errbuf, sizeof(errbuf)); ERR_error_string_n(error, errbuf, sizeof(errbuf));
log_debug("Failed to invoke SSL_do_handshake: %s", errbuf); return log_debug_errno(SYNTHETIC_ERRNO(ECONNREFUSED),
return -ECONNREFUSED; "Failed to invoke SSL_do_handshake: %s",
errbuf);
} }
} }

View file

@ -47,10 +47,10 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
r = extract_first_word(&line, &address_str, NULL, EXTRACT_RELAX); r = extract_first_word(&line, &address_str, NULL, EXTRACT_RELAX);
if (r < 0) if (r < 0)
return log_error_errno(r, "Couldn't extract address, in line /etc/hosts:%u.", nr); return log_error_errno(r, "Couldn't extract address, in line /etc/hosts:%u.", nr);
if (r == 0) { if (r == 0)
log_error("Premature end of line, in line /etc/hosts:%u.", nr); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Premature end of line, in line /etc/hosts:%u.",
} nr);
r = in_addr_ifindex_from_string_auto(address_str, &address.family, &address.address, NULL); r = in_addr_ifindex_from_string_auto(address_str, &address.family, &address.address, NULL);
if (r < 0) if (r < 0)
@ -151,10 +151,10 @@ static int parse_line(EtcHosts *hosts, unsigned nr, const char *line) {
bn->addresses[bn->n_addresses++] = &item->address; bn->addresses[bn->n_addresses++] = &item->address;
} }
if (!found) { if (!found)
log_error("Line is missing any host names, in line /etc/hosts:%u.", nr); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Line is missing any host names, in line /etc/hosts:%u.",
} nr);
return 0; return 0;
} }

View file

@ -336,10 +336,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
r = dns_label_unescape(&p, label, sizeof label); r = dns_label_unescape(&p, label, sizeof label);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to unescape host name: %m"); return log_error_errno(r, "Failed to unescape host name: %m");
if (r == 0) { if (r == 0)
log_error("Couldn't find a single label in hostname."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Couldn't find a single label in hostname.");
}
#if HAVE_LIBIDN2 #if HAVE_LIBIDN2
r = idn2_to_unicode_8z8z(label, &utf8, 0); r = idn2_to_unicode_8z8z(label, &utf8, 0);
@ -356,10 +355,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
if (k > 0) if (k > 0)
r = k; r = k;
if (!utf8_is_valid(label)) { if (!utf8_is_valid(label))
log_error("System hostname is not UTF-8 clean."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "System hostname is not UTF-8 clean.");
}
decoded = label; decoded = label;
#else #else
decoded = label; /* no decoding */ decoded = label; /* no decoding */
@ -369,10 +367,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to escape host name: %m"); return log_error_errno(r, "Failed to escape host name: %m");
if (is_localhost(n)) { if (is_localhost(n))
log_debug("System hostname is 'localhost', ignoring."); return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "System hostname is 'localhost', ignoring.");
}
r = dns_name_concat(n, "local", mdns_hostname); r = dns_name_concat(n, "local", mdns_hostname);
if (r < 0) if (r < 0)

View file

@ -251,10 +251,9 @@ static int load_state(
l = write(rfkill_fd, &we, sizeof(we)); l = write(rfkill_fd, &we, sizeof(we));
if (l < 0) if (l < 0)
return log_error_errno(errno, "Failed to restore rfkill state for %i: %m", event->idx); return log_error_errno(errno, "Failed to restore rfkill state for %i: %m", event->idx);
if (l != sizeof(we)) { if (l != sizeof(we))
log_error("Couldn't write rfkill event structure, too short."); return log_error_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Couldn't write rfkill event structure, too short.");
}
log_debug("Loaded state '%s' from %s.", one_zero(b), state_file); log_debug("Loaded state '%s' from %s.", one_zero(b), state_file);
return 0; return 0;

View file

@ -408,10 +408,9 @@ static int parse_argv(int argc, char *argv[]) {
with_trigger = !!arg_path_property || !!arg_socket_property || with_timer; with_trigger = !!arg_path_property || !!arg_socket_property || with_timer;
/* currently, only single trigger (path, socket, timer) unit can be created simultaneously */ /* currently, only single trigger (path, socket, timer) unit can be created simultaneously */
if ((int) !!arg_path_property + (int) !!arg_socket_property + (int) with_timer > 1) { if ((int) !!arg_path_property + (int) !!arg_socket_property + (int) with_timer > 1)
log_error("Only single trigger (path, socket, timer) unit can be created."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Only single trigger (path, socket, timer) unit can be created.");
}
if (arg_stdio == ARG_STDIO_AUTO) { if (arg_stdio == ARG_STDIO_AUTO) {
/* If we both --pty and --pipe are specified we'll automatically pick --pty if we are connected fully /* If we both --pty and --pipe are specified we'll automatically pick --pty if we are connected fully
@ -422,66 +421,54 @@ static int parse_argv(int argc, char *argv[]) {
ARG_STDIO_DIRECT; ARG_STDIO_DIRECT;
} }
if ((optind >= argc) && (!arg_unit || !with_trigger)) { if ((optind >= argc) && (!arg_unit || !with_trigger))
log_error("Command line to execute required."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Command line to execute required.");
}
if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Execution in user context is not supported on non-local systems."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Execution in user context is not supported on non-local systems.");
}
if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL) { if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL)
log_error("Scope execution is not supported on non-local systems."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Scope execution is not supported on non-local systems.");
}
if (arg_scope && (arg_remain_after_exit || arg_service_type)) { if (arg_scope && (arg_remain_after_exit || arg_service_type))
log_error("--remain-after-exit and --service-type= are not supported in --scope mode."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--remain-after-exit and --service-type= are not supported in --scope mode.");
}
if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope)) { if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope))
log_error("--pty/--pipe is not compatible in timer or --scope mode."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--pty/--pipe is not compatible in timer or --scope mode.");
}
if (arg_stdio != ARG_STDIO_NONE && arg_transport == BUS_TRANSPORT_REMOTE) { if (arg_stdio != ARG_STDIO_NONE && arg_transport == BUS_TRANSPORT_REMOTE)
log_error("--pty/--pipe is only supported when connecting to the local system or containers."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--pty/--pipe is only supported when connecting to the local system or containers.");
}
if (arg_stdio != ARG_STDIO_NONE && arg_no_block) { if (arg_stdio != ARG_STDIO_NONE && arg_no_block)
log_error("--pty/--pipe is not compatible with --no-block."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--pty/--pipe is not compatible with --no-block.");
}
if (arg_scope && with_trigger) { if (arg_scope && with_trigger)
log_error("Path, socket or timer options are not supported in --scope mode."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Path, socket or timer options are not supported in --scope mode.");
}
if (arg_timer_property && !with_timer) { if (arg_timer_property && !with_timer)
log_error("--timer-property= has no effect without any other timer options."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--timer-property= has no effect without any other timer options.");
}
if (arg_wait) { if (arg_wait) {
if (arg_no_block) { if (arg_no_block)
log_error("--wait may not be combined with --no-block."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--wait may not be combined with --no-block.");
}
if (with_trigger) { if (with_trigger)
log_error("--wait may not be combined with path, socket or timer operations."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--wait may not be combined with path, socket or timer operations.");
}
if (arg_scope) { if (arg_scope)
log_error("--wait may not be combined with --scope."); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "--wait may not be combined with --scope.");
}
} }
return 1; return 1;
@ -787,10 +774,10 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
* name our transient units. */ * name our transient units. */
id = startswith(unique, ":1."); id = startswith(unique, ":1.");
if (!id) { if (!id)
log_error("Unique name %s has unexpected format.", unique); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unique name %s has unexpected format.",
} unique);
p = strjoin("run-u", id, ".", unit_type_to_string(t)); p = strjoin("run-u", id, ".", unit_type_to_string(t));
if (!p) if (!p)

View file

@ -593,10 +593,10 @@ int find_esp_and_warn(
path = getenv("SYSTEMD_ESP_PATH"); path = getenv("SYSTEMD_ESP_PATH");
if (path) { if (path) {
if (!path_is_valid(path) || !path_is_absolute(path)) { if (!path_is_valid(path) || !path_is_absolute(path))
log_error("$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s", path); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "$SYSTEMD_ESP_PATH does not refer to absolute path, refusing to use it: %s",
} path);
/* Note: when the user explicitly configured things with an env var we won't validate the mount /* Note: when the user explicitly configured things with an env var we won't validate the mount
* point. After all we want this to be useful for testing. */ * point. After all we want this to be useful for testing. */
@ -649,10 +649,9 @@ int find_default_boot_entry(
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to load bootspec config from \"%s/loader\": %m", where); return log_error_errno(r, "Failed to load bootspec config from \"%s/loader\": %m", where);
if (config->default_entry < 0) { if (config->default_entry < 0)
log_error("No entry suitable as default, refusing to guess."); return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
return -ENOENT; "No entry suitable as default, refusing to guess.");
}
*e = &config->entries[config->default_entry]; *e = &config->entries[config->default_entry];
log_debug("Found default boot entry in file \"%s\"", (*e)->path); log_debug("Found default boot entry in file \"%s\"", (*e)->path);

View file

@ -83,10 +83,8 @@ int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) {
int r; \ int r; \
\ \
r = parse_func(eq); \ r = parse_func(eq); \
if (r < 0) { \ if (r < 0) \
log_error("Failed to parse %s: %s", field, eq); \ return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s: %s", field, eq); \
return -EINVAL; \
} \
\ \
r = sd_bus_message_append(m, "(sv)", field, \ r = sd_bus_message_append(m, "(sv)", field, \
bus_type, (int32_t) r); \ bus_type, (int32_t) r); \
@ -277,8 +275,8 @@ static int bus_append_exec_command(sd_bus_message *m, const char *field, const c
case '+': case '+':
case '!': case '!':
/* The bus API doesn't support +, ! and !! currently, unfortunately. :-( */ /* The bus API doesn't support +, ! and !! currently, unfortunately. :-( */
log_error("Sorry, but +, ! and !! are currently not supported for transient services."); return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
return -EOPNOTSUPP; "Sorry, but +, ! and !! are currently not supported for transient services.");
default: default:
done = true; done = true;
@ -450,10 +448,9 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY); r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
else { else {
r = parse_permille_unbounded(eq); r = parse_permille_unbounded(eq);
if (r == 0) { if (r == 0)
log_error("CPU quota too small."); return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
return -ERANGE; "CPU quota too small.");
}
if (r < 0) if (r < 0)
return log_error_errno(r, "CPU quota '%s' invalid.", eq); return log_error_errno(r, "CPU quota '%s' invalid.", eq);
@ -497,10 +494,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
uint64_t bytes; uint64_t bytes;
e = strchr(eq, ' '); e = strchr(eq, ' ');
if (!e) { if (!e)
log_error("Failed to parse %s value %s.", field, eq); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse %s value %s.",
} field, eq);
path = strndupa(eq, e - eq); path = strndupa(eq, e - eq);
bandwidth = e+1; bandwidth = e+1;
@ -531,10 +528,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
uint64_t u; uint64_t u;
e = strchr(eq, ' '); e = strchr(eq, ' ');
if (!e) { if (!e)
log_error("Failed to parse %s value %s.", field, eq); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse %s value %s.",
} field, eq);
path = strndupa(eq, e - eq); path = strndupa(eq, e - eq);
weight = e+1; weight = e+1;
@ -562,10 +559,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
usec_t usec; usec_t usec;
e = strchr(eq, ' '); e = strchr(eq, ' ');
if (!e) { if (!e)
log_error("Failed to parse %s value %s.", field, eq); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse %s value %s.",
} field, eq);
path = strndupa(eq, e - eq); path = strndupa(eq, e - eq);
target = e+1; target = e+1;
@ -1125,10 +1122,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_QUOTES|EXTRACT_DONT_COALESCE_SEPARATORS); r = extract_first_word(&p, &destination, ":" WHITESPACE, EXTRACT_QUOTES|EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m"); return log_error_errno(r, "Failed to parse argument: %m");
if (r == 0) { if (r == 0)
log_error("Missing argument after ':': %s", eq); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Missing argument after ':': %s",
} eq);
d = destination; d = destination;
@ -1143,10 +1140,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
flags = MS_REC; flags = MS_REC;
else if (streq(options, "norbind")) else if (streq(options, "norbind"))
flags = 0; flags = 0;
else { else
log_error("Unknown options: %s", eq); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown options: %s",
} eq);
} }
} else } else
d = s; d = s;
@ -1204,10 +1201,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS); r = extract_first_word(&w, &path, ":", EXTRACT_DONT_COALESCE_SEPARATORS);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m"); return log_error_errno(r, "Failed to parse argument: %m");
if (r == 0) { if (r == 0)
log_error("Failed to parse argument: %s", p); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to parse argument: %s",
} p);
r = sd_bus_message_append(m, "(ss)", path, w); r = sd_bus_message_append(m, "(ss)", path, w);
if (r < 0) if (r < 0)
@ -1603,10 +1600,9 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
assert(assignment); assert(assignment);
eq = strchr(assignment, '='); eq = strchr(assignment, '=');
if (!eq) { if (!eq)
log_error("Not an assignment: %s", assignment); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not an assignment: %s", assignment);
}
field = strndupa(assignment, eq - assignment); field = strndupa(assignment, eq - assignment);
eq++; eq++;
@ -1709,20 +1705,20 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
case UNIT_TARGET: case UNIT_TARGET:
case UNIT_DEVICE: case UNIT_DEVICE:
case UNIT_SWAP: case UNIT_SWAP:
log_error("Not supported unit type"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Not supported unit type");
default: default:
log_error("Invalid unit type"); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Invalid unit type");
} }
r = bus_append_unit_property(m, field, eq); r = bus_append_unit_property(m, field, eq);
if (r != 0) if (r != 0)
return r; return r;
log_error("Unknown assignment: %s", assignment); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Unknown assignment: %s", assignment);
} }
int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char **l) { int bus_append_unit_property_assignment_many(sd_bus_message *m, UnitType t, char **l) {
@ -2006,8 +2002,8 @@ static int check_wait_response(BusWaitForJobs *d, bool quiet, const char* const*
else if (STR_IN_SET(d->result, "done", "skipped")) else if (STR_IN_SET(d->result, "done", "skipped"))
return 0; return 0;
log_debug("Unexpected job result, assuming server side newer than us: %s", d->result); return log_debug_errno(SYNTHETIC_ERRNO(EIO),
return -EIO; "Unexpected job result, assuming server side newer than us: %s", d->result);
} }
int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_args) { int bus_wait_for_jobs(BusWaitForJobs *d, bool quiet, const char* const* extra_args) {

View file

@ -1382,12 +1382,10 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
if (user) if (user)
r = bus_connect_user_systemd(bus); r = bus_connect_user_systemd(bus);
else { else {
if (sd_booted() <= 0) { if (sd_booted() <= 0)
/* Print a friendly message when the local system is actually not running systemd as PID 1. */ /* Print a friendly message when the local system is actually not running systemd as PID 1. */
log_error("System has not been booted with systemd as init system (PID 1). Can't operate."); return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
"System has not been booted with systemd as init system (PID 1). Can't operate.");
return -EHOSTDOWN;
}
r = bus_connect_system_systemd(bus); r = bus_connect_system_systemd(bus);
} }
break; break;

View file

@ -1086,10 +1086,9 @@ int dissected_image_decrypt_interactively(
else if (r != -ENOKEY) else if (r != -ENOKEY)
return log_error_errno(r, "Failed to decrypt image: %m"); return log_error_errno(r, "Failed to decrypt image: %m");
if (--n < 0) { if (--n < 0)
log_error("Too many retries."); return log_error_errno(SYNTHETIC_ERRNO(EKEYREJECTED),
return -EKEYREJECTED; "Too many retries.");
}
z = strv_free(z); z = strv_free(z);

View file

@ -204,10 +204,10 @@ static int unit_file_find_dirs(
return 0; return 0;
type = unit_name_to_type(name); type = unit_name_to_type(name);
if (type < 0) { if (type < 0)
log_error("Failed to to derive unit type from unit name: %s", name); return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
return -EINVAL; "Failed to to derive unit type from unit name: %s",
} name);
if (is_instance) { if (is_instance) {
r = unit_name_to_instance(name, &instance); r = unit_name_to_instance(name, &instance);

Some files were not shown because too many files have changed in this diff Show more