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");
}
if (optind < argc) {
log_error("%s takes no arguments.", program_invocation_short_name);
return -EINVAL;
}
if (optind < argc)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s takes no arguments.",
program_invocation_short_name);
return 1;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -202,10 +202,10 @@ void log_assert_failed_return_realm(
#define log_full_errno_realm(realm, level, error, ...) \
({ \
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, \
__FILE__, __LINE__, __func__, __VA_ARGS__) \
: -abs(_e); \
: -ERRNO_VALUE(_e); \
})
#define log_full_errno(level, error, ...) \

View File

@ -1227,8 +1227,7 @@ int must_be_root(void) {
if (geteuid() == 0)
return 0;
log_error("Need to be root.");
return -EPERM;
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "Need to be root.");
}
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
* call. This is extra paranoia to never cause a really
* seriously broken system. */
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 -EPERM;
}
if (path_equal_or_files_same(path, "/", AT_SYMLINK_NOFOLLOW))
return log_error_errno(SYNTHETIC_ERRNO(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)) {
/* Try to remove as subvolume first */
@ -194,10 +194,10 @@ int rm_rf(const char *path, RemoveFlags flags) {
if (statfs(path, &s) < 0)
return -errno;
if (is_physical_fs(&s)) {
log_error("Attempted to remove files from a disk file system under \"%s\", refusing.", path);
return -EPERM;
}
if (is_physical_fs(&s))
return log_error_errno(SYNTHETIC_ERRNO(EPERM),
"Attempted to remove files from a disk file system under \"%s\", refusing.",
path);
}
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 = 0;
if (!filename_is_valid(x + 1)) {
log_error("Rule file name '%s' is not valid, refusing.", x+1);
return -EINVAL;
}
if (!filename_is_valid(x + 1))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Rule file name '%s' is not valid, refusing.", x + 1);
fn = strappend("/proc/sys/fs/binfmt_misc/", x+1);
if (!fn)
@ -170,10 +169,9 @@ static int parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
if (arg_cat_config && argc > optind) {
log_error("Positional arguments are not allowed with --cat-config");
return -EINVAL;
}
if (arg_cat_config && argc > optind)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Positional arguments are not allowed with --cat-config");
return 1;
}

View File

@ -121,10 +121,10 @@ static int parse_counter(
e++;
k = strspn(e, DIGITS);
if (k == 0) {
log_error("Can't parse empty 'tries left' counter from LoaderBootCountPath: %s", path);
return -EINVAL;
}
if (k == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Can't parse empty 'tries left' counter from LoaderBootCountPath: %s",
path);
z = strndupa(e, k);
r = safe_atou64(z, &left);
@ -137,10 +137,10 @@ static int parse_counter(
e++;
k = strspn(e, DIGITS);
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 -EINVAL;
}
if (k == 0) /* If there's a "-" there also needs to be at least one digit */
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Can't parse empty 'tries done' counter from LoaderBootCountPath: %s",
path);
z = strndupa(e, k);
r = safe_atou64(z, &done);
@ -185,22 +185,22 @@ static int acquire_boot_count_path(
efi_tilt_backslashes(path);
if (!path_is_normalized(path)) {
log_error("Path read from LoaderBootCountPath is not normalized, refusing: %s", path);
return -EINVAL;
}
if (!path_is_normalized(path))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path read from LoaderBootCountPath is not normalized, refusing: %s",
path);
if (!path_is_absolute(path)) {
log_error("Path read from LoaderBootCountPath is not absolute, refusing: %s", path);
return -EINVAL;
}
if (!path_is_absolute(path))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path read from LoaderBootCountPath is not absolute, refusing: %s",
path);
last = last_path_component(path);
e = strrchr(last, '+');
if (!e) {
log_error("Path read from LoaderBootCountPath does not contain a counter, refusing: %s", path);
return -EINVAL;
}
if (!e)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path read from LoaderBootCountPath does not contain a counter, refusing: %s",
path);
if (ret_prefix) {
prefix = strndup(path, e - path);
@ -458,15 +458,13 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
return r;
if (detect_container() > 0) {
log_error("Marking a boot is not supported in containers.");
return -EOPNOTSUPP;
}
if (detect_container() > 0)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Marking a boot is not supported in containers.");
if (!is_efi_boot()) {
log_error("Marking a boot is only supported on EFI systems.");
return -EOPNOTSUPP;
}
if (!is_efi_boot())
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Marking a boot is only supported on EFI systems.");
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);
if (r < 0)
return r;
if (r == 0) {
log_error("Source file \"%s\" does not carry version information!", from);
return -EINVAL;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Source file \"%s\" does not carry version information!",
from);
r = get_file_version(fd_to, &b);
if (r < 0)
return r;
if (r == 0 || compare_product(a, b) != 0) {
log_notice("Skipping \"%s\", since it's owned by another boot loader.", to);
return -EEXIST;
}
if (r == 0 || compare_product(a, b) != 0)
return log_notice_errno(SYNTHETIC_ERRNO(EEXIST),
"Skipping \"%s\", since it's owned by another boot loader.",
to);
if (compare_version(a, b) < 0) {
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;
int r;
if (!is_efi_boot()) {
log_error("Not booted with UEFI.");
return -EOPNOTSUPP;
}
if (!is_efi_boot())
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Not booted with UEFI.");
if (access("/sys/firmware/efi/efivars/LoaderInfo-4a67b082-0a4c-41cf-b6c7-440b29bb8c4f", F_OK) < 0) {
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]);
}
if (detect_container() > 0) {
log_error("'%s' operation not supported in a container.", argv[0]);
return -EOPNOTSUPP;
}
if (detect_container() > 0)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"'%s' operation not supported in a container.",
argv[0]);
if (!arg_touch_variables) {
log_error("'%s' operation cannot be combined with --touch-variables=no.", argv[0]);
return -EINVAL;
}
if (!arg_touch_variables)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"'%s' operation cannot be combined with --touch-variables=no.",
argv[0]);
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;
}
if (t == XML_END) {
log_error("Premature end of XML data.");
return -EBADMSG;
}
if (t == XML_END)
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Premature end of XML data.");
switch (state) {
@ -84,10 +83,10 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
else if (streq_ptr(name, "value"))
state = STATE_VALUE;
else {
log_error("Unexpected <annotation> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <annotation> attribute %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(t == XML_TAG_CLOSE && streq_ptr(name, "annotation"))) {
@ -116,10 +115,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
return 0;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <annotation>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <annotation>. (1)");
break;
@ -129,10 +127,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(field, name);
state = STATE_ANNOTATION;
} else {
log_error("Unexpected token in <annotation>. (2)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <annotation>. (2)");
break;
@ -142,10 +139,9 @@ static int parse_xml_annotation(Context *context, uint64_t *flags) {
free_and_replace(value, name);
state = STATE_ANNOTATION;
} else {
log_error("Unexpected token in <annotation>. (3)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <annotation>. (3)");
break;
@ -187,10 +183,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
assert(context);
assert(prefix);
if (n_depth > NODE_DEPTH_MAX) {
log_error("<node> depth too high.");
return -EINVAL;
}
if (n_depth > NODE_DEPTH_MAX)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "<node> depth too high.");
for (;;) {
_cleanup_free_ char *name = NULL;
@ -202,10 +196,8 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
return t;
}
if (t == XML_END) {
log_error("Premature end of XML data.");
return -EBADMSG;
}
if (t == XML_END)
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG), "Premature end of XML data.");
switch (state) {
@ -214,10 +206,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (streq_ptr(name, "name"))
state = STATE_NODE_NAME;
else {
log_error("Unexpected <node> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <node> attribute %s.", name);
} 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);
if (r < 0)
return r;
} else {
log_error("Unexpected <node> tag %s.", name);
return -EBADMSG;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <node> tag %s.", name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <node>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <node>. (1)");
break;
@ -271,10 +260,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
np = node_path;
state = STATE_NODE;
} else {
log_error("Unexpected token in <node>. (2)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <node>. (2)");
break;
@ -283,10 +271,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_INTERFACE_NAME;
else {
log_error("Unexpected <interface> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <interface> attribute %s.",
name);
} else if (t == XML_TAG_OPEN) {
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);
if (r < 0)
return r;
} else {
log_error("Unexpected <interface> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected <interface> tag %s.", name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <interface>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <interface>. (1)");
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);
state = STATE_INTERFACE;
} else {
log_error("Unexpected token in <interface>. (2)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <interface>. (2)");
break;
@ -345,10 +330,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_METHOD_NAME;
else {
log_error("Unexpected <method> attribute %s", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <method> attribute %s",
name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "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);
if (r < 0)
return r;
} else {
log_error("Unexpected <method> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected <method> tag %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <method> (1).");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <method> (1).");
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);
state = STATE_METHOD;
} else {
log_error("Unexpected token in <method> (2).");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <method> (2).");
break;
@ -405,19 +388,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_METHOD_ARG_TYPE;
else if (streq_ptr(name, "direction"))
state = STATE_METHOD_ARG_DIRECTION;
else {
log_error("Unexpected method <arg> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected method <arg> attribute %s.",
name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL);
if (r < 0)
return r;
} else {
log_error("Unexpected method <arg> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected method <arg> tag %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in method <arg>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in method <arg>. (1)");
break;
@ -450,10 +432,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE)
state = STATE_METHOD_ARG;
else {
log_error("Unexpected token in method <arg>. (2)");
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in method <arg>. (2)");
break;
@ -463,10 +444,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name);
state = STATE_METHOD_ARG;
} else {
log_error("Unexpected token in method <arg>. (3)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in method <arg>. (3)");
break;
@ -476,10 +456,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name);
state = STATE_METHOD_ARG;
} else {
log_error("Unexpected token in method <arg>. (4)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in method <arg>. (4)");
break;
@ -488,10 +467,10 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_NAME) {
if (streq_ptr(name, "name"))
state = STATE_SIGNAL_NAME;
else {
log_error("Unexpected <signal> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <signal> attribute %s.",
name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "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);
if (r < 0)
return r;
} else {
log_error("Unexpected <signal> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected <signal> tag %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <signal>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <signal>. (1)");
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);
state = STATE_SIGNAL;
} else {
log_error("Unexpected token in <signal>. (2)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <signal>. (2)");
break;
@ -548,19 +525,19 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_SIGNAL_ARG_TYPE;
else if (streq_ptr(name, "direction"))
state = STATE_SIGNAL_ARG_DIRECTION;
else {
log_error("Unexpected signal <arg> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected signal <arg> attribute %s.",
name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, NULL);
if (r < 0)
return r;
} else {
log_error("Unexpected signal <arg> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected signal <arg> tag %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in signal <arg> (1).");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in signal <arg> (1).");
break;
@ -586,10 +562,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
if (t == XML_ATTRIBUTE_VALUE)
state = STATE_SIGNAL_ARG;
else {
log_error("Unexpected token in signal <arg> (2).");
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in signal <arg> (2).");
break;
@ -599,10 +574,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_type, name);
state = STATE_SIGNAL_ARG;
} else {
log_error("Unexpected token in signal <arg> (3).");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in signal <arg> (3).");
break;
@ -612,10 +586,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
free_and_replace(argument_direction, name);
state = STATE_SIGNAL_ARG;
} else {
log_error("Unexpected token in signal <arg>. (4)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in signal <arg>. (4)");
break;
@ -628,20 +601,20 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
state = STATE_PROPERTY_TYPE;
else if (streq_ptr(name, "access"))
state = STATE_PROPERTY_ACCESS;
else {
log_error("Unexpected <property> attribute %s.", name);
return -EBADMSG;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Unexpected <property> attribute %s.",
name);
} else if (t == XML_TAG_OPEN) {
if (streq_ptr(name, "annotation")) {
r = parse_xml_annotation(context, &context->member_flags);
if (r < 0)
return r;
} else {
log_error("Unexpected <property> tag %s.", name);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected <property> tag %s.",
name);
} else if (t == XML_TAG_CLOSE_EMPTY ||
(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;
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE)) {
log_error("Unexpected token in <property>. (1)");
return -EINVAL;
}
} else if (t != XML_TEXT || !in_charset(name, WHITESPACE))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <property>. (1)");
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);
state = STATE_PROPERTY;
} else {
log_error("Unexpected token in <property>. (2)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <property>. (2)");
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);
state = STATE_PROPERTY;
} else {
log_error("Unexpected token in <property>. (3)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <property>. (3)");
break;
@ -701,10 +671,9 @@ static int parse_xml_node(Context *context, const char *prefix, unsigned n_depth
context->member_writable = true;
state = STATE_PROPERTY;
} else {
log_error("Unexpected token in <property>. (4)");
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unexpected token in <property>. (4)");
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) {
int r;
if (isatty(fileno(stdout)) > 0) {
log_error("Refusing to write message data to console, please redirect output to a file.");
return -EINVAL;
}
if (isatty(fileno(stdout)) > 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Refusing to write message data to console, please redirect output to a file.");
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)
break;
if (!v) {
log_error("Too few parameters for signature.");
return -EINVAL;
}
if (!v)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too few parameters for signature.");
signature++;
p++;
@ -1539,12 +1537,12 @@ static int message_append_cmdline(sd_bus_message *m, const char *signature, char
}
case SD_BUS_TYPE_UNIX_FD:
log_error("UNIX file descriptor not supported as type.");
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"UNIX file descriptor not supported as type.");
default:
log_error("Unknown signature type %c.", t);
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown signature type %c.", t);
}
if (r < 0)
@ -2291,10 +2289,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Failed to parse size '%s': %m", optarg);
if ((uint64_t) (size_t) sz != sz) {
log_error("Size out of range.");
return -E2BIG;
}
if ((uint64_t) (size_t) sz != sz)
return log_error_errno(SYNTHETIC_ERRNO(E2BIG),
"Size out of range.");
arg_snaplen = (size_t) sz;
break;
@ -2385,10 +2382,10 @@ static int parse_argv(int argc, char *argv[]) {
fputs("short\n"
"pretty\n", stdout);
return 0;
} else {
log_error("Unknown JSON out mode: %s", optarg);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown JSON out mode: %s",
optarg);
break;

View File

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

View File

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

View File

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

View File

@ -244,10 +244,10 @@ int job_install_deserialized(Job *j) {
assert(!j->installed);
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 -EINVAL;
}
if (j->type < 0 || j->type >= _JOB_TYPE_MAX_IN_TRANSACTION)
return log_debug_errno(SYNTHETIC_ERRNO(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;
if (*pj) {

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -351,16 +351,15 @@ static int save_external_coredump(
/* Is coredumping disabled? Then don't bother saving/processing the coredump.
* 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. */
log_info("Resource limits disable core dumping for process %s (%s).",
context[CONTEXT_PID], context[CONTEXT_COMM]);
return -EBADSLT;
return log_info_errno(SYNTHETIC_ERRNO(EBADSLT),
"Resource limits disable core dumping for process %s (%s).",
context[CONTEXT_PID], context[CONTEXT_COMM]);
}
process_limit = MAX(arg_process_size_max, storage_size_max());
if (process_limit == 0) {
log_debug("Limits for coredump processing and storage are both 0, not dumping core.");
return -EBADSLT;
}
if (process_limit == 0)
return log_debug_errno(SYNTHETIC_ERRNO(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 */
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);
if (n < 0)
return log_error_errno((int) n, "Failed to read core data: %m");
if ((size_t) n < size) {
log_error("Core data too short.");
return -EIO;
}
if ((size_t) n < size)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Core data too short.");
*ret = TAKE_PTR(field);
*ret_size = size + 9;
@ -1236,10 +1234,10 @@ static int process_kernel(int argc, char* argv[]) {
log_debug("Processing coredump received from the kernel...");
if (argc < CONTEXT_COMM + 1) {
log_error("Not enough arguments passed by the kernel (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1);
return -EINVAL;
}
if (argc < CONTEXT_COMM + 1)
return log_error_errno(SYNTHETIC_ERRNO(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_UID] = argv[1 + CONTEXT_UID];
@ -1293,10 +1291,10 @@ static int process_backtrace(int argc, char *argv[]) {
log_debug("Processing backtrace on stdin...");
if (argc < CONTEXT_COMM + 1) {
log_error("Not enough arguments passed (%i, expected %i).", argc - 1, CONTEXT_COMM + 1 - 1);
return -EINVAL;
}
if (argc < CONTEXT_COMM + 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Not enough arguments passed (%i, expected %i).",
argc - 1, CONTEXT_COMM + 1 - 1);
context[CONTEXT_PID] = argv[2 + CONTEXT_PID];
context[CONTEXT_UID] = argv[2 + CONTEXT_UID];
@ -1407,8 +1405,8 @@ static int run(int argc, char *argv[]) {
} else if (r == 1)
return process_socket(SD_LISTEN_FDS_START);
log_error("Received unexpected number of file descriptors.");
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Received unexpected number of file descriptors.");
}
DEFINE_MAIN_FUNCTION(run);

View File

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

View File

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

View File

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

View File

@ -145,10 +145,9 @@ static int generate_wants_symlinks(void) {
static int run(int argc, char *argv[]) {
int r, q;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
return -EINVAL;
}
if (argc > 1 && argc != 4)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program takes three or no arguments.");
if (argc > 1)
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 -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid suffix specification %s.", arg);
}
static int help(void) {
@ -604,10 +604,9 @@ static int parse_argv(int argc, char *argv[]) {
case 't': {
int f;
f = parse_flags(optarg, arg_flags);
if (f < 0) {
log_error("Failed to parse flags field.");
return -EINVAL;
}
if (f < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse flags field.");
arg_flags = f;
break;
}
@ -619,10 +618,9 @@ static int parse_argv(int argc, char *argv[]) {
int b;
b = parse_boolean(optarg);
if (b < 0) {
log_error("Failed to parse diff boolean.");
return -EINVAL;
}
if (b < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse diff boolean.");
arg_diff = b;
}

View File

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

View File

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

View File

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

View File

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

View File

@ -74,10 +74,9 @@ static int run(int argc, char *argv[]) {
log_setup_generator();
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
return -EINVAL;
}
if (argc > 1 && argc != 4)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program takes three or no arguments.");
if (argc > 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
action = 0;
if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK) {
log_debug("Failed to propagate IO event.");
return -EINVAL;
}
if (curl_multi_socket_action(g->curl, translated_fd, action, &k) != CURLM_OK)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to propagate IO event.");
curl_glue_check_finished(g);
return 0;
@ -151,10 +150,9 @@ static int curl_glue_on_timer(sd_event_source *s, uint64_t usec, void *userdata)
assert(s);
assert(g);
if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK) {
log_debug("Failed to propagate timeout.");
return -EINVAL;
}
if (curl_multi_socket_action(g->curl, CURL_SOCKET_TIMEOUT, 0, &k) != CURLM_OK)
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to propagate timeout.");
curl_glue_check_finished(g);
return 0;

View File

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

View File

@ -338,10 +338,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
if (r < 0)
return log_oom();
if (!filename_is_valid(fn)) {
log_error("Cannot verify checksum, could not determine server-side file name.");
return -EBADMSG;
}
if (!filename_is_valid(fn))
return log_error_errno(SYNTHETIC_ERRNO(EBADMSG),
"Cannot verify checksum, could not determine server-side file name.");
line = strjoina(job->checksum, " *", fn, "\n");
@ -359,10 +358,9 @@ static int verify_one(PullJob *checksum_job, PullJob *job) {
strlen(line));
}
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 -EBADMSG;
}
if (!p || (p != (char*) checksum_job->payload && p[-1] != '\n'))
return log_error_errno(SYNTHETIC_ERRNO(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);
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)
return 0;
if (j->written_uncompressed + sz < j->written_uncompressed) {
log_error("File too large, overflow");
return -EOVERFLOW;
}
if (j->written_uncompressed + sz < j->written_uncompressed)
return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW),
"File too large, overflow");
if (j->written_uncompressed + sz > j->uncompressed_max) {
log_error("File overly large, refusing");
return -EFBIG;
}
if (j->written_uncompressed + sz > j->uncompressed_max)
return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
"File overly large, refusing");
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)
return log_error_errno((int) n, "Failed to write file: %m");
if ((size_t) n < sz) {
log_error("Short write");
return -EIO;
}
if ((size_t) n < sz)
return log_error_errno(SYNTHETIC_ERRNO(EIO), "Short write");
} else {
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)
return 0;
if (j->written_compressed + sz < j->written_compressed) {
log_error("File too large, overflow");
return -EOVERFLOW;
}
if (j->written_compressed + sz < j->written_compressed)
return log_error_errno(SYNTHETIC_ERRNO(EOVERFLOW), "File too large, overflow");
if (j->written_compressed + sz > j->compressed_max) {
log_error("File overly large, refusing.");
return -EFBIG;
}
if (j->written_compressed + sz > j->compressed_max)
return log_error_errno(SYNTHETIC_ERRNO(EFBIG), "File overly large, refusing.");
if (j->content_length != (uint64_t) -1 &&
j->written_compressed + sz > j->content_length) {
log_error("Content length incorrect.");
return -EFBIG;
}
j->written_compressed + sz > j->content_length)
return log_error_errno(SYNTHETIC_ERRNO(EFBIG),
"Content length incorrect.");
if (j->checksum_context)
gcry_md_write(j->checksum_context, p, sz);
@ -323,10 +314,9 @@ static int pull_job_open_disk(PullJob *j) {
if (j->calc_checksum) {
initialize_libgcrypt(false);
if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0) {
log_error("Failed to initialize hash context.");
return -EIO;
}
if (gcry_md_open(&j->checksum_context, GCRY_MD_SHA256, 0) != 0)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to initialize hash context.");
}
return 0;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -153,8 +153,7 @@ static int log_enable_gnutls_category(const char *cat) {
log_reset_gnutls_level();
return 0;
}
log_error("No such log category: %s", cat);
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No such log category: %s", cat);
}
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);
pcert = gnutls_certificate_get_peers(session, &listsize);
if (!pcert || !listsize) {
log_error("Failed to retrieve certificate chain");
return -EINVAL;
}
if (!pcert || !listsize)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to retrieve certificate chain");
r = gnutls_x509_crt_init(&cert);
if (r < 0) {

View File

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

View File

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

View File

@ -566,13 +566,14 @@ static int journal_file_verify_header(JournalFile *f) {
if (state == STATE_ARCHIVED)
return -ESHUTDOWN; /* Already archived */
else if (state == STATE_ONLINE) {
log_debug("Journal file %s is already online. Assuming unclean closing.", f->path);
return -EBUSY;
} else if (state != STATE_OFFLINE) {
log_debug("Journal file %s has unknown state %i.", f->path, state);
return -EBUSY;
}
else if (state == STATE_ONLINE)
return log_debug_errno(SYNTHETIC_ERRNO(EBUSY),
"Journal file %s is already online. Assuming unclean closing.",
f->path);
else if (state != STATE_OFFLINE)
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)
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
* be strictly ordered in the entries in the file anymore, and we can't have that since it breaks
* bisection. */
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 -ETXTBSY;
}
if (le64toh(f->header->tail_entry_realtime) > now(CLOCK_REALTIME))
return log_debug_errno(SYNTHETIC_ERRNO(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);
@ -747,153 +748,124 @@ static int journal_file_check_object(JournalFile *f, uint64_t offset, Object *o)
switch (o->object.type) {
case OBJECT_DATA: {
if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0)) {
log_debug("Bad n_entries: %"PRIu64": %"PRIu64,
le64toh(o->data.n_entries), offset);
return -EBADMSG;
}
if ((le64toh(o->data.entry_offset) == 0) ^ (le64toh(o->data.n_entries) == 0))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad n_entries: %" PRIu64 ": %" PRIu64,
le64toh(o->data.n_entries),
offset);
if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0) {
log_debug("Bad object size (<= %zu): %"PRIu64": %"PRIu64,
offsetof(DataObject, payload),
le64toh(o->object.size),
offset);
return -EBADMSG;
}
if (le64toh(o->object.size) - offsetof(DataObject, payload) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad object size (<= %zu): %" PRIu64 ": %" PRIu64,
offsetof(DataObject, payload),
le64toh(o->object.size),
offset);
if (!VALID64(le64toh(o->data.next_hash_offset)) ||
!VALID64(le64toh(o->data.next_field_offset)) ||
!VALID64(le64toh(o->data.entry_offset)) ||
!VALID64(le64toh(o->data.entry_array_offset))) {
log_debug("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_field_offset),
le64toh(o->data.entry_offset),
le64toh(o->data.entry_array_offset),
offset);
return -EBADMSG;
}
!VALID64(le64toh(o->data.entry_array_offset)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"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_field_offset),
le64toh(o->data.entry_offset),
le64toh(o->data.entry_array_offset),
offset);
break;
}
case OBJECT_FIELD:
if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0) {
log_debug(
"Bad field size (<= %zu): %"PRIu64": %"PRIu64,
offsetof(FieldObject, payload),
le64toh(o->object.size),
offset);
return -EBADMSG;
}
if (le64toh(o->object.size) - offsetof(FieldObject, payload) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad field size (<= %zu): %" PRIu64 ": %" PRIu64,
offsetof(FieldObject, payload),
le64toh(o->object.size),
offset);
if (!VALID64(le64toh(o->field.next_hash_offset)) ||
!VALID64(le64toh(o->field.head_data_offset))) {
log_debug(
"Invalid offset, next_hash_offset="OFSfmt
", head_data_offset="OFSfmt": %"PRIu64,
le64toh(o->field.next_hash_offset),
le64toh(o->field.head_data_offset),
offset);
return -EBADMSG;
}
!VALID64(le64toh(o->field.head_data_offset)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid offset, next_hash_offset=" OFSfmt ", head_data_offset=" OFSfmt ": %" PRIu64,
le64toh(o->field.next_hash_offset),
le64toh(o->field.head_data_offset),
offset);
break;
case OBJECT_ENTRY:
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0) {
log_debug(
"Bad entry size (<= %zu): %"PRIu64": %"PRIu64,
offsetof(EntryObject, items),
le64toh(o->object.size),
offset);
return -EBADMSG;
}
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) % sizeof(EntryItem) != 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Bad entry size (<= %zu): %" PRIu64 ": %" PRIu64,
offsetof(EntryObject, items),
le64toh(o->object.size),
offset);
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0) {
log_debug(
"Invalid number items in entry: %"PRIu64": %"PRIu64,
(le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem),
offset);
return -EBADMSG;
}
if ((le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid number items in entry: %" PRIu64 ": %" PRIu64,
(le64toh(o->object.size) - offsetof(EntryObject, items)) / sizeof(EntryItem),
offset);
if (le64toh(o->entry.seqnum) <= 0) {
log_debug(
"Invalid entry seqnum: %"PRIx64": %"PRIu64,
le64toh(o->entry.seqnum),
offset);
return -EBADMSG;
}
if (le64toh(o->entry.seqnum) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry seqnum: %" PRIx64 ": %" PRIu64,
le64toh(o->entry.seqnum),
offset);
if (!VALID_REALTIME(le64toh(o->entry.realtime))) {
log_debug(
"Invalid entry realtime timestamp: %"PRIu64": %"PRIu64,
le64toh(o->entry.realtime),
offset);
return -EBADMSG;
}
if (!VALID_REALTIME(le64toh(o->entry.realtime)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry realtime timestamp: %" PRIu64 ": %" PRIu64,
le64toh(o->entry.realtime),
offset);
if (!VALID_MONOTONIC(le64toh(o->entry.monotonic))) {
log_debug(
"Invalid entry monotonic timestamp: %"PRIu64": %"PRIu64,
le64toh(o->entry.monotonic),
offset);
return -EBADMSG;
}
if (!VALID_MONOTONIC(le64toh(o->entry.monotonic)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid entry monotonic timestamp: %" PRIu64 ": %" PRIu64,
le64toh(o->entry.monotonic),
offset);
break;
case OBJECT_DATA_HASH_TABLE:
case OBJECT_FIELD_HASH_TABLE:
if ((le64toh(o->object.size) - offsetof(HashTableObject, items)) % sizeof(HashItem) != 0 ||
(le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0) {
log_debug(
"Invalid %s hash table size: %"PRIu64": %"PRIu64,
o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field",
le64toh(o->object.size),
offset);
return -EBADMSG;
}
(le64toh(o->object.size) - offsetof(HashTableObject, items)) / sizeof(HashItem) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid %s hash table size: %" PRIu64 ": %" PRIu64,
o->object.type == OBJECT_DATA_HASH_TABLE ? "data" : "field",
le64toh(o->object.size),
offset);
break;
case OBJECT_ENTRY_ARRAY:
if ((le64toh(o->object.size) - offsetof(EntryArrayObject, items)) % sizeof(le64_t) != 0 ||
(le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0) {
log_debug(
"Invalid object entry array size: %"PRIu64": %"PRIu64,
le64toh(o->object.size),
offset);
return -EBADMSG;
}
(le64toh(o->object.size) - offsetof(EntryArrayObject, items)) / sizeof(le64_t) <= 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object entry array size: %" PRIu64 ": %" PRIu64,
le64toh(o->object.size),
offset);
if (!VALID64(le64toh(o->entry_array.next_entry_array_offset))) {
log_debug(
"Invalid object entry array next_entry_array_offset: "OFSfmt": %"PRIu64,
le64toh(o->entry_array.next_entry_array_offset),
offset);
return -EBADMSG;
}
if (!VALID64(le64toh(o->entry_array.next_entry_array_offset)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object entry array next_entry_array_offset: " OFSfmt ": %" PRIu64,
le64toh(o->entry_array.next_entry_array_offset),
offset);
break;
case OBJECT_TAG:
if (le64toh(o->object.size) != sizeof(TagObject)) {
log_debug(
"Invalid object tag size: %"PRIu64": %"PRIu64,
le64toh(o->object.size),
offset);
return -EBADMSG;
}
if (le64toh(o->object.size) != sizeof(TagObject))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object tag size: %" PRIu64 ": %" PRIu64,
le64toh(o->object.size),
offset);
if (!VALID_EPOCH(le64toh(o->tag.epoch))) {
log_debug(
"Invalid object tag epoch: %"PRIu64": %"PRIu64,
le64toh(o->tag.epoch),
offset);
return -EBADMSG;
}
if (!VALID_EPOCH(le64toh(o->tag.epoch)))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid object tag epoch: %" PRIu64 ": %" PRIu64,
le64toh(o->tag.epoch), offset);
break;
}
@ -912,16 +884,16 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
assert(ret);
/* Objects may only be located at multiple of 64 bit */
if (!VALID64(offset)) {
log_debug("Attempt to move to object at non-64bit boundary: %" PRIu64, offset);
return -EBADMSG;
}
if (!VALID64(offset))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to object at non-64bit boundary: %" PRIu64,
offset);
/* Object may not be located in the file header */
if (offset < le64toh(f->header->header_size)) {
log_debug("Attempt to move to object located in file header: %" PRIu64, offset);
return -EBADMSG;
}
if (offset < le64toh(f->header->header_size))
return log_debug_errno(SYNTHETIC_ERRNO(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);
if (r < 0)
@ -930,29 +902,29 @@ int journal_file_move_to_object(JournalFile *f, ObjectType type, uint64_t offset
o = (Object*) t;
s = le64toh(o->object.size);
if (s == 0) {
log_debug("Attempt to move to uninitialized object: %" PRIu64, offset);
return -EBADMSG;
}
if (s < sizeof(ObjectHeader)) {
log_debug("Attempt to move to overly short object: %" PRIu64, offset);
return -EBADMSG;
}
if (s == 0)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to uninitialized object: %" PRIu64,
offset);
if (s < sizeof(ObjectHeader))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to overly short object: %" PRIu64,
offset);
if (o->object.type <= OBJECT_UNUSED) {
log_debug("Attempt to move to object with invalid type: %" PRIu64, offset);
return -EBADMSG;
}
if (o->object.type <= OBJECT_UNUSED)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to object with invalid type: %" PRIu64,
offset);
if (s < minimum_header_size(o)) {
log_debug("Attempt to move to truncated object: %" PRIu64, offset);
return -EBADMSG;
}
if (s < minimum_header_size(o))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to truncated object: %" PRIu64,
offset);
if (type > OBJECT_UNUSED && o->object.type != type) {
log_debug("Attempt to move to object of unexpected type: %" PRIu64, offset);
return -EBADMSG;
}
if (type > OBJECT_UNUSED && o->object.type != type)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Attempt to move to object of unexpected type: %" PRIu64,
offset);
if (s > tsize) {
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);
if (ts) {
if (!VALID_REALTIME(ts->realtime)) {
log_debug("Invalid realtime timestamp %"PRIu64", refusing entry.", ts->realtime);
return -EBADMSG;
}
if (!VALID_MONOTONIC(ts->monotonic)) {
log_debug("Invalid monotomic timestamp %"PRIu64", refusing entry.", ts->monotonic);
return -EBADMSG;
}
if (!VALID_REALTIME(ts->realtime))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid realtime timestamp %" PRIu64 ", refusing entry.",
ts->realtime);
if (!VALID_MONOTONIC(ts->monotonic))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"Invalid monotomic timestamp %" PRIu64 ", refusing entry.",
ts->monotonic);
} else {
dual_timestamp_get(&_ts);
ts = &_ts;
@ -2744,10 +2716,10 @@ int journal_file_next_entry(
}
/* Ensure our array is properly ordered. */
if (p > 0 && !check_properly_ordered(ofs, p, direction)) {
log_debug("%s: entry array not properly ordered at entry %" PRIu64, f->path, i);
return -EBADMSG;
}
if (p > 0 && !check_properly_ordered(ofs, p, direction))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"%s: entry array not properly ordered at entry %" PRIu64,
f->path, i);
if (offset)
*offset = ofs;
@ -2820,10 +2792,10 @@ int journal_file_next_entry_for_data(
}
/* Ensure our array is properly ordered. */
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 -EBADMSG;
}
if (p > 0 && check_properly_ordered(ofs, p, direction))
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG),
"%s data entry array not properly ordered at entry %" PRIu64,
f->path, i);
if (offset)
*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);
log_error("Bad pattern \"%s\": %s",
pattern,
r < 0 ? "unknown error" : (char*) buf);
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Bad pattern \"%s\": %s", pattern,
r < 0 ? "unknown error" : (char *)buf);
}
*out = p;
@ -1070,10 +1069,10 @@ static int add_matches(sd_journal *j, char **args) {
r = add_matches_for_device(j, p);
if (r < 0)
return r;
} else {
log_error("File is neither a device node, nor regular file, nor executable: %s", *i);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"File is neither a device node, nor regular file, nor executable: %s",
*i);
have_term = true;
} 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);
}
if (!strv_isempty(args) && !have_term) {
log_error("\"+\" can only be used between terms");
return -EINVAL;
}
if (!strv_isempty(args) && !have_term)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"\"+\" can only be used between terms");
return 0;
}
@ -1179,10 +1177,9 @@ static int discover_next_boot(sd_journal *j,
r = sd_journal_previous(j);
if (r < 0)
return r;
else if (r == 0) {
log_debug("Whoopsie! We found a boot ID but can't read its last entry.");
return -ENODATA; /* This shouldn't happen. We just came from this very boot ID. */
}
else if (r == 0)
return log_debug_errno(SYNTHETIC_ERRNO(ENODATA),
"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);
if (r < 0)
@ -1833,8 +1830,8 @@ finish:
return r;
#else
log_error("Forward-secure sealing not available.");
return -EOPNOTSUPP;
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Forward-secure sealing not available.");
#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");
}
if (pollfds[1].revents & (POLLHUP|POLLERR)) { /* STDOUT has been closed? */
log_debug("Standard output has been closed.");
return -ECANCELED;
}
if (pollfds[1].revents & (POLLHUP|POLLERR)) /* STDOUT has been closed? */
return log_debug_errno(SYNTHETIC_ERRNO(ECANCELED),
"Standard output has been closed.");
r = sd_journal_process(j);
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(fd == s->native_fd || fd == s->syslog_fd || fd == s->audit_fd);
if (revents != EPOLLIN) {
log_error("Got invalid event from epoll for datagram fd: %"PRIx32, revents);
return -EIO;
}
if (revents != EPOLLIN)
return log_error_errno(SYNTHETIC_ERRNO(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
* 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 (s->native_fd >= 0) {
log_error("Too many native sockets passed.");
return -EINVAL;
}
if (s->native_fd >= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many native sockets passed.");
s->native_fd = fd;
} else if (sd_is_socket_unix(fd, SOCK_STREAM, 1, "/run/systemd/journal/stdout", 0) > 0) {
if (s->stdout_fd >= 0) {
log_error("Too many stdout sockets passed.");
return -EINVAL;
}
if (s->stdout_fd >= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many stdout sockets passed.");
s->stdout_fd = fd;
} 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) {
if (s->syslog_fd >= 0) {
log_error("Too many /dev/log sockets passed.");
return -EINVAL;
}
if (s->syslog_fd >= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many /dev/log sockets passed.");
s->syslog_fd = fd;
} else if (sd_is_socket(fd, AF_NETLINK, SOCK_RAW, -1) > 0) {
if (s->audit_fd >= 0) {
log_error("Too many audit sockets passed.");
return -EINVAL;
}
if (s->audit_fd >= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Too many audit sockets passed.");
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);
if (revents != EPOLLIN) {
log_error("Got invalid event from epoll for stdout server fd: %"PRIx32, revents);
return -EIO;
}
if (revents != EPOLLIN)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Got invalid event from epoll for stdout server fd: %" PRIx32,
revents);
fd = accept4(s->stdout_fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC);
if (fd < 0) {

View File

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

View File

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

View File

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

View File

@ -137,10 +137,10 @@ int device_set_syspath(sd_device *device, const char *_syspath, bool verify) {
assert(_syspath);
/* must be a subdirectory of /sys */
if (!path_startswith(_syspath, "/sys/")) {
log_debug("sd-device: Syspath '%s' is not a subdirectory of /sys", _syspath);
return -EINVAL;
}
if (!path_startswith(_syspath, "/sys/"))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"sd-device: Syspath '%s' is not a subdirectory of /sys",
_syspath);
if (verify) {
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");
p = path_startswith(syspath, real_sys);
if (!p) {
log_debug("sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'", syspath, real_sys);
return -ENODEV;
}
if (!p)
return log_debug_errno(SYNTHETIC_ERRNO(ENODEV),
"sd-device: Canonicalized path '%s' does not starts with sysfs mount point '%s'",
syspath, real_sys);
new_syspath = strjoin("/sys/", p);
if (!new_syspath)

View File

@ -224,10 +224,10 @@ int sd_netlink_send(sd_netlink *nl,
int rtnl_rqueue_make_room(sd_netlink *rtnl) {
assert(rtnl);
if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX) {
log_debug("rtnl: exhausted the read queue size (%d)", RTNL_RQUEUE_MAX);
return -ENOBUFS;
}
if (rtnl->rqueue_size >= RTNL_RQUEUE_MAX)
return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
"rtnl: exhausted the read queue size (%d)",
RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue, rtnl->rqueue_allocated, rtnl->rqueue_size + 1))
return -ENOMEM;
@ -238,10 +238,10 @@ int rtnl_rqueue_make_room(sd_netlink *rtnl) {
int rtnl_rqueue_partial_make_room(sd_netlink *rtnl) {
assert(rtnl);
if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX) {
log_debug("rtnl: exhausted the partial read queue size (%d)", RTNL_RQUEUE_MAX);
return -ENOBUFS;
}
if (rtnl->rqueue_partial_size >= RTNL_RQUEUE_MAX)
return log_debug_errno(SYNTHETIC_ERRNO(ENOBUFS),
"rtnl: exhausted the partial read queue size (%d)",
RTNL_RQUEUE_MAX);
if (!GREEDY_REALLOC(rtnl->rqueue_partial, rtnl->rqueue_partial_allocated,
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();
}
if (strv_isempty(list)) {
log_error("Couldn't find any entries.");
return -ENOENT;
}
if (strv_isempty(list))
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
"Couldn't find any entries.");
strv_sort(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)
arg_action = ACTION_LIST;
else if (arg_action == ACTION_INHIBIT && optind >= argc) {
log_error("Missing command line to execute.");
return -EINVAL;
}
else if (arg_action == ACTION_INHIBIT && optind >= argc)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Missing command line to execute.");
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)
return bus_log_parse_error(r);
if (!uid_is_valid(uid)) {
log_error("Invalid user ID: " UID_FMT, uid);
return -EINVAL;
}
if (!uid_is_valid(uid))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid user ID: " UID_FMT,
uid);
bus_print_property_value(name, expected_value, value, UID_FMT, uid);
return 1;
@ -1419,10 +1419,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'n':
if (safe_atou(optarg, &arg_lines) < 0) {
log_error("Failed to parse lines '%s'", optarg);
return -EINVAL;
}
if (safe_atou(optarg, &arg_lines) < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse lines '%s'", optarg);
break;
case 'o':
@ -1432,10 +1431,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_output = output_mode_from_string(optarg);
if (arg_output < 0) {
log_error("Unknown output '%s'.", optarg);
return -EINVAL;
}
if (arg_output < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown output '%s'.", optarg);
break;
case ARG_NO_PAGER:
@ -1461,10 +1459,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_signal = signal_from_string(optarg);
if (arg_signal < 0) {
log_error("Failed to parse signal string %s.", optarg);
return -EINVAL;
}
if (arg_signal < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse signal string %s.", optarg);
break;
case 'H':

View File

@ -329,10 +329,10 @@ int button_open(Button *b) {
r = button_suitable(b);
if (r < 0)
return log_warning_errno(r, "Failed to determine whether input device is relevant to us: %m");
if (r == 0) {
log_debug("Device %s does not expose keys or switches relevant to us, ignoring.", p);
return -EADDRNOTAVAIL;
}
if (r == 0)
return log_debug_errno(SYNTHETIC_ERRNO(EADDRNOTAVAIL),
"Device %s does not expose keys or switches relevant to us, ignoring.",
p);
if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {
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)
return r;
if (!streq(load_state, "loaded")) {
log_notice("Unit %s is %s, refusing operation.", unit_name, load_state);
return -EACCES;
}
if (!streq(load_state, "loaded"))
return log_notice_errno(SYNTHETIC_ERRNO(EACCES),
"Unit %s is %s, refusing operation.",
unit_name, load_state);
/* Tell everybody to prepare for shutdown/sleep */
(void) send_prepare_for(m, w, true);

View File

@ -175,10 +175,9 @@ static int session_device_start(SessionDevice *sd) {
switch (sd->type) {
case DEVICE_TYPE_DRM:
if (sd->fd < 0) {
log_error("Failed to re-activate DRM fd, as the fd was lost (maybe logind restart went wrong?)");
return -EBADF;
}
if (sd->fd < 0)
return log_error_errno(SYNTHETIC_ERRNO(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
* 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;
User *user;
if (!uid) {
log_error("UID not specified for session %s", s->id);
return -ENOENT;
}
if (!uid)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
"UID not specified for session %s",
s->id);
r = parse_uid(uid, &u);
if (r < 0) {
@ -453,10 +453,10 @@ int session_load(Session *s) {
}
user = hashmap_get(s->manager->users, UID_TO_PTR(u));
if (!user) {
log_error("User of session %s not known.", s->id);
return -ENOENT;
}
if (!user)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
"User of session %s not known.",
s->id);
session_set_user(s, user);
}

View File

@ -824,10 +824,10 @@ static int manager_connect_console(Manager *m) {
* release events immediately.
*/
if (SIGRTMIN + 1 > SIGRTMAX) {
log_error("Not enough real-time signals available: %u-%u", SIGRTMIN, SIGRTMAX);
return -EINVAL;
}
if (SIGRTMIN + 1 > SIGRTMAX)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Not enough real-time signals available: %u-%u",
SIGRTMIN, SIGRTMAX);
assert_se(ignore_signals(SIGRTMIN + 1, -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_open();
if (argc != 3) {
log_error("This program takes two arguments.");
return -EINVAL;
}
if (!STR_IN_SET(argv[1], "start", "stop")) {
log_error("First argument must be either \"start\" or \"stop\".");
return -EINVAL;
}
if (argc != 3)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"This program takes two arguments.");
if (!STR_IN_SET(argv[1], "start", "stop"))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"First argument must be either \"start\" or \"stop\".");
r = mac_selinux_init();
if (r < 0)

View File

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

View File

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

View File

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

View File

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

View File

@ -525,8 +525,8 @@ static int mount_unified_cgroups(const char *dest) {
if (errno != ENOENT)
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 -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(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);

View File

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

View File

@ -94,69 +94,60 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) {
log_error("Failed to resolve user %s.", user);
return -ESRCH;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Failed to resolve user %s.", user);
if (r < 0)
return log_error_errno(r, "Failed to read from getent: %m");
(void) wait_for_terminate_and_check("getent passwd", pid, WAIT_LOG);
x = strchr(line, ':');
if (!x) {
log_error("/etc/passwd entry has invalid user field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid user field.");
u = strchr(x+1, ':');
if (!u) {
log_error("/etc/passwd entry has invalid password field.");
return -EIO;
}
if (!u)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid password field.");
u++;
g = strchr(u, ':');
if (!g) {
log_error("/etc/passwd entry has invalid UID field.");
return -EIO;
}
if (!g)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid UID field.");
*g = 0;
g++;
x = strchr(g, ':');
if (!x) {
log_error("/etc/passwd entry has invalid GID field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid GID field.");
*x = 0;
h = strchr(x+1, ':');
if (!h) {
log_error("/etc/passwd entry has invalid GECOS field.");
return -EIO;
}
if (!h)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid GECOS field.");
h++;
x = strchr(h, ':');
if (!x) {
log_error("/etc/passwd entry has invalid home directory field.");
return -EIO;
}
if (!x)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"/etc/passwd entry has invalid home directory field.");
*x = 0;
r = parse_uid(u, &uid);
if (r < 0) {
log_error("Failed to parse UID of user.");
return -EIO;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to parse UID of user.");
r = parse_gid(g, &gid);
if (r < 0) {
log_error("Failed to parse GID of user.");
return -EIO;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Failed to parse GID of user.");
home = strdup(h);
if (!home)
@ -176,10 +167,9 @@ int change_uid_gid(const char *user, char **_home) {
fd = -1;
r = read_line(f, LONG_LINE_MAX, &line);
if (r == 0) {
log_error("Failed to resolve user %s.", user);
return -ESRCH;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Failed to resolve user %s.", user);
if (r < 0)
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];
if (path_equal(m->destination, "/") && arg_userns_mode != USER_NAMESPACE_NO) {
if (arg_userns_chown) {
log_error("--private-users-chown may not be combined with custom root mounts.");
return -EINVAL;
} else if (arg_uid_shift == UID_INVALID) {
log_error("--private-users with automatic UID shift may not be combined with custom root mounts.");
return -EINVAL;
}
if (arg_userns_chown)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--private-users-chown may not be combined with custom root mounts.");
else if (arg_uid_shift == UID_INVALID)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--private-users with automatic UID shift may not be combined with custom root mounts.");
}
}
@ -609,10 +607,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_BRIDGE:
if (!ifname_valid(optarg)) {
log_error("Bridge interface name not valid: %s", optarg);
return -EINVAL;
}
if (!ifname_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Bridge interface name not valid: %s", optarg);
r = free_and_strdup(&arg_network_bridge, optarg);
if (r < 0)
@ -635,10 +632,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_NETWORK_INTERFACE:
if (!ifname_valid(optarg)) {
log_error("Network interface name not valid: %s", optarg);
return -EINVAL;
}
if (!ifname_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_interfaces, optarg) < 0)
return log_oom();
@ -649,10 +645,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_MACVLAN:
if (!ifname_valid(optarg)) {
log_error("MACVLAN network interface name not valid: %s", optarg);
return -EINVAL;
}
if (!ifname_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"MACVLAN network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_macvlan, optarg) < 0)
return log_oom();
@ -663,10 +658,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NETWORK_IPVLAN:
if (!ifname_valid(optarg)) {
log_error("IPVLAN network interface name not valid: %s", optarg);
return -EINVAL;
}
if (!ifname_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"IPVLAN network interface name not valid: %s", optarg);
if (strv_extend(&arg_network_ipvlan, optarg) < 0)
return log_oom();
@ -685,20 +679,18 @@ static int parse_argv(int argc, char *argv[]) {
break;
case 'b':
if (arg_start_mode == START_PID2) {
log_error("--boot and --as-pid2 may not be combined.");
return -EINVAL;
}
if (arg_start_mode == START_PID2)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--boot and --as-pid2 may not be combined.");
arg_start_mode = START_BOOT;
arg_settings_mask |= SETTING_START_MODE;
break;
case 'a':
if (arg_start_mode == START_BOOT) {
log_error("--boot and --as-pid2 may not be combined.");
return -EINVAL;
}
if (arg_start_mode == START_BOOT)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--boot and --as-pid2 may not be combined.");
arg_start_mode = START_PID2;
arg_settings_mask |= SETTING_START_MODE;
@ -709,10 +701,9 @@ static int parse_argv(int argc, char *argv[]) {
if (r < 0)
return log_error_errno(r, "Invalid UUID: %s", optarg);
if (sd_id128_is_null(arg_uuid)) {
log_error("Machine UUID may not be all zeroes.");
return -EINVAL;
}
if (sd_id128_is_null(arg_uuid))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Machine UUID may not be all zeroes.");
arg_settings_mask |= SETTING_MACHINE_ID;
break;
@ -725,10 +716,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg))
arg_machine = mfree(arg_machine);
else {
if (!machine_name_is_valid(optarg)) {
log_error("Invalid machine name: %s", optarg);
return -EINVAL;
}
if (!machine_name_is_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid machine name: %s", optarg);
r = free_and_strdup(&arg_machine, optarg);
if (r < 0)
@ -740,10 +730,9 @@ static int parse_argv(int argc, char *argv[]) {
if (isempty(optarg))
arg_hostname = mfree(arg_hostname);
else {
if (!hostname_is_valid(optarg, false)) {
log_error("Invalid hostname: %s", optarg);
return -EINVAL;
}
if (!hostname_is_valid(optarg, false))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid hostname: %s", optarg);
r = free_and_strdup(&arg_hostname, optarg);
if (r < 0)
@ -788,10 +777,9 @@ static int parse_argv(int argc, char *argv[]) {
int cap;
cap = capability_from_name(t);
if (cap < 0) {
log_error("Failed to parse capability %s.", t);
return -EINVAL;
}
if (cap < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse capability %s.", t);
if (c == ARG_CAPABILITY)
plus |= 1ULL << (uint64_t) cap;
@ -860,10 +848,9 @@ static int parse_argv(int argc, char *argv[]) {
case 'E': {
char **n;
if (!env_assignment_is_valid(optarg)) {
log_error("Environment variable assignment '%s' is not valid.", optarg);
return -EINVAL;
}
if (!env_assignment_is_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Environment variable assignment '%s' is not valid.", optarg);
n = strv_env_set(arg_setenv, optarg);
if (!n)
@ -902,10 +889,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PERSONALITY:
arg_personality = personality_from_string(optarg);
if (arg_personality == PERSONALITY_INVALID) {
log_error("Unknown or unsupported personality '%s'.", optarg);
return -EINVAL;
}
if (arg_personality == PERSONALITY_INVALID)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown or unsupported personality '%s'.", optarg);
arg_settings_mask |= SETTING_PERSONALITY;
break;
@ -921,10 +907,10 @@ static int parse_argv(int argc, char *argv[]) {
VolatileMode m;
m = volatile_mode_from_string(optarg);
if (m < 0) {
log_error("Failed to parse --volatile= argument: %s", optarg);
return -EINVAL;
} else
if (m < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse --volatile= argument: %s", optarg);
else
arg_volatile_mode = m;
}
@ -998,10 +984,9 @@ static int parse_argv(int argc, char *argv[]) {
arg_userns_mode = USER_NAMESPACE_FIXED;
}
if (arg_uid_range <= 0) {
log_error("UID range cannot be 0.");
return -EINVAL;
}
if (arg_uid_range <= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"UID range cannot be 0.");
arg_settings_mask |= SETTING_USERNS;
break;
@ -1031,10 +1016,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_kill_signal = signal_from_string(optarg);
if (arg_kill_signal < 0) {
log_error("Cannot parse signal: %s", optarg);
return -EINVAL;
}
if (arg_kill_signal < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Cannot parse signal: %s", optarg);
arg_settings_mask |= SETTING_KILL_SIGNAL;
break;
@ -1075,10 +1059,9 @@ static int parse_argv(int argc, char *argv[]) {
break;
case ARG_CHDIR:
if (!path_is_absolute(optarg)) {
log_error("Working directory %s is not an absolute path.", optarg);
return -EINVAL;
}
if (!path_is_absolute(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Working directory %s is not an absolute path.", optarg);
r = free_and_strdup(&arg_chdir, optarg);
if (r < 0)
@ -1097,10 +1080,9 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_NOTIFY_READY:
r = parse_boolean(optarg);
if (r < 0) {
log_error("%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg);
return -EINVAL;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s is not a valid notify mode. Valid modes are: yes, no, and ready.", optarg);
arg_notify_ready = r;
arg_settings_mask |= SETTING_NOTIFY_READY;
break;
@ -1165,20 +1147,18 @@ static int parse_argv(int argc, char *argv[]) {
}
eq = strchr(optarg, '=');
if (!eq) {
log_error("--rlimit= expects an '=' assignment.");
return -EINVAL;
}
if (!eq)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--rlimit= expects an '=' assignment.");
name = strndup(optarg, eq - optarg);
if (!name)
return log_oom();
rl = rlimit_from_string_harder(name);
if (rl < 0) {
log_error("Unknown resource limit: %s", name);
return -EINVAL;
}
if (rl < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown resource limit: %s", name);
if (!arg_rlimit[rl]) {
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);
if (arg_resolv_conf < 0) {
log_error("Failed to parse /etc/resolv.conf mode: %s", optarg);
return -EINVAL;
}
if (arg_resolv_conf < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse /etc/resolv.conf mode: %s", optarg);
arg_settings_mask |= SETTING_RESOLV_CONF;
break;
@ -1241,10 +1220,9 @@ static int parse_argv(int argc, char *argv[]) {
}
arg_timezone = timezone_mode_from_string(optarg);
if (arg_timezone < 0) {
log_error("Failed to parse /etc/localtime mode: %s", optarg);
return -EINVAL;
}
if (arg_timezone < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse /etc/localtime mode: %s", optarg);
arg_settings_mask |= SETTING_TIMEZONE;
break;
@ -1262,10 +1240,9 @@ static int parse_argv(int argc, char *argv[]) {
(arg_network_interfaces || arg_network_macvlan ||
arg_network_ipvlan || arg_network_veth_extra ||
arg_network_bridge || arg_network_zone ||
arg_network_veth || arg_private_network)) {
log_error("--network-namespace-path cannot be combined with other network options.");
return -EINVAL;
}
arg_network_veth || arg_private_network))
return log_error_errno(SYNTHETIC_ERRNO(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_PID", CLONE_NEWPID);
@ -1283,31 +1260,27 @@ static int parse_argv(int argc, char *argv[]) {
if (!(arg_clone_ns_flags & CLONE_NEWPID) ||
!(arg_clone_ns_flags & CLONE_NEWUTS)) {
arg_register = false;
if (arg_start_mode != START_PID1) {
log_error("--boot cannot be used without namespacing.");
return -EINVAL;
}
if (arg_start_mode != START_PID1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--boot cannot be used without namespacing.");
}
if (arg_userns_mode == USER_NAMESPACE_PICK)
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.
* 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 -EINVAL;
}
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--keep-unit --register=yes may not be used when invoked from a user session.");
if (arg_directory && arg_image) {
log_error("--directory= and --image= may not be combined.");
return -EINVAL;
}
if (arg_directory && arg_image)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--directory= and --image= may not be combined.");
if (arg_template && arg_image) {
log_error("--template= and --image= may not be combined.");
return -EINVAL;
}
if (arg_template && arg_image)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--template= and --image= may not be combined.");
if (arg_ephemeral && arg_template && !arg_directory) {
/* 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);
}
if (arg_template && !(arg_directory || arg_machine)) {
log_error("--template= needs --directory= or --machine=.");
return -EINVAL;
}
if (arg_template && !(arg_directory || arg_machine))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--template= needs --directory= or --machine=.");
if (arg_ephemeral && arg_template) {
log_error("--ephemeral and --template= may not be combined.");
return -EINVAL;
}
if (arg_ephemeral && arg_template)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--ephemeral and --template= may not be combined.");
if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO)) {
log_error("--ephemeral and --link-journal= may not be combined.");
return -EINVAL;
}
if (arg_ephemeral && !IN_SET(arg_link_journal, LINK_NO, LINK_AUTO))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--ephemeral and --link-journal= may not be combined.");
if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported()) {
log_error("--private-users= is not supported, kernel compiled without user namespace support.");
return -EOPNOTSUPP;
}
if (arg_userns_mode != USER_NAMESPACE_NO && !userns_supported())
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"--private-users= is not supported, kernel compiled without user namespace support.");
if (arg_userns_chown && arg_read_only) {
log_error("--read-only and --private-users-chown may not be combined.");
return -EINVAL;
}
if (arg_userns_chown && arg_read_only)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--read-only and --private-users-chown may not be combined.");
if (arg_network_bridge && arg_network_zone) {
log_error("--network-bridge= and --network-zone= may not be combined.");
return -EINVAL;
}
if (arg_network_bridge && arg_network_zone)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--network-bridge= and --network-zone= may not be combined.");
if (argc > optind) {
arg_parameters = strv_copy(argv + optind);
@ -1388,31 +1355,26 @@ static int parse_argv(int argc, char *argv[]) {
}
static int verify_arguments(void) {
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 -EINVAL;
}
if (arg_userns_mode != USER_NAMESPACE_NO && (arg_mount_settings & MOUNT_APPLY_APIVFS_NETNS) && !arg_private_network)
return log_error_errno(SYNTHETIC_ERRNO(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)) {
log_error("Cannot combine --private-users with read-write mounts.");
return -EINVAL;
}
if (arg_userns_mode != USER_NAMESPACE_NO && !(arg_mount_settings & MOUNT_APPLY_APIVFS_RO))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Cannot combine --private-users with read-write mounts.");
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 -EINVAL;
}
if (arg_volatile_mode != VOLATILE_NO && arg_read_only)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Cannot combine --read-only with --volatile. Note that --volatile already implies a read-only base hierarchy.");
if (arg_expose_ports && !arg_private_network) {
log_error("Cannot use --port= without private networking.");
return -EINVAL;
}
if (arg_expose_ports && !arg_private_network)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Cannot use --port= without private networking.");
#if ! HAVE_LIBIPTC
if (arg_expose_ports) {
log_error("--port= is not supported, compiled without libiptc support.");
return -EOPNOTSUPP;
}
if (arg_expose_ports)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"--port= is not supported, compiled without libiptc support.");
#endif
if (arg_start_mode == START_BOOT && arg_kill_signal <= 0)
@ -1804,12 +1766,10 @@ static int copy_devnodes(const char *dest) {
if (errno != ENOENT)
return log_error_errno(errno, "Failed to stat %s: %m", from);
} else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode)) {
log_error("%s is not a char or block device, cannot copy.", from);
return -EIO;
} else {
} else if (!S_ISCHR(st.st_mode) && !S_ISBLK(st.st_mode))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"%s is not a char or block device, cannot copy.", from);
else {
_cleanup_free_ char *sl = NULL, *prefixed = NULL, *dn = NULL, *t = NULL;
if (mknod(to, st.st_mode, st.st_rdev) < 0) {
@ -2071,16 +2031,16 @@ static int setup_journal(const char *directory) {
if (try)
return 0;
log_error("%s: already a mount point, refusing to use for journal", p);
return -EEXIST;
return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
"%s: already a mount point, refusing to use for journal", p);
}
if (path_is_mount_point(q, NULL, 0) > 0) {
if (try)
return 0;
log_error("%s: already a mount point, refusing to use for journal", q);
return -EEXIST;
return log_error_errno(SYNTHETIC_ERRNO(EEXIST),
"%s: already a mount point, refusing to use for journal", q);
}
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");
}
} else {
if (sd_id128_is_null(id)) {
log_error("Machine ID in container image is zero, refusing.");
return -EINVAL;
}
if (sd_id128_is_null(id))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Machine ID in container image is zero, refusing.");
arg_uuid = id;
}
@ -2336,12 +2295,12 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) {
_fallthrough_;
case CLD_DUMPED:
log_error("Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status));
return -EIO;
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status));
default:
log_error("Container %s failed due to unknown reason.", arg_machine);
return -EIO;
return log_error_errno(SYNTHETIC_ERRNO(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);
if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000))) {
log_error("UID and GID base of %s don't match.", directory);
return -EINVAL;
}
if (arg_uid_shift != (st.st_gid & UINT32_C(0xffff0000)))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"UID and GID base of %s don't match.", directory);
arg_uid_range = UINT32_C(0x10000);
}
if (arg_uid_shift > (uid_t) -1 - arg_uid_range) {
log_error("UID base too high for UID range.");
return -EINVAL;
}
if (arg_uid_shift > (uid_t) -1 - arg_uid_range)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"UID base too high for UID range.");
return 0;
}
@ -2595,10 +2552,9 @@ static int inner_child(
(void) barrier_place(barrier); /* #1 */
/* Wait until the parent wrote the UID map */
if (!barrier_place_and_sync(barrier)) { /* #2 */
log_error("Parent died too early");
return -ESRCH;
}
if (!barrier_place_and_sync(barrier)) /* #2 */
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Parent died too early");
}
r = reset_uid_gid();
@ -2627,10 +2583,9 @@ static int inner_child(
/* Wait until we are cgroup-ified, so that we
* can mount the right cgroup path writable */
if (!barrier_place_and_sync(barrier)) { /* #4 */
log_error("Parent died too early");
return -ESRCH;
}
if (!barrier_place_and_sync(barrier)) /* #4 */
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Parent died too early");
if (arg_use_cgns && cg_ns_supported()) {
r = unshare(CLONE_NEWCGROUP);
@ -2750,10 +2705,9 @@ static int inner_child(
/* Let the parent know that we are ready and
* wait until the parent is ready with the
* setup, too... */
if (!barrier_place_and_sync(barrier)) { /* #5 */
log_error("Parent died too early");
return -ESRCH;
}
if (!barrier_place_and_sync(barrier)) /* #5 */
return log_error_errno(SYNTHETIC_ERRNO(ESRCH),
"Parent died too early");
if (arg_chdir)
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);
if (l < 0)
return log_error_errno(errno, "Failed to send UID shift: %m");
if (l != sizeof(arg_uid_shift)) {
log_error("Short write while sending UID shift.");
return -EIO;
}
if (l != sizeof(arg_uid_shift))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short write while sending UID shift.");
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
@ -2954,10 +2907,9 @@ static int outer_child(
l = recv(uid_shift_socket, &arg_uid_shift, sizeof(arg_uid_shift), 0);
if (l < 0)
return log_error_errno(errno, "Failed to recv UID shift: %m");
if (l != sizeof(arg_uid_shift)) {
log_error("Short read while receiving UID shift.");
return -EIO;
}
if (l != sizeof(arg_uid_shift))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short read while receiving UID shift.");
}
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);
if (l < 0)
return log_error_errno(errno, "Failed to send cgroup mode: %m");
if (l != sizeof(arg_unified_cgroup_hierarchy)) {
log_error("Short write while sending cgroup mode.");
return -EIO;
}
if (l != sizeof(arg_unified_cgroup_hierarchy))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short write while sending cgroup mode.");
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);
if (l < 0)
return log_error_errno(errno, "Failed to send PID: %m");
if (l != sizeof(pid)) {
log_error("Short write while sending PID.");
return -EIO;
}
if (l != sizeof(pid))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short write while sending PID.");
l = send(uuid_socket, &arg_uuid, sizeof(arg_uuid), MSG_NOSIGNAL);
if (l < 0)
return log_error_errno(errno, "Failed to send machine ID: %m");
if (l != sizeof(arg_uuid)) {
log_error("Short write while sending machine ID.");
return -EIO;
}
if (l != sizeof(arg_uuid))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Short write while sending machine ID.");
l = send_one_fd(notify_socket, fd, 0);
if (l < 0)

View File

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

View File

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

View File

@ -100,8 +100,8 @@ static int print_home(const char *n) {
}
}
log_error("Path %s not known.", n);
return -EOPNOTSUPP;
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Path %s not known.", n);
}
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;
}
if (arg_transport != BUS_TRANSPORT_LOCAL) {
log_error("Operations on images by path not supported when connecting to remote systems.");
return -EOPNOTSUPP;
}
if (arg_transport != BUS_TRANSPORT_LOCAL)
return log_error_errno(SYNTHETIC_ERRNO(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);
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("-"))) {
if (!allow_any) {
log_error("Refusing all unit file match.");
return -EINVAL;
}
if (!allow_any)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Refusing all unit file match.");
if (!arg_quiet)
log_info("(Matching all unit files.)");
@ -896,10 +894,9 @@ static int parse_argv(int argc, char *argv[]) {
if (streq(optarg, "help"))
return dump_profiles();
if (!filename_is_valid(optarg)) {
log_error("Unit profile name not valid: %s", optarg);
return -EINVAL;
}
if (!filename_is_valid(optarg))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unit profile name not valid: %s", optarg);
arg_profile = optarg;
break;
@ -914,10 +911,9 @@ static int parse_argv(int argc, char *argv[]) {
"copy\n"
"symlink");
return 0;
} else {
log_error("Failed to parse --copy= argument: %s", optarg);
return -EINVAL;
}
} else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse --copy= argument: %s", optarg);
break;

View File

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

View File

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

View File

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

View File

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

View File

@ -91,10 +91,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
if (arg_ifname) {
assert(arg_ifindex >= 0);
if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX) {
log_error("Interface can't be the loopback interface (lo). Sorry.");
return -EINVAL;
}
if (!allow_loopback && arg_ifindex == LOOPBACK_IFINDEX)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Interface can't be the loopback interface (lo). Sorry.");
return 1;
}
@ -124,10 +123,9 @@ int ifname_mangle(const char *s, bool allow_loopback) {
}
}
if (!allow_loopback && r == LOOPBACK_IFINDEX) {
log_error("Interface can't be the loopback interface (lo). Sorry.");
return -EINVAL;
}
if (!allow_loopback && r == LOOPBACK_IFINDEX)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Interface can't be the loopback interface (lo). Sorry.");
arg_ifindex = r;
arg_ifname = TAKE_PTR(iface);
@ -579,10 +577,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL;
const char *e;
if (class != 0) {
log_error("DNS class specified twice.");
return -EINVAL;
}
if (class != 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"DNS class specified twice.");
e = strchrnul(f, ';');
t = strndup(f, e - f);
@ -590,10 +587,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom();
r = dns_class_from_string(t);
if (r < 0) {
log_error("Unknown DNS class %s.", t);
return -EINVAL;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown DNS class %s.", t);
class = r;
@ -610,10 +606,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
_cleanup_free_ char *t = NULL;
const char *e;
if (type != 0) {
log_error("DNS type specified twice.");
return -EINVAL;
}
if (type != 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"DNS type specified twice.");
e = strchrnul(f, ';');
t = strndup(f, e - f);
@ -621,10 +616,9 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return log_oom();
r = dns_type_from_string(t);
if (r < 0) {
log_error("Unknown DNS type %s.", t);
return -EINVAL;
}
if (r < 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown DNS type %s.", t);
type = r;
@ -649,8 +643,8 @@ static int resolve_rfc4501(sd_bus *bus, const char *name) {
return resolve_record(bus, n, class, type, true);
invalid:
log_error("Invalid DNS URI: %s", name);
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid DNS URI: %s", name);
}
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);
domain = strrchr(address, '@');
if (!domain) {
log_error("Address does not contain '@': \"%s\"", address);
return -EINVAL;
} else if (domain == address || domain[1] == '\0') {
log_error("Address starts or ends with '@': \"%s\"", address);
return -EINVAL;
}
if (!domain)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Address does not contain '@': \"%s\"", address);
if (domain == address || domain[1] == '\0')
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Address starts or ends with '@': \"%s\"", address);
domain++;
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;
else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6;
else {
log_error("Unknown protocol specifier: %s", optarg);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown protocol specifier: %s", optarg);
break;
@ -2585,26 +2577,24 @@ static int compat_parse_argv(int argc, char *argv[]) {
arg_mode = MODE_RESOLVE_TLSA;
if (!optarg || service_family_is_valid(optarg))
arg_service_family = optarg;
else {
log_error("Unknown service family \"%s\".", optarg);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown service family \"%s\".", optarg);
break;
case ARG_RAW:
if (on_tty()) {
log_error("Refusing to write binary data to tty.");
return -ENOTTY;
}
if (on_tty())
return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
"Refusing to write binary data to tty.");
if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET;
else {
log_error("Unknown --raw specifier \"%s\".", optarg);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown --raw specifier \"%s\".",
optarg);
arg_legend = false;
break;
@ -2716,15 +2706,13 @@ static int compat_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
if (arg_type == 0 && arg_class != 0) {
log_error("--class= may only be used in conjunction with --type=.");
return -EINVAL;
}
if (arg_type == 0 && arg_class != 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--class= may only be used in conjunction with --type=.");
if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE) {
log_error("--service and --type= may not be combined.");
return -EINVAL;
}
if (arg_type != 0 && arg_mode == MODE_RESOLVE_SERVICE)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--service and --type= may not be combined.");
if (arg_type != 0 && arg_class == 0)
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 (arg_ifindex <= 0) {
log_error("--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=.");
return -EINVAL;
}
if (arg_ifindex <= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--set-dns=, --set-domain=, --set-llmnr=, --set-mdns=, --set-dnsovertls=, --set-dnssec=, --set-nta= and --revert require --interface=.");
if (arg_ifindex == LOOPBACK_IFINDEX) {
log_error("Interface can't be the loopback interface (lo). Sorry.");
return -EINVAL;
}
if (arg_ifindex == LOOPBACK_IFINDEX)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Interface can't be the loopback interface (lo). Sorry.");
}
return 1 /* work to do */;
@ -2864,27 +2850,26 @@ static int native_parse_argv(int argc, char *argv[]) {
arg_flags |= SD_RESOLVED_MDNS_IPV4;
else if (streq(optarg, "mdns-ipv6"))
arg_flags |= SD_RESOLVED_MDNS_IPV6;
else {
log_error("Unknown protocol specifier: %s", optarg);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown protocol specifier: %s",
optarg);
break;
case ARG_RAW:
if (on_tty()) {
log_error("Refusing to write binary data to tty.");
return -ENOTTY;
}
if (on_tty())
return log_error_errno(SYNTHETIC_ERRNO(ENOTTY),
"Refusing to write binary data to tty.");
if (optarg == NULL || streq(optarg, "payload"))
arg_raw = RAW_PAYLOAD;
else if (streq(optarg, "packet"))
arg_raw = RAW_PACKET;
else {
log_error("Unknown --raw specifier \"%s\".", optarg);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown --raw specifier \"%s\".",
optarg);
arg_legend = false;
break;
@ -2928,10 +2913,9 @@ static int native_parse_argv(int argc, char *argv[]) {
assert_not_reached("Unhandled option");
}
if (arg_type == 0 && arg_class != 0) {
log_error("--class= may only be used in conjunction with --type=.");
return -EINVAL;
}
if (arg_type == 0 && arg_class != 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--class= may only be used in conjunction with --type=.");
if (arg_type != 0 && arg_class == 0)
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)
return -EINVAL;
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 -EOPNOTSUPP;
}
if (nsec3->nsec3.iterations > NSEC3_ITERATIONS_MAX)
return log_debug_errno(SYNTHETIC_ERRNO(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);
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
* allocate a DNS packet bigger than 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 -EFBIG;
}
if (min_alloc_dsize > DNS_PACKET_SIZE_MAX)
return log_error_errno(SYNTHETIC_ERRNO(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
* 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) {
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).",
aux->id,
dns_resource_key_to_string(t->key, s, sizeof s),
t->id,
dns_resource_key_to_string(aux->key, saux, sizeof saux));
return -ELOOP;
return log_debug_errno(SYNTHETIC_ERRNO(ELOOP),
"Potential cyclic dependency, refusing to add transaction %" PRIu16 " (%s) as dependency for %" PRIu16 " (%s).",
aux->id,
dns_resource_key_to_string(t->key, s, sizeof s),
t->id,
dns_resource_key_to_string(aux->key, saux, sizeof saux));
}
}
@ -2445,8 +2444,8 @@ static int dns_transaction_requires_rrsig(DnsTransaction *t, DnsResourceRecord *
return true;
/* A CNAME/DNAME without a parent? That's sooo weird. */
log_debug("Transaction %" PRIu16 " claims CNAME/DNAME at root. Refusing.", t->id);
return -EBADMSG;
return log_debug_errno(SYNTHETIC_ERRNO(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)
return log_debug_errno(r, "Failed to replace specifiers: %m");
if (!dns_service_name_is_valid(name)) {
log_debug("Service instance name '%s' is invalid.", name);
return -EINVAL;
}
if (!dns_service_name_is_valid(name))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"Service instance name '%s' is invalid.",
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:
return -EAGAIN;
default:
log_debug("Failed to invoke gnutls_record_send: %s", gnutls_strerror(ss));
return -EPIPE;
return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
"Failed to invoke gnutls_record_send: %s",
gnutls_strerror(ss));
}
return ss;
@ -178,8 +179,9 @@ ssize_t dnstls_stream_read(DnsStream *stream, void *buf, size_t count) {
case GNUTLS_E_AGAIN:
return -EAGAIN;
default:
log_debug("Failed to invoke gnutls_record_recv: %s", gnutls_strerror(ss));
return -EPIPE;
return log_debug_errno(SYNTHETIC_ERRNO(EPIPE),
"Failed to invoke gnutls_record_recv: %s",
gnutls_strerror(ss));
}
return ss;

View File

@ -174,8 +174,9 @@ int dnstls_stream_on_io(DnsStream *stream, uint32_t revents) {
char errbuf[256];
ERR_error_string_n(error, errbuf, sizeof(errbuf));
log_debug("Failed to invoke SSL_do_handshake: %s", errbuf);
return -ECONNREFUSED;
return log_debug_errno(SYNTHETIC_ERRNO(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);
if (r < 0)
return log_error_errno(r, "Couldn't extract address, in line /etc/hosts:%u.", nr);
if (r == 0) {
log_error("Premature end of line, in line /etc/hosts:%u.", nr);
return -EINVAL;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(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);
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;
}
if (!found) {
log_error("Line is missing any host names, in line /etc/hosts:%u.", nr);
return -EINVAL;
}
if (!found)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Line is missing any host names, in line /etc/hosts:%u.",
nr);
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);
if (r < 0)
return log_error_errno(r, "Failed to unescape host name: %m");
if (r == 0) {
log_error("Couldn't find a single label in hostname.");
return -EINVAL;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Couldn't find a single label in hostname.");
#if HAVE_LIBIDN2
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)
r = k;
if (!utf8_is_valid(label)) {
log_error("System hostname is not UTF-8 clean.");
return -EINVAL;
}
if (!utf8_is_valid(label))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"System hostname is not UTF-8 clean.");
decoded = label;
#else
decoded = label; /* no decoding */
@ -369,10 +367,9 @@ static int determine_hostname(char **full_hostname, char **llmnr_hostname, char
if (r < 0)
return log_error_errno(r, "Failed to escape host name: %m");
if (is_localhost(n)) {
log_debug("System hostname is 'localhost', ignoring.");
return -EINVAL;
}
if (is_localhost(n))
return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
"System hostname is 'localhost', ignoring.");
r = dns_name_concat(n, "local", mdns_hostname);
if (r < 0)

View File

@ -251,10 +251,9 @@ static int load_state(
l = write(rfkill_fd, &we, sizeof(we));
if (l < 0)
return log_error_errno(errno, "Failed to restore rfkill state for %i: %m", event->idx);
if (l != sizeof(we)) {
log_error("Couldn't write rfkill event structure, too short.");
return -EIO;
}
if (l != sizeof(we))
return log_error_errno(SYNTHETIC_ERRNO(EIO),
"Couldn't write rfkill event structure, too short.");
log_debug("Loaded state '%s' from %s.", one_zero(b), state_file);
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;
/* 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) {
log_error("Only single trigger (path, socket, timer) unit can be created.");
return -EINVAL;
}
if ((int) !!arg_path_property + (int) !!arg_socket_property + (int) with_timer > 1)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Only single trigger (path, socket, timer) unit can be created.");
if (arg_stdio == ARG_STDIO_AUTO) {
/* 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;
}
if ((optind >= argc) && (!arg_unit || !with_trigger)) {
log_error("Command line to execute required.");
return -EINVAL;
}
if ((optind >= argc) && (!arg_unit || !with_trigger))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Command line to execute required.");
if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL) {
log_error("Execution in user context is not supported on non-local systems.");
return -EINVAL;
}
if (arg_user && arg_transport != BUS_TRANSPORT_LOCAL)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Execution in user context is not supported on non-local systems.");
if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL) {
log_error("Scope execution is not supported on non-local systems.");
return -EINVAL;
}
if (arg_scope && arg_transport != BUS_TRANSPORT_LOCAL)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Scope execution is not supported on non-local systems.");
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 -EINVAL;
}
if (arg_scope && (arg_remain_after_exit || arg_service_type))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--remain-after-exit and --service-type= are not supported in --scope mode.");
if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope)) {
log_error("--pty/--pipe is not compatible in timer or --scope mode.");
return -EINVAL;
}
if (arg_stdio != ARG_STDIO_NONE && (with_trigger || arg_scope))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--pty/--pipe is not compatible in timer or --scope mode.");
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 -EINVAL;
}
if (arg_stdio != ARG_STDIO_NONE && arg_transport == BUS_TRANSPORT_REMOTE)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--pty/--pipe is only supported when connecting to the local system or containers.");
if (arg_stdio != ARG_STDIO_NONE && arg_no_block) {
log_error("--pty/--pipe is not compatible with --no-block.");
return -EINVAL;
}
if (arg_stdio != ARG_STDIO_NONE && arg_no_block)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--pty/--pipe is not compatible with --no-block.");
if (arg_scope && with_trigger) {
log_error("Path, socket or timer options are not supported in --scope mode.");
return -EINVAL;
}
if (arg_scope && with_trigger)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Path, socket or timer options are not supported in --scope mode.");
if (arg_timer_property && !with_timer) {
log_error("--timer-property= has no effect without any other timer options.");
return -EINVAL;
}
if (arg_timer_property && !with_timer)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--timer-property= has no effect without any other timer options.");
if (arg_wait) {
if (arg_no_block) {
log_error("--wait may not be combined with --no-block.");
return -EINVAL;
}
if (arg_no_block)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--wait may not be combined with --no-block.");
if (with_trigger) {
log_error("--wait may not be combined with path, socket or timer operations.");
return -EINVAL;
}
if (with_trigger)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--wait may not be combined with path, socket or timer operations.");
if (arg_scope) {
log_error("--wait may not be combined with --scope.");
return -EINVAL;
}
if (arg_scope)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"--wait may not be combined with --scope.");
}
return 1;
@ -787,10 +774,10 @@ static int make_unit_name(sd_bus *bus, UnitType t, char **ret) {
* name our transient units. */
id = startswith(unique, ":1.");
if (!id) {
log_error("Unique name %s has unexpected format.", unique);
return -EINVAL;
}
if (!id)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unique name %s has unexpected format.",
unique);
p = strjoin("run-u", id, ".", unit_type_to_string(t));
if (!p)

View File

@ -593,10 +593,10 @@ int find_esp_and_warn(
path = getenv("SYSTEMD_ESP_PATH");
if (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 -EINVAL;
}
if (!path_is_valid(path) || !path_is_absolute(path))
return log_error_errno(SYNTHETIC_ERRNO(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
* point. After all we want this to be useful for testing. */
@ -649,10 +649,9 @@ int find_default_boot_entry(
if (r < 0)
return log_error_errno(r, "Failed to load bootspec config from \"%s/loader\": %m", where);
if (config->default_entry < 0) {
log_error("No entry suitable as default, refusing to guess.");
return -ENOENT;
}
if (config->default_entry < 0)
return log_error_errno(SYNTHETIC_ERRNO(ENOENT),
"No entry suitable as default, refusing to guess.");
*e = &config->entries[config->default_entry];
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; \
\
r = parse_func(eq); \
if (r < 0) { \
log_error("Failed to parse %s: %s", field, eq); \
return -EINVAL; \
} \
if (r < 0) \
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to parse %s: %s", field, eq); \
\
r = sd_bus_message_append(m, "(sv)", field, \
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 '!':
/* The bus API doesn't support +, ! and !! currently, unfortunately. :-( */
log_error("Sorry, but +, ! and !! are currently not supported for transient services.");
return -EOPNOTSUPP;
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP),
"Sorry, but +, ! and !! are currently not supported for transient services.");
default:
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);
else {
r = parse_permille_unbounded(eq);
if (r == 0) {
log_error("CPU quota too small.");
return -ERANGE;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(ERANGE),
"CPU quota too small.");
if (r < 0)
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;
e = strchr(eq, ' ');
if (!e) {
log_error("Failed to parse %s value %s.", field, eq);
return -EINVAL;
}
if (!e)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse %s value %s.",
field, eq);
path = strndupa(eq, e - eq);
bandwidth = e+1;
@ -531,10 +528,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
uint64_t u;
e = strchr(eq, ' ');
if (!e) {
log_error("Failed to parse %s value %s.", field, eq);
return -EINVAL;
}
if (!e)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse %s value %s.",
field, eq);
path = strndupa(eq, e - eq);
weight = e+1;
@ -562,10 +559,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
usec_t usec;
e = strchr(eq, ' ');
if (!e) {
log_error("Failed to parse %s value %s.", field, eq);
return -EINVAL;
}
if (!e)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse %s value %s.",
field, eq);
path = strndupa(eq, e - eq);
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);
if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m");
if (r == 0) {
log_error("Missing argument after ':': %s", eq);
return -EINVAL;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Missing argument after ':': %s",
eq);
d = destination;
@ -1143,10 +1140,10 @@ static int bus_append_execute_property(sd_bus_message *m, const char *field, con
flags = MS_REC;
else if (streq(options, "norbind"))
flags = 0;
else {
log_error("Unknown options: %s", eq);
return -EINVAL;
}
else
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown options: %s",
eq);
}
} else
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);
if (r < 0)
return log_error_errno(r, "Failed to parse argument: %m");
if (r == 0) {
log_error("Failed to parse argument: %s", p);
return -EINVAL;
}
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Failed to parse argument: %s",
p);
r = sd_bus_message_append(m, "(ss)", path, w);
if (r < 0)
@ -1603,10 +1600,9 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
assert(assignment);
eq = strchr(assignment, '=');
if (!eq) {
log_error("Not an assignment: %s", assignment);
return -EINVAL;
}
if (!eq)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Not an assignment: %s", assignment);
field = strndupa(assignment, eq - assignment);
eq++;
@ -1709,20 +1705,20 @@ int bus_append_unit_property_assignment(sd_bus_message *m, UnitType t, const cha
case UNIT_TARGET:
case UNIT_DEVICE:
case UNIT_SWAP:
log_error("Not supported unit type");
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Not supported unit type");
default:
log_error("Invalid unit type");
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Invalid unit type");
}
r = bus_append_unit_property(m, field, eq);
if (r != 0)
return r;
log_error("Unknown assignment: %s", assignment);
return -EINVAL;
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"Unknown assignment: %s", assignment);
}
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"))
return 0;
log_debug("Unexpected job result, assuming server side newer than us: %s", d->result);
return -EIO;
return log_debug_errno(SYNTHETIC_ERRNO(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) {

View File

@ -1382,12 +1382,10 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, bool
if (user)
r = bus_connect_user_systemd(bus);
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. */
log_error("System has not been booted with systemd as init system (PID 1). Can't operate.");
return -EHOSTDOWN;
}
return log_error_errno(SYNTHETIC_ERRNO(EHOSTDOWN),
"System has not been booted with systemd as init system (PID 1). Can't operate.");
r = bus_connect_system_systemd(bus);
}
break;

View File

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

View File

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

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