diff options
author | Mike Yuan <me@yhndnzj.com> | 2024-11-19 00:22:59 +0100 |
---|---|---|
committer | Mike Yuan <me@yhndnzj.com> | 2024-11-19 00:38:18 +0100 |
commit | d911778877c18827c64e21cc98e86c31dff9a627 (patch) | |
tree | 7c54652fdb0ceb37b8465e7cd5eac666a5c04750 /src/core | |
parent | basic/user-util: split out placeholder suppression from USER_CREDS_CLEAN into... (diff) | |
download | systemd-d911778877c18827c64e21cc98e86c31dff9a627.tar.xz systemd-d911778877c18827c64e21cc98e86c31dff9a627.zip |
core/exec-invoke: minor cleanup for apply_working_directory() error handling
Assign exit_status at the same site where error log is emitted,
for readability.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/exec-invoke.c | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/src/core/exec-invoke.c b/src/core/exec-invoke.c index 517727a7b2..31493049a1 100644 --- a/src/core/exec-invoke.c +++ b/src/core/exec-invoke.c @@ -3471,20 +3471,16 @@ static int apply_working_directory( const ExecContext *context, const ExecParameters *params, ExecRuntime *runtime, - const char *home, - int *exit_status) { + const char *home) { const char *wd; int r; assert(context); - assert(exit_status); if (context->working_directory_home) { - if (!home) { - *exit_status = EXIT_CHDIR; + if (!home) return -ENXIO; - } wd = home; } else @@ -3503,13 +3499,7 @@ static int apply_working_directory( if (r >= 0) r = RET_NERRNO(fchdir(dfd)); } - - if (r < 0 && !context->working_directory_missing_ok) { - *exit_status = EXIT_CHDIR; - return r; - } - - return 0; + return context->working_directory_missing_ok ? 0 : r; } static int apply_root_directory( @@ -5382,9 +5372,11 @@ int exec_invoke( * running this service might have the correct privilege to change to the working directory. Also, it * is absolutely 💣 crucial 💣 we applied all mount namespacing rearrangements before this, so that * the cwd cannot be used to pin directories outside of the sandbox. */ - r = apply_working_directory(context, params, runtime, home, exit_status); - if (r < 0) + r = apply_working_directory(context, params, runtime, home); + if (r < 0) { + *exit_status = EXIT_CHDIR; return log_exec_error_errno(context, params, r, "Changing to the requested working directory failed: %m"); + } if (needs_sandboxing) { /* Apply other MAC contexts late, but before seccomp syscall filtering, as those should really be last to |