1 | /* $Id: $ */
|
---|
2 | /** @file
|
---|
3 | *
|
---|
4 | * The shell instance and it's methods.
|
---|
5 | *
|
---|
6 | * Copyright (c) 2007 knut st. osmundsen <bird-src-spam@anduin.net>
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * This file is part of kBuild.
|
---|
10 | *
|
---|
11 | * kBuild is free software; you can redistribute it and/or modify
|
---|
12 | * it under the terms of the GNU General Public License as published by
|
---|
13 | * the Free Software Foundation; either version 2 of the License, or
|
---|
14 | * (at your option) any later version.
|
---|
15 | *
|
---|
16 | * kBuild is distributed in the hope that it will be useful,
|
---|
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | * GNU General Public License for more details.
|
---|
20 | *
|
---|
21 | * You should have received a copy of the GNU General Public License
|
---|
22 | * along with kBuild; if not, write to the Free Software
|
---|
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifndef ___shinstance_h___
|
---|
28 | #define ___shinstance_h___
|
---|
29 |
|
---|
30 | #include "shtypes.h"
|
---|
31 | #include "shthread.h"
|
---|
32 | #include "shfile.h"
|
---|
33 |
|
---|
34 | #include "var.h"
|
---|
35 |
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * A shell instance.
|
---|
39 | *
|
---|
40 | * This is the core structure of the shell, it contains all
|
---|
41 | * the data associated with a shell process except that it's
|
---|
42 | * running in a thread and not a separate process.
|
---|
43 | */
|
---|
44 | typedef struct shinstance
|
---|
45 | {
|
---|
46 | struct shinstance *next; /**< The next shell instance. */
|
---|
47 | struct shinstance *prev; /**< The previous shell instance. */
|
---|
48 | struct shinstance *parent; /**< The parent shell instance. */
|
---|
49 | pid_t pid; /**< The (fake) process id of this shell instance. */
|
---|
50 | shtid tid; /**< The thread identifier of the thread for this shell. */
|
---|
51 | shfdtab fdtab; /**< The file descriptor table. */
|
---|
52 |
|
---|
53 | /* error.h */
|
---|
54 | struct jmploc *handler;
|
---|
55 | int exception;
|
---|
56 | int exerrno;
|
---|
57 | int volatile suppressint;
|
---|
58 | int volatile intpending;
|
---|
59 |
|
---|
60 | /* main.h */
|
---|
61 | int rootpid; /**< pid of main shell. */
|
---|
62 | int rootshell; /**< true if we aren't a child of the main shell. */
|
---|
63 | struct shinstance *psh_rootshell; /**< The root shell pointer. (!rootshell) */
|
---|
64 |
|
---|
65 | /* trap.h */
|
---|
66 | int pendingsigs;
|
---|
67 |
|
---|
68 | /* parse.h */
|
---|
69 | int tokpushback;
|
---|
70 | int whichprompt; /**< 1 == PS1, 2 == PS2 */
|
---|
71 |
|
---|
72 | /* output.h */
|
---|
73 | struct output output;
|
---|
74 | struct output errout;
|
---|
75 | struct output memout;
|
---|
76 | struct output *out1;
|
---|
77 | struct output *out2;
|
---|
78 |
|
---|
79 | /* options.h */
|
---|
80 | struct optent optlist[NOPTS];
|
---|
81 | char *minusc; /**< argument to -c option */
|
---|
82 | char *arg0; /**< $0 */
|
---|
83 | struct shparam shellparam; /**< $@ */
|
---|
84 | char **argptr; /**< argument list for builtin commands */
|
---|
85 | char *optionarg; /**< set by nextopt */
|
---|
86 | char *optptr; /**< used by nextopt */
|
---|
87 |
|
---|
88 | /* var.h */
|
---|
89 | struct localvar *localvars;
|
---|
90 | #if ATTY
|
---|
91 | struct var vatty;
|
---|
92 | #endif
|
---|
93 | struct var vifs;
|
---|
94 | struct var vmail;
|
---|
95 | struct var vmpath;
|
---|
96 | struct var vpath;
|
---|
97 | #ifdef _MSC_VER
|
---|
98 | struct var vpath2;
|
---|
99 | #endif
|
---|
100 | struct var vps1;
|
---|
101 | struct var vps2;
|
---|
102 | struct var vps4;
|
---|
103 | #ifndef SMALL
|
---|
104 | struct var vterm;
|
---|
105 | struct var vtermcap;
|
---|
106 | struct var vhistsize;
|
---|
107 | #endif
|
---|
108 |
|
---|
109 | /* myhistedit.h */
|
---|
110 | int displayhist;
|
---|
111 | #ifndef SMALL
|
---|
112 | History *hist;
|
---|
113 | EditLine *el;
|
---|
114 | #endif
|
---|
115 |
|
---|
116 | /* memalloc.h */
|
---|
117 | char *stacknxt;
|
---|
118 | int stacknleft;
|
---|
119 | int sstrnleft;
|
---|
120 | int herefd;
|
---|
121 |
|
---|
122 | /* jobs.h */
|
---|
123 | pid_t backgndpid; /**< pid of last background process */
|
---|
124 | int job_warning; /**< user was warned about stopped jobs */
|
---|
125 |
|
---|
126 | /* input.h */
|
---|
127 | int plinno;
|
---|
128 | int parsenleft; /**< number of characters left in input buffer */
|
---|
129 | char *parsenextc; /**< next character in input buffer */
|
---|
130 | int init_editline; /**< 0 == not setup, 1 == OK, -1 == failed */
|
---|
131 |
|
---|
132 | /* exec.h */
|
---|
133 | const char *pathopt; /**< set by padvance */
|
---|
134 |
|
---|
135 | /* eval.h */
|
---|
136 | char *commandname; /**< currently executing command */
|
---|
137 | int exitstatus; /**< exit status of last command */
|
---|
138 | int back_exitstatus;/**< exit status of backquoted command */
|
---|
139 | struct strlist *cmdenviron; /**< environment for builtin command */
|
---|
140 | int funcnest;
|
---|
141 | int evalskip;
|
---|
142 |
|
---|
143 | /* builtins.h */
|
---|
144 |
|
---|
145 | /* alias.c */
|
---|
146 | #define ATABSIZE 39
|
---|
147 | struct alias *atab[ATABSIZE];
|
---|
148 |
|
---|
149 | /* cd.c */
|
---|
150 | char *curdir; /**< current working directory */
|
---|
151 | char *prevdir; /**< previous working directory */
|
---|
152 | char *cdcomppath;
|
---|
153 | int getpwd_first; /**< static in getpwd. (initialized to 1!) */
|
---|
154 |
|
---|
155 | /* error.c */
|
---|
156 | char errmsg_buf[16]; /**< static in errmsg. (bss) */
|
---|
157 |
|
---|
158 | } shinstance;
|
---|
159 |
|
---|
160 |
|
---|
161 | extern shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv);
|
---|
162 | char *sh_getenv(shinstance *, const char *);
|
---|
163 |
|
---|
164 | /* signals */
|
---|
165 | #include <signal.h>
|
---|
166 | #ifdef _MSC_VER
|
---|
167 | typedef uint32_t sh_sigset_t;
|
---|
168 | #else
|
---|
169 | typedef sigset_t sh_sigset_t;
|
---|
170 | #endif
|
---|
171 |
|
---|
172 | typedef void (*sh_handler)(int);
|
---|
173 | sh_handler sh_signal(shinstance *, int, sh_handler handler);
|
---|
174 | void sh_raise_sigint(shinstance *);
|
---|
175 | void sh_sigemptyset(sh_sigset_t *set);
|
---|
176 | int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);
|
---|
177 |
|
---|
178 | #endif
|
---|