| version 1.2, 2002/02/21 02:22:04 |
version 1.3, 2002/02/28 09:23:31 |
| Line 365 analyze_proc_optarg(arg, link) |
|
| Line 365 analyze_proc_optarg(arg, link) |
|
| c == 'o' ? FD_OUT : c == 'e' ? FD_ERR : INVALID_FD) |
c == 'o' ? FD_OUT : c == 'e' ? FD_ERR : INVALID_FD) |
| #endif |
#endif |
| |
|
| |
/** |
| |
** This is from old conf.c file. |
| |
**/ |
| |
|
| |
#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; |
| |
|
| |
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 */ |
| |
|