static void waitchildren(const char *name, int waitall) { pid_t pid; int status; while ((pid = xwait(waitall || pids_full(), &status)) > 0) { /* If we couldn't invoke the utility, exit. */ if (childerr != 0) { errno = childerr; err(errno == ENOENT ? 127 : 126, "%s", name); } /* * If utility signaled or exited with a value of 255, * exit 1-125. */ if (WIFSIGNALED(status)) errx(1, "%s: terminated with signal %d, aborting", name, WTERMSIG(status)); if (WEXITSTATUS(status) == 255) errx(1, "%s: exited with status 255, aborting", name); if (WEXITSTATUS(status)) rval = 1; } if (pid == -1 && errno != ECHILD) err(1, "waitpid"); }
void lpwd() { pid_t pid; my_putstr("SUCCESS : Working Directory Path\n"); pid = xfork(); if (pid == 0) execlp("pwd", "pwd", NULL); else xwait(NULL); my_putstr("{ftp} "); }
void lls(char *buffer) { char opt[CMD]; char *pointer; pid_t pid; get_info_c(opt, buffer, my_strlen(buffer)); pointer = opt; if (opt[0] == '\0') pointer = NULL; my_putstr("SUCCESS : Working Listing\n"); pid = xfork(); if (pid == 0) execlp("/bin/sh", "sh", "-c", "ls -la", NULL); else xwait(NULL); my_putstr("{ftp} "); }
shell() { register int i; register char *p; register char *shellfile; char *getfilename(); char *macro(); shellfile = getfilename(); if (*shellfile == 0) shellfile = 0; fclose(Qryiop); if ((Xwaitpid = fork()) == -1) syserr("shell: fork"); if (Xwaitpid == 0) { setuid(getuid()); # ifndef xB_UNIX setgid(getgid()); # endif for (i = 3; i < MAXFILES; i++) close(i); p = macro("{shell}"); # ifdef xMTR3 tTfp(7, 0, "{shell} = '%o'\n", p); # endif if (p != 0) { execl(p, p, shellfile, Qbname, 0); printf("Cannot call %s; using /bin/sh\n", p); } execl("/bin/sh", "sh", shellfile, Qbname, 0); syserr("shell: exec"); } if (Nodayfile >= 0) printf(">>shell\n"); /* wait for shell to complete */ xwait(); }
static void waitchildren(const char *name, int waitall) { pid_t pid; int status; int cause_exit = 0; while ((pid = xwait(waitall || pids_full(), &status)) > 0) { /* * If we couldn't invoke the utility or if utility exited * because of a signal or with a value of 255, warn (per * POSIX), and then wait until all other children have * exited before exiting 1-125. POSIX requires us to stop * reading if child exits because of a signal or with 255, * but it does not require us to exit immediately; waiting * is preferable to orphaning. */ if (childerr != 0 && cause_exit == 0) { errno = childerr; waitall = 1; cause_exit = ENOENT ? 127 : 126; warn("%s", name); } else if (WIFSIGNALED(status)) { waitall = cause_exit = 1; warnx("%s: terminated with signal %d; aborting", name, WTERMSIG(status)); } else if (WEXITSTATUS(status) == 255) { waitall = cause_exit = 1; warnx("%s: exited with status 255; aborting", name); } else if (WEXITSTATUS(status)) rval = 1; } if (cause_exit) exit(cause_exit); if (pid == -1 && errno != ECHILD) err(1, "waitpid"); }