From bc9b35c38cac8fc35475c0af4e69d9294d7d575f Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Thu, 29 Jun 2023 15:20:39 +0100 Subject: [PATCH] Rename struct exit_status in os_calls This conflicts with struct exit_status in --- common/os_calls.c | 24 ++++++++++++++---------- common/os_calls.h | 16 ++++++++-------- sesman/sesexec/sesexec.c | 2 +- sesman/sesexec/session.c | 10 +++++----- sesman/sesexec/session.h | 4 ++-- sesman/sesexec/xwait.c | 6 +++--- tests/common/test_os_calls_signals.c | 14 +++++++------- xrdp/xrdp_listen.c | 4 ++-- 8 files changed, 42 insertions(+), 38 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index b8f6b633..da288fbe 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -3302,10 +3302,10 @@ g_set_allusercontext(int uid) /*****************************************************************************/ /* does not work in win32 returns pid of process that exits or zero if signal occurred - an exit_status struct can optionally be passed in to get the + a proc_exit_status struct can optionally be passed in to get the exit status of the child */ int -g_waitchild(struct exit_status *e) +g_waitchild(struct proc_exit_status *e) { #if defined(_WIN32) return 0; @@ -3313,14 +3313,14 @@ g_waitchild(struct exit_status *e) int wstat; int rv; - struct exit_status dummy; + struct proc_exit_status dummy; if (e == NULL) { e = &dummy; // Set this, then throw it away } - e->reason = E_XR_UNEXPECTED; + e->reason = E_PXR_UNEXPECTED; e->val = 0; rv = waitpid(-1, &wstat, WNOHANG); @@ -3335,12 +3335,12 @@ g_waitchild(struct exit_status *e) } else if (WIFEXITED(wstat)) { - e->reason = E_XR_STATUS_CODE; + e->reason = E_PXR_STATUS_CODE; e->val = WEXITSTATUS(wstat); } else if (WIFSIGNALED(wstat)) { - e->reason = E_XR_SIGNAL; + e->reason = E_PXR_SIGNAL; e->val = WTERMSIG(wstat); } @@ -3381,10 +3381,14 @@ g_waitpid(int pid) Note that signal handlers are established with BSD-style semantics, so this call is NOT interrupted by a signal */ -struct exit_status +struct proc_exit_status g_waitpid_status(int pid) { - struct exit_status exit_status = {.reason = E_XR_UNEXPECTED, .val = 0}; + struct proc_exit_status exit_status = + { + .reason = E_PXR_UNEXPECTED, + .val = 0 + }; #if !defined(_WIN32) if (pid > 0) @@ -3399,12 +3403,12 @@ g_waitpid_status(int pid) { if (WIFEXITED(status)) { - exit_status.reason = E_XR_STATUS_CODE; + exit_status.reason = E_PXR_STATUS_CODE; exit_status.val = WEXITSTATUS(status); } if (WIFSIGNALED(status)) { - exit_status.reason = E_XR_SIGNAL; + exit_status.reason = E_PXR_SIGNAL; exit_status.val = WTERMSIG(status); } } diff --git a/common/os_calls.h b/common/os_calls.h index aa64b41f..9fdbad8b 100644 --- a/common/os_calls.h +++ b/common/os_calls.h @@ -23,16 +23,16 @@ #include "arch.h" -enum exit_reason +enum proc_exit_reason { - E_XR_STATUS_CODE = 0, ///< 'val' contains exit status - E_XR_SIGNAL, ///< 'val' contains a signal number - E_XR_UNEXPECTED + E_PXR_STATUS_CODE = 0, ///< 'val' contains exit status + E_PXR_SIGNAL, ///< 'val' contains a signal number + E_PXR_UNEXPECTED }; -struct exit_status +struct proc_exit_status { - enum exit_reason reason; + enum proc_exit_reason reason; int val; }; @@ -352,9 +352,9 @@ int g_setlogin(const char *name); */ int g_set_allusercontext(int uid); #endif -int g_waitchild(struct exit_status *e); +int g_waitchild(struct proc_exit_status *e); int g_waitpid(int pid); -struct exit_status g_waitpid_status(int pid); +struct proc_exit_status g_waitpid_status(int pid); /* * Sets the process group ID of the indicated process to the specified value. * (POSIX.1) diff --git a/sesman/sesexec/sesexec.c b/sesman/sesexec/sesexec.c index 3e9763dd..67b493e8 100644 --- a/sesman/sesexec/sesexec.c +++ b/sesman/sesexec/sesexec.c @@ -241,7 +241,7 @@ sesexec_terminate_main_loop(int status) static void process_sigchld_event(void) { - struct exit_status e; + struct proc_exit_status e; int pid; // Check for any finished children diff --git a/sesman/sesexec/session.c b/sesman/sesexec/session.c index a54aa23e..7eb5399b 100644 --- a/sesman/sesexec/session.c +++ b/sesman/sesexec/session.c @@ -811,11 +811,11 @@ cleanup_sockets(int uid, int display) /******************************************************************************/ static void -exit_status_to_str(const struct exit_status *e, char buff[], int bufflen) +exit_status_to_str(const struct proc_exit_status *e, char buff[], int bufflen) { switch (e->reason) { - case E_XR_STATUS_CODE: + case E_PXR_STATUS_CODE: if (e->val == 0) { g_snprintf(buff, bufflen, "exit code zero"); @@ -826,7 +826,7 @@ exit_status_to_str(const struct exit_status *e, char buff[], int bufflen) } break; - case E_XR_SIGNAL: + case E_PXR_SIGNAL: { char sigstr[MAXSTRSIGLEN]; g_snprintf(buff, bufflen, "signal %s", @@ -844,7 +844,7 @@ exit_status_to_str(const struct exit_status *e, char buff[], int bufflen) void session_process_child_exit(struct session_data *sd, int pid, - const struct exit_status *e) + const struct proc_exit_status *e) { if (pid == sd->x_server) { @@ -864,7 +864,7 @@ session_process_child_exit(struct session_data *sd, { int wm_wait_time = g_time1() - sd->start_time; - if (e->reason == E_XR_STATUS_CODE && e->val == 0) + if (e->reason == E_PXR_STATUS_CODE && e->val == 0) { LOG(LOG_LEVEL_INFO, "Window manager (pid %d, display %d) " diff --git a/sesman/sesexec/session.h b/sesman/sesexec/session.h index dee9fe36..5cfab140 100644 --- a/sesman/sesexec/session.h +++ b/sesman/sesexec/session.h @@ -35,7 +35,7 @@ #include "xrdp_constants.h" struct login_info; -struct exit_status; +struct proc_exit_status; /** * Information used to start a session @@ -89,7 +89,7 @@ session_start(struct login_info *login_info, void session_process_child_exit(struct session_data *sd, int pid, - const struct exit_status *e); + const struct proc_exit_status *e); /** * Returns a count of active processes in the session diff --git a/sesman/sesexec/xwait.c b/sesman/sesexec/xwait.c index 9a7bd376..7531d451 100644 --- a/sesman/sesexec/xwait.c +++ b/sesman/sesexec/xwait.c @@ -142,7 +142,7 @@ wait_for_xserver(uid_t uid, } else { - struct exit_status e; + struct proc_exit_status e; fd[0] = -1; // File descriptor closed by fclose() log_waitforx_messages(dp); @@ -150,11 +150,11 @@ wait_for_xserver(uid_t uid, e = g_waitpid_status(pid); switch (e.reason) { - case E_XR_STATUS_CODE: + case E_PXR_STATUS_CODE: rv = (enum xwait_status)e.val; break; - case E_XR_SIGNAL: + case E_PXR_SIGNAL: { char sigstr[MAXSTRSIGLEN]; LOG(LOG_LEVEL_ERROR, diff --git a/tests/common/test_os_calls_signals.c b/tests/common/test_os_calls_signals.c index e917bfec..a44f9276 100644 --- a/tests/common/test_os_calls_signals.c +++ b/tests/common/test_os_calls_signals.c @@ -79,7 +79,7 @@ END_TEST /******************************************************************************/ START_TEST(test_g_signal_child_stop_1) { - struct exit_status e; + struct proc_exit_status e; g_reset_wait_obj(g_wobj1); ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0); @@ -98,7 +98,7 @@ START_TEST(test_g_signal_child_stop_1) e = g_waitpid_status(pid); - ck_assert_int_eq(e.reason, E_XR_STATUS_CODE); + ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE); ck_assert_int_eq(e.val, 45); // Try another one to make sure the signal handler is still in place. @@ -116,7 +116,7 @@ START_TEST(test_g_signal_child_stop_1) e = g_waitpid_status(pid); - ck_assert_int_eq(e.reason, E_XR_SIGNAL); + ck_assert_int_eq(e.reason, E_PXR_SIGNAL); ck_assert_int_eq(e.val, SIGSEGV); // Clean up @@ -133,7 +133,7 @@ START_TEST(test_g_signal_child_stop_2) int pids[CHILD_COUNT]; unsigned int i; - struct exit_status e; + struct proc_exit_status e; g_reset_wait_obj(g_wobj1); ck_assert_int_eq(g_is_wait_obj_set(g_wobj1), 0); @@ -157,7 +157,7 @@ START_TEST(test_g_signal_child_stop_2) for (i = 0 ; i < CHILD_COUNT; ++i) { e = g_waitpid_status(pids[i]); - ck_assert_int_eq(e.reason, E_XR_STATUS_CODE); + ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE); ck_assert_int_eq(e.val, (i + 1)); } @@ -246,12 +246,12 @@ START_TEST(test_waitpid_not_interrupted_by_sig) g_reset_wait_obj(g_wobj1); g_set_alarm(set_wobj1, 1); - struct exit_status e = g_waitpid_status(child_pid); + struct proc_exit_status e = g_waitpid_status(child_pid); // We should have had the alarm... ck_assert_int_ne(g_is_wait_obj_set(g_wobj1), 0); // ..and got the status of the child - ck_assert_int_eq(e.reason, E_XR_STATUS_CODE); + ck_assert_int_eq(e.reason, E_PXR_STATUS_CODE); ck_assert_int_eq(e.val, 42); // Clean up diff --git a/xrdp/xrdp_listen.c b/xrdp/xrdp_listen.c index 5dd9c19b..49426e8d 100644 --- a/xrdp/xrdp_listen.c +++ b/xrdp/xrdp_listen.c @@ -856,12 +856,12 @@ xrdp_listen_conn_in(struct trans *self, struct trans *new_self) static void process_pending_sigchld_events(void) { - struct exit_status e; + struct proc_exit_status e; int pid; while ((pid = g_waitchild(&e)) > 0) { - if (e.reason == E_XR_SIGNAL) + if (e.reason == E_PXR_SIGNAL) { char sigstr[MAXSTRSIGLEN]; LOG(LOG_LEVEL_ERROR,