[1233] | 1 | /* $Id: shinstance.h 3480 2020-09-21 11:20:56Z bird $ */
|
---|
[1218] | 2 | /** @file
|
---|
| 3 | * The shell instance and it's methods.
|
---|
[2291] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[2413] | 7 | * Copyright (c) 2007-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
---|
[1218] | 8 | *
|
---|
| 9 | *
|
---|
| 10 | * This file is part of kBuild.
|
---|
| 11 | *
|
---|
| 12 | * kBuild is free software; you can redistribute it and/or modify
|
---|
| 13 | * it under the terms of the GNU General Public License as published by
|
---|
| 14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 15 | * (at your option) any later version.
|
---|
| 16 | *
|
---|
| 17 | * kBuild is distributed in the hope that it will be useful,
|
---|
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 20 | * GNU General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with kBuild; if not, write to the Free Software
|
---|
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 25 | *
|
---|
| 26 | */
|
---|
| 27 |
|
---|
| 28 | #ifndef ___shinstance_h
|
---|
| 29 | #define ___shinstance_h
|
---|
| 30 |
|
---|
| 31 | #include <stdio.h> /* BUFSIZ */
|
---|
| 32 | #include <signal.h> /* NSIG */
|
---|
| 33 | #ifndef _MSC_VER
|
---|
| 34 | # include <termios.h>
|
---|
[2498] | 35 | # include <sys/types.h>
|
---|
[1218] | 36 | # include <sys/ioctl.h>
|
---|
| 37 | # include <sys/resource.h>
|
---|
| 38 | #endif
|
---|
| 39 | #include <errno.h>
|
---|
| 40 | #ifdef _MSC_VER
|
---|
[2639] | 41 | # define EWOULDBLOCK 140
|
---|
[1218] | 42 | #endif
|
---|
| 43 |
|
---|
| 44 | #include "shtypes.h"
|
---|
| 45 | #include "shthread.h"
|
---|
| 46 | #include "shfile.h"
|
---|
[2291] | 47 | #include "shheap.h"
|
---|
[1784] | 48 | #include "shell.h"
|
---|
[1218] | 49 | #include "output.h"
|
---|
| 50 | #include "options.h"
|
---|
| 51 |
|
---|
| 52 | #include "expand.h"
|
---|
| 53 | #include "exec.h"
|
---|
| 54 | #include "var.h"
|
---|
[1785] | 55 | #include "show.h"
|
---|
[1218] | 56 |
|
---|
| 57 | #ifdef _MSC_VER
|
---|
| 58 | # define strcasecmp stricmp
|
---|
| 59 | # define strncasecmp strnicmp
|
---|
| 60 | #endif
|
---|
| 61 |
|
---|
[3451] | 62 | #ifndef SH_FORKED_MODE
|
---|
[3447] | 63 | extern shmtx g_sh_exec_inherit_mtx;
|
---|
[3451] | 64 | #endif
|
---|
[3447] | 65 |
|
---|
[3460] | 66 | #ifndef SH_FORKED_MODE
|
---|
[2293] | 67 | /**
|
---|
[3460] | 68 | * Subshell status.
|
---|
| 69 | */
|
---|
| 70 | typedef struct shsubshellstatus
|
---|
| 71 | {
|
---|
| 72 | unsigned volatile refs; /**< Reference counter. */
|
---|
| 73 | int volatile status; /**< The exit code. */
|
---|
| 74 | KBOOL volatile done; /**< Set if done (valid exit code). */
|
---|
| 75 | void *towaiton; /**< Event semaphore / whatever to wait on. */
|
---|
| 76 | # if K_OS == K_OS_WINDOWS
|
---|
| 77 | uintptr_t volatile hThread; /**< The thread handle (child closes this). */
|
---|
| 78 | # endif
|
---|
| 79 | struct shsubshellstatus *next; /**< Next free one on the free chain. */
|
---|
| 80 | } shsubshellstatus;
|
---|
[3480] | 81 | #else
|
---|
| 82 | struct shsubshellstatus;
|
---|
[3460] | 83 | #endif
|
---|
| 84 |
|
---|
| 85 | /**
|
---|
[2293] | 86 | * A child process.
|
---|
| 87 | */
|
---|
| 88 | typedef struct shchild
|
---|
| 89 | {
|
---|
[3460] | 90 | shpid pid; /**< The pid. */
|
---|
[2293] | 91 | #if K_OS == K_OS_WINDOWS
|
---|
[3460] | 92 | void *hChild; /**< The handle to wait on. */
|
---|
[2293] | 93 | #endif
|
---|
[3438] | 94 | #ifndef SH_FORKED_MODE
|
---|
[3460] | 95 | shsubshellstatus *subshellstatus; /**< Pointer to the subshell status structure. NULL if child process. */
|
---|
[3438] | 96 | #endif
|
---|
[2293] | 97 | } shchild;
|
---|
[1218] | 98 |
|
---|
| 99 | /* memalloc.c */
|
---|
| 100 | #define MINSIZE 504 /* minimum size of a block */
|
---|
| 101 | struct stack_block {
|
---|
| 102 | struct stack_block *prev;
|
---|
| 103 | char space[MINSIZE];
|
---|
| 104 | };
|
---|
| 105 |
|
---|
[3457] | 106 | #ifdef KASH_SEPARATE_PARSER_ALLOCATOR
|
---|
| 107 | /** Parser stack allocator block.
|
---|
| 108 | * These are reference counted so they can be shared between the parent and
|
---|
| 109 | * child shells. They are also using as an alternative to copying function
|
---|
| 110 | * definitions, here the final goal is to automatically emit separate
|
---|
| 111 | * pstack_blocks for function while parsing to make it more flexible. */
|
---|
| 112 | typedef struct pstack_block {
|
---|
| 113 | /** Pointer to the next unallocated byte (= stacknxt). */
|
---|
| 114 | char *nextbyte;
|
---|
| 115 | /** Number of bytes available in the current stack block (= stacknleft). */
|
---|
| 116 | size_t avail;
|
---|
| 117 | /* Number of chars left for string data (PSTPUTC, PSTUPUTC, et al) (= sstrnleft). */
|
---|
| 118 | size_t strleft;
|
---|
| 119 | /** Top of the allocation stack (nextbyte points within this). */
|
---|
| 120 | struct stack_block *top;
|
---|
| 121 | /** Size of the top stack element (user space only). */
|
---|
| 122 | size_t topsize;
|
---|
| 123 | /** @name statistics
|
---|
| 124 | * @{ */
|
---|
| 125 | size_t allocations;
|
---|
| 126 | size_t bytesalloced;
|
---|
| 127 | size_t nodesalloced;
|
---|
| 128 | size_t entriesalloced;
|
---|
| 129 | size_t strbytesalloced;
|
---|
| 130 | size_t blocks;
|
---|
| 131 | size_t fragmentation;
|
---|
| 132 | /** @} */
|
---|
| 133 | /** Reference counter. */
|
---|
| 134 | unsigned volatile refs;
|
---|
[3461] | 135 | /** Whether to make it current when is restored to the top of the stack. */
|
---|
| 136 | KBOOL done;
|
---|
[3457] | 137 | /** The first stack block. */
|
---|
| 138 | struct stack_block first;
|
---|
| 139 | } pstack_block;
|
---|
| 140 | #endif
|
---|
| 141 |
|
---|
[1218] | 142 | /* input.c */
|
---|
| 143 | struct strpush {
|
---|
| 144 | struct strpush *prev; /* preceding string on stack */
|
---|
| 145 | char *prevstring;
|
---|
| 146 | int prevnleft;
|
---|
| 147 | int prevlleft;
|
---|
| 148 | struct alias *ap; /* if push was associated with an alias */
|
---|
| 149 | };
|
---|
| 150 |
|
---|
| 151 | /*
|
---|
| 152 | * The parsefile structure pointed to by the global variable parsefile
|
---|
| 153 | * contains information about the current file being read.
|
---|
| 154 | */
|
---|
| 155 | struct parsefile {
|
---|
| 156 | struct parsefile *prev; /* preceding file on stack */
|
---|
| 157 | int linno; /* current line */
|
---|
| 158 | int fd; /* file descriptor (or -1 if string) */
|
---|
| 159 | int nleft; /* number of chars left in this line */
|
---|
| 160 | int lleft; /* number of chars left in this buffer */
|
---|
| 161 | char *nextc; /* next char in buffer */
|
---|
| 162 | char *buf; /* input buffer */
|
---|
| 163 | struct strpush *strpush; /* for pushing strings at this level */
|
---|
| 164 | struct strpush basestrpush; /* so pushing one is fast */
|
---|
| 165 | };
|
---|
| 166 |
|
---|
| 167 | /* exec.c */
|
---|
| 168 | #define CMDTABLESIZE 31 /* should be prime */
|
---|
| 169 | #define ARB 1 /* actual size determined at run time */
|
---|
| 170 |
|
---|
| 171 | struct tblentry {
|
---|
| 172 | struct tblentry *next; /* next entry in hash chain */
|
---|
| 173 | union param param; /* definition of builtin function */
|
---|
| 174 | short cmdtype; /* index identifying command */
|
---|
| 175 | char rehash; /* if set, cd done since entry created */
|
---|
| 176 | char cmdname[ARB]; /* name of command */
|
---|
| 177 | };
|
---|
| 178 |
|
---|
| 179 | /* expand.c */
|
---|
| 180 | /*
|
---|
| 181 | * Structure specifying which parts of the string should be searched
|
---|
| 182 | * for IFS characters.
|
---|
| 183 | */
|
---|
| 184 | struct ifsregion {
|
---|
| 185 | struct ifsregion *next; /* next region in list */
|
---|
| 186 | int begoff; /* offset of start of region */
|
---|
| 187 | int endoff; /* offset of end of region */
|
---|
| 188 | int inquotes; /* search for nul bytes only */
|
---|
| 189 | };
|
---|
| 190 |
|
---|
[3459] | 191 | /* redir.c */
|
---|
| 192 | struct redirtab {
|
---|
| 193 | struct redirtab *next;
|
---|
| 194 | short renamed[10];
|
---|
| 195 | };
|
---|
| 196 |
|
---|
[3449] | 197 | /**
|
---|
| 198 | * This is a replacement for temporary node field nfile.expfname.
|
---|
| 199 | * Uses stack allocator, created by expredir(), duplicated by
|
---|
| 200 | * subshellinitredir() and popped (but not freed) by expredircleanup().
|
---|
| 201 | */
|
---|
| 202 | typedef struct redirexpfnames
|
---|
| 203 | {
|
---|
| 204 | struct redirexpfnames *prev; /**< Previous record. */
|
---|
| 205 | unsigned depth; /**< Nesting depth. */
|
---|
| 206 | unsigned count; /**< Number of expanded filenames in the array. */
|
---|
| 207 | char *names[1]; /**< Variable size. */
|
---|
| 208 | } redirexpfnames;
|
---|
[1218] | 209 |
|
---|
[3449] | 210 |
|
---|
[1218] | 211 | /**
|
---|
| 212 | * A shell instance.
|
---|
| 213 | *
|
---|
| 214 | * This is the core structure of the shell, it contains all
|
---|
| 215 | * the data associated with a shell process except that it's
|
---|
| 216 | * running in a thread and not a separate process.
|
---|
| 217 | */
|
---|
| 218 | struct shinstance
|
---|
| 219 | {
|
---|
| 220 | struct shinstance *next; /**< The next shell instance. */
|
---|
| 221 | struct shinstance *prev; /**< The previous shell instance. */
|
---|
| 222 | struct shinstance *parent; /**< The parent shell instance. */
|
---|
[3438] | 223 | shpid pid; /**< The (fake) process id of this shell instance. */
|
---|
[1218] | 224 | shtid tid; /**< The thread identifier of the thread for this shell. */
|
---|
[3438] | 225 | shpid pgid; /**< Process group ID. */
|
---|
[1218] | 226 | shfdtab fdtab; /**< The file descriptor table. */
|
---|
[1784] | 227 | shsigaction_t sigactions[NSIG]; /**< The signal actions registered with this shell instance. */
|
---|
[2286] | 228 | shsigset_t sigmask; /**< Our signal mask. */
|
---|
| 229 | char **shenviron; /**< The environment vector. */
|
---|
[3439] | 230 | int linked; /**< Set if we're still linked. */
|
---|
| 231 | unsigned num_children; /**< Number of children in the array. */
|
---|
[2293] | 232 | shchild *children; /**< The child array. */
|
---|
[3438] | 233 | #ifndef SH_FORKED_MODE
|
---|
| 234 | int (*thread)(struct shinstance *, void *); /**< The thread procedure. */
|
---|
| 235 | void *threadarg; /**< The thread argument. */
|
---|
[3439] | 236 | struct jmploc *exitjmp; /**< Long jump target in sh_thread_wrapper for use by sh__exit. */
|
---|
[3460] | 237 | shsubshellstatus *subshellstatus; /**< Pointer to the subshell status structure (NULL if root). */
|
---|
[3438] | 238 | #endif
|
---|
[1218] | 239 |
|
---|
| 240 | /* alias.c */
|
---|
| 241 | #define ATABSIZE 39
|
---|
| 242 | struct alias *atab[ATABSIZE];
|
---|
[3438] | 243 | unsigned aliases; /**< Number of active aliases. */
|
---|
[1218] | 244 |
|
---|
| 245 | /* cd.c */
|
---|
| 246 | char *curdir; /**< current working directory */
|
---|
| 247 | char *prevdir; /**< previous working directory */
|
---|
[3439] | 248 | char *cdcomppath; /**< (stalloc) */
|
---|
[1218] | 249 | int getpwd_first; /**< static in getpwd. (initialized to 1!) */
|
---|
| 250 |
|
---|
| 251 | /* error.h */
|
---|
| 252 | struct jmploc *handler;
|
---|
| 253 | int exception;
|
---|
| 254 | int exerrno/* = 0 */; /**< Last exec error */
|
---|
| 255 | int volatile suppressint;
|
---|
| 256 | int volatile intpending;
|
---|
| 257 |
|
---|
| 258 | /* error.c */
|
---|
| 259 | char errmsg_buf[16]; /**< static in errmsg. (bss) */
|
---|
| 260 |
|
---|
| 261 | /* eval.h */
|
---|
| 262 | char *commandname; /**< currently executing command */
|
---|
| 263 | int exitstatus; /**< exit status of last command */
|
---|
| 264 | int back_exitstatus;/**< exit status of backquoted command */
|
---|
[3439] | 265 | struct strlist *cmdenviron; /**< environment for builtin command (varlist from evalcommand()) */
|
---|
[1218] | 266 | int funcnest; /**< depth of function calls */
|
---|
| 267 | int evalskip; /**< set if we are skipping commands */
|
---|
| 268 | int skipcount; /**< number of levels to skip */
|
---|
| 269 | int loopnest; /**< current loop nesting level */
|
---|
[3438] | 270 | int commandnamemalloc; /**< Set if commandname is malloc'ed (only subshells). */
|
---|
[1218] | 271 |
|
---|
| 272 | /* expand.c */
|
---|
[3459] | 273 | char *expdest; /**< output of current string (stack) */
|
---|
[1218] | 274 | struct nodelist *argbackq; /**< list of back quote expressions */
|
---|
| 275 | struct ifsregion ifsfirst; /**< first struct in list of ifs regions */
|
---|
| 276 | struct ifsregion *ifslastp; /**< last struct in list */
|
---|
[3459] | 277 | struct arglist exparg; /**< holds expanded arg list (stack) */
|
---|
[1218] | 278 | char *expdir; /**< Used by expandmeta. */
|
---|
| 279 |
|
---|
| 280 | /* exec.h */
|
---|
| 281 | const char *pathopt; /**< set by padvance */
|
---|
| 282 |
|
---|
| 283 | /* exec.c */
|
---|
| 284 | struct tblentry *cmdtable[CMDTABLESIZE];
|
---|
| 285 | int builtinloc/* = -1*/; /**< index in path of %builtin, or -1 */
|
---|
| 286 |
|
---|
| 287 | /* input.h */
|
---|
| 288 | int plinno/* = 1 */;/**< input line number */
|
---|
| 289 | int parsenleft; /**< number of characters left in input buffer */
|
---|
| 290 | char *parsenextc; /**< next character in input buffer */
|
---|
| 291 | int init_editline/* = 0 */; /**< 0 == not setup, 1 == OK, -1 == failed */
|
---|
| 292 |
|
---|
| 293 | /* input.c */
|
---|
| 294 | int parselleft; /**< copy of parsefile->lleft */
|
---|
| 295 | struct parsefile basepf; /**< top level input file */
|
---|
| 296 | char basebuf[BUFSIZ];/**< buffer for top level input file */
|
---|
| 297 | struct parsefile *parsefile/* = &basepf*/; /**< current input file */
|
---|
| 298 | #ifndef SMALL
|
---|
| 299 | EditLine *el; /**< cookie for editline package */
|
---|
| 300 | #endif
|
---|
| 301 |
|
---|
| 302 | /* jobs.h */
|
---|
[3438] | 303 | shpid backgndpid/* = -1 */; /**< pid of last background process */
|
---|
[1218] | 304 | int job_warning; /**< user was warned about stopped jobs */
|
---|
| 305 |
|
---|
| 306 | /* jobs.c */
|
---|
| 307 | struct job *jobtab; /**< array of jobs */
|
---|
| 308 | int njobs; /**< size of array */
|
---|
| 309 | int jobs_invalid; /**< set in child */
|
---|
[3438] | 310 | shpid initialpgrp; /**< pgrp of shell on invocation */
|
---|
[1218] | 311 | int curjob/* = -1*/;/**< current job */
|
---|
| 312 | int ttyfd/* = -1*/;
|
---|
| 313 | int jobctl; /**< job control enabled / disabled */
|
---|
| 314 | char *cmdnextc;
|
---|
| 315 | int cmdnleft;
|
---|
| 316 |
|
---|
[1229] | 317 |
|
---|
[1218] | 318 | /* mail.c */
|
---|
| 319 | #define MAXMBOXES 10
|
---|
| 320 | int nmboxes; /**< number of mailboxes */
|
---|
| 321 | time_t mailtime[MAXMBOXES]; /**< times of mailboxes */
|
---|
| 322 |
|
---|
| 323 | /* main.h */
|
---|
[3438] | 324 | shpid rootpid; /**< pid of main shell. */
|
---|
[1218] | 325 | int rootshell; /**< true if we aren't a child of the main shell. */
|
---|
| 326 | struct shinstance *psh_rootshell; /**< The root shell pointer. (!rootshell) */
|
---|
| 327 |
|
---|
| 328 | /* memalloc.h */
|
---|
| 329 | char *stacknxt/* = stackbase.space*/;
|
---|
| 330 | int stacknleft/* = MINSIZE*/;
|
---|
| 331 | int sstrnleft;
|
---|
| 332 | int herefd/* = -1 */;
|
---|
| 333 |
|
---|
| 334 | /* memalloc.c */
|
---|
| 335 | struct stack_block stackbase;
|
---|
| 336 | struct stack_block *stackp/* = &stackbase*/;
|
---|
| 337 | struct stackmark *markp;
|
---|
| 338 |
|
---|
[3457] | 339 | #ifdef KASH_SEPARATE_PARSER_ALLOCATOR
|
---|
| 340 | pstack_block *curpstack; /**< The pstack entry we're currently allocating from (NULL when not in parse.c). */
|
---|
| 341 | pstack_block **pstack; /**< Stack of parsed stuff. */
|
---|
| 342 | unsigned pstacksize; /**< Number of entries in pstack. */
|
---|
| 343 | unsigned pstackalloced; /**< The allocated size of pstack. */
|
---|
[3461] | 344 | pstack_block *freepstack; /**< One cached pstack entry (lots of parsecmd calls). */
|
---|
[3457] | 345 | #endif
|
---|
| 346 |
|
---|
[1218] | 347 | /* myhistedit.h */
|
---|
| 348 | int displayhist;
|
---|
| 349 | #ifndef SMALL
|
---|
| 350 | History *hist;
|
---|
| 351 | EditLine *el;
|
---|
| 352 | #endif
|
---|
| 353 |
|
---|
| 354 | /* output.h */
|
---|
| 355 | struct output output;
|
---|
| 356 | struct output errout;
|
---|
| 357 | struct output memout;
|
---|
| 358 | struct output *out1;
|
---|
| 359 | struct output *out2;
|
---|
| 360 |
|
---|
| 361 | /* output.c */
|
---|
| 362 | #define OUTBUFSIZ BUFSIZ
|
---|
| 363 | #define MEM_OUT -3 /**< output to dynamically allocated memory */
|
---|
| 364 |
|
---|
| 365 | /* options.h */
|
---|
| 366 | struct optent optlist[NOPTS];
|
---|
| 367 | char *minusc; /**< argument to -c option */
|
---|
| 368 | char *arg0; /**< $0 */
|
---|
| 369 | struct shparam shellparam; /**< $@ */
|
---|
| 370 | char **argptr; /**< argument list for builtin commands */
|
---|
| 371 | char *optionarg; /**< set by nextopt */
|
---|
| 372 | char *optptr; /**< used by nextopt */
|
---|
[3438] | 373 | char **orgargv; /**< The original argument vector (for cleanup). */
|
---|
| 374 | int arg0malloc; /**< Indicates whether arg0 was allocated or is part of orgargv. */
|
---|
[1218] | 375 |
|
---|
| 376 | /* parse.h */
|
---|
| 377 | int tokpushback;
|
---|
| 378 | int whichprompt; /**< 1 == PS1, 2 == PS2 */
|
---|
| 379 |
|
---|
| 380 | /* parser.c */
|
---|
| 381 | int noalias/* = 0*/;/**< when set, don't handle aliases */
|
---|
| 382 | struct heredoc *heredoclist; /**< list of here documents to read */
|
---|
| 383 | int parsebackquote; /**< nonzero if we are inside backquotes */
|
---|
| 384 | int doprompt; /**< if set, prompt the user */
|
---|
| 385 | int needprompt; /**< true if interactive and at start of line */
|
---|
| 386 | int lasttoken; /**< last token read */
|
---|
| 387 | char *wordtext; /**< text of last word returned by readtoken */
|
---|
| 388 | int checkkwd; /**< 1 == check for kwds, 2 == also eat newlines */
|
---|
| 389 | struct nodelist *backquotelist;
|
---|
| 390 | union node *redirnode;
|
---|
| 391 | struct heredoc *heredoc;
|
---|
| 392 | int quoteflag; /**< set if (part of) last token was quoted */
|
---|
| 393 | int startlinno; /**< line # where last token started */
|
---|
| 394 |
|
---|
| 395 | /* redir.c */
|
---|
| 396 | struct redirtab *redirlist;
|
---|
| 397 | int fd0_redirected/* = 0*/;
|
---|
[3449] | 398 | redirexpfnames *expfnames; /**< Expanded filenames for current redirection setup. */
|
---|
[1218] | 399 |
|
---|
[2296] | 400 | /* show.c */
|
---|
| 401 | char tracebuf[1024];
|
---|
| 402 | size_t tracepos;
|
---|
| 403 | int tracefd;
|
---|
| 404 |
|
---|
[1218] | 405 | /* trap.h */
|
---|
| 406 | int pendingsigs; /**< indicates some signal received */
|
---|
| 407 |
|
---|
| 408 | /* trap.c */
|
---|
| 409 | char gotsig[NSIG]; /**< indicates specified signal received */
|
---|
| 410 | char *trap[NSIG+1]; /**< trap handler commands */
|
---|
| 411 | char sigmode[NSIG]; /**< current value of signal */
|
---|
| 412 |
|
---|
| 413 | /* var.h */
|
---|
| 414 | struct localvar *localvars;
|
---|
| 415 | struct var vatty;
|
---|
| 416 | struct var vifs;
|
---|
| 417 | struct var vmail;
|
---|
| 418 | struct var vmpath;
|
---|
| 419 | struct var vpath;
|
---|
| 420 | #ifdef _MSC_VER
|
---|
| 421 | struct var vpath2;
|
---|
| 422 | #endif
|
---|
| 423 | struct var vps1;
|
---|
| 424 | struct var vps2;
|
---|
| 425 | struct var vps4;
|
---|
| 426 | #ifndef SMALL
|
---|
| 427 | struct var vterm;
|
---|
| 428 | struct var vhistsize;
|
---|
| 429 | #endif
|
---|
| 430 | struct var voptind;
|
---|
| 431 | #ifdef PC_OS2_LIBPATHS
|
---|
| 432 | struct var libpath_vars[4];
|
---|
| 433 | #endif
|
---|
| 434 | #ifdef SMALL
|
---|
| 435 | # define VTABSIZE 39
|
---|
| 436 | #else
|
---|
| 437 | # define VTABSIZE 517
|
---|
| 438 | #endif
|
---|
| 439 | struct var *vartab[VTABSIZE];
|
---|
| 440 |
|
---|
| 441 | /* builtins.h */
|
---|
| 442 |
|
---|
| 443 | /* bltin/test.c */
|
---|
| 444 | char **t_wp;
|
---|
| 445 | struct t_op const *t_wp_op;
|
---|
| 446 | };
|
---|
| 447 |
|
---|
[3468] | 448 | extern void sh_init_globals(void);
|
---|
[3438] | 449 | extern shinstance *sh_create_root_shell(char **, char **);
|
---|
| 450 | extern shinstance *sh_create_child_shell(shinstance *);
|
---|
[1222] | 451 |
|
---|
| 452 | /* environment & pwd.h */
|
---|
[1218] | 453 | char *sh_getenv(shinstance *, const char *);
|
---|
[1222] | 454 | char **sh_environ(shinstance *);
|
---|
[1218] | 455 | const char *sh_gethomedir(shinstance *, const char *);
|
---|
| 456 |
|
---|
| 457 | /* signals */
|
---|
[1784] | 458 | #define SH_SIG_UNK ((shsig_t)(intptr_t)-199)
|
---|
[3240] | 459 | #define SH_SIG_DFL ((shsig_t)(intptr_t)SIG_DFL)
|
---|
| 460 | #define SH_SIG_IGN ((shsig_t)(intptr_t)SIG_IGN)
|
---|
| 461 | #define SH_SIG_ERR ((shsig_t)(intptr_t)SIG_ERR)
|
---|
[1218] | 462 | #ifdef _MSC_VER
|
---|
[2287] | 463 | # define SA_RESTART 0x02
|
---|
[1218] | 464 | # define SIG_BLOCK 1
|
---|
| 465 | # define SIG_UNBLOCK 2
|
---|
| 466 | # define SIG_SETMASK 3
|
---|
[2392] | 467 |
|
---|
| 468 | # define SIGHUP 1 /* _SIGHUP_IGNORE */
|
---|
| 469 | /*# define SIGINT 2 */
|
---|
| 470 | # define SIGQUIT 3 /* _SIGQUIT_IGNORE */
|
---|
| 471 | /*# define SIGILL 4 */
|
---|
| 472 | /*# define SIGFPE 8 */
|
---|
| 473 | /*# define SIGSEGV 11 */
|
---|
| 474 | # define SIGPIPE 13 /* _SIGPIPE_IGNORE */
|
---|
| 475 | /*# define SIGTERM 15 */
|
---|
| 476 | # define SIGTTIN 16 /* _SIGIOINT_IGNORE */
|
---|
| 477 | # define SIGTSTP 17 /* _SIGSTOP_IGNORE */
|
---|
| 478 | # define SIGTTOU 18
|
---|
[1218] | 479 | # define SIGCONT 20
|
---|
[2392] | 480 | /*# define SIGBREAK 21 */
|
---|
| 481 | /*# define SIGABRT 22 */
|
---|
[3408] | 482 | const char *strsignal(int iSig);
|
---|
[1218] | 483 | #endif /* _MSC_VER */
|
---|
[1225] | 484 | #ifndef HAVE_SYS_SIGNAME
|
---|
[3409] | 485 | extern const char * const sys_signame[NSIG];
|
---|
[1225] | 486 | #endif
|
---|
[1218] | 487 |
|
---|
[1240] | 488 | int sh_sigaction(shinstance *, int, const struct shsigaction *, struct shsigaction *);
|
---|
| 489 | shsig_t sh_signal(shinstance *, int, shsig_t);
|
---|
[1218] | 490 | int sh_siginterrupt(shinstance *, int, int);
|
---|
[1240] | 491 | void sh_sigemptyset(shsigset_t *);
|
---|
[2286] | 492 | void sh_sigfillset(shsigset_t *);
|
---|
[1784] | 493 | void sh_sigaddset(shsigset_t *, int);
|
---|
| 494 | void sh_sigdelset(shsigset_t *, int);
|
---|
[2287] | 495 | int sh_sigismember(shsigset_t const *, int);
|
---|
[1240] | 496 | int sh_sigprocmask(shinstance *, int, shsigset_t const *, shsigset_t *);
|
---|
[2298] | 497 | SH_NORETURN_1 void sh_abort(shinstance *) SH_NORETURN_2;
|
---|
[1218] | 498 | void sh_raise_sigint(shinstance *);
|
---|
[3438] | 499 | int sh_kill(shinstance *, shpid, int);
|
---|
| 500 | int sh_killpg(shinstance *, shpid, int);
|
---|
[1218] | 501 |
|
---|
| 502 | /* times */
|
---|
| 503 | #include <time.h>
|
---|
| 504 | #ifdef _MSC_VER
|
---|
| 505 | typedef struct shtms
|
---|
| 506 | {
|
---|
| 507 | clock_t tms_utime;
|
---|
| 508 | clock_t tms_stime;
|
---|
| 509 | clock_t tms_cutime;
|
---|
| 510 | clock_t tms_cstime;
|
---|
| 511 | } shtms;
|
---|
| 512 | #else
|
---|
| 513 | # include <sys/times.h>
|
---|
| 514 | typedef struct tms shtms;
|
---|
| 515 | #endif
|
---|
| 516 | clock_t sh_times(shinstance *, shtms *);
|
---|
| 517 | int sh_sysconf_clk_tck(void);
|
---|
| 518 |
|
---|
| 519 | /* wait / process */
|
---|
[3467] | 520 | int sh_add_child(shinstance *psh, shpid pid, void *hChild, struct shsubshellstatus *sts);
|
---|
[1218] | 521 | #ifdef _MSC_VER
|
---|
| 522 | # include <process.h>
|
---|
| 523 | # define WNOHANG 1 /* Don't hang in wait. */
|
---|
| 524 | # define WUNTRACED 2 /* Tell about stopped, untraced children. */
|
---|
| 525 | # define WCONTINUED 4 /* Report a job control continued process. */
|
---|
| 526 | # define _W_INT(w) (*(int *)&(w)) /* Convert union wait to int. */
|
---|
| 527 | # define WCOREFLAG 0200
|
---|
| 528 | # define _WSTATUS(x) (_W_INT(x) & 0177)
|
---|
| 529 | # define _WSTOPPED 0177 /* _WSTATUS if process is stopped */
|
---|
| 530 | # define WIFSTOPPED(x) (_WSTATUS(x) == _WSTOPPED)
|
---|
| 531 | # define WSTOPSIG(x) (_W_INT(x) >> 8)
|
---|
| 532 | # define WIFSIGNALED(x) (_WSTATUS(x) != 0 && !WIFSTOPPED(x) && !WIFCONTINUED(x)) /* bird: made GLIBC tests happy. */
|
---|
| 533 | # define WTERMSIG(x) (_WSTATUS(x))
|
---|
| 534 | # define WIFEXITED(x) (_WSTATUS(x) == 0)
|
---|
| 535 | # define WEXITSTATUS(x) (_W_INT(x) >> 8)
|
---|
| 536 | # define WIFCONTINUED(x) (x == 0x13) /* 0x13 == SIGCONT */
|
---|
| 537 | # define WCOREDUMP(x) (_W_INT(x) & WCOREFLAG)
|
---|
| 538 | # define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
|
---|
| 539 | # define W_STOPCODE(sig) ((sig) << 8 | _WSTOPPED)
|
---|
| 540 | #else
|
---|
| 541 | # include <sys/wait.h>
|
---|
[2546] | 542 | # ifdef __HAIKU__
|
---|
[2657] | 543 | # define WCOREDUMP(x) WIFCORED(x)
|
---|
[2546] | 544 | # endif
|
---|
[1218] | 545 | #endif
|
---|
[3438] | 546 | #ifdef SH_FORKED_MODE
|
---|
| 547 | shpid sh_fork(shinstance *);
|
---|
| 548 | #else
|
---|
| 549 | shpid sh_thread_start(shinstance *pshparent, shinstance *pshchild, int (*thread)(shinstance *, void *), void *arg);
|
---|
| 550 | #endif
|
---|
| 551 | shpid sh_waitpid(shinstance *, shpid, int *, int);
|
---|
[2298] | 552 | SH_NORETURN_1 void sh__exit(shinstance *, int) SH_NORETURN_2;
|
---|
[1218] | 553 | int sh_execve(shinstance *, const char *, const char * const*, const char * const *);
|
---|
| 554 | uid_t sh_getuid(shinstance *);
|
---|
| 555 | uid_t sh_geteuid(shinstance *);
|
---|
| 556 | gid_t sh_getgid(shinstance *);
|
---|
| 557 | gid_t sh_getegid(shinstance *);
|
---|
[3438] | 558 | shpid sh_getpid(shinstance *);
|
---|
| 559 | shpid sh_getpgrp(shinstance *);
|
---|
| 560 | shpid sh_getpgid(shinstance *, shpid);
|
---|
| 561 | int sh_setpgid(shinstance *, shpid, shpid);
|
---|
[1218] | 562 |
|
---|
| 563 | /* tc* */
|
---|
[3438] | 564 | shpid sh_tcgetpgrp(shinstance *, int);
|
---|
| 565 | int sh_tcsetpgrp(shinstance *, int, shpid);
|
---|
[1218] | 566 |
|
---|
[1225] | 567 | /* sys/resource.h */
|
---|
[1218] | 568 | #ifdef _MSC_VER
|
---|
| 569 | typedef int64_t shrlim_t;
|
---|
| 570 | typedef struct shrlimit
|
---|
| 571 | {
|
---|
| 572 | shrlim_t rlim_cur;
|
---|
| 573 | shrlim_t rlim_max;
|
---|
| 574 | } shrlimit;
|
---|
| 575 | # define RLIMIT_CPU 0
|
---|
| 576 | # define RLIMIT_FSIZE 1
|
---|
| 577 | # define RLIMIT_DATA 2
|
---|
| 578 | # define RLIMIT_STACK 3
|
---|
| 579 | # define RLIMIT_CORE 4
|
---|
| 580 | # define RLIMIT_RSS 5
|
---|
| 581 | # define RLIMIT_MEMLOCK 6
|
---|
| 582 | # define RLIMIT_NPROC 7
|
---|
| 583 | # define RLIMIT_NOFILE 8
|
---|
| 584 | # define RLIMIT_SBSIZE 9
|
---|
| 585 | # define RLIMIT_VMEM 10
|
---|
| 586 | # define RLIM_NLIMITS 11
|
---|
| 587 | # define RLIM_INFINITY (0x7fffffffffffffffLL)
|
---|
| 588 | #else
|
---|
| 589 | typedef rlim_t shrlim_t;
|
---|
| 590 | typedef struct rlimit shrlimit;
|
---|
| 591 | #endif
|
---|
| 592 | int sh_getrlimit(shinstance *, int, shrlimit *);
|
---|
| 593 | int sh_setrlimit(shinstance *, int, const shrlimit *);
|
---|
| 594 |
|
---|
[2648] | 595 | /* string.h */
|
---|
| 596 | const char *sh_strerror(shinstance *, int);
|
---|
[1785] | 597 |
|
---|
| 598 | #ifdef DEBUG
|
---|
| 599 | # define TRACE2(param) trace param
|
---|
| 600 | # define TRACE2V(param) tracev param
|
---|
| 601 | #else
|
---|
[2648] | 602 | # define TRACE2(param) do { } while (0)
|
---|
| 603 | # define TRACE2V(param) do { } while (0)
|
---|
[1218] | 604 | #endif
|
---|
[1785] | 605 |
|
---|
| 606 | #endif
|
---|