httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Randy Terbush <ra...@zyzzyva.com>
Subject Centralized exec()
Date Sun, 14 Jul 1996 21:05:28 GMT

After processing some comments from RST regarding my approach to
centralizing the call to exec(), I submit the following patch
which is greatly simplified. This patch only effects util_script.*,
mod_cgi.c, and mod_include.c.  KISS

Since there were few arguments regarding the previous approach,
unless I hear something within the next few hours, I'll probably
commit this later tonight.


Index: src/mod_cgi.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_cgi.c,v
retrieving revision 1.10
diff -c -r1.10 mod_cgi.c
*** mod_cgi.c	1996/06/17 20:43:47	1.10
--- mod_cgi.c	1996/07/13 21:59:13
***************
*** 144,191 ****
      
      cleanup_for_exec();
      
! #ifdef __EMX__    
!     if((!r->args) || (!r->args[0]) || (ind(r->args,'=') >= 0)) {
!             int emxloop;
!             char *emxtemp;
! 
!             /* For OS/2 place the variables in the current
!             enviornment then it will be inherited. This way
!             the program will also get all of OS/2's other SETs. */
!             for (emxloop=0; ((emxtemp = env[emxloop]) != NULL); emxloop++)
!                 putenv(emxtemp);
!                 
!             if (strstr(strupr(r->filename), ".CMD") > 0) {
!                 /* Special case to allow use of REXX commands as scripts. */
!                 os2pathname(r->filename);
!                 execl("CMD.EXE", "CMD.EXE", "/C", r->filename, NULL);
!             } else {
!                 execl(r->filename, argv0, NULL);
!             }
!     } else {
!             int emxloop;
!             char *emxtemp;
!             
!             /* For OS/2 place the variables in the current
!             enviornment then it will be inherited. This way
!             the program will also get all of OS/2's other SETs. */
!             for (emxloop=0; ((emxtemp = env[emxloop]) != NULL); emxloop++)
!                 putenv(emxtemp);
!                 
!             if (strstr(strupr(r->filename), ".CMD") > 0) {
!                 /* Special case to allow use of REXX commands as scripts. */
!                 os2pathname(r->filename);
!                 execv("CMD.EXE", create_argv_cmd(r->pool, argv0, r->args, r->filename));
!             } else {
!                 execv(r->filename, create_argv(r->pool, argv0, r->args));
!             }
!     }
! #else
!     if((!r->args) || (!r->args[0]) || (ind(r->args,'=') >= 0)) 
!         execle(r->filename, argv0, NULL, env);
!     else 
!         execve(r->filename, create_argv(r->pool, argv0, r->args), env);
! #endif        
  
      /* Uh oh.  Still here.  Where's the kaboom?  There was supposed to be an
       * EARTH-shattering kaboom!
--- 144,150 ----
      
      cleanup_for_exec();
      
!     call_exec(r, argv0, env, 0);
  
      /* Uh oh.  Still here.  Where's the kaboom?  There was supposed to be an
       * EARTH-shattering kaboom!
Index: src/mod_include.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_include.c,v
retrieving revision 1.9
diff -c -r1.9 mod_include.c
*** mod_include.c	1996/06/07 21:15:33	1.9
--- mod_include.c	1996/07/13 21:59:52
***************
*** 479,486 ****
      fprintf (dbg, "Attempting to exec '%s'\n", s);
  #endif    
      cleanup_for_exec();
!     execle(SHELL_PATH, SHELL_PATH, "-c", s, NULL,
! 	   create_environment (r->pool, env));
      
      /* Oh, drat.  We're still here.  The log file descriptors are closed,
       * so we have to whimper a complaint onto stderr...
--- 479,486 ----
      fprintf (dbg, "Attempting to exec '%s'\n", s);
  #endif    
      cleanup_for_exec();
!     /* set shellcmd flag to pass arg to SHELL_PATH */
!     call_exec(r, s, create_environment (r->pool, env), 1);
      
      /* Oh, drat.  We're still here.  The log file descriptors are closed,
       * so we have to whimper a complaint onto stderr...
Index: src/util_script.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.c,v
retrieving revision 1.12
diff -c -r1.12 util_script.c
*** util_script.c	1996/06/03 12:04:20	1.12
--- util_script.c	1996/07/13 22:01:23
***************
*** 362,364 ****
--- 362,452 ----
  }
  #endif
  
+ 
+ void call_exec (request_rec *r, char *argv0, char **env, int shellcmd) 
+ {
+     
+ #ifdef RLIMIT_CPU
+     struct rlimit cpulim = { 9, 10 };
+ #endif
+ 
+ #ifdef RLIMIT_DATA
+     struct rlimit datalim = { 2000000, 2500000 };
+ #endif
+ 
+ #ifdef RLIMIT_NPROC
+     struct rlimit proclim = { 20, 40 };
+ #endif
+     
+ #ifdef RLIMIT_VMEM
+     struct rlimit vmlim = { 2000000, 2500000 };
+ #endif
+     
+ #ifdef RLIMIT_CPU
+     setrlimit (RLIMIT_CPU, &cpulim);
+ #endif
+ 
+ #ifdef RLIMIT_DATA
+     setrlimit (RLIMIT_DATA, &datalim);
+ #endif
+ 
+ #ifdef RLIMIT_NPROC
+     setrlimit (RLIMIT_NPROC, &proclim);
+ #endif
+     
+ #ifdef RLIMIT_VMEM
+     setrlimit (RLIMIT_VMEM, &vmlim);
+ #endif
+     
+ 
+ #ifdef __EMX__    
+     if ((!r->args) || (!r->args[0]) || (ind(r->args,'=') >= 0)) {
+ 	int emxloop;
+ 	char *emxtemp;
+ 
+ 	/* For OS/2 place the variables in the current
+ 	   enviornment then it will be inherited. This way
+ 	   the program will also get all of OS/2's other SETs. */
+ 	for (emxloop=0; ((emxtemp = env[emxloop]) != NULL); emxloop++)
+ 	    putenv(emxtemp);
+                 
+ 	if (strstr(strupr(r->filename), ".CMD") > 0) {
+ 	    /* Special case to allow use of REXX commands as scripts. */
+ 	    os2pathname(r->filename);
+ 	    execl("CMD.EXE", "CMD.EXE", "/C", r->filename, NULL);
+ 	}
+ 	else {
+ 	    execl(r->filename, argv0, NULL);
+ 	}
+     }
+     else {
+ 	int emxloop;
+ 	char *emxtemp;
+             
+ 	/* For OS/2 place the variables in the current
+ 	   enviornment then it will be inherited. This way
+ 	   the program will also get all of OS/2's other SETs. */
+ 	for (emxloop=0; ((emxtemp = env[emxloop]) != NULL); emxloop++)
+ 	    putenv(emxtemp);
+                 
+ 	if (strstr(strupr(r->filename), ".CMD") > 0) {
+ 	    /* Special case to allow use of REXX commands as scripts. */
+ 	    os2pathname(r->filename);
+ 	    execv("CMD.EXE", create_argv_cmd(r->pool, argv0, r->args, r->filename));
+ 	}
+ 	else
+ 	    execv(r->filename, create_argv(r->pool, argv0, r->args));
+     }
+ #else
+ 
+     if (shellcmd) 
+ 	execle(SHELL_PATH, SHELL_PATH, "-c", argv0, NULL, env);
+ 
+     else if((!r->args) || (!r->args[0]) || (ind(r->args,'=') >= 0))
+ 	execle(r->filename, argv0, NULL, env);
+ 
+     else
+ 	execve(r->filename, create_argv(r->pool, argv0, r->args), env);
+     
+ #endif
+ }
Index: src/util_script.h
===================================================================
RCS file: /export/home/cvs/apache/src/util_script.h,v
retrieving revision 1.3
diff -c -r1.3 util_script.h
*** util_script.h	1996/03/01 02:50:55	1.3
--- util_script.h	1996/07/13 22:01:25
***************
*** 61,64 ****
--- 61,65 ----
  void add_common_vars(request_rec *r);
  int scan_script_header(request_rec *r, FILE *f);
  void send_size(size_t size, request_rec *r);
+ void call_exec (request_rec *r, char *argv0, char **env, int shellcmd);
  



Mime
View raw message