mirror of
https://github.com/systemd/systemd
synced 2024-09-06 08:46:19 +00:00
notify: don't exit silently when --exec but no msg
Before this commit, if --exec is used but no message shall be sent, we silently ignore --exec and exit, which is pretty surprising. Therefore, let's emit clear error instead.
This commit is contained in:
parent
5d4cf5a87d
commit
953134a585
|
@ -273,22 +273,11 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optind >= argc &&
|
|
||||||
!arg_ready &&
|
|
||||||
!arg_stopping &&
|
|
||||||
!arg_reloading &&
|
|
||||||
!arg_status &&
|
|
||||||
!arg_pid &&
|
|
||||||
!arg_booted &&
|
|
||||||
fdset_isempty(arg_fds)) {
|
|
||||||
help();
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (arg_fdname && fdset_isempty(arg_fds))
|
if (arg_fdname && fdset_isempty(arg_fds))
|
||||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No file descriptors passed, but --fdname= set, refusing.");
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No file descriptors passed, but --fdname= set, refusing.");
|
||||||
|
|
||||||
size_t n_env;
|
bool have_env = arg_ready || arg_stopping || arg_reloading || arg_status || arg_pid > 0 || !fdset_isempty(arg_fds);
|
||||||
|
size_t n_arg_env;
|
||||||
|
|
||||||
if (do_exec) {
|
if (do_exec) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -306,12 +295,23 @@ static int parse_argv(int argc, char *argv[]) {
|
||||||
if (!arg_exec)
|
if (!arg_exec)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
|
||||||
n_env = i - optind;
|
n_arg_env = i - optind;
|
||||||
} else
|
} else
|
||||||
n_env = argc - optind;
|
n_arg_env = argc - optind;
|
||||||
|
|
||||||
if (n_env > 0) {
|
have_env = have_env || n_arg_env > 0;
|
||||||
arg_env = strv_copy_n(argv + optind, n_env);
|
|
||||||
|
if (!have_env && !arg_booted) {
|
||||||
|
if (do_exec)
|
||||||
|
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No notify message specified while --exec, refusing.");
|
||||||
|
|
||||||
|
/* No argument at all? */
|
||||||
|
help();
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n_arg_env > 0) {
|
||||||
|
arg_env = strv_copy_n(argv + optind, n_arg_env);
|
||||||
if (!arg_env)
|
if (!arg_env)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
}
|
}
|
||||||
|
@ -392,9 +392,7 @@ static int run(int argc, char* argv[]) {
|
||||||
final_env = strv_env_merge((char**) our_env, arg_env);
|
final_env = strv_env_merge((char**) our_env, arg_env);
|
||||||
if (!final_env)
|
if (!final_env)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
|
assert(!strv_isempty(final_env));
|
||||||
if (strv_isempty(final_env))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
msg = strv_join(final_env, "\n");
|
msg = strv_join(final_env, "\n");
|
||||||
if (!msg)
|
if (!msg)
|
||||||
|
|
Loading…
Reference in a new issue