| 1 | /*
|
|---|
| 2 | * push - anyone remember TOPS-20?
|
|---|
| 3 | *
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | #include <config.h>
|
|---|
| 7 | #include <stdio.h>
|
|---|
| 8 | #include <errno.h>
|
|---|
| 9 |
|
|---|
| 10 | #include "builtins.h"
|
|---|
| 11 | #include "shell.h"
|
|---|
| 12 | #include "jobs.h"
|
|---|
| 13 | #include "bashgetopt.h"
|
|---|
| 14 |
|
|---|
| 15 | #ifndef errno
|
|---|
| 16 | extern int errno;
|
|---|
| 17 | #endif
|
|---|
| 18 |
|
|---|
| 19 | extern int dollar_dollar_pid;
|
|---|
| 20 | extern int last_command_exit_value;
|
|---|
| 21 |
|
|---|
| 22 | int
|
|---|
| 23 | push_builtin (list)
|
|---|
| 24 | WORD_LIST *list;
|
|---|
| 25 | {
|
|---|
| 26 | pid_t pid;
|
|---|
| 27 | int xstatus, opt;
|
|---|
| 28 |
|
|---|
| 29 | xstatus = EXECUTION_SUCCESS;
|
|---|
| 30 | reset_internal_getopt ();
|
|---|
| 31 | while ((opt = internal_getopt (list, "")) != -1)
|
|---|
| 32 | {
|
|---|
| 33 | switch (opt)
|
|---|
| 34 | {
|
|---|
| 35 | default:
|
|---|
| 36 | builtin_usage ();
|
|---|
| 37 | return (EX_USAGE);
|
|---|
| 38 | }
|
|---|
| 39 | }
|
|---|
| 40 | list = loptend;
|
|---|
| 41 |
|
|---|
| 42 | pid = make_child (savestring ("push"), 0);
|
|---|
| 43 | if (pid == -1)
|
|---|
| 44 | {
|
|---|
| 45 | builtin_error ("cannot fork: %s", strerror (errno));
|
|---|
| 46 | return (EXECUTION_FAILURE);
|
|---|
| 47 | }
|
|---|
| 48 | else if (pid == 0)
|
|---|
| 49 | {
|
|---|
| 50 | /* Shell variable adjustments: $SHLVL, $$, $PPID, $! */
|
|---|
| 51 | adjust_shell_level (1);
|
|---|
| 52 | dollar_dollar_pid = getpid ();
|
|---|
| 53 | set_ppid ();
|
|---|
| 54 |
|
|---|
| 55 | /* Clean up job control stuff. */
|
|---|
| 56 | stop_making_children ();
|
|---|
| 57 | cleanup_the_pipeline ();
|
|---|
| 58 | delete_all_jobs (0);
|
|---|
| 59 |
|
|---|
| 60 | last_asynchronous_pid = NO_PID;
|
|---|
| 61 |
|
|---|
| 62 | /* Make sure the job control code has the right values for
|
|---|
| 63 | the shell's process group and tty process group, and that
|
|---|
| 64 | the signals are set correctly for job control. */
|
|---|
| 65 | initialize_job_control (0);
|
|---|
| 66 | initialize_job_signals ();
|
|---|
| 67 |
|
|---|
| 68 | /* And read commands until exit. */
|
|---|
| 69 | reader_loop ();
|
|---|
| 70 | exit_shell (last_command_exit_value);
|
|---|
| 71 | }
|
|---|
| 72 | else
|
|---|
| 73 | {
|
|---|
| 74 | stop_pipeline (0, (COMMAND *)NULL);
|
|---|
| 75 | xstatus = wait_for (pid);
|
|---|
| 76 | return (xstatus);
|
|---|
| 77 | }
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | char *push_doc[] = {
|
|---|
| 81 | "Create a child that is an exact duplicate of the running shell",
|
|---|
| 82 | "and wait for it to exit. The $SHLVL, $!, $$, and $PPID variables",
|
|---|
| 83 | "are adjusted in the child. The return value is the exit status",
|
|---|
| 84 | "of the child.",
|
|---|
| 85 | (char *)NULL
|
|---|
| 86 | };
|
|---|
| 87 |
|
|---|
| 88 | struct builtin push_struct = {
|
|---|
| 89 | "push",
|
|---|
| 90 | push_builtin,
|
|---|
| 91 | BUILTIN_ENABLED,
|
|---|
| 92 | push_doc,
|
|---|
| 93 | "push",
|
|---|
| 94 | 0
|
|---|
| 95 | };
|
|---|