Index: runas.c =================================================================== RCS file: /cvs/linux-2.4-xfs/cmd/xfstests/src/runas.c,v retrieving revision 1.1 diff -u -u -r1.1 runas.c --- runas.c 2001/01/15 05:01:19 1.1 +++ runas.c 2001/02/07 09:57:51 @@ -62,7 +62,8 @@ int c; uid_t uid = -1; gid_t gid = -1; - char *cmd=NULL; + int pid; + char **cmd; gid_t sgids[SUP_MAX]; int sup_cnt = 0; int status; @@ -91,13 +92,18 @@ } /* build up the cmd */ - for ( ; optind < argc; optind++) { - cmd = realloc(cmd, (cmd==NULL?0:strlen(cmd)) + - strlen(argv[optind]) + 4); - strcat(cmd, " "); - strcat(cmd, argv[optind]); - } - + if (optind == argc) { + usage(); + exit(1); + } + else { + char **p; + p = cmd = (char **)malloc(sizeof(char *) * (argc - optind + 1)); + for ( ; optind < argc; optind++, p++) { + *p = strdup(argv[optind]); + } + *p = NULL; + } if (gid != -1) { if (setegid(gid) == -1) { @@ -122,9 +128,19 @@ exit(1); } } - - status = system(cmd); + pid = fork(); + if (pid == -1) { + fprintf(stderr, "%s: fork failed: %s\n", + prog, strerror(errno)); + exit(1); + } + if (pid == 0) { + execvp(cmd[0], cmd); + fprintf(stderr, "%s: %s\n", cmd[0], strerror(errno)); + exit(127); + } + wait(&status); if (WIFSIGNALED(status)) { fprintf(stderr, "%s: command terminated with signal %d\n", prog, WTERMSIG(status));