VirtualBox

source: kBuild/trunk/src/kash/shinstance.h@ 1198

Last change on this file since 1198 was 1198, checked in by bird, 17 years ago

moving globals into shinstance...

File size: 8.2 KB
Line 
1/* $Id: $ */
2/** @file
3 *
4 * The shell instance and it's methods.
5 *
6 * Copyright (c) 2007 knut st. osmundsen <[email protected]>
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#include "output.h"
34#include "options.h"
35
36#include "var.h"
37
38#define MINSIZE 504 /* minimum size of a block */
39struct stack_block {
40 struct stack_block *prev;
41 char space[MINSIZE];
42};
43
44
45/**
46 * A shell instance.
47 *
48 * This is the core structure of the shell, it contains all
49 * the data associated with a shell process except that it's
50 * running in a thread and not a separate process.
51 */
52typedef struct shinstance
53{
54 struct shinstance *next; /**< The next shell instance. */
55 struct shinstance *prev; /**< The previous shell instance. */
56 struct shinstance *parent; /**< The parent shell instance. */
57 pid_t pid; /**< The (fake) process id of this shell instance. */
58 shtid tid; /**< The thread identifier of the thread for this shell. */
59 shfdtab fdtab; /**< The file descriptor table. */
60
61 /* error.h */
62 struct jmploc *handler;
63 int exception;
64 int exerrno;
65 int volatile suppressint;
66 int volatile intpending;
67
68 /* main.h */
69 int rootpid; /**< pid of main shell. */
70 int rootshell; /**< true if we aren't a child of the main shell. */
71 struct shinstance *psh_rootshell; /**< The root shell pointer. (!rootshell) */
72
73 /* trap.h */
74 int pendingsigs;
75
76 /* parse.h */
77 int tokpushback;
78 int whichprompt; /**< 1 == PS1, 2 == PS2 */
79
80 /* output.h */
81 struct output output;
82 struct output errout;
83 struct output memout;
84 struct output *out1;
85 struct output *out2;
86
87 /* options.h */
88 struct optent optlist[NOPTS];
89 char *minusc; /**< argument to -c option */
90 char *arg0; /**< $0 */
91 struct shparam shellparam; /**< $@ */
92 char **argptr; /**< argument list for builtin commands */
93 char *optionarg; /**< set by nextopt */
94 char *optptr; /**< used by nextopt */
95
96 /* var.h */
97 struct localvar *localvars;
98#if ATTY
99 struct var vatty;
100#endif
101 struct var vifs;
102 struct var vmail;
103 struct var vmpath;
104 struct var vpath;
105#ifdef _MSC_VER
106 struct var vpath2;
107#endif
108 struct var vps1;
109 struct var vps2;
110 struct var vps4;
111#ifndef SMALL
112 struct var vterm;
113 struct var vtermcap;
114 struct var vhistsize;
115#endif
116
117 /* myhistedit.h */
118 int displayhist;
119#ifndef SMALL
120 History *hist;
121 EditLine *el;
122#endif
123
124 /* memalloc.h */
125 char *stacknxt/* = stackbase.space*/;
126 int stacknleft/* = MINSIZE*/;
127 int sstrnleft;
128 int herefd/* = -1 */;
129
130 /* memalloc.c */
131 struct stack_block stackbase;
132 struct stack_block *stackp/* = &stackbase*/;
133 struct stackmark *markp;
134
135
136 /* jobs.h */
137 pid_t backgndpid; /**< pid of last background process */
138 int job_warning; /**< user was warned about stopped jobs */
139
140 /* input.h */
141 int plinno;
142 int parsenleft; /**< number of characters left in input buffer */
143 char *parsenextc; /**< next character in input buffer */
144 int init_editline; /**< 0 == not setup, 1 == OK, -1 == failed */
145
146 /* exec.h */
147 const char *pathopt; /**< set by padvance */
148
149 /* eval.h */
150 char *commandname; /**< currently executing command */
151 int exitstatus; /**< exit status of last command */
152 int back_exitstatus;/**< exit status of backquoted command */
153 struct strlist *cmdenviron; /**< environment for builtin command */
154 int funcnest; /**< depth of function calls */
155 int evalskip; /**< set if we are skipping commands */
156 int skipcount; /**< number of levels to skip */
157 int loopnest; /**< current loop nesting level */
158
159 /* builtins.h */
160
161 /* alias.c */
162#define ATABSIZE 39
163 struct alias *atab[ATABSIZE];
164
165 /* cd.c */
166 char *curdir; /**< current working directory */
167 char *prevdir; /**< previous working directory */
168 char *cdcomppath;
169 int getpwd_first; /**< static in getpwd. (initialized to 1!) */
170
171 /* error.c */
172 char errmsg_buf[16]; /**< static in errmsg. (bss) */
173
174 /* eval.c */
175 int vforked;
176
177 /* mail.c */
178#define MAXMBOXES 10
179 int nmboxes; /**< number of mailboxes */
180 time_t mailtime[MAXMBOXES]; /**< times of mailboxes */
181
182} shinstance;
183
184
185extern shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv);
186char *sh_getenv(shinstance *, const char *);
187
188/* signals */
189#include <signal.h>
190#ifdef _MSC_VER
191 typedef uint32_t sh_sigset_t;
192#else
193 typedef sigset_t sh_sigset_t;
194#endif
195
196typedef void (*sh_handler)(int);
197sh_handler sh_signal(shinstance *, int, sh_handler handler);
198void sh_raise_sigint(shinstance *);
199void sh_sigemptyset(sh_sigset_t *set);
200int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);
201void sh_abort(shinstance *);
202
203/* times */
204#include <time.h>
205#ifdef _MSC_VER
206 typedef struct sh_tms
207 {
208 clock_t tms_utime;
209 clock_t tms_stime;
210 clock_t tms_cutime;
211 clock_t tms_cstime;
212 } sh_tms;
213#else
214# include <times.h>
215 typedef struct tms sh_tms;
216#endif
217clock_t sh_times(sh_tms *);
218int sh_sysconf_clk_tck(void);
219
220/* wait */
221#ifdef _MSC_VER
222# include <process.h>
223# define WNOHANG 1 /* Don't hang in wait. */
224# define WUNTRACED 2 /* Tell about stopped, untraced children. */
225# define WCONTINUED 4 /* Report a job control continued process. */
226# define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */
227# define WCOREFLAG 0200
228# define _WSTATUS(x) (_W_INT(x) & 0177)
229# define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
230# define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
231# define WSTOPSIG(x) (_W_INT(x) >> 8)
232# define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
233# define WTERMSIG(x) (_WSTATUS(x))
234# define WIFEXITED(x) (_WSTATUS(x) == 0)
235# define WEXITSTATUS(x) (_W_INT(x) >> 8)
236# define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
237# define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
238# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
239# define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
240#else
241# include <sys/wait.h>
242#endif
243pid_t sh_waitpid(shinstance *, pid_t, int *, int);
244void sh__exit(shinstance *, int);
245
246
247#endif
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette