IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 14, 2008, 1:50:11 PM (18 years ago)
Author:
eugene
Message:

convert to new gauss-jordan code (non-Press); fixing Wall,Werror warnings; fixed bug in shell command; fixed bug in matrix element lookup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/opihi/cmd.basic/shell.c

    r15868 r16059  
    11# include "basic.h"
     2
     3static char *defshell = "/bin/sh";
     4static char *cmdflag = "-c";
    25
    36int shell (int argc, char **argv) {
     
    69  int exit_status;
    710  int wait_status;
    8   int result;
    9   char **args;
     11  int result, length;
     12  char **args, *shell;
    1013
    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;
    1224  for (i = 1; i < argc; i++) {
    13     args[i-1] = argv[i];
     25    length += strlen(argv[i]) + 1;
    1426  }
    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
    1637
    1738  // use execvp to enable a timeout on the system call
    1839  pid = fork ();
    1940  if (!pid) { /* must be child process */
    20     execvp (args[0], args);
     41    execvp (shell, args);
    2142    exit (1);
    2243  }
Note: See TracChangeset for help on using the changeset viewer.