From 4b02d18f5ad4721211b8e17034d4da4ae3625476 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 10 May 2019 20:53:27 +1000 Subject: [PATCH] Don't fail service on failure to write utmp entry. This can simply be the result of the utmp database not existing on the system. --- src/baseproc-service.cc | 10 ++-------- src/includes/proc-service.h | 10 ++++------ 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index 43b3b75..b6809c4 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -154,15 +154,9 @@ bool base_process_service::start_ps_process(const std::vector &cmd if (forkpid == 0) { const char * working_dir_c = nullptr; if (! working_dir.empty()) working_dir_c = working_dir.c_str(); - if (after_fork(getpid())) { - run_child_proc(cmd.data(), working_dir_c, logfile, on_console, pipefd[1], control_socket[1], + after_fork(getpid()); + run_child_proc(cmd.data(), working_dir_c, logfile, on_console, pipefd[1], control_socket[1], socket_fd, notify_pipe[1], force_notification_fd, nullptr, run_as_uid, run_as_gid); - } - else { - int exec_status = errno; - write(pipefd[1], &exec_status, sizeof(int)); - _exit(0); - } } else { // Parent process diff --git a/src/includes/proc-service.h b/src/includes/proc-service.h index 4b6f5ab..fcb5f8c 100644 --- a/src/includes/proc-service.h +++ b/src/includes/proc-service.h @@ -145,9 +145,8 @@ class base_process_service : public service_record // Start the process, return true on success virtual bool bring_up() noexcept override; - // Called after forking (before executing remote process). Returns true to continue - // execution, otherwise sets errno and returns false. - virtual bool after_fork(pid_t child_pid) noexcept { return true; } + // Called after forking (before executing remote process). + virtual void after_fork(pid_t child_pid) noexcept { } // Called when the process exits. The exit_status is the status value yielded by // the "wait" system call. @@ -304,12 +303,11 @@ class process_service : public base_process_service char inittab_line[sizeof(utmpx().ut_line)]; protected: - bool after_fork(pid_t child_pid) noexcept override + void after_fork(pid_t child_pid) noexcept override { if (*inittab_id || *inittab_line) { - return create_utmp_entry(inittab_id, inittab_line, child_pid); + create_utmp_entry(inittab_id, inittab_line, child_pid); } - return true; } #endif -- 2.25.1