ben         96/07/27 06:08:31

  Modified:    src       conf.h http_config.c http_config.h http_core.c
                        http_core.h
  Log:
  Major rehash of setrlimit stuff, for two reasons, first, to make it compile,
  and second, to remove much redundant code.
  
  Revision  Changes    Path
  1.26      +1 -0      apache/src/conf.h
  
  Index: conf.h
  ===================================================================
  RCS file: /export/home/cvs/apache/src/conf.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -C3 -r1.25 -r1.26
  *** conf.h    1996/07/25 19:49:03     1.25
  --- conf.h    1996/07/27 13:08:27     1.26
  ***************
  *** 217,222 ****
  --- 217,223 ----
    #define HAVE_SYS_SELECT_H
    #define USE_FCNTL_SERIALIZED_ACCEPT
    #define HAVE_MMAP
  + #define NEED_SYS_RESOURCE_H
    #define SecureWare
    
    /* Although SCO 5 defines these in <strings.h> (note the "s") they don't 
have
  
  
  
  1.15      +1 -0      apache/src/http_config.c
  
  Index: http_config.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/http_config.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -C3 -r1.14 -r1.15
  *** http_config.c     1996/07/16 19:39:12     1.14
  --- http_config.c     1996/07/27 13:08:28     1.15
  ***************
  *** 395,400 ****
  --- 395,401 ----
            return pstrcat (parms->pool, cmd->name, " not allowed here", NULL);
        
        parms->info = cmd->cmd_data;
  +     parms->cmd = cmd;
        
        switch (cmd->args_how) {
        case RAW_ARGS:
  
  
  
  1.8       +1 -0      apache/src/http_config.h
  
  Index: http_config.h
  ===================================================================
  RCS file: /export/home/cvs/apache/src/http_config.h,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -C3 -r1.7 -r1.8
  *** http_config.h     1996/07/16 19:39:12     1.7
  --- http_config.h     1996/07/27 13:08:28     1.8
  ***************
  *** 123,128 ****
  --- 123,129 ----
        char *path;                     /* If configuring for a directory,
                                 * pathname of that directory.
                                 */
  +     command_rec *cmd;               /* configuration command */
    } cmd_parms;
    
    /* This structure records the existence of handlers in a module... */
  
  
  
  1.21      +50 -83    apache/src/http_core.c
  
  Index: http_core.c
  ===================================================================
  RCS file: /export/home/cvs/apache/src/http_core.c,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -C3 -r1.20 -r1.21
  *** http_core.c       1996/07/27 02:49:34     1.20
  --- http_core.c       1996/07/27 13:08:29     1.21
  ***************
  *** 839,859 ****
        return NULL;
    }
    
  ! char *set_limit_cpu (cmd_parms *cmd, core_dir_config *conf, char *arg)
    {
  - #ifdef RLIMIT_CPU
        char *str;
  !     quad_t cur = 0;
  !     quad_t max = 0;
    
        if ((str = getword_conf(cmd->pool, &arg)))
        if (!strcasecmp(str, "max"))
  !         cur = conf->limit_cpu->rlim_max;
        else
            cur = atol(str);
        else {
  !     log_error("Invalid parameters for RLimitCPU", cmd->server);
  !     return NULL;
        }
        
        if ((str = getword_conf(cmd->pool, &arg)))
  --- 839,859 ----
        return NULL;
    }
    
  ! static void set_rlimit(cmd_parms *cmd, struct rlimit *limit, char *arg)
    {
        char *str;
  !     /* If your platform doesn't define rlim_t then typedef it in conf.h */
  !     rlim_t cur = 0;
  !     rlim_t max = 0;
    
        if ((str = getword_conf(cmd->pool, &arg)))
        if (!strcasecmp(str, "max"))
  !         cur = limit->rlim_max;
        else
            cur = atol(str);
        else {
  !     log_printf(cmd->server, "Invalid parameters for %s", cmd->cmd->name);
  !     return;
        }
        
        if ((str = getword_conf(cmd->pool, &arg)))
  ***************
  *** 861,957 ****
    
        /* if we aren't running as root, cannot increase max */
        if (geteuid()) {
  !     conf->limit_cpu->rlim_cur = cur;
        if (max)
  !         log_error("Must be uid 0 to raise maximum RLIMIT_CPU", cmd->server);
        }
        else {
        if (cur)
  !         conf->limit_cpu->rlim_cur = cur;
        if (max)
  !         conf->limit_cpu->rlim_max = max;
        }
  - #else
  -     log_error("RLimitCPU not supported on this platform", cmd->server);
  - #endif
  -     return NULL;
    }
    
  ! char *set_limit_mem (cmd_parms *cmd, core_dir_config *conf, char *arg)
    {
  ! #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM)
  !     char *str;
  !     quad_t cur = 0;
  !     quad_t max = 0;
  ! 
  !     if ((str = getword_conf(cmd->pool, &arg)))
  !     if (!strcasecmp(str, "max"))
  !         cur = conf->limit_mem->rlim_max;
  !     else
  !         cur = atol(str);
  !     else {
  !     log_error("Invalid parameters for RLimitMEM", cmd->server);
  !     return NULL;
  !     }
  !     
  !     if ((str = getword_conf(cmd->pool, &arg)))
  !     max = atol(str);
    
  !     /* if we aren't running as root, cannot increase max */
  !     if (geteuid()) {
  !     conf->limit_mem->rlim_cur = cur;
  !     if (max)
  !         log_error("Must be uid 0 to change maximum RLIMIT_MEM", 
cmd->server);
  !     }
  !     else {
  !     if (cur)
  !         conf->limit_mem->rlim_cur = cur;
  !     if (max)
  !         conf->limit_mem->rlim_max = max;
  !     }
  ! #else
  !     log_error("RLimitMEM not supported on this platform", cmd->server);
    #endif
        return NULL;
    }
    
    char *set_limit_nproc (cmd_parms *cmd, core_dir_config *conf, char *arg)
    {
  ! #ifdef RLIMIT_NPROC
  !     char *str;
  !     quad_t cur = 0;
  !     quad_t max = 0;
  ! 
  !     if ((str = getword_conf(cmd->pool, &arg)))
  !     if (!strcasecmp(str, "max"))
  !         cur = conf->limit_nproc->rlim_max;
  !     else
  !         cur = atol(str);
  !     else {
  !     log_error("Invalid parameters for RLimitNPROC", cmd->server);
  !     return NULL;
  !     }
  !     
  !     if ((str = getword_conf(cmd->pool, &arg)))
  !     max = atol(str);
  ! 
  !     /* if we aren't running as root, cannot increase max */
  !     if (geteuid()) {
  !     conf->limit_nproc->rlim_cur = cur;
  !     if (max)
  !         log_error("Must be uid 0 to raise maximum RLIMIT_NPROC", 
cmd->server);
  !     }
  !     else {
  !     if (cur)
  !         conf->limit_nproc->rlim_cur = cur;
  !     if (max)
  !         conf->limit_nproc->rlim_max = max;
  !     }
  ! #else
  !     log_error("RLimitNPROC not supported on this platform", cmd->server);
  ! #endif
        return NULL;
    }
    
    char *set_bind_address (cmd_parms *cmd, void *dummy, char *arg) {
        bind_address.s_addr = get_virthost_addr (arg, NULL);
  --- 861,909 ----
    
        /* if we aren't running as root, cannot increase max */
        if (geteuid()) {
  !     limit->rlim_cur = cur;
        if (max)
  !         log_printf(cmd->server, "Must be uid 0 to raise maximum %s",
  !                   cmd->cmd->name);
        }
        else {
        if (cur)
  !         limit->rlim_cur = cur;
        if (max)
  !         limit->rlim_max = max;
        }
    }
    
  ! static char *no_set_limit (cmd_parms *cmd, core_dir_config *conf, char *arg)
    {
  !     log_printf(cmd->server, "%s not supported on this platform",
  !            cmd->cmd->name);
  !     return NULL;
  ! }
    
  ! #ifdef RLIMIT_CPU
  ! char *set_limit_cpu (cmd_parms *cmd, core_dir_config *conf, char *arg)
  ! {
  !     set_rlimit(cmd,conf->limit_cpu,arg);
  !     return NULL;
  ! }
    #endif
  + 
  + #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM)
  + char *set_limit_mem (cmd_parms *cmd, core_dir_config *conf, char *arg)
  + {
  +     set_rlimit(cmd,conf->limit_mem,arg);
        return NULL;
    }
  + #endif
    
  + #ifdef RLIMIT_NPROC
    char *set_limit_nproc (cmd_parms *cmd, core_dir_config *conf, char *arg)
    {
  !     set_rlimit(cmd,conf->limit_nproc,arg);
        return NULL;
    }
  + #endif
    
    char *set_bind_address (cmd_parms *cmd, void *dummy, char *arg) {
        bind_address.s_addr = get_virthost_addr (arg, NULL);
  ***************
  *** 1064,1074 ****
    { "ServersSafetyLimit", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
    { "MaxClients", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
    { "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, TAKE1, NULL },
  ! { "RLimitCPU", set_limit_cpu, (void*)XtOffsetOf(core_dir_config, limit_cpu),
          OR_ALL, RAW_ARGS, "soft/hard limits for max CPU usage in seconds" },
  ! { "RLimitMEM", set_limit_mem, (void*)XtOffsetOf(core_dir_config, limit_mem),
          OR_ALL, RAW_ARGS, "soft/hard limits for max memory usage per process" 
},
  ! { "RLimitNPROC", set_limit_nproc, (void*)XtOffsetOf(core_dir_config, 
limit_nproc),
          OR_ALL, RAW_ARGS, "soft/hard limits for max number of processes per 
uid" },
    { "BindAddress", set_bind_address, NULL, RSRC_CONF, TAKE1,
      "'*', a numeric IP address, or the name of a host with a unique IP 
address"},
  --- 1016,1041 ----
    { "ServersSafetyLimit", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
    { "MaxClients", set_server_limit, NULL, RSRC_CONF, TAKE1, NULL },
    { "MaxRequestsPerChild", set_max_requests, NULL, RSRC_CONF, TAKE1, NULL },
  ! { "RLimitCPU",
  ! #ifdef RMLIMIT_CPU
  !  set_limit_cpu, (void*)XtOffsetOf(core_dir_config, limit_cpu),
  ! #else
  !  no_set_limit, NULL,
  ! #endif
          OR_ALL, RAW_ARGS, "soft/hard limits for max CPU usage in seconds" },
  ! { "RLimitMEM",
  ! #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM)
  !  set_limit_mem, (void*)XtOffsetOf(core_dir_config, limit_mem),
  ! #else
  !  no_set_limit, NULL,
  ! #endif
          OR_ALL, RAW_ARGS, "soft/hard limits for max memory usage per process" 
},
  ! { "RLimitNPROC",
  ! #ifdef RLIMIT_NPROC
  !  set_limit_nproc, (void*)XtOffsetOf(core_dir_config, limit_nproc),
  ! #else
  !  no_set_limit, NULL,
  ! #endif
          OR_ALL, RAW_ARGS, "soft/hard limits for max number of processes per 
uid" },
    { "BindAddress", set_bind_address, NULL, RSRC_CONF, TAKE1,
      "'*', a numeric IP address, or the name of a host with a unique IP 
address"},
  
  
  
  1.9       +5 -2      apache/src/http_core.h
  
  Index: http_core.h
  ===================================================================
  RCS file: /export/home/cvs/apache/src/http_core.h,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -C3 -r1.8 -r1.9
  *** http_core.h       1996/07/27 02:49:35     1.8
  --- http_core.h       1996/07/27 13:08:29     1.9
  ***************
  *** 108,113 ****
  --- 108,116 ----
    
    #ifdef CORE_PRIVATE
    
  + #ifdef NEED_SYS_RESOURCE_H
  +  #include <sys/resource.h>
  + #endif
    /*
     * Core is also unlike other modules in being implemented in more than
     * one file... so, data structures are declared here, even though most of
  ***************
  *** 156,165 ****
    #ifdef RLIMIT_CPU
        struct rlimit *limit_cpu;
    #endif
  ! #if defined(RLIMIT_DATA) || defined(RLIMIT_VMEM)
        struct rlimit *limit_mem;
    #endif
  ! #ifdef RLIMIT_NPROC    
        struct rlimit *limit_nproc;
    #endif
    
  --- 159,168 ----
    #ifdef RLIMIT_CPU
        struct rlimit *limit_cpu;
    #endif
  ! #if defined (RLIMIT_DATA) || defined (RLIMIT_VMEM)
        struct rlimit *limit_mem;
    #endif
  ! #ifdef RLIMIT_NPROC
        struct rlimit *limit_nproc;
    #endif
    
  
  
  

Reply via email to