From: Jim Jagielski Date: Mon, 3 Jun 2002 12:28:27 +0000 (+0000) Subject: Attached is a patch for allowing user changes on the cygwin platform X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e0d04ebac30ec7d93fbcecf4f94c33080f04e034;p=thirdparty%2Fapache%2Fhttpd.git Attached is a patch for allowing user changes on the cygwin platform and a #define wrapper for the timeout singal we use to kill of pending open childs that do not react on "usual" signals. The signalling issue seems to be a problem on the Cygwin platform, but it's abstracted, so other platforms may benefit from it. Again, nothing else is changed in behaviour. Changes are: * src/include/ap_config.h: added the system uid for Cygwin that is the "root" user on Cygwin * src/main/http_main.c: some cygwin specific #defines around setpgrp() and getuid() calls. Adding the #define SIG_TIMEOUT_KILL to define which singal should be used to kill of timed out childs. Defaulting to the know value for all other plaforms. * src/modules/proxy/proxy_cache.c: cygwin specific #define around setpgrp() PR: Obtained from: Submitted by: Stipe Tolj Reviewed by: git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@95482 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/include/ap_config.h b/src/include/ap_config.h index 47ed5199611..81a8ca59952 100644 --- a/src/include/ap_config.h +++ b/src/include/ap_config.h @@ -1003,8 +1003,10 @@ typedef int rlim_t; #define NEED_HASHBANG_EMUL #elif defined(CYGWIN) /* Cygwin 1.x POSIX layer for Win32 */ +#define SYSTEM_UID 18 #define JMP_BUF jmp_buf #define NO_KILLPG +#define NO_SETSID #define USE_LONGJMP #define GDBM_STATIC #define HAVE_MMAP 1 diff --git a/src/main/http_main.c b/src/main/http_main.c index f464d43071c..ce369c328b4 100644 --- a/src/main/http_main.c +++ b/src/main/http_main.c @@ -3409,6 +3409,13 @@ static void detach(void) #elif defined(MPE) /* MPE uses negative pid for process group */ pgrp = -getpid(); +#elif defined(CYGWIN) + /* Cygwin does not take any argument for setpgrp() */ + if ((pgrp = setpgrp()) == -1) { + perror("setpgrp"); + fprintf(stderr, "%s: setpgrp failed\n", ap_server_argv0); + exit(1); + } #else if ((pgrp = setpgrp(getpid(), 0)) == -1) { perror("setpgrp"); @@ -4225,8 +4232,15 @@ static void child_main(int child_num_arg) } GETUSERMODE(); #else - /* Only try to switch if we're running as root */ + /* + * Only try to switch if we're running as root + * In case of Cygwin we have the special super-user named SYSTEM + */ +#ifdef CYGWIN + if (getuid() == SYSTEM_UID && ( +#else if (!geteuid() && ( +#endif #ifdef _OSD_POSIX os_init_job_environment(server_conf, ap_user_name, one_process) != 0 || #endif @@ -4798,13 +4812,16 @@ static int hold_off_on_exponential_spawning; * is greater then ap_daemons_max_free. Usually we will use SIGUSR1 * to gracefully shutdown, but unfortunatly some OS will need other * signals to ensure that the child process is terminated and the - * scoreboard pool is not growing to infinity. This effect has been - * seen at least on Cygwin 1.x. -- Stipe Tolj + * scoreboard pool is not growing to infinity. Also set the signal we + * use to kill of childs that exceed timeout. This effect has been +* seen at least on Cygwin 1.x. -- Stipe Tolj */ #if defined(CYGWIN) #define SIG_IDLE_KILL SIGKILL +#define SIG_TIMEOUT_KILL SIGUSR2 #else #define SIG_IDLE_KILL SIGUSR1 +#define SIG_TIMEOUT_KILL SIGALRM #endif static void perform_idle_server_maintenance(void) @@ -4876,7 +4893,7 @@ static void perform_idle_server_maintenance(void) else if (ps->last_rtime + ss->timeout_len < now) { /* no progress, and the timeout length has been exceeded */ ss->timeout_len = 0; - kill(ps->pid, SIGALRM); + kill(ps->pid, SIG_TIMEOUT_KILL); } } #endif @@ -5492,8 +5509,16 @@ int REALMAIN(int argc, char *argv[]) } GETUSERMODE(); #else - /* Only try to switch if we're running as root */ + /* + * Only try to switch if we're running as root + * In case of Cygwin we have the special super-user named SYSTEM + * with a pre-defined uid. + */ +#ifdef CYGWIN + if ((getuid() == SYSTEM_UID) && setuid(ap_user_id) == -1) { +#else if (!geteuid() && setuid(ap_user_id) == -1) { +#endif ap_log_error(APLOG_MARK, APLOG_ALERT, server_conf, "setuid: unable to change to uid: %ld", (long) ap_user_id); @@ -7686,7 +7711,7 @@ __declspec(dllimport) #endif -int ap_main(int argc, char *argv[]); /* Load time linked from libhttpd.dll */ +int ap_main(int argc, char *argv[]); /* Load time linked from cyghttpd.dll */ int main(int argc, char *argv[]) { diff --git a/src/modules/proxy/proxy_cache.c b/src/modules/proxy/proxy_cache.c index 390488438c1..ff2bb0681f2 100644 --- a/src/modules/proxy/proxy_cache.c +++ b/src/modules/proxy/proxy_cache.c @@ -248,6 +248,14 @@ static void detached_proxy_garbage_coll(request_rec *r) ap_server_argv0); exit(1); } +#elif defined(CYGWIN) + /* Cygwin does not take any argument for setpgrp() */ + if ((pgrp = setpgrp()) == -1) { + perror("setpgrp"); + fprintf(stderr, "%S: setpgrp failed\n", + ap_server_argv0); + exit(1); + } #else if ((pgrp = setpgrp(getpid(), 0)) == -1) { perror("setpgrp");