Bash  5.0-beta2
Bash - Bourne Again shell
push.c
Go to the documentation of this file.
1 /*
2  * push - anyone remember TOPS-20?
3  *
4  */
5 
6 /*
7  Copyright (C) 1999-2009 Free Software Foundation, Inc.
8 
9  This file is part of GNU Bash.
10  Bash is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  Bash is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with Bash. If not, see <http://www.gnu.org/licenses/>.
22 */
23 
24 #include <config.h>
25 #include <stdio.h>
26 #include <errno.h>
27 
28 #include "builtins.h"
29 #include "shell.h"
30 #include "jobs.h"
31 #include "bashgetopt.h"
32 #include "common.h"
33 
34 #ifndef errno
35 extern int errno;
36 #endif
37 
38 extern int dollar_dollar_pid;
39 extern int last_command_exit_value;
40 
41 int
43  WORD_LIST *list;
44 {
45  pid_t pid;
46  int xstatus, opt;
47 
48  xstatus = EXECUTION_SUCCESS;
50  while ((opt = internal_getopt (list, "")) != -1)
51  {
52  switch (opt)
53  {
55  default:
56  builtin_usage ();
57  return (EX_USAGE);
58  }
59  }
60  list = loptend;
61 
62  pid = make_child (savestring ("push"), 0);
63  if (pid == -1)
64  {
65  builtin_error ("cannot fork: %s", strerror (errno));
66  return (EXECUTION_FAILURE);
67  }
68  else if (pid == 0)
69  {
70  /* Shell variable adjustments: $SHLVL, $$, $PPID, $! */
73  set_ppid ();
74 
75  /* Clean up job control stuff. */
78  delete_all_jobs (0);
79 
81 
82  /* Make sure the job control code has the right values for
83  the shell's process group and tty process group, and that
84  the signals are set correctly for job control. */
87 
88  /* And read commands until exit. */
89  reader_loop ();
91  }
92  else
93  {
94  stop_pipeline (0, (COMMAND *)NULL);
95  xstatus = wait_for (pid);
96  return (xstatus);
97  }
98 }
99 
100 char *push_doc[] = {
101  "Create child shell.",
102  "",
103  "Create a child that is an exact duplicate of the running shell",
104  "and wait for it to exit. The $SHLVL, $!, $$, and $PPID variables",
105  "are adjusted in the child. The return value is the exit status",
106  "of the child.",
107  (char *)NULL
108 };
109 
111  "push",
112  push_builtin,
114  push_doc,
115  "push",
116  0
117 };
int errno
struct builtin push_struct
Definition: push.c:110
list
Definition: subst.c:10212
void set_ppid()
Definition: variables.c:926
int initialize_job_control(int force)
Definition: jobs.c:4178
char * strerror()
char * push_doc[]
Definition: push.c:100
void adjust_shell_level(int change)
Definition: variables.c:804
volatile pid_t last_asynchronous_pid
Definition: jobs.c:215
#define CASE_HELPOPT
Definition: common.h:38
void builtin_error(char *format, va_alist) const
Definition: common.c:106
int stop_pipeline(int async, COMMAND *deferred)
Definition: jobs.c:537
void builtin_usage()
Definition: common.c:145
void stop_making_children()
Definition: jobs.c:421
char * savestring(const char *s)
Definition: savestring.c:33
pid_t make_child(char *command, int async_p)
Definition: jobs.c:1919
#define BUILTIN_ENABLED
Definition: builtins.h:41
#define EXECUTION_SUCCESS
Definition: shell.h:53
#define NO_PID
Definition: jobs.h:177
#define EX_USAGE
Definition: shell.h:71
void reset_internal_getopt()
Definition: bashgetopt.c:177
void initialize_job_signals()
Definition: jobs.c:4405
void exit_shell(int s)
Definition: shell.c:956
#define NULL
Definition: general.h:53
WORD_LIST * loptend
Definition: bashgetopt.c:47
#define EXECUTION_FAILURE
Definition: shell.h:52
int internal_getopt(WORD_LIST *list, char *opts)
Definition: bashgetopt.c:50
pid_t getpid()
void delete_all_jobs(int running_only)
Definition: jobs.c:4529
void cleanup_the_pipeline()
Definition: jobs.c:427
int last_command_exit_value
Definition: execute_cmd.c:215
int dollar_dollar_pid
Definition: variables.c:148
int push_builtin(WORD_LIST *list)
Definition: push.c:42
int reader_loop()
Definition: eval.c:61
int wait_for(pid_t pid)
Definition: jobs.c:2705