You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by gs...@locus.apache.org on 2000/11/29 18:33:19 UTC

cvs commit: apache-2.0/src/modules/mpm/winnt mpm_winnt.c registry.c service.c

gstein      00/11/29 09:33:10

  Modified:    src/include httpd.h
               src/main http_main.c
               src/support ab.c
               src/modules/mpm/winnt mpm_winnt.c registry.c service.c
  Log:
  Use "const char * const *" for process->argv (which is the correct
  const-ness since we sometimes put "some string" in there, and also the CRT's
  argv). propagate this change within http_main and mpm/winnt/ (also correct
  some other const type usage within the MPM).
  
  fix ab's call to parse_url() which removed a const to actually manipulate an
  arg from the CRT's argv (indirectly via opt->arg). no idea how this has
  avoided segfaulting.
  
  Revision  Changes    Path
  1.120     +1 -1      apache-2.0/src/include/httpd.h
  
  Index: httpd.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/include/httpd.h,v
  retrieving revision 1.119
  retrieving revision 1.120
  diff -u -u -r1.119 -r1.120
  --- httpd.h	2000/11/26 04:47:27	1.119
  +++ httpd.h	2000/11/29 17:32:44	1.120
  @@ -597,7 +597,7 @@
       /** How many command line arguments were pass to the program */
       int argc;
       /** The command line arguments */
  -    char *const *argv;
  +    const char * const *argv;
       /** The program name used to execute the program */
       const char *short_name;
   };
  
  
  
  1.74      +15 -17    apache-2.0/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_main.c,v
  retrieving revision 1.73
  retrieving revision 1.74
  diff -u -u -r1.73 -r1.74
  --- http_main.c	2000/11/26 04:47:30	1.73
  +++ http_main.c	2000/11/29 17:32:53	1.74
  @@ -203,26 +203,24 @@
       exit(process_exit_value);
   }
   
  -static process_rec *create_process(int argc, char *const *argv)
  +static process_rec *create_process(int argc, const char * const *argv)
   {
       process_rec *process;
  -    
  -    {
  -	apr_pool_t *cntx;
  -        apr_status_t stat;
  -
  -	stat = apr_create_pool(&cntx, NULL);
  -        if (stat != APR_SUCCESS) {
  -            ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
  -                         "apr_create_pool() failed to create "
  -                         "initial context");
  -            apr_terminate();
  -            exit(1);
  -        }
  +    apr_pool_t *cntx;
  +    apr_status_t stat;
   
  -	process = apr_palloc(cntx, sizeof(process_rec));
  -	process->pool = cntx;
  +    stat = apr_create_pool(&cntx, NULL);
  +    if (stat != APR_SUCCESS) {
  +        ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, NULL,
  +                     "apr_create_pool() failed to create "
  +                     "initial context");
  +        apr_terminate();
  +        exit(1);
       }
  +
  +    process = apr_palloc(cntx, sizeof(process_rec));
  +    process->pool = cntx;
  +
       apr_create_pool(&process->pconf, process->pool);
       process->argc = argc;
       process->argv = argv;
  @@ -281,7 +279,7 @@
       destroy_and_exit_process(process, 1);
   }
   
  -int main(int argc, char *argv[])
  +int main(int argc, const char * const argv[])
   {
       char c;
       int configtestonly = 0;
  
  
  
  1.39      +3 -3      apache-2.0/src/support/ab.c
  
  Index: ab.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/support/ab.c,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -u -r1.38 -r1.39
  --- ab.c	2000/11/29 13:02:11	1.38
  +++ ab.c	2000/11/29 17:32:57	1.39
  @@ -893,14 +893,14 @@
   static void copyright(void)
   {
       if (!use_html) {
  -        printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.38 $> apache-2.0");
  +        printf("This is ApacheBench, Version %s\n", AB_VERSION " <$Revision: 1.39 $> apache-2.0");
           printf("Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n");
           printf("Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/\n");
           printf("\n");
       }
       else {
           printf("<p>\n");
  -        printf(" This is ApacheBench, Version %s <i>&lt;%s&gt;</i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.38 $");
  +        printf(" This is ApacheBench, Version %s <i>&lt;%s&gt;</i> apache-2.0<br>\n", AB_VERSION, "$Revision: 1.39 $");
           printf(" Copyright (c) 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n");
           printf(" Copyright (c) 1998-2000 The Apache Software Foundation, http://www.apache.org/<br>\n");
           printf("</p>\n<p>\n");
  @@ -1175,7 +1175,7 @@
           usage(argv[0]);
       }
   
  -    if (parse_url((char*)opt->argv[opt->ind++])) {
  +    if (parse_url(apr_pstrdup(cntxt, opt->argv[opt->ind++]))) {
           fprintf(stderr, "%s: invalid URL\n", argv[0]);
           usage(argv[0]);
       }
  
  
  
  1.114     +16 -17    apache-2.0/src/modules/mpm/winnt/mpm_winnt.c
  
  Index: mpm_winnt.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/mpm_winnt.c,v
  retrieving revision 1.113
  retrieving revision 1.114
  diff -u -u -r1.113 -r1.114
  --- mpm_winnt.c	2000/11/29 01:57:46	1.113
  +++ mpm_winnt.c	2000/11/29 17:33:01	1.114
  @@ -1789,7 +1789,7 @@
   }
   
   
  -#define SERVICE_UNNAMED -1
  +#define SERVICE_UNNAMED (-1)
   
   /* service_nt_main_fn needs to append the StartService() args 
    * outside of our call stack and thread as the service starts...
  @@ -1803,7 +1803,7 @@
   
   static apr_status_t service_to_start_success;
   static int inst_argc;
  -static char **inst_argv;
  +static const char * const *inst_argv;
       
   void winnt_rewrite_args(process_rec *process) 
   {
  @@ -1887,18 +1887,16 @@
        * initial pre-flight of the config parser.
        */
   
  -    mpm_new_argv = apr_make_array(process->pool, process->argc + 2, sizeof(char *));
  -    new_arg = (char**) apr_push_array(mpm_new_argv);
  -    *new_arg = (char *) process->argv[0];
  -    
  -    new_arg = (char**) apr_push_array(mpm_new_argv);
  -    *new_arg = "-d";
  -    new_arg = (char**) apr_push_array(mpm_new_argv);
  -    *new_arg = def_server_root;
  +    mpm_new_argv = apr_make_array(process->pool, process->argc + 2,
  +                                  sizeof(const char *));
  +    *(const char **)apr_push_array(mpm_new_argv) = process->argv[0];
  +    *(const char **)apr_push_array(mpm_new_argv) = "-d";
  +    *(const char **)apr_push_array(mpm_new_argv) = def_server_root;
   
       fixed_args = mpm_new_argv->nelts;
   
  -    optbuf[0] = '-'; optbuf[2] = '\0';
  +    optbuf[0] = '-';
  +    optbuf[2] = '\0';
       apr_initopt(&opt, process->pool, process->argc, (char**) process->argv);
       while (apr_getopt(opt, "n:k:iu" AP_SERVER_BASEARGS, 
                         optbuf + 1, &optarg) == APR_SUCCESS) {
  @@ -1920,11 +1918,11 @@
               signal_arg = "uninstall";
               break;
           default:
  -            new_arg = (char**) apr_push_array(mpm_new_argv);
  -            *new_arg = apr_pstrdup(process->pool, optbuf);
  +            *(const char **)apr_push_array(mpm_new_argv) =
  +                apr_pstrdup(process->pool, optbuf);
  +
               if (optarg) {
  -                new_arg = (char**) apr_push_array(mpm_new_argv);
  -                *new_arg = optarg;
  +                *(const char **)apr_push_array(mpm_new_argv) = optarg;
               }
               break;
           }
  @@ -2005,10 +2003,11 @@
        * These will be used for the -k install parameters, as well as
        * for the -k start service override arguments.
        */
  -    inst_argv = (char**) mpm_new_argv->elts + mpm_new_argv->nelts - inst_argc;
  +    inst_argv = (const char * const *)mpm_new_argv->elts
  +        + mpm_new_argv->nelts - inst_argc;
   
       process->argc = mpm_new_argv->nelts; 
  -    process->argv = (char**) mpm_new_argv->elts;
  +    process->argv = (const char * const *) mpm_new_argv->elts;
   }
   
   
  
  
  
  1.29      +3 -1      apache-2.0/src/modules/mpm/winnt/registry.c
  
  Index: registry.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/registry.c,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -u -r1.28 -r1.29
  --- registry.c	2000/10/06 17:24:42	1.28
  +++ registry.c	2000/11/29 17:33:02	1.29
  @@ -358,7 +358,9 @@
       return_error(rv);
   }
   
  -apr_status_t ap_registry_store_array(apr_pool_t *p, const char *key, const char *name, int nelts, char const* const* elts)
  +apr_status_t ap_registry_store_array(apr_pool_t *p,
  +                                     const char *key, const char *name,
  +                                     int nelts, const char * const * elts)
   {
       int  bufsize, i;
       char *buf, *tmp;
  
  
  
  1.26      +32 -27    apache-2.0/src/modules/mpm/winnt/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/winnt/service.c,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -u -r1.25 -r1.26
  --- service.c	2000/11/03 04:39:41	1.25
  +++ service.c	2000/11/29 17:33:03	1.26
  @@ -88,10 +88,11 @@
   #include "mpm_winnt.h"
   #include "apr_strings.h"
   
  -char const* service_name = NULL;
  -char const* display_name = NULL;
  -char const* signal_arg = NULL;
  -    
  +static const char * service_name = NULL;
  +
  +/* ### should be namespace-protected */
  +const char * display_name = NULL;
  +
   static struct
   {
       HANDLE mpm_thread;       /* primary thread handle of the apache server */
  @@ -536,7 +537,7 @@
       globdat.ssStatus.dwServiceSpecificExitCode = 0;
       globdat.ssStatus.dwCheckPoint = 1;
   
  -    if(!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl)))
  +    if (!(globdat.hServiceStatus = RegisterServiceCtrlHandler(argv[0], service_nt_ctrl)))
       {
           ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, apr_get_os_error(), 
                        NULL, "Failure registering service handler");
  @@ -594,9 +595,11 @@
        */
       if (argc > 1) 
       {
  -        char **cmb_data;
  -        cmb_data = apr_palloc(mpm_new_argv->cont, 
  -                             (mpm_new_argv->nelts + argc - 1) * sizeof(char *));
  +        const char **cmb_data;
  +
  +        mpm_new_argv->nalloc = mpm_new_argv->nelts + argc - 1;
  +        cmb_data = apr_palloc(mpm_new_argv->cont,
  +                              mpm_new_argv->nalloc * sizeof(const char *));
   
           /* mpm_new_argv remains first (of lower significance) */
           memcpy (cmb_data, mpm_new_argv->elts, 
  @@ -607,8 +610,8 @@
                   mpm_new_argv->elt_size * (argc - 1));
           
           /* The replacement arg list is complete */
  -        mpm_new_argv->elts = (char*) cmb_data;
  -        mpm_new_argv->nalloc = mpm_new_argv->nelts += argc - 1;
  +        mpm_new_argv->elts = (char *)cmb_data;
  +        mpm_new_argv->nelts = mpm_new_argv->nalloc;
       }
           
       /* Let the main thread continue now... but hang on to the
  @@ -670,7 +673,7 @@
   {
       apr_array_header_t *svc_args = NULL;
       char conf_key[MAX_PATH];
  -    char **cmb_data;
  +    const char **cmb_data;
       apr_status_t rv;
   
       apr_snprintf(conf_key, sizeof(conf_key), SERVICEPARAMS, service_name);
  @@ -696,22 +699,23 @@
        * time to _prepend_ the default arguments for the server from 
        * the service's default arguments (all others override them)...
        */
  -    cmb_data = apr_palloc(p, (args->nelts + svc_args->nelts) * sizeof(char *));
  +    args->nalloc = args->nelts + svc_args->nelts;
  +    cmb_data = apr_palloc(p, args->nalloc * sizeof(const char *));
   
       /* First three args (argv[0], -f, path) remain first */
  -    memcpy (cmb_data, args->elts, args->elt_size * fixed_args);
  +    memcpy(cmb_data, args->elts, args->elt_size * fixed_args);
       
       /* Service args follow from service registry array */
  -    memcpy (cmb_data + fixed_args, svc_args->elts, 
  -            svc_args->elt_size * svc_args->nelts);
  +    memcpy(cmb_data + fixed_args, svc_args->elts, 
  +           svc_args->elt_size * svc_args->nelts);
       
       /* Remaining new args follow  */
  -    memcpy (cmb_data + fixed_args + svc_args->nelts,
  -            (char**) args->elts + fixed_args, 
  -            args->elt_size * (args->nelts - fixed_args));
  +    memcpy(cmb_data + fixed_args + svc_args->nelts,
  +           (const char **)args->elts + fixed_args, 
  +           args->elt_size * (args->nelts - fixed_args));
       
  -    args->elts = (char*) cmb_data;
  -    args->nalloc = (args->nelts += svc_args->nelts);
  +    args->elts = (char *)cmb_data;
  +    args->nelts = args->nalloc;
   
       return APR_SUCCESS;
   }
  @@ -814,7 +818,7 @@
   
   
   apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, 
  -                                char const* const* argv)
  +                                 const char * const * argv)
   {
       char key_name[MAX_PATH];
       char exe_path[MAX_PATH];
  @@ -1020,7 +1024,7 @@
   
   
   apr_status_t mpm_service_start(apr_pool_t *ptemp, int argc, 
  -                              char const* const* argv)
  +                               const char * const * argv)
   {
       apr_status_t rv;
       
  @@ -1028,7 +1032,7 @@
   
       if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
       {
  -        char **start_argv;
  +        const char **start_argv;
           SC_HANDLE   schService;
           SC_HANDLE   schSCManager;
   
  @@ -1062,10 +1066,10 @@
           }
           
           argc += 1;
  -        start_argv = apr_palloc(ptemp, argc * sizeof(char**));
  -        start_argv[0] = (char*) service_name;
  +        start_argv = apr_palloc(ptemp, argc * sizeof(const char **));
  +        start_argv[0] = service_name;
           if (argc > 1)
  -            memcpy(start_argv + 1, argv, (argc - 1) * sizeof(char**));
  +            memcpy(start_argv + 1, argv, (argc - 1) * sizeof(const char **));
           
           rv = APR_EINIT;
           if (StartService(schService, argc, start_argv)
  @@ -1115,7 +1119,8 @@
           pCommand = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice", 
                                  exe_path, service_name);  
           for (i = 0; i < argc; ++i) {
  -            pCommand = apr_pstrcat(ptemp, pCommand, " \"", argv[i], "\"", NULL);
  +            pCommand = apr_pstrcat(ptemp, pCommand,
  +                                   " \"", argv[i], "\"", NULL);
           }
           
           memset(&si, 0, sizeof(si));