/[monit]/monit/env.c
ViewVC logotype

Diff of /monit/env.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.15 by hauk, Thu Jun 26 14:24:11 2003 UTC revision 1.16 by martinp, Wed Jul 23 07:04:28 2003 UTC
# Line 127  void init_env() { Line 127  void init_env() {
127  static void set_sandbox(void) {  static void set_sandbox(void) {
128    
129    int    i;    int    i;
   int    max_descriptors = 1024;  
130    struct stat st;    struct stat st;
131    extern char **environ;    extern char **environ;
132    char   *path = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";    char   *path = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";
133    
134    /*    /*
135       * Purge the environment. Then make sure PATH is set; some shells default
136       * to a path with '.' first. You may have to putenv() other stuff, too,
137       * but be careful with importing too much.
138       */
139      environ[0]= 0;
140      
141      if(putenv(path)) {
142        
143        log("%s: cannot set the PATH variable -- %s\n", prog, STRERROR);
144        exit(1);
145        
146      }
147    
148      /*
149     * Require that file descriptors 0,1,2 are open. Mysterious things     * Require that file descriptors 0,1,2 are open. Mysterious things
150     * can happen if that is not the case.     * can happen if that is not the case.
151     */     */
# Line 147  static void set_sandbox(void) { Line 160  static void set_sandbox(void) {
160            
161    }    }
162    
163    /*    fd_close();
    * Require that the other file descriptios are closed. Everything  
    * seems to have getdtablesize, so we'll use it here, and back  
    * out to use 1024 if getdtablesize not available.  
    */  
 #ifdef HAVE_UNISTD_H  
   max_descriptors = getdtablesize();  
 #endif  
   for(i = 3; i < max_descriptors; i++)  
       (void) close(i);  
   errno= 0;  
   
   /*  
    * Purge the environment. Then make sure PATH is set; some shells default  
    * to a path with '.' first. You may have to putenv() other stuff, too,  
    * but be careful with importing too much.  
    */  
   environ[0]= 0;  
     
   if(putenv(path)) {  
       
     log("%s: cannot set the PATH variable -- %s\n", prog, STRERROR);  
     exit(1);  
       
   }  
164    
165  }  }
166    

Legend:
Removed from v.1.15  
changed lines
  Added in v.1.16

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26