| version 1.3, 2001/09/21 19:54:45 |
version 1.4, 2001/12/02 23:30:07 |
|
|
| /* |
/* |
| * $Log$ |
* $Log$ |
| |
* Revision 1.4 2001/12/02 23:30:07 jombik9 |
| |
* A lot of new functions added. |
| |
* Various improvements. |
| |
* |
| * Revision 1.3 2001/09/21 19:54:45 host8 |
* Revision 1.3 2001/09/21 19:54:45 host8 |
| * Cosmetics changes in *.c |
* Cosmetics changes in *.c |
| * |
* |
| * Revision 1.2 2001/09/21 19:44:51 host8 |
* Revision 1.2 2001/09/21 19:44:51 host8 |
| * Added $Log$ |
* Added $Log$ |
| |
* Added Revision 1.4 2001/12/02 23:30:07 jombik9 |
| |
* Added A lot of new functions added. |
| |
* Added Various improvements. |
| |
* Added |
| * Added Revision 1.3 2001/09/21 19:54:45 host8 |
* Added Revision 1.3 2001/09/21 19:54:45 host8 |
| * Added Cosmetics changes in *.c |
* Added Cosmetics changes in *.c |
| * Added keyword substitution |
* Added keyword substitution |
|
|
| #include <sys/stat.h> |
#include <sys/stat.h> |
| #include <getopt.h> |
#include <getopt.h> |
| |
|
| |
#include <cfg/str/strdyn.h> |
| |
|
| #include "process.h" |
#include "process.h" |
| #include "message.h" |
#include "message.h" |
| |
|
| Line 45 static char *strdel(char *s) { |
|
| Line 55 static char *strdel(char *s) { |
|
| |
|
| #ifndef optchar2fd_no |
#ifndef optchar2fd_no |
| # define optchar2fd_no(c) (c == 'i' ? FD_IN : \ |
# define optchar2fd_no(c) (c == 'i' ? FD_IN : \ |
| c == 'o' ? FD_OUT : c == 'e' ? FD_ERR : INVALID_FD) |
c == 'o' ? FD_OUT : c == 'e' ? FD_ERR : INVALID_FD) |
| #endif |
#endif |
| |
|
| |
|
| Line 75 analyze_proc_optarg(arg, link) |
|
| Line 85 analyze_proc_optarg(arg, link) |
|
| if (!isalnum(arg[i])) |
if (!isalnum(arg[i])) |
| strdel(arg + i); |
strdel(arg + i); |
| |
|
| /* Check the konzistention. */ |
/* Check the consistency. */ |
| if (strlen(arg) < 2) |
if (strlen(arg) < 2) |
| return -1; |
return -1; |
| if ((isdigit(arg[0]) && isalpha(arg[strlen(arg)-1])) || |
if ((isdigit(arg[0]) && isalpha(arg[strlen(arg)-1])) || |
| (isalpha(arg[0]) && isdigit(arg[strlen(arg)-1]))) |
(isalpha(arg[0]) && isdigit(arg[strlen(arg)-1]))) |
| ; |
; |
| else |
else |
| return -1; |
return -1; |
| Line 88 analyze_proc_optarg(arg, link) |
|
| Line 98 analyze_proc_optarg(arg, link) |
|
| } |
} |
| |
|
| /* |
/* |
| * Set next_sub_arg to the next subarument. |
* Set next_sub_arg to the next subargument. |
| * Set curr_2nd_part to the 2nd part of current subargument. |
* Set curr_2nd_part to the 2nd part of current subargument. |
| */ |
*/ |
| for (curr_2nd_part = next_sub_arg = curr_sub_arg; ; next_sub_arg++) { |
for (curr_2nd_part = next_sub_arg = curr_sub_arg; ; next_sub_arg++) { |
| if ((curr_2nd_part == curr_sub_arg) && |
if ((curr_2nd_part == curr_sub_arg) && |
| ((isdigit(curr_sub_arg[0]) && isalpha(next_sub_arg[0])) || |
((isdigit(curr_sub_arg[0]) && isalpha(next_sub_arg[0])) || |
| (isalpha(curr_sub_arg[0]) && isdigit(next_sub_arg[0])))) |
(isalpha(curr_sub_arg[0]) && isdigit(next_sub_arg[0])))) |
| curr_2nd_part = next_sub_arg; |
curr_2nd_part = next_sub_arg; |
| if ((next_sub_arg[1] == '\0') || |
if ((next_sub_arg[1] == '\0') || |
| (isdigit(curr_sub_arg[0]) && |
(isdigit(curr_sub_arg[0]) && |
| isdigit(next_sub_arg[1]) && isalpha(next_sub_arg[0])) || |
isdigit(next_sub_arg[1]) && isalpha(next_sub_arg[0])) || |
| (isalpha(curr_sub_arg[0]) && |
(isalpha(curr_sub_arg[0]) && |
| isalpha(next_sub_arg[1]) && isdigit(next_sub_arg[0]))) |
isalpha(next_sub_arg[1]) && isdigit(next_sub_arg[0]))) |
| break; |
break; |
| } |
} |
| next_sub_arg++; |
next_sub_arg++; |
| Line 127 analyze_proc_optarg(arg, link) |
|
| Line 137 analyze_proc_optarg(arg, link) |
|
| link->fd_id = INVALID_FD; |
link->fd_id = INVALID_FD; |
| for (i = 0; i < N_FD_STR * N_FD; i++) { |
for (i = 0; i < N_FD_STR * N_FD; i++) { |
| if (strlen(fd_str[i/N_FD][i%N_FD]) == |
if (strlen(fd_str[i/N_FD][i%N_FD]) == |
| fd_end - fd_start + 1 && |
fd_end - fd_start + 1 && |
| fd_start == (char *)strstr(fd_start, |
fd_start == (char *)strstr(fd_start, |
| fd_str[i/N_FD][i%N_FD])) |
fd_str[i/N_FD][i%N_FD])) |
| link->fd_id = i % N_FD; |
link->fd_id = i % N_FD; |
| } |
} |
| } |
} |
| Line 153 process_init(proc) |
|
| Line 163 process_init(proc) |
|
| for (k = 0; k < N_FD; k++) { |
for (k = 0; k < N_FD; k++) { |
| proc->fd[k].n_link = 0; |
proc->fd[k].n_link = 0; |
| proc->fd[k].link = NULL; |
proc->fd[k].link = NULL; |
| |
|
| |
proc->fd[k].pipe[0] = proc->fd[k].pipe[1] = 0; |
| } |
} |
| |
|
| |
proc->pid = 0; |
| |
|
| proc->argv = NULL; |
proc->argv = NULL; |
| |
proc->name = NULL; |
| } |
} |
| |
|
| int |
int |
| Line 183 process_init_by_array(proc, size, array) |
|
| Line 198 process_init_by_array(proc, size, array) |
|
| |
|
| while (1) { |
while (1) { |
| c = getopt_long(size + 1, array - 1, "+i:o:e:", |
c = getopt_long(size + 1, array - 1, "+i:o:e:", |
| long_options, &option_index); |
long_options, &option_index); |
| |
|
| #if DEBUG |
#if DEBUG |
| msg_debug_print("process_init_by_array(): " |
msg_debug_print("process_init_by_array(): " |
| "getopt_long() = %d [%c]\n", c, c); |
"getopt_long() = %d [%c]\n", c, c); |
| #endif |
#endif |
| |
|
| if (c == -1) { |
if (c == -1) { |
| return process_argv_init_by_array( |
return process_argv_init_by_array( |
| proc, |
proc, |
| size + 1 - optind, |
size + 1 - optind, |
| array - 1 + optind); |
array - 1 + optind); |
| } |
} |
| |
|
| switch (c) { |
switch (c) { |
| Line 209 process_init_by_array(proc, size, array) |
|
| Line 224 process_init_by_array(proc, size, array) |
|
| a_ret = analyze_proc_optarg(optarg, &link); |
a_ret = analyze_proc_optarg(optarg, &link); |
| if (a_ret == -1) { |
if (a_ret == -1) { |
| msg_error_print("invalid filedescriptor " |
msg_error_print("invalid filedescriptor " |
| "specification -- %s\n", |
"specification -- %s\n", |
| optarg); |
optarg); |
| return 0; |
return 0; |
| } |
} |
| |
|
| if (!fd_add_proclink(&proc->fd[optchar2fd_no(c)], |
if (!fd_add_proclink(&proc->fd[optchar2fd_no(c)], |
| &link)) |
&link)) |
| return 0; |
return 0; |
| |
|
| } while (a_ret > 0); |
} while (a_ret > 0); |
| Line 245 process_destroy(proc) |
|
| Line 260 process_destroy(proc) |
|
| { |
{ |
| register int k; |
register int k; |
| |
|
| |
#if DEBUG |
| |
msg_debug_print("process_destroy(): destroyed process = %p\n", proc); |
| |
#endif |
| |
|
| for (k = 0; k < N_FD; k++) { |
for (k = 0; k < N_FD; k++) { |
| free(proc->fd[k].link); |
|
| |
#if 0 && DEBUG |
| |
msg_debug_print("process_destroy(): proc->fd[%d] = %p\n", |
| |
k, proc->fd[k].link); |
| |
#endif |
| |
if (proc->fd[k].link != NULL) |
| |
free(proc->fd[k].link); |
| |
|
| proc->fd[k].link = NULL; |
proc->fd[k].link = NULL; |
| proc->fd[k].n_link = 0; |
proc->fd[k].n_link = 0; |
| } |
} |
| |
|
| process_argv_destroy(proc); |
strdyn_safe_free(proc->argv); |
| |
proc->argv = NULL; |
| |
|
| |
strdyn_safe_free(proc->name); |
| |
proc->name = NULL; |
| } |
} |
| |
|
| |
|
| Line 281 process_argv_init_by_array(proc, size, a |
|
| Line 310 process_argv_init_by_array(proc, size, a |
|
| for (i = 0; i < size; i++) { |
for (i = 0; i < size; i++) { |
| proc->argv[i] = strdup(array[i]); |
proc->argv[i] = strdup(array[i]); |
| if (proc->argv[i] == NULL) { |
if (proc->argv[i] == NULL) { |
| process_argv_destroy(proc); |
strdyn_free(proc->argv); |
| |
proc->argv = NULL; |
| return 0; |
return 0; |
| } |
} |
| } |
} |
| Line 291 process_argv_init_by_array(proc, size, a |
|
| Line 321 process_argv_init_by_array(proc, size, a |
|
| |
|
| |
|
| void |
void |
| process_argv_destroy(proc) |
process_print_cmdline(proc) |
| struct process *proc; |
struct process *proc; |
| { |
{ |
| if (proc->argv != NULL) { |
register int j = 0; |
| register int i; |
|
| |
|
| for (i = 0; proc->argv[i] != NULL; i++) { |
if (proc == NULL) { |
| free(proc->argv[i]); |
msg_warn_print("NULL struct process pointer in " |
| } |
"process_print_cmdline()\n"); |
| |
return; |
| |
} |
| |
|
| free(proc->argv); |
while (proc->argv != NULL && proc->argv[j] != NULL) { |
| proc->argv = NULL; |
msg_print(proc->argv[j]); |
| |
msg_print(" "); |
| |
j++; |
| } |
} |
| } |
} |
| |
|
| |
|
| void |
void |
| process_print_cmdline(proc) |
process_print_names(proc) |
| struct process *proc; |
struct process *proc; |
| { |
{ |
| |
register int j = 0; |
| |
|
| if (proc == NULL) { |
if (proc == NULL) { |
| msg_warn_print("\nNULL struct process pointer in " |
msg_warn_print("NULL struct process pointer in " |
| "process_print_cmdline()\n"); |
"process_print_names()\n"); |
| |
return; |
| } |
} |
| else { |
|
| register int j = 0; |
|
| |
|
| while (proc->argv != NULL && proc->argv[j] != NULL) { |
while (proc->name != NULL && proc->name[j] != NULL) { |
| msg_print(proc->argv[j]); |
msg_print(proc->name[j]); |
| msg_print(" "); |
if (proc->name[j + 1] != NULL) |
| j++; |
msg_print(", "); |
| } |
j++; |
| } |
} |
| } |
} |
| |
|
| |
|
| void |
void |
| process_print_struct(proc) |
process_print_struct(proc) |
| struct process *proc; |
struct process *proc; |
| { |
{ |
| |
|
| |
register int i; |
| |
struct stat buf; |
| |
|
| if (proc == NULL) { |
if (proc == NULL) { |
| msg_warn_print("\nNULL struct process pointer in " |
msg_warn_print("NULL struct process pointer in " |
| "process_print_struct()\n"); |
"process_print_struct()\n"); |
| |
|
| |
return; |
| } |
} |
| else { |
|
| register int i; |
|
| struct stat buf; |
|
| |
|
| process_print_cmdline(proc); |
process_print_cmdline(proc); |
| msg_print("\n\tPID=%d", proc->pid); |
msg_print("\n\tPID = %d", proc->pid); |
| |
|
| for (i = 0; i < N_FD; i++) |
for (i = 0; i < N_FD; i++) |
| msg_print("\n\tfd[%d].n_link=%d",i, proc->fd[i].n_link); |
msg_print("\n\tfd[%d].n_link = %d",i, proc->fd[i].n_link); |
| |
|
| for (i = 0; i < N_FD; i++) |
for (i = 0; i < N_FD; i++) |
| msg_print("\n\tfd[%d].pipe=(%d, %d)",i, |
msg_print("\n\tfd[%d].pipe = (%d, %d)",i, |
| fstat(proc->fd[i].pipe[0], &buf), |
fstat(proc->fd[i].pipe[0], &buf), |
| fstat(proc->fd[i].pipe[1], &buf)); |
fstat(proc->fd[i].pipe[1], &buf)); |
| |
|
| /* Toto je urcite zle!! |
/* Toto je urcite zle!! |
| * Nepto [3/4/2001] |
* Nepto [3/4/2001] |
| |
|
| for (i = 0; i < N_FD; i++) |
for (i = 0; i < N_FD; i++) |
| msg_print("\n\tfd[%d].link=(proc_id=%d, fstat(fd)=%d)", |
msg_print("\n\tfd[%d].link=(proc_id=%d, fstat(fd)=%d)", |
| i, proc->fd[i].link->proc_id, |
i, proc->fd[i].link->proc_id, |
| fstat(proc->fd[i].link->fd, &buf)); |
fstat(proc->fd[i].link->fd, &buf)); |
| */ |
*/ |
| } |
|
| } |
} |
| |
|
| void |
void |