| version 1.5, 2002/02/05 22:37:03 |
version 1.6, 2002/02/11 16:17:55 |
| Line 20 static char *name_vs_stream_separator[2] |
|
| Line 20 static char *name_vs_stream_separator[2] |
|
| |
|
| /* static */ struct cfglocal_struct_global globalcfg; |
/* static */ struct cfglocal_struct_global globalcfg; |
| static struct cfglocal_struct_process processcfg; |
static struct cfglocal_struct_process processcfg; |
| /* |
|
| static struct cfg_option options_global[] = { |
static struct cfg_option options_global[] = { |
| {"verbose", 'v', "verbose", CFG_BOOLEAN + CFG_MULTI, (void *) &(globalcfg.verbose), 0}, |
{"verbose", 'v', "verbose", |
| CFG_END_OF_LIST |
CFG_BOOLEAN + CFG_MULTI, (void *) &(globalcfg.verbose), 0}, |
| |
CFG_END_OF_LIST |
| }; |
}; |
| */ |
|
| static struct cfg_option options_process[] = { |
static struct cfg_option options_process[] = { |
| {"nice", 'N', "nice", CFG_INT, (void *) &(processcfg.nice), 0}, |
{"nice", 'N', "nice", CFG_INT, (void *) &(processcfg.nice), 0}, |
| {"name", 'n', "name", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.name), 0}, |
{ "name", 'n', "name", |
| {"input", 'i', "input", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[0]), 0}, |
CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.name), 0 }, |
| {"output", 'o', "output", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[1]), 0}, |
{"input", 'i', "input", |
| {"errput", 'e', "errput", CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[2]), 0}, |
CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[0]), 0}, |
| {NULL, '\0', NULL, CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI, (void *) &(processcfg.argv), 0}, |
{"output", 'o', "output", |
| CFG_END_OF_LIST |
CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[1]), 0}, |
| |
{"errput", 'e', "errput", |
| |
CFG_STRING+CFG_MULTI_SEPARATED, (void *) &(processcfg.fd[2]), 0}, |
| |
{NULL, '\0', NULL, |
| |
CFG_LEFTOVER_ARGS+CFG_STRING+CFG_MULTI, (void *) &(processcfg.argv), 0}, |
| |
CFG_END_OF_LIST |
| }; |
}; |
| |
|
| static int cfglocal_cmdline_parse_process(int argc, char **argv); |
|
| static PROCTABLE proc_ar_to_proctable(int n_proc_ar, |
static PROCTABLE proc_ar_to_proctable(int n_proc_ar, |
| struct cfglocal_struct_process *proc_ar); |
struct cfglocal_struct_process *proc_ar); |
| |
static int cfglocal_cmdline_parse_process(int argc, char **argv, int silent); |
| |
static int cfglocal_cmdline_parse_global(int argc, char **argv); |
| |
|
| PROCTABLE cfglocal_process(int argc, char **argv) |
PROCTABLE cfglocal_process(int argc, char **argv) |
| { |
{ |
| |
register int idx; |
| register int index; |
register int index; |
| register int n_proc_ar; |
register int n_proc_ar; |
| |
register int first_loop; |
| struct cfglocal_struct_process *proc_ar; |
struct cfglocal_struct_process *proc_ar; |
| |
|
| PROCTABLE ptbl; |
PROCTABLE ptbl; |
| |
|
| |
/* |
| |
* PARSING SCHEME (do not delete) |
| |
* ------------------------------ |
| |
* |
| |
* cfglocal_cmdline_parse_process(); |
| |
* if (error) { |
| |
* cfglocal_cmdline_parse_global(); |
| |
* if (err) { |
| |
* fail; |
| |
* } |
| |
* |
| |
* if (config_file) { |
| |
* cfglocal_cfgfile_parse_all(); |
| |
* } |
| |
* } |
| |
* |
| |
* while(1) { |
| |
* |
| |
* cfglocal_cmdline_parse_process(); |
| |
* |
| |
* if (error) { |
| |
* fail; |
| |
* } |
| |
* } |
| |
*/ |
| |
|
| |
idx = 1; |
| index = 1; |
index = 1; |
| |
first_loop = 1; |
| n_proc_ar = 0; |
n_proc_ar = 0; |
| proc_ar = NULL; |
proc_ar = NULL; |
| ptbl = NULL; |
ptbl = NULL; |
| |
|
| /* |
memset((void *) &globalcfg, '\0', |
| PARSING SCHEME (do not delete!) |
sizeof(struct cfglocal_struct_global)); |
| ------------------------------- |
|
| |
for (first_loop = 1; idx != 0 && index < argc; first_loop = 0) { |
| cfglocal_cmdline_parse_process(); |
|
| if (err) { |
|
| cfglocal_cmdline_parse_global(); |
|
| if (err) { |
|
| fail; |
|
| } |
|
| |
|
| if (config_file) { |
|
| cfglocal_cfgfile_parse_all(); |
|
| } |
|
| } |
|
| */ |
|
| |
|
| while (1) { |
idx = cfglocal_cmdline_parse_process(argc - index, argv + index, |
| register int idx; |
first_loop ? 1 : 0); |
| |
|
| idx = cfglocal_cmdline_parse_process(argc - index, argv + index); |
|
| if (idx < 0) { |
if (idx < 0) { |
| if (proc_ar != NULL) |
if (first_loop) { |
| free(proc_ar); |
if (idx == CFG_ERROR_STOP_STR) { |
| return NULL; |
index += 1; |
| } |
continue; |
| |
} |
| |
#if DEBUG |
| |
msg_debug_print("cfglocal_process(): global options detected," |
| |
" idx = %d\n", idx); |
| |
#endif |
| |
/* Global options parsing. */ |
| |
idx = cfglocal_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 (processcfg.argv == NULL) { |
if (processcfg.argv == NULL) { |
| msg_error_print("one of process doesn't have specified what to run\n"); |
msg_error_print("one of process doesn't have specified" |
| |
" what to run\n"); |
| if (proc_ar != NULL) |
if (proc_ar != NULL) |
| free(proc_ar); |
free(proc_ar); |
| return NULL; |
return NULL; |
| } |
} |
| |
|
| proc_ar = (struct cfglocal_struct_process *) realloc((void *) proc_ar, |
proc_ar = (struct cfglocal_struct_process *) realloc((void *) proc_ar, |
| (n_proc_ar + 1) |
(n_proc_ar + 1) |
| * sizeof(struct cfglocal_struct_process)); |
* sizeof(struct cfglocal_struct_process)); |
| if (proc_ar == NULL) { |
if (proc_ar == NULL) { |
| msg_error_print("not enought memory for command line parsing\n"); |
msg_error_print("not enought memory for command line parsing\n"); |
| return NULL; |
return NULL; |
| Line 98 PROCTABLE cfglocal_process(int argc, cha |
|
| Line 143 PROCTABLE cfglocal_process(int argc, cha |
|
| proc_ar[n_proc_ar] = processcfg; |
proc_ar[n_proc_ar] = processcfg; |
| n_proc_ar++; |
n_proc_ar++; |
| |
|
| if (! idx) |
|
| break; |
|
| |
|
| index += idx + 1; |
index += idx + 1; |
| } |
} |
| |
|
| Line 123 PROCTABLE cfglocal_process(int argc, cha |
|
| Line 165 PROCTABLE cfglocal_process(int argc, cha |
|
| } |
} |
| |
|
| static PROCTABLE proc_ar_to_proctable(int n_proc_ar, |
static PROCTABLE proc_ar_to_proctable(int n_proc_ar, |
| struct cfglocal_struct_process *proc_ar) |
struct cfglocal_struct_process *proc_ar) |
| { |
{ |
| PROCTABLE ptbl; |
PROCTABLE ptbl; |
| register int i, j, k; |
register int i, j, k; |
| Line 150 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 192 static PROCTABLE proc_ar_to_proctable(in |
|
| /* DELETE THIS! |
/* DELETE THIS! |
| printf("%d:%d -> size = %d\n", i, j, size); |
printf("%d:%d -> size = %d\n", i, j, size); |
| printf("=== ptbl[1]->fd[0].link = %p\n", ptbl[1]->fd[0].link); |
printf("=== ptbl[1]->fd[0].link = %p\n", ptbl[1]->fd[0].link); |
| */ |
*/ |
| |
|
| for (k = 0; k < size; k++) { |
for (k = 0; k < size; k++) { |
| struct proclink link; |
struct proclink link; |
| Line 161 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 203 static PROCTABLE proc_ar_to_proctable(in |
|
| continue; |
continue; |
| |
|
| ar = strdyn_explode2_ar(proc_ar[i].fd[j][k], |
ar = strdyn_explode2_ar(proc_ar[i].fd[j][k], |
| name_vs_stream_separator); |
name_vs_stream_separator); |
| |
|
| if (ar == NULL) { |
if (ar == NULL) { |
| msg_error_print("not enough memory" |
msg_error_print("not enough memory" |
| " for link argument exploding"); |
" for link argument exploding"); |
| proctable_destroy(&ptbl); |
proctable_destroy(&ptbl); |
| return NULL; |
return NULL; |
| } |
} |
| Line 192 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 234 static PROCTABLE proc_ar_to_proctable(in |
|
| } |
} |
| |
|
| link.proc_id = proctable_get_process_index_by_name( |
link.proc_id = proctable_get_process_index_by_name( |
| ptbl, ar[0]); |
ptbl, ar[0]); |
| if (link.proc_id >= 0) |
if (link.proc_id >= 0) |
| break; |
break; |
| |
|
| Line 202 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 244 static PROCTABLE proc_ar_to_proctable(in |
|
| |
|
| default: |
default: |
| msg_error_print("bad link specification: %s\n", |
msg_error_print("bad link specification: %s\n", |
| proc_ar[i].fd[j][k]); |
proc_ar[i].fd[j][k]); |
| proctable_destroy(&ptbl); |
proctable_destroy(&ptbl); |
| return NULL; |
return NULL; |
| } |
} |
| Line 210 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 252 static PROCTABLE proc_ar_to_proctable(in |
|
| link.fd_id = fd_str_to_fd_id(fd_str); |
link.fd_id = fd_str_to_fd_id(fd_str); |
| if (link.fd_id < 0) { |
if (link.fd_id < 0) { |
| msg_error_print("bad stream specification '%s'\n", |
msg_error_print("bad stream specification '%s'\n", |
| fd_str); |
fd_str); |
| proctable_destroy(&ptbl); |
proctable_destroy(&ptbl); |
| return NULL; |
return NULL; |
| } |
} |
| |
|
| if (! fd_add_proclink(&(ptbl[i]->fd[j]), &link)) { |
if (! fd_add_proclink(&(ptbl[i]->fd[j]), &link)) { |
| msg_error_print("not enought memory for" |
msg_error_print("not enought memory for" |
| " process link addition\n"); |
" process link addition\n"); |
| proctable_destroy(&ptbl); |
proctable_destroy(&ptbl); |
| return NULL; |
return NULL; |
| } |
} |
| } |
} |
| |
|
| |
/* TODO: why is this commented? */ |
| /* strdyn_safe_free(proc_ar[i].fd[j]); */ |
/* strdyn_safe_free(proc_ar[i].fd[j]); */ |
| } |
} |
| } |
} |
| Line 230 static PROCTABLE proc_ar_to_proctable(in |
|
| Line 273 static PROCTABLE proc_ar_to_proctable(in |
|
| return ptbl; |
return ptbl; |
| } |
} |
| |
|
| static int cfglocal_cmdline_parse_process(int argc, char **argv) |
static int cfglocal_cmdline_parse_process(int argc, char **argv, int silent) |
| { |
{ |
| struct cfg_context *con; |
struct cfg_context *con; |
| register int ret; |
register int ret; |
| Line 242 static int cfglocal_cmdline_parse_proces |
|
| Line 285 static int cfglocal_cmdline_parse_proces |
|
| |
|
| con = cfg_get_cmdline_context(argc, argv, options_process); |
con = cfg_get_cmdline_context(argc, argv, options_process); |
| if (con == NULL) { |
if (con == NULL) { |
| msg_error_print("not enought memory for command line parsing\n"); |
msg_error_print("not enough memory for command line parsing" |
| return -1; |
" 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; |
| |
} |
| |
|
| |
static int cfglocal_cmdline_parse_global(int argc, char **argv) |
| |
{ |
| |
struct cfg_context *con; |
| |
register int ret; |
| |
|
| |
con = cfg_get_cmdline_context(argc, argv, options_global); |
| |
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_set_context_flags(con, CFG_PROCESS_FIRST); |
| Line 255 static int cfglocal_cmdline_parse_proces |
|
| Line 347 static int cfglocal_cmdline_parse_proces |
|
| ret = cfg_parse(con); |
ret = cfg_parse(con); |
| |
|
| if (ret < 0 && ret != CFG_ERR_STOP_STR_FOUND) { |
if (ret < 0 && ret != CFG_ERR_STOP_STR_FOUND) { |
| /* TODO: |
msg_error_print("error on command line in global options" |
| better specification about error on command line |
" (error %d at %s)\n", ret, argv[cfg_get_cur_idx(con)]); |
| */ |
|
| msg_error_print("error on command line (error %d at %s)\n", |
|
| ret, argv[cfg_get_cur_idx(con)]); |
|
| cfg_free_context(con); |
cfg_free_context(con); |
| return ret; |
return ret; |
| } |
} |
| |
|
| if (cfg_get_cur_idx(con) == 0) { |
if (cfg_get_cur_idx(con) == 0) { |
| msg_error_print("misplaced process separator '--'\n"); |
msg_error_print("misplaced process separator '--'\n"); |
| |
|
| cfg_free_context(con); |
cfg_free_context(con); |
| return -1; |
return CFG_ERROR_STOP_STR; |
| } |
} |
| |
|
| if (ret == CFG_OK) |
if (ret == CFG_OK) |
| Line 280 static int cfglocal_cmdline_parse_proces |
|
| Line 371 static int cfglocal_cmdline_parse_proces |
|
| return ret; |
return ret; |
| } |
} |
| |
|
| |
|