inhibit: fix argv[] usage
Another fix in style of ed179fd710
and
bd169c2be0fbdaf6eb2ea7951e650d5e5983fbf6..
I hope we are soon complete with these.
Fixes: #12246
This commit is contained in:
parent
ab80eca144
commit
b473691d41
|
@ -286,8 +286,9 @@ static int run(int argc, char *argv[]) {
|
||||||
|
|
||||||
else {
|
else {
|
||||||
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
|
||||||
_cleanup_close_ int fd = -1;
|
_cleanup_strv_free_ char **arguments = NULL;
|
||||||
_cleanup_free_ char *w = NULL;
|
_cleanup_free_ char *w = NULL;
|
||||||
|
_cleanup_close_ int fd = -1;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
/* Ignore SIGINT and allow the forked process to receive it */
|
/* Ignore SIGINT and allow the forked process to receive it */
|
||||||
|
@ -303,12 +304,16 @@ static int run(int argc, char *argv[]) {
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
return log_error_errno(fd, "Failed to inhibit: %s", bus_error_message(&error, fd));
|
return log_error_errno(fd, "Failed to inhibit: %s", bus_error_message(&error, fd));
|
||||||
|
|
||||||
|
arguments = strv_copy(argv + optind);
|
||||||
|
if (!arguments)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
|
r = safe_fork("(inhibit)", FORK_RESET_SIGNALS|FORK_DEATHSIG|FORK_CLOSE_ALL_FDS|FORK_RLIMIT_NOFILE_SAFE|FORK_LOG, &pid);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
if (r == 0) {
|
if (r == 0) {
|
||||||
/* Child */
|
/* Child */
|
||||||
execvp(argv[optind], argv + optind);
|
execvp(arguments[0], arguments);
|
||||||
log_open();
|
log_open();
|
||||||
log_error_errno(errno, "Failed to execute %s: %m", argv[optind]);
|
log_error_errno(errno, "Failed to execute %s: %m", argv[optind]);
|
||||||
_exit(EXIT_FAILURE);
|
_exit(EXIT_FAILURE);
|
||||||
|
|
Loading…
Reference in a new issue