From b80f07d2a7aa5ef619df1148885c263efe42559b Mon Sep 17 00:00:00 2001 From: matt335672 <30179339+matt335672@users.noreply.github.com> Date: Tue, 9 Jan 2024 11:47:49 +0000 Subject: [PATCH] Improve portability - Use clearenv() if it exists - Don't rely on being pulled in by - Rename the DEFAULT_TYPE macro in sesrun.c. This name appears to be used on Solaris. It's not a good choice. --- common/os_calls.c | 17 +++++++---------- configure.ac | 2 +- sesman/tools/sesrun.c | 8 ++++---- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/common/os_calls.c b/common/os_calls.c index 765ad472..d8062f72 100644 --- a/common/os_calls.c +++ b/common/os_calls.c @@ -95,16 +95,11 @@ struct sockaddr_hvs #endif #include "os_calls.h" +#include "limits.h" #include "string_calls.h" #include "log.h" #include "xrdp_constants.h" -/* for clearenv() */ -#if defined(_WIN32) -#else -extern char **environ; -#endif - #if defined(__linux__) #include #endif @@ -3446,14 +3441,16 @@ g_setpgid(int pid, int pgid) void g_clearenv(void) { -#if defined(_WIN32) -#else -#if defined(BSD) +#if defined(HAVE_CLEARENV) + clearenv(); +#elif defined(_WIN32) +#elif defined(BSD) + extern char **environ; environ[0] = 0; #else + extern char **environ; environ = 0; #endif -#endif } /*****************************************************************************/ diff --git a/configure.ac b/configure.ac index c6cb5ef7..c21f68da 100644 --- a/configure.ac +++ b/configure.ac @@ -211,7 +211,7 @@ AM_COND_IF([DEVEL_DEBUG], AC_SEARCH_LIBS([setusercontext], [util]) # Define HAVE_XXXXX macros for some system functions -AC_CHECK_FUNCS([setusercontext getgrouplist]) +AC_CHECK_FUNCS([setusercontext getgrouplist clearenv]) # The type used by getgrouplist() is the same type used by getgroups() AC_TYPE_GETGROUPS diff --git a/sesman/tools/sesrun.c b/sesman/tools/sesrun.c index affc7835..b727da35 100644 --- a/sesman/tools/sesrun.c +++ b/sesman/tools/sesrun.c @@ -68,8 +68,8 @@ # define DEFAULT_BPP 32 #endif -#ifndef DEFAULT_TYPE -# define DEFAULT_TYPE "Xorg" +#ifndef DEFAULT_SESSION_TYPE +# define DEFAULT_SESSION_TYPE "Xorg" #endif /** @@ -176,7 +176,7 @@ usage(void) g_printf(" -g Default:%dx%d\n", DEFAULT_WIDTH, DEFAULT_HEIGHT); g_printf(" -b Default:%d\n", DEFAULT_BPP); - g_printf(" -t Default:%s\n", DEFAULT_TYPE); + g_printf(" -t Default:%s\n", DEFAULT_SESSION_TYPE); g_printf(" -D Default: $HOME\n" " -S Default: Defined window manager\n" " -p TESTING ONLY - DO NOT USE IN PRODUCTION\n" @@ -290,7 +290,7 @@ parse_program_args(int argc, char *argv[], struct session_params *sp, sp->width = DEFAULT_WIDTH; sp->height = DEFAULT_HEIGHT; sp->bpp = DEFAULT_BPP; - (void)string_to_session_type(DEFAULT_TYPE, &sp->session_type); + (void)string_to_session_type(DEFAULT_SESSION_TYPE, &sp->session_type); sp->directory = ""; sp->shell = "";