VirtualBox

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

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

moving globals into shinstance...

File size: 8.3 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 /* output.c */
87#define OUTBUFSIZ BUFSIZ
88#define MEM_OUT -3 /**< output to dynamically allocated memory */
89
90 /* options.h */
91 struct optent optlist[NOPTS];
92 char *minusc; /**< argument to -c option */
93 char *arg0; /**< $0 */
94 struct shparam shellparam; /**< $@ */
95 char **argptr; /**< argument list for builtin commands */
96 char *optionarg; /**< set by nextopt */
97 char *optptr; /**< used by nextopt */
98
99 /* var.h */
100 struct localvar *localvars;
101#if ATTY
102 struct var vatty;
103#endif
104 struct var vifs;
105 struct var vmail;
106 struct var vmpath;
107 struct var vpath;
108#ifdef _MSC_VER
109 struct var vpath2;
110#endif
111 struct var vps1;
112 struct var vps2;
113 struct var vps4;
114#ifndef SMALL
115 struct var vterm;
116 struct var vtermcap;
117 struct var vhistsize;
118#endif
119
120 /* myhistedit.h */
121 int displayhist;
122#ifndef SMALL
123 History *hist;
124 EditLine *el;
125#endif
126
127 /* memalloc.h */
128 char *stacknxt/* = stackbase.space*/;
129 int stacknleft/* = MINSIZE*/;
130 int sstrnleft;
131 int herefd/* = -1 */;
132
133 /* memalloc.c */
134 struct stack_block stackbase;
135 struct stack_block *stackp/* = &stackbase*/;
136 struct stackmark *markp;
137
138
139 /* jobs.h */
140 pid_t backgndpid; /**< pid of last background process */
141 int job_warning; /**< user was warned about stopped jobs */
142
143 /* input.h */
144 int plinno;
145 int parsenleft; /**< number of characters left in input buffer */
146 char *parsenextc; /**< next character in input buffer */
147 int init_editline; /**< 0 == not setup, 1 == OK, -1 == failed */
148
149 /* exec.h */
150 const char *pathopt; /**< set by padvance */
151
152 /* eval.h */
153 char *commandname; /**< currently executing command */
154 int exitstatus; /**< exit status of last command */
155 int back_exitstatus;/**< exit status of backquoted command */
156 struct strlist *cmdenviron; /**< environment for builtin command */
157 int funcnest; /**< depth of function calls */
158 int evalskip; /**< set if we are skipping commands */
159 int skipcount; /**< number of levels to skip */
160 int loopnest; /**< current loop nesting level */
161
162 /* builtins.h */
163
164 /* alias.c */
165#define ATABSIZE 39
166 struct alias *atab[ATABSIZE];
167
168 /* cd.c */
169 char *curdir; /**< current working directory */
170 char *prevdir; /**< previous working directory */
171 char *cdcomppath;
172 int getpwd_first; /**< static in getpwd. (initialized to 1!) */
173
174 /* error.c */
175 char errmsg_buf[16]; /**< static in errmsg. (bss) */
176
177 /* eval.c */
178 int vforked;
179
180 /* mail.c */
181#define MAXMBOXES 10
182 int nmboxes; /**< number of mailboxes */
183 time_t mailtime[MAXMBOXES]; /**< times of mailboxes */
184
185} shinstance;
186
187
188extern shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv);
189char *sh_getenv(shinstance *, const char *);
190
191/* signals */
192#include <signal.h>
193#ifdef _MSC_VER
194 typedef uint32_t sh_sigset_t;
195#else
196 typedef sigset_t sh_sigset_t;
197#endif
198
199typedef void (*sh_handler)(int);
200sh_handler sh_signal(shinstance *, int, sh_handler handler);
201void sh_raise_sigint(shinstance *);
202void sh_sigemptyset(sh_sigset_t *set);
203int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);
204void sh_abort(shinstance *);
205
206/* times */
207#include <time.h>
208#ifdef _MSC_VER
209 typedef struct sh_tms
210 {
211 clock_t tms_utime;
212 clock_t tms_stime;
213 clock_t tms_cutime;
214 clock_t tms_cstime;
215 } sh_tms;
216#else
217# include <times.h>
218 typedef struct tms sh_tms;
219#endif
220clock_t sh_times(sh_tms *);
221int sh_sysconf_clk_tck(void);
222
223/* wait */
224#ifdef _MSC_VER
225# include <process.h>
226# define WNOHANG 1 /* Don't hang in wait. */
227# define WUNTRACED 2 /* Tell about stopped, untraced children. */
228# define WCONTINUED 4 /* Report a job control continued process. */
229# define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */
230# define WCOREFLAG 0200
231# define _WSTATUS(x) (_W_INT(x) & 0177)
232# define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
233# define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
234# define WSTOPSIG(x) (_W_INT(x) >> 8)
235# define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
236# define WTERMSIG(x) (_WSTATUS(x))
237# define WIFEXITED(x) (_WSTATUS(x) == 0)
238# define WEXITSTATUS(x) (_W_INT(x) >> 8)
239# define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
240# define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
241# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
242# define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
243#else
244# include <sys/wait.h>
245#endif
246pid_t sh_waitpid(shinstance *, pid_t, int *, int);
247void sh__exit(shinstance *, int);
248
249
250#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