VirtualBox

source: kBuild/trunk/src/ash-messup/shinstance.h@ 936

Last change on this file since 936 was 884, checked in by bird, 18 years ago

hacking...

File size: 7.6 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
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 */
44typedef 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; /**< depth of function calls */
141 int evalskip; /**< set if we are skipping commands */
142 int skipcount; /**< number of levels to skip */
143 int loopnest; /**< current loop nesting level */
144
145 /* builtins.h */
146
147 /* alias.c */
148#define ATABSIZE 39
149 struct alias *atab[ATABSIZE];
150
151 /* cd.c */
152 char *curdir; /**< current working directory */
153 char *prevdir; /**< previous working directory */
154 char *cdcomppath;
155 int getpwd_first; /**< static in getpwd. (initialized to 1!) */
156
157 /* error.c */
158 char errmsg_buf[16]; /**< static in errmsg. (bss) */
159
160 /* eval.c */
161 int vforked;
162} shinstance;
163
164
165extern shinstance *sh_create_root_shell(shinstance *inherit, int argc, char **argv);
166char *sh_getenv(shinstance *, const char *);
167
168/* signals */
169#include <signal.h>
170#ifdef _MSC_VER
171 typedef uint32_t sh_sigset_t;
172#else
173 typedef sigset_t sh_sigset_t;
174#endif
175
176typedef void (*sh_handler)(int);
177sh_handler sh_signal(shinstance *, int, sh_handler handler);
178void sh_raise_sigint(shinstance *);
179void sh_sigemptyset(sh_sigset_t *set);
180int sh_sigprocmask(shinstance *, int op, sh_sigset_t const *new, sh_sigset_t *old);
181
182/* times */
183#include <time.h>
184#ifdef _MSC_VER
185 typedef struct sh_tms
186 {
187 clock_t tms_utime;
188 clock_t tms_stime;
189 clock_t tms_cutime;
190 clock_t tms_cstime;
191 } sh_tms;
192#else
193# include <times.h>
194 typedef struct tms sh_tms;
195#endif
196clock_t sh_times(sh_tms *);
197int sh_sysconf_clk_tck(void);
198
199/* wait */
200#ifdef _MSC_VER
201# include <process.h>
202# define WNOHANG 1 /* Don't hang in wait. */
203# define WUNTRACED 2 /* Tell about stopped, untraced children. */
204# define WCONTINUED 4 /* Report a job control continued process. */
205# define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */
206# define WCOREFLAG 0200
207# define _WSTATUS(x) (_W_INT(x) & 0177)
208# define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
209# define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
210# define WSTOPSIG(x) (_W_INT(x) >> 8)
211# define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
212# define WTERMSIG(x) (_WSTATUS(x))
213# define WIFEXITED(x) (_WSTATUS(x) == 0)
214# define WEXITSTATUS(x) (_W_INT(x) >> 8)
215# define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
216# define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
217# define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
218# define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
219#else
220# include <sys/wait.h>
221#endif
222pid_t sh_waitpid(shinstance *, pid_t, int *, int);
223void sh__exit(shinstance *, int);
224
225#endif
Note: See TracBrowser for help on using the repository browser.

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