VirtualBox

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

最後變更 在這個檔案從1218是 1218,由 bird 提交於 17 年 前

changed eol-style to LF.

  • 屬性 svn:eol-style 設為 LF
檔案大小: 15.2 KB
 
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 <stdio.h> /* BUFSIZ */
31#include <signal.h> /* NSIG */
32#ifndef _MSC_VER
33# include <termios.h>
34# include <sys/ioctl.h>
35# include <sys/resource.h>
36#endif
37#include <errno.h>
38#ifdef _MSC_VER
39# define EWOULDBLOCK 512
40#endif
41
42#include "shtypes.h"
43#include "shthread.h"
44#include "shfile.h"
45#include "output.h"
46#include "options.h"
47
48#include "expand.h"
49#include "exec.h"
50#include "var.h"
51
52#ifdef _MSC_VER
53# define strcasecmp stricmp
54# define strncasecmp strnicmp
55#endif
56
57
58/* memalloc.c */
59#define MINSIZE 504 /* minimum size of a block */
60struct stack_block {
61 struct stack_block *prev;
62 char space[MINSIZE];
63};
64
65/* input.c */
66struct strpush {
67 struct strpush *prev; /* preceding string on stack */
68 char *prevstring;
69 int prevnleft;
70 int prevlleft;
71 struct alias *ap; /* if push was associated with an alias */
72};
73
74/*
75 * The parsefile structure pointed to by the global variable parsefile
76 * contains information about the current file being read.
77 */
78struct parsefile {
79 struct parsefile *prev; /* preceding file on stack */
80 int linno; /* current line */
81 int fd; /* file descriptor (or -1 if string) */
82 int nleft; /* number of chars left in this line */
83 int lleft; /* number of chars left in this buffer */
84 char *nextc; /* next char in buffer */
85 char *buf; /* input buffer */
86 struct strpush *strpush; /* for pushing strings at this level */
87 struct strpush basestrpush; /* so pushing one is fast */
88};
89
90/* exec.c */
91#define CMDTABLESIZE 31 /* should be prime */
92#define ARB 1 /* actual size determined at run time */
93
94struct tblentry {
95 struct tblentry *next; /* next entry in hash chain */
96 union param param; /* definition of builtin function */
97 short cmdtype; /* index identifying command */
98 char rehash; /* if set, cd done since entry created */
99 char cmdname[ARB]; /* name of command */
100};
101
102/* expand.c */
103/*
104 * Structure specifying which parts of the string should be searched
105 * for IFS characters.
106 */
107struct ifsregion {
108 struct ifsregion *next; /* next region in list */
109 int begoff; /* offset of start of region */
110 int endoff; /* offset of end of region */
111 int inquotes; /* search for nul bytes only */
112};
113
114
115/**
116 * A shell instance.
117 *
118 * This is the core structure of the shell, it contains all
119 * the data associated with a shell process except that it's
120 * running in a thread and not a separate process.
121 */
122struct shinstance
123{
124 struct shinstance *next; /**< The next shell instance. */
125 struct shinstance *prev; /**< The previous shell instance. */
126 struct shinstance *parent; /**< The parent shell instance. */
127 pid_t pid; /**< The (fake) process id of this shell instance. */
128 shtid tid; /**< The thread identifier of the thread for this shell. */
129 shfdtab fdtab; /**< The file descriptor table. */
130
131 /* alias.c */
132#define ATABSIZE 39
133 struct alias *atab[ATABSIZE];
134
135 /* cd.c */
136 char *curdir; /**< current working directory */
137 char *prevdir; /**< previous working directory */
138 char *cdcomppath;
139 int getpwd_first; /**< static in getpwd. (initialized to 1!) */
140
141 /* error.h */
142 struct jmploc *handler;
143 int exception;
144 int exerrno/* = 0 */; /**< Last exec error */
145 int volatile suppressint;
146 int volatile intpending;
147
148 /* error.c */
149 char errmsg_buf[16]; /**< static in errmsg. (bss) */
150
151 /* eval.h */
152 char *commandname; /**< currently executing command */
153 int exitstatus; /**< exit status of last command */
154 int back_exitstatus;/**< exit status of backquoted command */
155 struct strlist *cmdenviron; /**< environment for builtin command */
156 int funcnest; /**< depth of function calls */
157 int evalskip; /**< set if we are skipping commands */
158 int skipcount; /**< number of levels to skip */
159 int loopnest; /**< current loop nesting level */
160
161 /* eval.c */
162 int vforked;
163
164 /* expand.c */
165 char *expdest; /**< output of current string */
166 struct nodelist *argbackq; /**< list of back quote expressions */
167 struct ifsregion ifsfirst; /**< first struct in list of ifs regions */
168 struct ifsregion *ifslastp; /**< last struct in list */
169 struct arglist exparg; /**< holds expanded arg list */
170 char *expdir; /**< Used by expandmeta. */
171
172 /* exec.h */
173 const char *pathopt; /**< set by padvance */
174
175 /* exec.c */
176 struct tblentry *cmdtable[CMDTABLESIZE];
177 int builtinloc/* = -1*/; /**< index in path of %builtin, or -1 */
178
179 /* input.h */
180 int plinno/* = 1 */;/**< input line number */
181 int parsenleft; /**< number of characters left in input buffer */
182 char *parsenextc; /**< next character in input buffer */
183 int init_editline/* = 0 */; /**< 0 == not setup, 1 == OK, -1 == failed */
184
185 /* input.c */
186 int parselleft; /**< copy of parsefile->lleft */
187 struct parsefile basepf; /**< top level input file */
188 char basebuf[BUFSIZ];/**< buffer for top level input file */
189 struct parsefile *parsefile/* = &basepf*/; /**< current input file */
190#ifndef SMALL
191 EditLine *el; /**< cookie for editline package */
192#endif
193
194 /* jobs.h */
195 pid_t backgndpid/* = -1 */; /**< pid of last background process */
196 int job_warning; /**< user was warned about stopped jobs */
197
198 /* jobs.c */
199 struct job *jobtab; /**< array of jobs */
200 int njobs; /**< size of array */
201 int jobs_invalid; /**< set in child */
202#if JOBS
203 int initialpgrp; /**< pgrp of shell on invocation */
204 int curjob/* = -1*/;/**< current job */
205#endif
206 int ttyfd/* = -1*/;
207 int jobctl; /**< job control enabled / disabled */
208 char *cmdnextc;
209 int cmdnleft;
210
211 /* mail.c */
212#define MAXMBOXES 10
213 int nmboxes; /**< number of mailboxes */
214 time_t mailtime[MAXMBOXES]; /**< times of mailboxes */
215
216 /* main.h */
217 int rootpid; /**< pid of main shell. */
218 int rootshell; /**< true if we aren't a child of the main shell. */
219 struct shinstance *psh_rootshell; /**< The root shell pointer. (!rootshell) */
220
221 /* memalloc.h */
222 char *stacknxt/* = stackbase.space*/;
223 int stacknleft/* = MINSIZE*/;
224 int sstrnleft;
225 int herefd/* = -1 */;
226
227 /* memalloc.c */
228 struct stack_block stackbase;
229 struct stack_block *stackp/* = &stackbase*/;
230 struct stackmark *markp;
231
232 /* myhistedit.h */
233 int displayhist;
234#ifndef SMALL
235 History *hist;
236 EditLine *el;
237#endif
238
239 /* output.h */
240 struct output output;
241 struct output errout;
242 struct output memout;
243 struct output *out1;
244 struct output *out2;
245
246 /* output.c */
247#define OUTBUFSIZ BUFSIZ
248#define MEM_OUT -3 /**< output to dynamically allocated memory */
249
250 /* options.h */
251 struct optent optlist[NOPTS];
252 char *minusc; /**< argument to -c option */
253 char *arg0; /**< $0 */
254 struct shparam shellparam; /**< $@ */
255 char **argptr; /**< argument list for builtin commands */
256 char *optionarg; /**< set by nextopt */
257 char *optptr; /**< used by nextopt */
258
259 /* parse.h */
260 int tokpushback;
261 int whichprompt; /**< 1 == PS1, 2 == PS2 */
262
263 /* parser.c */
264 int noalias/* = 0*/;/**< when set, don't handle aliases */
265 struct heredoc *heredoclist; /**< list of here documents to read */
266 int parsebackquote; /**< nonzero if we are inside backquotes */
267 int doprompt; /**< if set, prompt the user */
268 int needprompt; /**< true if interactive and at start of line */
269 int lasttoken; /**< last token read */
270 char *wordtext; /**< text of last word returned by readtoken */
271 int checkkwd; /**< 1 == check for kwds, 2 == also eat newlines */
272 struct nodelist *backquotelist;
273 union node *redirnode;
274 struct heredoc *heredoc;
275 int quoteflag; /**< set if (part of) last token was quoted */
276 int startlinno; /**< line # where last token started */
277
278 /* redir.c */
279 struct redirtab *redirlist;
280 int fd0_redirected/* = 0*/;
281
282 /* trap.h */
283 int pendingsigs; /**< indicates some signal received */
284
285 /* trap.c */
286 char gotsig[NSIG]; /**< indicates specified signal received */
287 char *trap[NSIG+1]; /**< trap handler commands */
288 char sigmode[NSIG]; /**< current value of signal */
289
290 /* var.h */
291 struct localvar *localvars;
292#if ATTY
293 struct var vatty;
294#endif
295 struct var vifs;
296 struct var vmail;
297 struct var vmpath;
298 struct var vpath;
299#ifdef _MSC_VER
300 struct var vpath2;
301#endif
302 struct var vps1;
303 struct var vps2;
304 struct var vps4;
305#ifndef SMALL
306 struct var vterm;
307 struct var vhistsize;
308#endif
309 struct var voptind;
310#ifdef PC_OS2_LIBPATHS
311 struct var libpath_vars[4];
312#endif
313#ifdef SMALL
314# define VTABSIZE 39
315#else
316# define VTABSIZE 517
317#endif
318 struct var *vartab[VTABSIZE];
319
320 /* builtins.h */
321
322 /* bltin/test.c */
323 char **t_wp;
324 struct t_op const *t_wp_op;
325
326};
327
328
329extern shinstance *sh_create_root_shell(shinstance *, int, char **);
330char *sh_getenv(shinstance *, const char *);
331const char *sh_gethomedir(shinstance *, const char *);
332
333/* signals */
334typedef void (*sh_sig_t)(shinstance *, int);
335#ifdef _MSC_VER
336 typedef uint32_t sh_sigset_t;
337#else
338 typedef sigset_t sh_sigset_t;
339#endif
340struct sh_sigaction
341{
342 sh_sig_t sh_handler;
343 sh_sigset_t sh_mask;
344 int sh_flags;
345};
346#define SH_SIG_DFL ((sh_sig_t)SIG_DFL)
347#define SH_SIG_IGN ((sh_sig_t)SIG_IGN)
348#ifdef _MSC_VER
349# define SIG_BLOCK 1
350# define SIG_UNBLOCK 2
351# define SIG_SETMASK 3
352# define SIGHUP 5
353# define SIGQUIT 9
354# define SIGPIPE 12
355# define SIGTTOU 17
356# define SIGTSTP 18
357# define SIGTTIN 19
358# define SIGCONT 20
359 extern const char * const sys_siglist[NSIG];
360#endif /* _MSC_VER */
361#ifdef __sun__
362# define sys_siglist _sys_siglist
363#endif
364
365int sh_sigaction(int, const struct sh_sigaction *, struct sh_sigaction *);
366sh_sig_t sh_signal(shinstance *, int, sh_sig_t);
367int sh_siginterrupt(shinstance *, int, int);
368void sh_sigemptyset(sh_sigset_t *);
369int sh_sigprocmask(shinstance *, int, sh_sigset_t const *, sh_sigset_t *);
370void sh_abort(shinstance *);
371void sh_raise_sigint(shinstance *);
372int sh_kill(shinstance *, pid_t, int);
373int sh_killpg(shinstance *, pid_t, int);
374
375/* times */
376#include <time.h>
377#ifdef _MSC_VER
378 typedef struct shtms
379 {
380 clock_t tms_utime;
381 clock_t tms_stime;
382 clock_t tms_cutime;
383 clock_t tms_cstime;
384 } shtms;
385#else
386# include <sys/times.h>
387 typedef struct tms shtms;
388#endif
389clock_t sh_times(shinstance *, shtms *);
390int sh_sysconf_clk_tck(void);
391
392/* wait / process */
393#ifdef _MSC_VER
394# include <process.h>
395# define WNOHANG 1 /* Don't hang in wait. */
396# define WUNTRACED 2 /* Tell about stopped, untraced children. */
397# define WCONTINUED 4 /* Report a job control continued process. */
398# define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */
399# define WCOREFLAG 0200
400# define _WSTATUS(x) (_W_INT(x) & 0177)
401# define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
402# define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
403# define WSTOPSIG(x) (_W_INT(x) >> 8)
404# define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
405# define WTERMSIG(x) (_WSTATUS(x))
406# define WIFEXITED(x) (_WSTATUS(x) == 0)
407# define WEXITSTATUS(x) (_W_INT(x) >> 8)
408# define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
409# define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
410# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
411# define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
412#else
413# include <sys/wait.h>
414#endif
415pid_t sh_fork(shinstance *);
416pid_t sh_waitpid(shinstance *, pid_t, int *, int);
417void sh__exit(shinstance *, int);
418int sh_execve(shinstance *, const char *, const char * const*, const char * const *);
419uid_t sh_getuid(shinstance *);
420uid_t sh_geteuid(shinstance *);
421gid_t sh_getgid(shinstance *);
422gid_t sh_getegid(shinstance *);
423pid_t sh_getpid(shinstance *);
424pid_t sh_getpgrp(shinstance *);
425pid_t sh_getpgid(shinstance *, pid_t);
426int sh_setpgid(shinstance *, pid_t, pid_t);
427
428/* tc* */
429pid_t sh_tcgetpgrp(shinstance *, int);
430int sh_tcsetpgrp(shinstance *, int, pid_t);
431
432/* sys/resourece.h */
433#ifdef _MSC_VER
434 typedef int64_t shrlim_t;
435 typedef struct shrlimit
436 {
437 shrlim_t rlim_cur;
438 shrlim_t rlim_max;
439 } shrlimit;
440# define RLIMIT_CPU 0
441# define RLIMIT_FSIZE 1
442# define RLIMIT_DATA 2
443# define RLIMIT_STACK 3
444# define RLIMIT_CORE 4
445# define RLIMIT_RSS 5
446# define RLIMIT_MEMLOCK 6
447# define RLIMIT_NPROC 7
448# define RLIMIT_NOFILE 8
449# define RLIMIT_SBSIZE 9
450# define RLIMIT_VMEM 10
451# define RLIM_NLIMITS 11
452# define RLIM_INFINITY (0x7fffffffffffffffLL)
453#else
454 typedef rlim_t shrlim_t;
455 typedef struct rlimit shrlimit;
456#endif
457int sh_getrlimit(shinstance *, int, shrlimit *);
458int sh_setrlimit(shinstance *, int, const shrlimit *);
459
460#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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