Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, October 16, 2026

Diff for ep/src/conf.c between version 1.14 and 1.15

version 1.14, 2002/02/25 18:45:52 version 1.15, 2002/02/28 09:23:29
Line 103  static int add_processes_to_proctable(
Line 103  static int add_processes_to_proctable(
  * Function definitions   * Function definitions
  */   */
   
   /*
    *      PARSING SCHEME (do not delete)
    *      ------------------------------
    *
    *      conf_cmdline_parse_process();
    *      if (error) {
    *              conf_cmdline_parse_global();
    *              if (err) {
    *                      fail;
    *              }
    *
    *              if (config_file) {
    *                      conf_cfgfile_parse_all();
    *              }
    *      }
    *
    *      while(1) {
    *
    *              conf_cmdline_parse_process();
    *
    *              if (error) {
    *                      fail;
    *              }
    *      }
    */
   
   
         PROCTABLE          PROCTABLE
 conf_parse_all(argc, argv)  conf_parse_all(argc, argv)
         int    argc;          int    argc;
Line 122  conf_parse_all(argc, argv)
Line 149  conf_parse_all(argc, argv)
         ret = conf_cmdline_parse(argc - 1, argv + 1, &global, &processes);          ret = conf_cmdline_parse(argc - 1, argv + 1, &global, &processes);
   
         if (ret != CFG_OK) {          if (ret != CFG_OK) {
                   /* TODO: better error informations */
                 msg_error_print("command line parsing error %d\n", ret);                  msg_error_print("command line parsing error %d\n", ret);
                 /* TODO: free structures */                  /* TODO: free structures */
                 return NULL;                  return NULL;
Line 237  conf_parse_all(argc, argv)
Line 265  conf_parse_all(argc, argv)
                 return NULL;                  return NULL;
         }          }
   
           /* TODO: error check */
         add_processes_to_proctable(&ptbl, processes, start_idx_size, start_idx);          add_processes_to_proctable(&ptbl, processes, start_idx_size, start_idx);
   
         free(start_idx);          free(start_idx);
Line 371  conf_cmdline_parse(argc, argv, global, p
Line 400  conf_cmdline_parse(argc, argv, global, p
                 else if (ret == CFG_ERR_STOP_STR_FOUND) {                  else if (ret == CFG_ERR_STOP_STR_FOUND) {
                         if (cfg_get_cur_idx(cur_context) < 1) {                          if (cfg_get_cur_idx(cur_context) < 1) {
                                 if (! first_loop) {                                  if (! first_loop) {
                                         msg_error_print("misplaced process separator '--'\n");                                          msg_error_print("misplaced process separator '--'"
                                                           " on command line");
                                         break;                                          break;
                                 }                                  }
                         }                          }
Line 458  check_process_context(void)
Line 487  check_process_context(void)
         static int          static int
 check_context(context, options)  check_context(context, options)
         CFG_CONTEXT       *context;          CFG_CONTEXT       *context;
         struct cfg_option options[];          struct cfg_option options[];
 {  {
         if (*context == NULL) {          if (*context == NULL) {
                 if ((*context = cfg_get_context(options)) == NULL)                  if ((*context = cfg_get_context(options)) == NULL)
Line 615  add_processes_to_processes(dest_processe
Line 644  add_processes_to_processes(dest_processe
         return 1;          return 1;
 }  }
   
   /*
    * XXX: TODO: FIXME: reindexing proctable! remove +1 above too
    */
   
         static int          static int
 add_processes_to_proctable(p_ptbl, processes, start_idx_size, start_idx)  add_processes_to_proctable(p_ptbl, processes, start_idx_size, start_idx)
         PROCTABLE                  *p_ptbl;          PROCTABLE                  *p_ptbl;
Line 709  add_processes_to_proctable(p_ptbl, proce
Line 742  add_processes_to_proctable(p_ptbl, proce
   
                                                 fd_str = ar[1];                                                  fd_str = ar[1];
   
                                                 if (*char_in_name == '\0') { /* number init */                                                  /*
                                                    * Process link initialization by local number
                                                    */
   
                                                   if (*char_in_name == '\0') {
                                                         char *end;                                                          char *end;
                                                         link.proc_id = (int) strtol(ar[0], &end, 0);                                                          link.proc_id = (int) strtol(ar[0], &end, 0);
   
Line 732  add_processes_to_proctable(p_ptbl, proce
Line 769  add_processes_to_proctable(p_ptbl, proce
                                                         return -1;                                                          return -1;
                                                 }                                                  }
   
                                                   /*
                                                    * Process link initialization by name
                                                    */
   
                                                 /* Searching name in existing proctable. */                                                  /* Searching name in existing proctable. */
                                                 link.proc_id = proctable_get_process_index_by_name(                                                  link.proc_id = proctable_get_process_index_by_name(
                                                                 new_ptbl, ar[0]);                                                                  new_ptbl, ar[0]);
Line 744  add_processes_to_proctable(p_ptbl, proce
Line 785  add_processes_to_proctable(p_ptbl, proce
                                                                 processes, ar[0]);                                                                  processes, ar[0]);
   
                                                 if (link.proc_id >= 0) {                                                  if (link.proc_id >= 0) {
                                                           link.proc_id += 1;
                                                         link.proc_id += start_idx[resource_idx];                                                          link.proc_id += start_idx[resource_idx];
                                                         break;                                                          break;
                                                 }                                                  }
Line 789  add_processes_to_proctable(p_ptbl, proce
Line 831  add_processes_to_proctable(p_ptbl, proce
         return 0;          return 0;
 }  }
   
 #if 0  
   
 static PROCTABLE proc_ar_to_proctable(int n_proc_ar,  
                 struct conf_struct_process *proc_ar);  
 static int conf_cmdline_parse_process(int argc, char **argv, int silent);  
 static int conf_cmdline_parse_global(int argc, char **argv);  
   
         PROCTABLE  
 conf_process(argc, argv)  
         int  argc;  
         char **argv;  
 {  
         register int idx;  
         register int index;  
         register int n_proc_ar;  
         register int first_loop;  
         struct conf_struct_process *proc_ar;  
         PROCTABLE ptbl;  
   
         /*  
          *      PARSING SCHEME (do not delete)  
          *      ------------------------------  
          *  
          *      conf_cmdline_parse_process();  
          *      if (error) {  
          *              conf_cmdline_parse_global();  
          *              if (err) {  
          *                      fail;  
          *              }  
          *  
          *              if (config_file) {  
          *                      conf_cfgfile_parse_all();  
          *              }  
          *      }  
          *  
          *      while(1) {  
          *  
          *              conf_cmdline_parse_process();  
          *  
          *              if (error) {  
          *                      fail;  
          *              }  
          *      }  
          */  
   
         idx = 1;  
         index = 1;  
         first_loop = 1;  
         n_proc_ar = 0;  
         proc_ar = NULL;  
         ptbl = NULL;  
   
         memset((void *) &global_cfg, '\0',  
                         sizeof(struct conf_struct_global));  
   
         for (first_loop = 1; idx != 0 && index < argc; first_loop = 0) {  
   
                 idx = conf_cmdline_parse_process(argc - index, argv + index,  
                                 first_loop ? 1 : 0);  
   
                 if (idx < 0) {  
                         if (first_loop) {  
                                 if (idx == CFG_ERROR_STOP_STR) {  
                                         index += 1;  
                                         continue;  
                                 }  
 #if DEBUG  
                                 msg_debug_print("conf_process(): global options detected,"  
                                                 " idx = %d\n", idx);  
 #endif  
                                 /* Global options parsing. */  
                                 idx = conf_cmdline_parse_global(argc - index, argv + index);  
                                 if (idx < 0)  
                                         return NULL;  
   
                                 index += idx + 1;  
   
                                 continue;  
                         }  
                         else {  
                                 if (proc_ar != NULL)  
                                         free(proc_ar);  
                                 return NULL;  
                         }  
                 }  
   
                 /* TODO: which process on command line? */  
                 if (process_cfg.argv == NULL) {  
                         msg_error_print("one of process doesn't have specified"  
                                         " what to run\n");  
                         if (proc_ar != NULL)  
                                 free(proc_ar);  
                         return NULL;  
                 }  
   
                 proc_ar = (struct conf_struct_process *) realloc((void *) proc_ar,  
                                 (n_proc_ar + 1)  
                                 * sizeof(struct conf_struct_process));  
                 if (proc_ar == NULL) {  
                         msg_error_print("not enought memory for command line parsing\n");  
                         return NULL;  
                 }  
   
                 proc_ar[n_proc_ar] = process_cfg;  
                 n_proc_ar++;  
   
                 index += idx + 1;  
         }  
   
 #if DEBUG  
         msg_debug_print("%d processes found on command line\n", n_proc_ar);  
 #endif  
   
         ptbl = proc_ar_to_proctable(n_proc_ar, proc_ar);  
   
         /* Terrific freeing, but neccessary. */  
         for (; n_proc_ar > 0; n_proc_ar--)  
                 for (index = 0; index < N_FD; index++) {  
                         strdyn_safe_free(proc_ar[n_proc_ar - 1].fd[index]);  
                         proc_ar[n_proc_ar - 1].fd[index] = NULL;  
                 }  
   
         free(proc_ar);  
   
         return ptbl;  
 }  
   
         static PROCTABLE  
 proc_ar_to_proctable(n_proc_ar, proc_ar)  
         int                        n_proc_ar;  
         struct conf_struct_process *proc_ar;  
 {  
         PROCTABLE ptbl;  
         register int i, j, k;  
   
         ptbl = proctable_create(n_proc_ar);  
   
         if (ptbl == NULL) {  
                 msg_error_print("not enought memory for process table creation\n");  
                 return NULL;  
         }  
   
         for (i = 0; i < n_proc_ar; i++) {  
                 ptbl[i]->pid = 0;  
                 ptbl[i]->name = proc_ar[i].name;  
                 ptbl[i]->argv = proc_ar[i].argv;  
   
                 for (j = 0; j < N_FD; j++) {  
                         register int size = proc_ar[i].fd[j] == NULL ? 0  
                                 : strdyn_get_size(proc_ar[i].fd[j]);  
   
                         ptbl[i]->fd[j].n_link = 0;  
                         ptbl[i]->fd[j].pipe[0] = ptbl[i]->fd[j].pipe[1] = 0;  
   
                         for (k = 0; k < size; k++) {  
                                 struct proclink link;  
                                 char **ar;  
                                 char *fd_str = NULL;  
   
                                 if (strlen(proc_ar[i].fd[j][k]) <= 0)  
                                         continue;  
   
                                 ar      = strdyn_explode2_ar(proc_ar[i].fd[j][k],  
                                                 name_vs_stream_separator);  
   
                                 if (ar == NULL) {  
                                         msg_error_print("not enough memory"  
                                                         " for link argument exploding");  
                                         proctable_destroy(&ptbl);  
                                         return NULL;  
                                 }  
   
                                 switch (strdyn_get_size(ar)) {  
                                         case 1:  
                                                 link.proc_id = 0;  
                                                 fd_str = ar[0];  
                                                 break;  
   
                                         case 2:  
                                                 fd_str = ar[1];  
   
                                                 if (isdigit(ar[0][0])) {  
                                                         char *end;  
                                                         link.proc_id = (int) strtol(ar[0], &end, 0);  
   
                                                         if ((end && *end == '\0') && link.proc_id >= 0)  
                                                                 break;  
   
                                                         msg_error_print("bad process number '%s'\n", ar[0]);  
                                                         proctable_destroy(&ptbl);  
                                                         return NULL;  
                                                 }  
   
                                                 link.proc_id = proctable_get_process_index_by_name(  
                                                                 ptbl, ar[0]);  
                                                 if (link.proc_id >= 0)  
                                                         break;  
   
                                                 msg_error_print("bad process name '%s'\n", ar[0]);  
                                                 proctable_destroy(&ptbl);  
                                                 return NULL;  
   
                                         default:  
                                                 msg_error_print("bad link specification: %s\n",  
                                                                 proc_ar[i].fd[j][k]);  
                                                 proctable_destroy(&ptbl);  
                                                 return NULL;  
                                 }  
   
                                 link.fd_id = fd_str_to_fd_id(fd_str);  
                                 if (link.fd_id < 0) {  
                                         msg_error_print("bad stream specification '%s'\n",  
                                                         fd_str);  
                                         proctable_destroy(&ptbl);  
                                         return NULL;  
                                 }  
   
                                 if (! fd_add_proclink(&(ptbl[i]->fd[j]), &link)) {  
                                         msg_error_print("not enought memory for"  
                                                         " process link addition\n");  
                                         proctable_destroy(&ptbl);  
                                         return NULL;  
                                 }  
                         }  
   
                         /* TODO: why is this commented? */  
                         /* strdyn_safe_free(proc_ar[i].fd[j]); */  
                 }  
         }  
   
         return ptbl;  
 }  
   
         static int  
 conf_cmdline_parse_global(argc, argv)  
         int  argc;  
         char **argv;  
 {  
         struct cfg_context *con;  
         register int ret;  
   
         con = cfg_get_cmdline_context(argc, argv, global_options);  
         if (con == NULL) {  
                 msg_error_print("not enough memory for command line parsing"  
                                 " global options\n");  
                 return CFG_ERROR_NOMEM;  
         }  
   
         cfg_set_context_flags(con, CFG_PROCESS_FIRST);  
         cfg_clear_cmdline_stop_string(con);  
         cfg_add_cmdline_stop_string(con, "--");  
         cfg_clear_cmdline_multi_vals_separator(con);  
         cfg_add_cmdline_multi_vals_separator(con, ",");  
   
         ret = cfg_parse(con);  
   
         if (ret < 0 && ret != CFG_ERR_STOP_STR_FOUND) {  
                 msg_error_print("error on command line in global options"  
                                 " (error %d at %s)\n", ret, argv[cfg_get_cur_idx(con)]);  
   
                 cfg_free_context(con);  
                 return ret;  
         }  
   
         if (cfg_get_cur_idx(con) == 0) {  
                 msg_error_print("misplaced process separator '--'\n");  
   
                 cfg_free_context(con);  
                 return CFG_ERROR_STOP_STR;  
         }  
   
         if (ret == CFG_OK)  
                 ret = 0;  
         else  
                 ret = cfg_get_cur_idx(con);  
   
         cfg_free_context(con);  
   
         return ret;  
 }  
   
         static int  
 conf_cmdline_parse_process(argc, argv, silent)  
         int  argc;  
         char **argv;  
         int  silent;  
 {  
         struct cfg_context *con;  
         register int ret;  
   
         /* Clearing all properties. Some of them need to be set to NULL,  
          * because of valid handling of string multi lists.  
          */  
         memset((void *) &process_cfg, '\0', sizeof(struct conf_struct_process));  
   
         con = cfg_get_cmdline_context(argc, argv, process_options);  
         if (con == NULL) {  
                 msg_error_print("not enough memory for command line parsing"  
                                 " process options");  
                 return CFG_ERROR_NOMEM;  
         }  
   
         cfg_set_context_flags(con, CFG_PROCESS_FIRST);  
         cfg_clear_cmdline_stop_string(con);  
         cfg_add_cmdline_stop_string(con, "--");  
         cfg_clear_cmdline_multi_vals_separator(con);  
         cfg_add_cmdline_multi_vals_separator(con, ",");  
   
         ret = cfg_parse(con);  
   
         if (ret < 0 && ret != CFG_ERR_STOP_STR_FOUND) {  
                 if (! silent)  
                         /* TODO: better specification about error on command line */  
                         msg_error_print("error on command line (error %d at %s)\n",  
                                         ret, argv[cfg_get_cur_idx(con)]);  
   
                 cfg_free_context(con);  
                 return ret;  
         }  
   
         if (cfg_get_cur_idx(con) == 0 && ret == CFG_ERR_STOP_STR_FOUND) {  
                 if (! silent)  
                         msg_error_print("misplaced process separator '--'\n");  
   
                 cfg_free_context(con);  
                 return CFG_ERROR_STOP_STR;  
         }  
   
         if (ret == CFG_OK)  
                 ret = 0;  
         else  
                 ret = cfg_get_cur_idx(con);  
   
         cfg_free_context(con);  
   
         return ret;  
 }  
   
 #endif /* #if 0 */  
   

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

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top