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.17 and 1.18

version 1.17, 2002/04/08 21:26:08 version 1.18, 2002/04/09 21:16:45
Line 17 
Line 17 
 #include "conf.h"  #include "conf.h"
   
 /*  /*
  * Global variables  
  */  
   
 char *conf_global_filename = "/etc/ep.conf";  
 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";
   
   
 /* struct conf_struct_global cfg; */  
   
 /*  /*
  * Options structures   * Options structures (used only with libcfg context)
  */   */
   
 static struct conf_struct_global global_cfg;  static struct conf_struct_global global_cfg;
Line 53  static CFG_CONTEXT process_context = NUL
Line 44  static CFG_CONTEXT process_context = NUL
  */   */
   
 static struct cfg_option global_options[] = {  static struct cfg_option global_options[] = {
           {"silent", 's', "silent", CFG_BOOLEAN, (void *) &(global_cfg.silent), 0},
         {"verbose", 'v', "verbose", CFG_BOOLEAN + CFG_MULTI, (void *) &(global_cfg.verbose), 0},          {"verbose", 'v', "verbose", CFG_BOOLEAN + CFG_MULTI, (void *) &(global_cfg.verbose), 0},
         {NULL, 'f', NULL, CFG_STRING + CFG_MULTI, (void *) &(global_cfg.config_file), 0},          {NULL, 'f', NULL, CFG_STRING + CFG_MULTI, (void *) &(global_cfg.config_file), 0},
         {"disable-global-config",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.disable_global_config),0},          {"disable-global-config",'\0',NULL,CFG_BOOLEAN,(void*)&(global_cfg.disable_global_config),0},
Line 80  static struct cfg_option process_options
Line 72  static struct cfg_option process_options
  */   */
   
 static char *get_user_config_filename(void);  static char *get_user_config_filename(void);
 static void global_cfg_clear(void);  static void clear_global_cfg(void);
 static void process_cfg_clear(void);  static void clear_process_cfg(void);
 static int check_global_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 void free_global(struct conf_struct_global **global);
   static void free_processes(struct conf_struct_process ***processes);
 static int get_processes_index_by_name(  static int get_processes_index_by_name(
                 struct conf_struct_process **processes, char *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);
Line 130  static int add_processes_to_proctable(
Line 122  static int add_processes_to_proctable(
  *      }   *      }
  */   */
   
           int
   conf_init(void)
   {
           return check_context(&global_context, global_options)
                   && check_context(&process_context, process_options);
   }
   
           void
   conf_destroy(void)
   {
           if (global_context != NULL)
                   cfg_free_context(global_context);
           if (process_context != NULL)
                   cfg_free_context(process_context);
   }
   
         PROCTABLE          PROCTABLE
 conf_parse_all(argc, argv)  conf_parse_all(argc, argv)
Line 147  conf_parse_all(argc, argv)
Line 154  conf_parse_all(argc, argv)
         int *start_idx;          int *start_idx;
         int start_idx_size;          int start_idx_size;
   
           global    = NULL;
           processes = NULL;
         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 */                  /* 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 */                  /* XXX: free structures */
                   free_global(&global);
                   free_processes(&processes);
                 return NULL;                  return NULL;
         }          }
   
Line 162  conf_parse_all(argc, argv)
Line 173  conf_parse_all(argc, argv)
                 ;                  ;
   
         start_idx_size += 3; /* command line, global config, homedir config */          start_idx_size += 3; /* command line, global config, homedir config */
           start_idx = (int *) malloc(start_idx_size * sizeof(int));
   
         if ((start_idx = (int *) malloc(start_idx_size * sizeof(int))) == NULL) {          if (start_idx == NULL) {
                 msg_error_print("not enough memory\n");                  msg_error_print("not enough memory for parsing indexes\n");
                 /* TODO: free structures */                  /* XXX: free structures */
                   free_global(&global);
                   free_processes(&processes);
                 return NULL;                  return NULL;
         }          }
   
Line 184  conf_parse_all(argc, argv)
Line 198  conf_parse_all(argc, argv)
                         : global->config_file[i - 2];                          : global->config_file[i - 2];
   
                 if (/* i == 1 && */ filename == NULL) {                  if (/* i == 1 && */ filename == NULL) {
                         msg_error_print("not enough memory\n");                          msg_error_print("not enough memory for filename buffer\n");
                         /* TODO: free structures */                          /* XXX: free structures */
                         free(start_idx);                          free(start_idx);
                           free_global(&global);
                           free_processes(&processes);
                         return NULL;                          return NULL;
                 }                  }
   
Line 194  conf_parse_all(argc, argv)
Line 210  conf_parse_all(argc, argv)
                 msg_debug_print("conf_parse_all(): parsing file '%s'\n", filename);                  msg_debug_print("conf_parse_all(): parsing file '%s'\n", filename);
 #endif  #endif
   
                   global_work    = NULL;
                   processes_work = NULL;
                 ret = conf_cfgfile_parse(filename, &global_work, &processes_work);                  ret = conf_cfgfile_parse(filename, &global_work, &processes_work);
   
                 /* TODO: Progressive config file type reporting in error messages.                  /* TODO: Progressive config file type reporting in error messages.
                    There are three types: global, local/user, user defined. */                     There are three types: global, local/user, user defined. */
   
                 if (ret != CFG_OK && (i >= 2                  if (ret != CFG_OK
                                         || (i < 2 && ret != CFG_ERR_FILE_NOT_FOUND))) {                                  && (i >= 2 || (i < 2 && ret != CFG_ERR_FILE_NOT_FOUND))) {
                         msg_error_print("config file '%s' parsing error %d\n",                          msg_error_print("config file '%s' parsing error %d\n",
                                         filename, ret);                                          filename, ret);
                         free(start_idx);                          /* XXX: free structures */
                         if (i == 1)                          if (i == 1)
                                 free(filename);                                  free(filename);
                           free(start_idx);
                           free_global(&global_work);
                           free_processes(&processes_work);
                           free_global(&global);
                           free_processes(&processes);
                         return NULL;                          return NULL;
                 }                  }
   
Line 218  conf_parse_all(argc, argv)
Line 241  conf_parse_all(argc, argv)
                 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);
                           /* XXX: free structures */
                         if (i == 1)                          if (i == 1)
                                 free(start_idx);                                  free(filename);
                         free(filename);                          free(start_idx);
                           free_global(&global_work);
                           free_processes(&processes_work);
                           free_global(&global);
                           free_processes(&processes);
                         return NULL;                          return NULL;
                 }                  }
   
Line 228  conf_parse_all(argc, argv)
Line 256  conf_parse_all(argc, argv)
                         free(filename);                          free(filename);
   
                 free(global_work);                  free(global_work);
                   free(processes_work);
         }          }
   
 #if DEBUG  #if DEBUG
Line 273  conf_parse_all(argc, argv)
Line 302  conf_parse_all(argc, argv)
         if ((ptbl = proctable_create(0)) == NULL ||          if ((ptbl = proctable_create(0)) == NULL ||
                         proctable_add_std_process(&ptbl) < 0) {                          proctable_add_std_process(&ptbl) < 0) {
                 msg_error_print("not enough memory\n");                  msg_error_print("not enough memory\n");
                 /* TODO: free structures */                  /* XXX: free structures */
                 free(start_idx);                  free(start_idx);
                   free_global(&global);
                   free_processes(&processes);
                 return NULL;                  return NULL;
         }          }
   
         /* TODO: error check */  
         if (add_processes_to_proctable(&ptbl, processes,          if (add_processes_to_proctable(&ptbl, processes,
                                 start_idx_size, start_idx) < 0) {                                  start_idx_size, start_idx) < 0) {
                 /* TODO: free structures */                  /* XXX: free structures */
                   proctable_destroy(&ptbl);
                 free(start_idx);                  free(start_idx);
                   free_global(&global);
                   free_processes(&processes);
                 return NULL;                  return NULL;
         }          }
   
           cfg = *global;
   
         free(start_idx);          free(start_idx);
           free_global(&global);
           free_processes(&processes);
   
         return ptbl;          return ptbl;
 }  }
Line 304  conf_cfgfile_parse(filename, global, pro
Line 341  conf_cfgfile_parse(filename, global, pro
         *processes = NULL;          *processes = NULL;
         processes_size = 0;          processes_size = 0;
   
         if (check_global_context() < 0 || check_process_context() < 0)          clear_global_cfg();
                 return CFG_ERR_NOMEM;          clear_process_cfg();
   
         global_cfg_clear();          cfg_reset_context(global_context);
         process_cfg_clear();          cfg_reset_context(process_context);
   
         cfg_set_cfgfile_context(global_context, 0, 0, filename);          cfg_set_cfgfile_context(global_context, 0, 0, filename);
         cfg_set_cfgfile_context(process_context, 0, 0, filename);          cfg_set_cfgfile_context(process_context, 0, 0, filename);
Line 338  conf_cfgfile_parse(filename, global, pro
Line 375  conf_cfgfile_parse(filename, global, pro
                                                                 &processes_size))                                                                  &processes_size))
                                                 return CFG_ERR_NOMEM;                                                  return CFG_ERR_NOMEM;
   
                                         process_cfg_clear();                                          clear_process_cfg();
                                 }                                  }
   
                                 if (sec_no == 1) { /* [Global] section */                                  if (sec_no == 1) { /* [Global] section */
Line 386  conf_cmdline_parse(argc, argv, global, p
Line 423  conf_cmdline_parse(argc, argv, global, p
         *processes = NULL;          *processes = NULL;
         processes_size = 0;          processes_size = 0;
   
         if (check_global_context() < 0 || check_process_context() < 0)          clear_global_cfg();
                 return CFG_ERR_NOMEM;          clear_process_cfg();
   
         global_cfg_clear();          cfg_reset_context(global_context);
         process_cfg_clear();          cfg_reset_context(process_context);
   
         cfg_set_cmdline_context(global_context, argc, argv);          cfg_set_cmdline_context(global_context, argc, argv);
         cfg_set_cmdline_context(process_context, argc, argv);          cfg_set_cmdline_context(process_context, argc, argv);
Line 431  conf_cmdline_parse(argc, argv, global, p
Line 468  conf_cmdline_parse(argc, argv, global, p
                                                         &processes_size))                                                          &processes_size))
                                         return CFG_ERR_NOMEM;                                          return CFG_ERR_NOMEM;
   
                                 process_cfg_clear();                                  clear_process_cfg();
                         }                          }
   
                         index += cfg_get_cur_idx(cur_context) + 1;                          index += cfg_get_cur_idx(cur_context) + 1;
Line 482  get_user_config_filename(void)
Line 519  get_user_config_filename(void)
 }  }
   
         static void          static void
 global_cfg_clear(void)  clear_global_cfg(void)
 {  {
         memset((void *) &global_cfg, '\0',          memset((void *) &global_cfg, '\0',
                         sizeof(struct conf_struct_global));                          sizeof(struct conf_struct_global));
 }  }
   
         static void          static void
 process_cfg_clear(void)  clear_process_cfg(void)
 {  {
         memset((void *) &process_cfg, '\0',          memset((void *) &process_cfg, '\0',
                         sizeof(struct conf_struct_process));                          sizeof(struct conf_struct_process));
 }  }
   
         static int          static int
 check_global_context(void)  
 {  
         return check_context(&global_context, global_options);  
 }  
   
         static int  
 check_process_context(void)  
 {  
         return check_context(&process_context, process_options);  
 }  
   
         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)
                         return -1;                          return 0;
   
                 cfg_set_context_flags(*context, CFG_PROCESS_FIRST);                  cfg_set_context_flags(*context, CFG_PROCESS_FIRST);
                 cfg_clear_cmdline_stop_string(*context);                  cfg_clear_cmdline_stop_string(*context);
Line 525  check_context(context, options)
Line 550  check_context(context, options)
                                 || ! cfg_add_cmdline_multi_vals_separator(*context, ",")                                  || ! cfg_add_cmdline_multi_vals_separator(*context, ",")
                                 || ! cfg_add_cfgfile_stop_prefix(*context,                                  || ! cfg_add_cfgfile_stop_prefix(*context,
                                         section_boundaries[0]))                                          section_boundaries[0]))
                         return -1;                          return 0;
         }          }
   
         cfg_reset_context(*context);          return 1;
   
         return 0;  
 }  }
   
         static int          static int
Line 572  is_cfgfile_section(section_str)
Line 595  is_cfgfile_section(section_str)
         return ret;          return ret;
 }  }
   
           static void
   free_global(global)
           struct conf_struct_global **global;
   {
           if (*global == NULL)
                   return;
   
           strdyn_safe_free((*global)->config_file);
   
           free(*global);
           *global = NULL;
   }
   
           static void
   free_processes(processes)
           struct conf_struct_process ***processes;
   {
           register int i, j;
   
           if (*processes == NULL)
                   return;
   
           for (i = 0; (*processes)[i] != NULL; i++) {
                   strdyn_safe_free((*processes)[i]->name);
                   strdyn_safe_free((*processes)[i]->argv);
   
                   for (j = 0; j < N_FD; j++)
                           strdyn_safe_free((*processes)[i]->fd_str[j]);
   
                   free((*processes)[i]);
           }
   
           free(*processes);
           *processes = NULL;
   }
   
         static int          static int
 get_processes_index_by_name(processes, name)  get_processes_index_by_name(processes, name)
         struct conf_struct_process **processes;          struct conf_struct_process **processes;
Line 719  add_processes_to_proctable(p_ptbl, proce
Line 778  add_processes_to_proctable(p_ptbl, proce
                 }                  }
   
                 new_ptbl[i]->pid  = 0;                  new_ptbl[i]->pid  = 0;
                 new_ptbl[i]->name = processes[i]->name;                  new_ptbl[i]->name = strdyn_safe_duplicate(processes[i]->name);
                 new_ptbl[i]->argv = processes[i]->argv;                  new_ptbl[i]->argv = strdyn_safe_duplicate(processes[i]->argv);
   
                 /* Converting filedescriptors strings to indexes. */                  /* Converting filedescriptors strings to indexes. */
                 for (j = 0; j < N_FD; j++) {                  for (j = 0; j < N_FD; j++) {
Line 872  add_processes_to_proctable(p_ptbl, proce
Line 931  add_processes_to_proctable(p_ptbl, proce
         return 0;          return 0;
 }  }
   
   

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

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