1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-17 06:04:07 +03:00

core/executor: do destruct static variables and selinux before exiting

I was wondering why I couldn't trigger the assertion in safe_fclose()
when submitting #30251. It turned out that the static destructor was
not run at all :/

Replace main() with a minimized version of main-func.h. This also
prevents emitting negative exit codes.
This commit is contained in:
Mike Yuan 2023-12-09 00:06:16 +08:00 committed by Yu Watanabe
parent f1e89cb9b1
commit ba8245a77a

View File

@ -19,9 +19,10 @@
#include "label-util.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "selinux-util.h"
#include "static-destruct.h"
static FILE* arg_serialization = NULL;
static FILE *arg_serialization = NULL;
STATIC_DESTRUCTOR_REGISTER(arg_serialization, fclosep);
@ -171,9 +172,8 @@ static int parse_argv(int argc, char *argv[]) {
return 1 /* work to do */;
}
int main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
_cleanup_fdset_free_ FDSet *fdset = NULL;
int exit_status = EXIT_SUCCESS, r;
_cleanup_(cgroup_context_done) CGroupContext cgroup_context = {};
_cleanup_(exec_context_done) ExecContext context = {};
_cleanup_(exec_command_done) ExecCommand command = {};
@ -188,15 +188,11 @@ int main(int argc, char *argv[]) {
.shared = &shared,
.dynamic_creds = &dynamic_creds,
};
int exit_status = EXIT_SUCCESS, r;
exec_context_init(&context);
cgroup_context_init(&cgroup_context);
/* We use safe_fork() for spawning sd-pam helper process, which internally calls rename_process().
* As the last step of renaming, all saved argvs are memzero()-ed. Hence, we need to save the argv
* first to prevent showing "intense" cmdline. See #30352. */
save_argc_argv(argc, argv);
/* We might be starting the journal itself, we'll be told by the caller what to do */
log_set_always_reopen_console(true);
log_set_prohibit_ipc(true);
@ -258,3 +254,19 @@ int main(int argc, char *argv[]) {
return exit_status;
}
int main(int argc, char *argv[]) {
int r;
/* We use safe_fork() for spawning sd-pam helper process, which internally calls rename_process().
* As the last step of renaming, all saved argvs are memzero()-ed. Hence, we need to save the argv
* first to prevent showing "intense" cmdline. See #30352. */
save_argc_argv(argc, argv);
r = run(argc, argv);
mac_selinux_finish();
static_destruct();
return r < 0 ? EXIT_FAILURE : r;
}