Changeset 16059 for trunk/Ohana/src/opihi/cmd.basic/shell.c
- Timestamp:
- Jan 14, 2008, 1:50:11 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/cmd.basic/shell.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/cmd.basic/shell.c
r15868 r16059 1 1 # include "basic.h" 2 3 static char *defshell = "/bin/sh"; 4 static char *cmdflag = "-c"; 2 5 3 6 int shell (int argc, char **argv) { … … 6 9 int exit_status; 7 10 int wait_status; 8 int result ;9 char **args ;11 int result, length; 12 char **args, *shell; 10 13 11 ALLOCATE (args, char *, argc); 14 shell = getenv ("SHELL"); 15 if (shell == NULL) shell = defshell; 16 17 // we are creating a command of the form /bin/sh -c argv[1] argv[2] etc, where 18 // the argv[1], etc elements are concatenated into a single string 19 ALLOCATE (args, char *, 4); 20 args[0] = shell; 21 args[1] = cmdflag; 22 23 length = 0; 12 24 for (i = 1; i < argc; i++) { 13 args[i-1] = argv[i];25 length += strlen(argv[i]) + 1; 14 26 } 15 args[i-1] = NULL; 27 28 ALLOCATE (args[2], char, length); 29 args[2][0] = 0; 30 for (i = 1; i < argc; i++) { 31 strcat (args[2], argv[i]); 32 if (i < argc - 1) strcat (args[2], " "); 33 } 34 args[3] = NULL; 35 36 // send the commands to the shell specified in the env variable SHELL, or else /bin/sh 16 37 17 38 // use execvp to enable a timeout on the system call 18 39 pid = fork (); 19 40 if (!pid) { /* must be child process */ 20 execvp ( args[0], args);41 execvp (shell, args); 21 42 exit (1); 22 43 }
Note:
See TracChangeset
for help on using the changeset viewer.
