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

Diff for ep/src/conf.c between version 1.12 and 1.13

version 1.12, 2002/02/20 14:16:44 version 1.13, 2002/02/21 02:22:00
Line 27  char *conf_user_filename = ".ep.conf";
Line 27  char *conf_user_filename = ".ep.conf";
  * Static variables   * Static variables
  */   */
 static char *section_boundaries[2] = {"[", "]"};  static char *section_boundaries[2] = {"[", "]"};
 /* static char *name_vs_stream_separator[4] = {".", "..", "-", NULL}; */  static char *name_vs_stream_separator[4] = {".", "..", "-", NULL};
 static char *global_str = "Global";  static char *global_str = "Global";
 static char *process_str = "Process";  static char *process_str = "Process";
   
Line 68  static struct cfg_option process_options
Line 68  static struct cfg_option process_options
         {"nice", 'N', "nice", CFG_INT, (void *) &(process_cfg.nice), 0},          {"nice", 'N', "nice", CFG_INT, (void *) &(process_cfg.nice), 0},
         {"name", 'n', "name", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.name), 0},          {"name", 'n', "name", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.name), 0},
         {"input", 'i', "input", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.fd_str[0]), 0},          {"input", 'i', "input", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.fd_str[0]), 0},
         {"output", 'o', "output", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.fd_str[1]), 0},          {"output", 'o', "output", CFG_STRING+CFG_MULTI_SEPARATED, (void *)&(process_cfg.fd_str[1]),0},
         {"errput", 'e', "errput", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(process_cfg.fd_str[2]), 0},          {"errput", 'e', "errput", CFG_STRING+CFG_MULTI_SEPARATED, (void *)&(process_cfg.fd_str[2]),0},
         {NULL, '\0', "command", CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI, (void *) &(process_cfg.argv), 0},          {NULL, '\0', "command", CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI,(void *)&(process_cfg.argv),0},
         CFG_END_OF_LIST          CFG_END_OF_LIST
 };  };
   
Line 85  static int check_global_context(void);
Line 85  static int check_global_context(void);
 static int check_process_context(void);  static int check_process_context(void);
 static int check_context(CFG_CONTEXT *context, struct cfg_option options[]);  static int check_context(CFG_CONTEXT *context, struct cfg_option options[]);
 static int is_cfgfile_section(char *section_str);  static int is_cfgfile_section(char *section_str);
   static int get_processes_index_by_name(
                   struct conf_struct_process **processes, char *name);
 static int add_global_cfg_to_global(struct conf_struct_global **global);  static int add_global_cfg_to_global(struct conf_struct_global **global);
 static int add_process_cfg_to_processes(  static int add_process_cfg_to_processes(
                 struct conf_struct_process ***processes,                  struct conf_struct_process ***processes,
Line 92  static int add_process_cfg_to_processes(
Line 94  static int add_process_cfg_to_processes(
 static int add_processes_to_processes(  static int add_processes_to_processes(
                 struct conf_struct_process ***dest_processes,                  struct conf_struct_process ***dest_processes,
                 struct conf_struct_process **src_processes);                  struct conf_struct_process **src_processes);
   static int add_processes_to_proctable(
                   PROCTABLE *p_ptbl,
                   struct conf_struct_process **processes,
                   int start_idx_size, int *start_idx);
   
 /*  /*
  * Function definitions   * Function definitions
Line 104  PROCTABLE conf_parse_all(int argc, char
Line 110  PROCTABLE conf_parse_all(int argc, char
         struct conf_struct_global *global_work;          struct conf_struct_global *global_work;
         struct conf_struct_process **processes;          struct conf_struct_process **processes;
         struct conf_struct_process **processes_work;          struct conf_struct_process **processes_work;
         /* int *start_idx; */  
           PROCTABLE ptbl;
   
           int *start_idx;
           int start_idx_size;
   
         ret = conf_cmdline_parse(argc - 1, argv + 1, &global, &processes);          ret = conf_cmdline_parse(argc - 1, argv + 1, &global, &processes);
   
Line 114  PROCTABLE conf_parse_all(int argc, char
Line 124  PROCTABLE conf_parse_all(int argc, char
                 return NULL;                  return NULL;
         }          }
   
         for (i = 0; i < 2 || (global->config_file != NULL          for (start_idx_size = 0; global->config_file != NULL
                                 && global->config_file[i - 2] != NULL); i++) {                          && global->config_file[start_idx_size] != NULL;
                           start_idx_size++)
                   ;
   
           start_idx_size += 3; /* command line, global config, homedir config */
   
           if ((start_idx = (int *) malloc(start_idx_size * sizeof(int))) == NULL) {
                   msg_error_print("not enough memory\n");
                   /* TODO: free structures */
                   return NULL;
           }
   
           start_idx[0] = 0;
   
           for (i = 0; i < start_idx_size - 1; i++) {
   
                 if (i >= 2                  if (i >= 2
                                 || (i == 0 && ! global->disable_global_config)                                  || (i == 0 && ! global->disable_global_config)
Line 147  PROCTABLE conf_parse_all(int argc, char
Line 171  PROCTABLE conf_parse_all(int argc, char
                                 return NULL;                                  return NULL;
                         }                          }
   
                           for (start_idx[i + 1] = 0; processes_work != NULL
                                           && processes_work[start_idx[i + 1]] != NULL;
                                           start_idx[i + 1]++)
                                   ;
                           start_idx[i + 1] += start_idx[i];
   
                         if (! add_processes_to_processes(&processes, processes_work)) {                          if (! add_processes_to_processes(&processes, processes_work)) {
                                 msg_error_print("not enough memory for config file '%s'"                                  msg_error_print("not enough memory for config file '%s'"
                                                 "process table merging\n", filename);                                                  "process table merging\n", filename);
Line 183  PROCTABLE conf_parse_all(int argc, char
Line 213  PROCTABLE conf_parse_all(int argc, char
                         else                          else
                                 argvs = strdup("-- N/A --");                                  argvs = strdup("-- N/A --");
   
                         msg_debug_print("Process %d\n  NAMES: %s\n  ARGVS: %s\n",                          msg_debug_print("Process %d\n", i);
                                         i, names, argvs);                          msg_debug_print("  NAMES: %s\n", names);
                           msg_debug_print("  ARGVS: %s\n", argvs);
   
                         free(names);                          free(names);
                         free(argvs);                          free(argvs);
                 }                  }
   
                   msg_debug_print("Indexes:\n");
                   for (i = 0; i < start_idx_size; i++)
                           msg_debug_print("  %d -> %d\n", i, start_idx[i]);
         }          }
 #endif  #endif
   
         return NULL;          if ((ptbl = proctable_create(0)) == NULL ||
                           proctable_add_std_process(&ptbl) < 0) {
                   msg_error_print("not enough memory\n");
                   /* TODO: free structures */
                   return NULL;
           }
   
           add_processes_to_proctable(&ptbl, processes, start_idx_size, start_idx);
   
           free(start_idx);
   
           return ptbl;
 }  }
   
 int conf_cfgfile_parse(  int conf_cfgfile_parse(
Line 342  int conf_cmdline_parse(
Line 388  int conf_cmdline_parse(
         }          }
   
         /* Set returning parameters. */          /* Set returning parameters. */
         if ((cur_context == process_context && index > 0 && ret == CFG_OK &&          if ((cur_context == process_context && ret == CFG_OK
                                   && cfg_get_cur_idx(cur_context) > 0 &&
                                 ! add_process_cfg_to_processes(processes, &processes_size))                                  ! add_process_cfg_to_processes(processes, &processes_size))
                         || ! add_global_cfg_to_global(global))                          || ! add_global_cfg_to_global(global))
                 return CFG_ERR_NOMEM;                  return CFG_ERR_NOMEM;
Line 423  static int check_context(CFG_CONTEXT *co
Line 470  static int check_context(CFG_CONTEXT *co
 static int is_cfgfile_section(char *section_str)  static int is_cfgfile_section(char *section_str)
 {  {
         register int secstr_size = strlen(section_str);          register int secstr_size = strlen(section_str);
         register int secb0_size = strlen(section_boundaries[0]);          register int secb0_size  = strlen(section_boundaries[0]);
         register int secb1_size = strlen(section_boundaries[1]);          register int secb1_size  = strlen(section_boundaries[1]);
   
         register int ret = 0;          register int ret = 0;
   
Line 457  static int is_cfgfile_section(char *sect
Line 504  static int is_cfgfile_section(char *sect
         return ret;          return ret;
 }  }
   
   static int get_processes_index_by_name(
                   struct conf_struct_process **processes, char *name)
   {
           register int i;
   
           for (i = 0; processes != NULL && processes[i] != NULL; i++)
                   if (processes[i]->name != NULL
                                   && ! strdyn_casecmp(processes[i]->name, name))
                           return i;
   
           return -1;
   }
   
 static int add_global_cfg_to_global(struct conf_struct_global **global)  static int add_global_cfg_to_global(struct conf_struct_global **global)
 {  {
         *global = (struct conf_struct_global *)          *global = (struct conf_struct_global *)
Line 533  static int add_processes_to_processes(
Line 593  static int add_processes_to_processes(
         return 1;          return 1;
 }  }
   
   static int add_processes_to_proctable(
                   PROCTABLE *p_ptbl,
                   struct conf_struct_process **processes,
                   int start_idx_size, int *start_idx)
   {
           register int i, j, k, idx;
           register int ptbl_size;
           PROCTABLE new_ptbl;
           register int new_ptbl_size;
   
           register int resource_idx = 0;
   
           for (new_ptbl_size = 0; processes != NULL
                           && processes[new_ptbl_size] != NULL; new_ptbl_size++)
                   ;
   #if DEBUG
           msg_debug_print("add_processes_to_proctable(): new_ptbl_size = %d\n",
                           new_ptbl_size);
   #endif
   
           if ((new_ptbl = proctable_create(new_ptbl_size)) == NULL)
                   return -1;
   
           ptbl_size = proctable_get_size(*p_ptbl);
   
           for (i = 0; i < new_ptbl_size; i++) {
   
                   /* Counting resource_idx. */
                   while (resource_idx < start_idx_size - 1
                                   && start_idx[resource_idx + 1] <= i)
                           resource_idx++;
   
                   /* Checking processes names. */
                   for (j = 0; processes[i]->name != NULL
                                   && processes[i]->name[j] != NULL; j++) {
                           idx = proctable_get_process_index_by_name(
                                           *p_ptbl, processes[i]->name[j]);
                           if (idx >= 0) {
                                   msg_error_print("process %d from resource %d (%s) already"
                                                   " exists in process table with index %d\n",
                                                   j - start_idx[resource_idx], resource_idx,
                                                   processes[i]->name[j], idx);
                                   return -1;
                           }
                   }
   
                   new_ptbl[i]->pid  = 0;
                   new_ptbl[i]->name = processes[i]->name;
                   new_ptbl[i]->argv = processes[i]->argv;
   
                   /* Converting filedescriptors strings to indexes. */
                   for (j = 0; j < N_FD; j++) {
                           register int size = processes[i]->fd_str[j] == NULL ? 0
                                   : strdyn_get_size(processes[i]->fd_str[j]);
   
                           new_ptbl[i]->fd[j].n_link  = 0;
                           new_ptbl[i]->fd[j].pipe[0] = 0;
                           new_ptbl[i]->fd[j].pipe[1] = 0;
   
                           for (k = 0; k < size; k++) {
                                   struct proclink link;
                                   char **ar;
                                   register char *fd_str = NULL, *char_in_name;
   
                                   if (strlen(processes[i]->fd_str[j][k]) <= 0)
                                           continue;
   
                                   ar      = strdyn_explode2_ar(processes[i]->fd_str[j][k],
                                                   name_vs_stream_separator);
   
                                   if (ar == NULL) {
                                           msg_error_print("not enough memory"
                                                           " for link argument exploding");
                                           proctable_destroy(&new_ptbl);
                                           return -1;
                                   }
   
                                   switch (strdyn_get_size(ar)) {
                                           case 1:
                                                   link.proc_id = 0;
                                                   fd_str = ar[0];
                                                   break;
   
                                           case 2:
   
                                                   for (char_in_name = ar[0];
                                                                   isdigit(*char_in_name);
                                                                   char_in_name++)
                                                           ;
   
                                                   fd_str = ar[1];
   
                                                   if (*char_in_name == '\0') { /* number init */
                                                           char *end;
                                                           link.proc_id = (int) strtol(ar[0], &end, 0);
   
                                                           if ((end && *end == '\0') && link.proc_id >= 0) {
                                                                   if (link.proc_id == 0) /* 0 is always valid */
                                                                           break;
   
                                                                   if (link.proc_id <=
                                                                                   start_idx[resource_idx + 1]
                                                                                   - start_idx[resource_idx]) {
   
                                                                           link.proc_id += start_idx[resource_idx];
                                                                           break;
                                                                   }
                                                           }
   
                                                           msg_error_print("bad process number '%s'\n",
                                                                           ar[0]);
                                                           proctable_destroy(&new_ptbl);
                                                           return -1;
                                                   }
   
                                                   /* Searching name in existing proctable. */
                                                   link.proc_id = proctable_get_process_index_by_name(
                                                                   new_ptbl, ar[0]);
   
                                                   if (link.proc_id >= 0)
                                                           break;
   
                                                   /* Searching name in processes. */
                                                   link.proc_id = get_processes_index_by_name(
                                                                   processes, ar[0]);
   
                                                   if (link.proc_id >= 0) {
                                                           link.proc_id += start_idx[resource_idx];
                                                           break;
                                                   }
   
                                                   msg_error_print("bad process name '%s'\n", ar[0]);
                                                   proctable_destroy(&new_ptbl);
                                                   return -1;
   
                                           default:
                                                   msg_error_print("bad link specification: %s\n",
                                                                   processes[i]->fd_str[j][k]);
                                                   proctable_destroy(&new_ptbl);
                                                   return -1;
                                   }
   
                                   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(&new_ptbl);
                                           return -1;
                                   }
   
                                   if (! fd_add_proclink(&(new_ptbl[i]->fd[j]), &link)) {
                                           msg_error_print("not enought memory for"
                                                           " process link addition\n");
                                           proctable_destroy(&new_ptbl);
                                           return -1;
                                   }
                           }
   
                           /* TODO: why is this commented? */
                           /* strdyn_safe_free(proc_ar[i].fd[j]); */
                   }
           }
   
           if (! proctable_join(p_ptbl, new_ptbl)) {
                   msg_error_print("not enought memory for"
                                   " process table resize\n");
                   proctable_destroy(&new_ptbl);
                   return -1;
           }
   
           return 0;
   }
   
 #if 0  #if 0
   
 static PROCTABLE proc_ar_to_proctable(int n_proc_ar,  static PROCTABLE proc_ar_to_proctable(int n_proc_ar,

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

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