2004-12-18 19:58:32 +01:00
|
|
|
/** $MirBSD: src/bin/ksh/main.c,v 2.7 2004/12/18 18:58:30 tg Exp $ */
|
2004-08-27 16:08:36 +02:00
|
|
|
/* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* startup, main loop, environments and error handling
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define EXTERN /* define EXTERNs in sh.h */
|
|
|
|
|
|
|
|
#include "sh.h"
|
|
|
|
#include "ksh_stat.h"
|
|
|
|
#include "ksh_time.h"
|
|
|
|
|
2004-12-13 19:53:25 +01:00
|
|
|
/*
|
|
|
|
* shell version
|
|
|
|
*/
|
2004-10-28 13:03:24 +02:00
|
|
|
|
2004-12-18 19:58:32 +01:00
|
|
|
__RCSID("$MirBSD: src/bin/ksh/main.c,v 2.7 2004/12/18 18:58:30 tg Exp $");
|
2004-12-13 19:53:25 +01:00
|
|
|
|
|
|
|
static const char version_param[] =
|
|
|
|
"KSH_VERSION"
|
|
|
|
;
|
|
|
|
|
|
|
|
const char ksh_version[] =
|
2004-12-14 16:54:26 +01:00
|
|
|
"@(#)PD KSH v5.2.14 MirOS R20 in "
|
2004-12-13 19:53:25 +01:00
|
|
|
#ifdef MIRBSD_NATIVE
|
|
|
|
"native "
|
|
|
|
#endif
|
2004-12-18 19:58:32 +01:00
|
|
|
"KSH mode"
|
2004-12-13 19:53:25 +01:00
|
|
|
#ifndef MIRBSD_NATIVE
|
|
|
|
" as mksh"
|
|
|
|
#endif
|
|
|
|
;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* global data
|
|
|
|
*/
|
|
|
|
|
2004-12-13 19:53:25 +01:00
|
|
|
extern char **environ;
|
|
|
|
|
2004-10-28 13:11:19 +02:00
|
|
|
static void reclaim(void);
|
|
|
|
static void remove_temps(struct temp *tp);
|
|
|
|
static int is_restricted(char *name);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* shell initialization
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const char initifs[] = "IFS= \t\n";
|
|
|
|
|
|
|
|
static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
|
|
|
|
|
|
|
|
static const char *const initcoms [] = {
|
|
|
|
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
|
|
|
|
"typeset", "-r", version_param, NULL,
|
|
|
|
"typeset", "-i", "PPID", NULL,
|
|
|
|
"typeset", "-i", "OPTIND=1", NULL,
|
2004-11-10 18:13:11 +01:00
|
|
|
"eval", "typeset -i RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
"alias",
|
|
|
|
/* Standard ksh aliases */
|
|
|
|
"hash=alias -t", /* not "alias -t --": hash -r needs to work */
|
|
|
|
"type=whence -v",
|
|
|
|
#ifdef JOBS
|
|
|
|
"stop=kill -STOP",
|
|
|
|
"suspend=kill -STOP $$",
|
|
|
|
#endif
|
|
|
|
"autoload=typeset -fu",
|
|
|
|
"functions=typeset -f",
|
|
|
|
# ifdef HISTORY
|
|
|
|
"history=fc -l",
|
|
|
|
# endif /* HISTORY */
|
|
|
|
"integer=typeset -i",
|
|
|
|
"nohup=nohup ",
|
|
|
|
"local=typeset",
|
|
|
|
"r=fc -e -",
|
|
|
|
/* Aliases that are builtin commands in at&t */
|
|
|
|
"login=exec login",
|
|
|
|
NULL,
|
|
|
|
/* this is what at&t ksh seems to track, with the addition of emacs */
|
|
|
|
"alias", "-tU",
|
|
|
|
"cat", "cc", "chmod", "cp", "date", "ed", "emacs", "grep", "ls",
|
|
|
|
"mail", "make", "mv", "pr", "rm", "sed", "sh", "vi", "who",
|
|
|
|
NULL,
|
|
|
|
#ifdef EXTRA_INITCOMS
|
|
|
|
EXTRA_INITCOMS, NULL,
|
|
|
|
#endif /* EXTRA_INITCOMS */
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
int
|
2003-06-29 16:51:25 +02:00
|
|
|
main(int argc, char *argv[])
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
2004-10-28 13:03:24 +02:00
|
|
|
int i;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
int argi;
|
|
|
|
Source *s;
|
|
|
|
struct block *l;
|
|
|
|
int restricted, errexit;
|
|
|
|
char **wp;
|
|
|
|
struct env env;
|
|
|
|
pid_t ppid;
|
|
|
|
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
chmem_set_defaults("ct", 1);
|
|
|
|
/* chmem_push("+c", 1); */
|
|
|
|
#endif /* MEM_DEBUG */
|
|
|
|
|
|
|
|
/* make sure argv[] is sane */
|
|
|
|
if (!*argv) {
|
|
|
|
static const char *empty_argv[] = {
|
2004-12-13 20:09:06 +01:00
|
|
|
"mksh", (char *) 0
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
argv = (char **) empty_argv;
|
|
|
|
argc = 1;
|
|
|
|
}
|
|
|
|
kshname = *argv;
|
|
|
|
|
|
|
|
ainit(&aperm); /* initialize permanent Area */
|
|
|
|
|
|
|
|
/* set up base environment */
|
|
|
|
memset(&env, 0, sizeof(env));
|
|
|
|
env.type = E_NONE;
|
|
|
|
ainit(&env.area);
|
|
|
|
e = &env;
|
|
|
|
newblock(); /* set up global l->vars and l->funs */
|
|
|
|
|
|
|
|
/* Do this first so output routines (eg, errorf, shellf) can work */
|
|
|
|
initio();
|
|
|
|
|
2004-11-01 00:01:18 +01:00
|
|
|
argi = parse_args(argv, OF_FIRSTTIME, NULL);
|
|
|
|
if (argi < 0)
|
|
|
|
exit(1);
|
|
|
|
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
initvar();
|
|
|
|
|
|
|
|
initctypes();
|
|
|
|
|
|
|
|
inittraps();
|
|
|
|
|
|
|
|
coproc_init();
|
|
|
|
|
|
|
|
/* set up variable and command dictionaries */
|
|
|
|
tinit(&taliases, APERM, 0);
|
|
|
|
tinit(&aliases, APERM, 0);
|
|
|
|
tinit(&homedirs, APERM, 0);
|
|
|
|
|
|
|
|
/* define shell keywords */
|
|
|
|
initkeywords();
|
|
|
|
|
|
|
|
/* define built-in commands */
|
|
|
|
tinit(&builtins, APERM, 64); /* must be 2^n (currently 40 builtins) */
|
|
|
|
for (i = 0; shbuiltins[i].name != NULL; i++)
|
|
|
|
builtin(shbuiltins[i].name, shbuiltins[i].func);
|
|
|
|
for (i = 0; kshbuiltins[i].name != NULL; i++)
|
|
|
|
builtin(kshbuiltins[i].name, kshbuiltins[i].func);
|
|
|
|
|
|
|
|
init_histvec();
|
|
|
|
|
|
|
|
def_path = DEFAULT__PATH;
|
|
|
|
#if defined(HAVE_CONFSTR) && defined(_CS_PATH)
|
|
|
|
{
|
|
|
|
size_t len = confstr(_CS_PATH, (char *) 0, 0);
|
|
|
|
char *new;
|
|
|
|
|
|
|
|
if (len > 0) {
|
|
|
|
confstr(_CS_PATH, new = alloc(len + 1, APERM), len + 1);
|
|
|
|
def_path = new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* HAVE_CONFSTR && _CS_PATH */
|
|
|
|
|
|
|
|
/* Set PATH to def_path (will set the path global variable).
|
|
|
|
* (import of environment below will probably change this setting).
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct tbl *vp = global("PATH");
|
|
|
|
/* setstr can't fail here */
|
|
|
|
setstr(vp, def_path, KSH_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-01-26 17:55:10 +01:00
|
|
|
/* Turn on nohup by default for now - will change to off
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
* by default once people are aware of its existence
|
|
|
|
* (at&t ksh does not have a nohup option - it always sends
|
|
|
|
* the hup).
|
|
|
|
*/
|
|
|
|
Flag(FNOHUP) = 1;
|
|
|
|
|
|
|
|
/* Turn on brace expansion by default. At&t ksh's that have
|
|
|
|
* alternation always have it on. BUT, posix doesn't have
|
|
|
|
* brace expansion, so set this before setting up FPOSIX
|
|
|
|
* (change_flag() clears FBRACEEXPAND when FPOSIX is set).
|
|
|
|
*/
|
|
|
|
#ifdef BRACE_EXPAND
|
|
|
|
Flag(FBRACEEXPAND) = 1;
|
|
|
|
#endif /* BRACE_EXPAND */
|
|
|
|
|
|
|
|
/* set posix flag just before environment so that it will have
|
|
|
|
* exactly the same effect as the POSIXLY_CORRECT environment
|
|
|
|
* variable. If this needs to be done sooner to ensure correct posix
|
|
|
|
* operation, an initial scan of the environment will also have
|
|
|
|
* done sooner.
|
|
|
|
*/
|
|
|
|
#ifdef POSIXLY_CORRECT
|
|
|
|
change_flag(FPOSIX, OF_SPECIAL, 1);
|
|
|
|
#endif /* POSIXLY_CORRECT */
|
|
|
|
|
|
|
|
/* Check to see if we're /bin/sh. */
|
|
|
|
if (!strcmp(&kshname[strlen(kshname) - 3], "/sh")
|
|
|
|
|| !strcmp(kshname, "sh") || !strcmp(kshname, "-sh"))
|
|
|
|
Flag(FSH) = 1;
|
|
|
|
|
|
|
|
/* Set edit mode to emacs by default, may be overridden
|
|
|
|
* by the environment or the user. Also, we want tab completion
|
|
|
|
* on in vi by default. */
|
|
|
|
#if defined(EDIT) && defined(EMACS)
|
|
|
|
change_flag(FEMACS, OF_SPECIAL, 1);
|
|
|
|
#endif /* EDIT && EMACS */
|
|
|
|
#if defined(EDIT) && defined(VI)
|
|
|
|
Flag(FVITABCOMPLETE) = 1;
|
|
|
|
#endif /* EDIT && VI */
|
|
|
|
|
|
|
|
/* import environment */
|
|
|
|
if (environ != NULL)
|
|
|
|
for (wp = environ; *wp != NULL; wp++)
|
|
|
|
typeset(*wp, IMPORT|EXPORT, 0, 0, 0);
|
|
|
|
|
|
|
|
kshpid = procpid = getpid();
|
|
|
|
typeset(initifs, 0, 0, 0, 0); /* for security */
|
|
|
|
|
|
|
|
/* assign default shell variable values */
|
|
|
|
substitute(initsubs, 0);
|
|
|
|
|
|
|
|
/* Figure out the current working directory and set $PWD */
|
|
|
|
{
|
|
|
|
struct stat s_pwd, s_dot;
|
|
|
|
struct tbl *pwd_v = global("PWD");
|
|
|
|
char *pwd = str_val(pwd_v);
|
|
|
|
char *pwdx = pwd;
|
|
|
|
|
|
|
|
/* Try to use existing $PWD if it is valid */
|
|
|
|
if (!ISABSPATH(pwd)
|
|
|
|
|| stat(pwd, &s_pwd) < 0 || stat(".", &s_dot) < 0
|
|
|
|
|| s_pwd.st_dev != s_dot.st_dev
|
|
|
|
|| s_pwd.st_ino != s_dot.st_ino)
|
|
|
|
pwdx = (char *) 0;
|
|
|
|
set_current_wd(pwdx);
|
|
|
|
if (current_wd[0])
|
|
|
|
simplify_path(current_wd);
|
|
|
|
/* Only set pwd if we know where we are or if it had a
|
|
|
|
* bogus value
|
|
|
|
*/
|
|
|
|
if (current_wd[0] || pwd != null)
|
|
|
|
/* setstr can't fail here */
|
|
|
|
setstr(pwd_v, current_wd, KSH_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
ppid = getppid();
|
|
|
|
setint(global("PPID"), (long) ppid);
|
2004-05-24 21:06:55 +02:00
|
|
|
rnd_seed( (*((long *)kshname))
|
|
|
|
^ ((long) (time(NULL) * kshpid * ppid)) );
|
|
|
|
setint(global("RANDOM"), rnd_get());
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
/* setstr can't fail here */
|
|
|
|
setstr(global(version_param), ksh_version, KSH_RETURN_ERROR);
|
|
|
|
|
|
|
|
/* execute initialization statements */
|
|
|
|
for (wp = (char**) initcoms; *wp != NULL; wp++) {
|
|
|
|
shcomexec(wp);
|
|
|
|
for (; *wp != NULL; wp++)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ksheuid = geteuid();
|
|
|
|
safe_prompt = ksheuid ? "$ " : "# ";
|
|
|
|
{
|
|
|
|
struct tbl *vp = global("PS1");
|
|
|
|
|
|
|
|
/* Set PS1 if it isn't set, or we are root and prompt doesn't
|
|
|
|
* contain a #.
|
|
|
|
*/
|
|
|
|
if (!(vp->flag & ISSET)
|
|
|
|
|| (!ksheuid && !strchr(str_val(vp), '#')))
|
|
|
|
/* setstr can't fail here */
|
|
|
|
setstr(vp, safe_prompt, KSH_RETURN_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set this before parsing arguments */
|
|
|
|
Flag(FPRIVILEGED) = getuid() != ksheuid || getgid() != getegid();
|
|
|
|
|
|
|
|
/* this to note if monitor is set on command line (see below) */
|
|
|
|
Flag(FMONITOR) = 127;
|
|
|
|
argi = parse_args(argv, OF_CMDLINE, (int *) 0);
|
|
|
|
if (argi < 0)
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
if (Flag(FCOMMAND)) {
|
|
|
|
s = pushs(SSTRING, ATEMP);
|
|
|
|
if (!(s->start = s->str = argv[argi++]))
|
|
|
|
errorf("-c requires an argument");
|
|
|
|
if (argv[argi])
|
|
|
|
kshname = argv[argi++];
|
|
|
|
} else if (argi < argc && !Flag(FSTDIN)) {
|
|
|
|
s = pushs(SFILE, ATEMP);
|
|
|
|
s->file = argv[argi++];
|
|
|
|
s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC);
|
|
|
|
if (s->u.shf == NULL) {
|
|
|
|
exstat = 127; /* POSIX */
|
|
|
|
errorf("%s: %s", s->file, strerror(errno));
|
|
|
|
}
|
|
|
|
kshname = s->file;
|
|
|
|
} else {
|
|
|
|
Flag(FSTDIN) = 1;
|
|
|
|
s = pushs(SSTDIN, ATEMP);
|
|
|
|
s->file = "<stdin>";
|
|
|
|
s->u.shf = shf_fdopen(0, SHF_RD | can_seek(0),
|
|
|
|
(struct shf *) 0);
|
|
|
|
if (isatty(0) && isatty(2)) {
|
|
|
|
Flag(FTALKING) = Flag(FTALKING_I) = 1;
|
|
|
|
/* The following only if isatty(0) */
|
|
|
|
s->flags |= SF_TTY;
|
|
|
|
s->u.shf->flags |= SHF_INTERRUPT;
|
|
|
|
s->file = (char *) 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This bizarreness is mandated by POSIX */
|
|
|
|
{
|
|
|
|
struct stat s_stdin;
|
|
|
|
|
|
|
|
if (fstat(0, &s_stdin) >= 0 && S_ISCHR(s_stdin.st_mode) &&
|
|
|
|
Flag(FTALKING))
|
|
|
|
reset_nonblock(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialize job control */
|
|
|
|
i = Flag(FMONITOR) != 127;
|
|
|
|
Flag(FMONITOR) = 0;
|
|
|
|
j_init(i);
|
|
|
|
#ifdef EDIT
|
|
|
|
/* Do this after j_init(), as tty_fd is not initialized 'til then */
|
|
|
|
if (Flag(FTALKING))
|
|
|
|
x_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
l = e->loc;
|
|
|
|
l->argv = &argv[argi - 1];
|
|
|
|
l->argc = argc - argi;
|
|
|
|
l->argv[0] = (char *) kshname;
|
|
|
|
getopts_reset(1);
|
|
|
|
|
|
|
|
/* Disable during .profile/ENV reading */
|
|
|
|
restricted = Flag(FRESTRICTED);
|
|
|
|
Flag(FRESTRICTED) = 0;
|
|
|
|
errexit = Flag(FERREXIT);
|
|
|
|
Flag(FERREXIT) = 0;
|
|
|
|
|
|
|
|
/* Do this before profile/$ENV so that if it causes problems in them,
|
|
|
|
* user will know why things broke.
|
|
|
|
*/
|
|
|
|
if (!current_wd[0] && Flag(FTALKING))
|
|
|
|
warningf(FALSE, "Cannot determine current working directory");
|
|
|
|
|
|
|
|
if (Flag(FLOGIN)) {
|
|
|
|
include(KSH_SYSTEM_PROFILE, 0, (char **) 0, 1);
|
|
|
|
if (!Flag(FPRIVILEGED))
|
|
|
|
include(substitute("$HOME/.profile", 0), 0,
|
|
|
|
(char **) 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Flag(FPRIVILEGED))
|
|
|
|
include("/etc/suid_profile", 0, (char **) 0, 1);
|
|
|
|
else {
|
|
|
|
char *env_file;
|
|
|
|
|
2004-12-18 19:58:32 +01:00
|
|
|
/* include $ENV */
|
|
|
|
env_file = str_val(global("ENV"));
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
#ifdef DEFAULT_ENV
|
|
|
|
/* If env isn't set, include default environment */
|
|
|
|
if (env_file == null)
|
|
|
|
env_file = DEFAULT_ENV;
|
|
|
|
#endif /* DEFAULT_ENV */
|
|
|
|
env_file = substitute(env_file, DOTILDE);
|
|
|
|
if (*env_file != '\0')
|
|
|
|
include(env_file, 0, (char **) 0, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_restricted(argv[0]) || is_restricted(str_val(global("SHELL"))))
|
|
|
|
restricted = 1;
|
|
|
|
if (restricted) {
|
|
|
|
static const char *const restr_com[] = {
|
|
|
|
"typeset", "-r", "PATH",
|
|
|
|
"ENV", "SHELL",
|
|
|
|
(char *) 0
|
|
|
|
};
|
|
|
|
shcomexec((char **) restr_com);
|
|
|
|
/* After typeset command... */
|
|
|
|
Flag(FRESTRICTED) = 1;
|
|
|
|
}
|
|
|
|
if (errexit)
|
|
|
|
Flag(FERREXIT) = 1;
|
|
|
|
|
|
|
|
if (Flag(FTALKING)) {
|
|
|
|
hist_init(s);
|
|
|
|
alarm_init();
|
|
|
|
} else
|
|
|
|
Flag(FTRACKALL) = 1; /* set after ENV */
|
|
|
|
|
|
|
|
shell(s, TRUE); /* doesn't return */
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-10-28 13:53:44 +02:00
|
|
|
include(const char *name, int argc, char **argv, int intr_ok)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
2004-10-28 13:03:24 +02:00
|
|
|
Source *volatile s = NULL;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
struct shf *shf;
|
|
|
|
char **volatile old_argv;
|
|
|
|
volatile int old_argc;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
shf = shf_open(name, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC);
|
|
|
|
if (shf == NULL)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (argv) {
|
|
|
|
old_argv = e->loc->argv;
|
|
|
|
old_argc = e->loc->argc;
|
|
|
|
} else {
|
|
|
|
old_argv = (char **) 0;
|
|
|
|
old_argc = 0;
|
|
|
|
}
|
|
|
|
newenv(E_INCL);
|
|
|
|
i = ksh_sigsetjmp(e->jbuf, 0);
|
|
|
|
if (i) {
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(s ? s->u.shf : NULL);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
if (old_argv) {
|
|
|
|
e->loc->argv = old_argv;
|
|
|
|
e->loc->argc = old_argc;
|
|
|
|
}
|
|
|
|
switch (i) {
|
|
|
|
case LRETURN:
|
|
|
|
case LERROR:
|
|
|
|
return exstat & 0xff; /* see below */
|
|
|
|
case LINTR:
|
|
|
|
/* intr_ok is set if we are including .profile or $ENV.
|
|
|
|
* If user ^C's out, we don't want to kill the shell...
|
|
|
|
*/
|
|
|
|
if (intr_ok && (exstat - 128) != SIGTERM)
|
|
|
|
return 1;
|
|
|
|
/* fall through... */
|
|
|
|
case LEXIT:
|
|
|
|
case LLEAVE:
|
|
|
|
case LSHELL:
|
|
|
|
unwind(i);
|
|
|
|
/*NOREACHED*/
|
|
|
|
default:
|
|
|
|
internal_errorf(1, "include: %d", i);
|
|
|
|
/*NOREACHED*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (argv) {
|
|
|
|
e->loc->argv = argv;
|
|
|
|
e->loc->argc = argc;
|
|
|
|
}
|
|
|
|
s = pushs(SFILE, ATEMP);
|
|
|
|
s->u.shf = shf;
|
|
|
|
s->file = str_save(name, ATEMP);
|
|
|
|
i = shell(s, FALSE);
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(s->u.shf);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
if (old_argv) {
|
|
|
|
e->loc->argv = old_argv;
|
|
|
|
e->loc->argc = old_argc;
|
|
|
|
}
|
|
|
|
return i & 0xff; /* & 0xff to ensure value not -1 */
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2004-10-28 13:53:44 +02:00
|
|
|
command(const char *comm)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
2004-10-28 13:03:24 +02:00
|
|
|
Source *s;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
s = pushs(SSTRING, ATEMP);
|
|
|
|
s->start = s->str = comm;
|
|
|
|
return shell(s, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* run the commands from the input source, returning status.
|
|
|
|
*/
|
|
|
|
int
|
2004-10-28 13:53:44 +02:00
|
|
|
shell(Source *volatile s, volatile int toplevel)
|
|
|
|
/* input source */
|
|
|
|
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
struct op *t;
|
|
|
|
volatile int wastty = s->flags & SF_TTY;
|
|
|
|
volatile int attempts = 13;
|
|
|
|
volatile int interactive = Flag(FTALKING) && toplevel;
|
|
|
|
Source *volatile old_source = source;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
newenv(E_PARSE);
|
|
|
|
if (interactive)
|
|
|
|
really_exit = 0;
|
|
|
|
i = ksh_sigsetjmp(e->jbuf, 0);
|
|
|
|
if (i) {
|
|
|
|
switch (i) {
|
|
|
|
case LINTR: /* we get here if SIGINT not caught or ignored */
|
|
|
|
case LERROR:
|
|
|
|
case LSHELL:
|
|
|
|
if (interactive) {
|
|
|
|
if (i == LINTR)
|
|
|
|
shellf(newline);
|
|
|
|
/* Reset any eof that was read as part of a
|
|
|
|
* multiline command.
|
|
|
|
*/
|
|
|
|
if (Flag(FIGNOREEOF) && s->type == SEOF
|
|
|
|
&& wastty)
|
|
|
|
s->type = SSTDIN;
|
|
|
|
/* Used by exit command to get back to
|
|
|
|
* top level shell. Kind of strange since
|
|
|
|
* interactive is set if we are reading from
|
|
|
|
* a tty, but to have stopped jobs, one only
|
|
|
|
* needs FMONITOR set (not FTALKING/SF_TTY)...
|
|
|
|
*/
|
|
|
|
/* toss any input we have so far */
|
|
|
|
s->start = s->str = null;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* fall through... */
|
|
|
|
case LEXIT:
|
|
|
|
case LLEAVE:
|
|
|
|
case LRETURN:
|
|
|
|
source = old_source;
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(NULL);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
unwind(i); /* keep on going */
|
|
|
|
/*NOREACHED*/
|
|
|
|
default:
|
|
|
|
source = old_source;
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(NULL);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
internal_errorf(1, "shell: %d", i);
|
|
|
|
/*NOREACHED*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
if (trap)
|
|
|
|
runtraps(0);
|
|
|
|
|
|
|
|
if (s->next == NULL) {
|
|
|
|
if (Flag(FVERBOSE))
|
|
|
|
s->flags |= SF_ECHO;
|
|
|
|
else
|
|
|
|
s->flags &= ~SF_ECHO;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (interactive) {
|
|
|
|
j_notify();
|
|
|
|
set_prompt(PS1, s);
|
|
|
|
}
|
|
|
|
|
|
|
|
t = compile(s);
|
|
|
|
if (t != NULL && t->type == TEOF) {
|
|
|
|
if (wastty && Flag(FIGNOREEOF) && --attempts > 0) {
|
2004-04-17 02:47:20 +02:00
|
|
|
shellf("Use 'exit' to leave ksh\n");
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
s->type = SSTDIN;
|
|
|
|
} else if (wastty && !really_exit
|
|
|
|
&& j_stopped_running())
|
|
|
|
{
|
|
|
|
really_exit = 1;
|
|
|
|
s->type = SSTDIN;
|
|
|
|
} else {
|
|
|
|
/* this for POSIX, which says EXIT traps
|
|
|
|
* shall be taken in the environment
|
|
|
|
* immediately after the last command
|
|
|
|
* executed.
|
|
|
|
*/
|
|
|
|
if (toplevel)
|
|
|
|
unwind(LEXIT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (t && (!Flag(FNOEXEC) || (s->flags & SF_TTY)))
|
|
|
|
exstat = execute(t, 0);
|
|
|
|
|
|
|
|
if (t != NULL && t->type != TEOF && interactive && really_exit)
|
|
|
|
really_exit = 0;
|
|
|
|
|
|
|
|
reclaim();
|
|
|
|
}
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(NULL);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
source = old_source;
|
|
|
|
return exstat;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* return to closest error handler or shell(), exit if none found */
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
unwind(int i)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
/* ordering for EXIT vs ERR is a bit odd (this is what at&t ksh does) */
|
|
|
|
if (i == LEXIT || (Flag(FERREXIT) && (i == LERROR || i == LINTR)
|
|
|
|
&& sigtraps[SIGEXIT_].trap))
|
|
|
|
{
|
|
|
|
runtrap(&sigtraps[SIGEXIT_]);
|
|
|
|
i = LLEAVE;
|
|
|
|
} else if (Flag(FERREXIT) && (i == LERROR || i == LINTR)) {
|
|
|
|
runtrap(&sigtraps[SIGERR_]);
|
|
|
|
i = LLEAVE;
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
switch (e->type) {
|
|
|
|
case E_PARSE:
|
|
|
|
case E_FUNC:
|
|
|
|
case E_INCL:
|
|
|
|
case E_LOOP:
|
|
|
|
case E_ERRH:
|
|
|
|
ksh_siglongjmp(e->jbuf, i);
|
|
|
|
/*NOTREACHED*/
|
|
|
|
|
|
|
|
case E_NONE:
|
|
|
|
if (i == LINTR)
|
|
|
|
e->flags |= EF_FAKE_SIGDIE;
|
|
|
|
/* Fall through... */
|
|
|
|
|
|
|
|
default:
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(NULL);
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
newenv(int type)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
2004-10-28 13:03:24 +02:00
|
|
|
struct env *ep;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
ep = (struct env *) alloc(sizeof(*ep), ATEMP);
|
|
|
|
ep->type = type;
|
|
|
|
ep->flags = 0;
|
|
|
|
ainit(&ep->area);
|
|
|
|
ep->loc = e->loc;
|
|
|
|
ep->savefd = NULL;
|
|
|
|
ep->oenv = e;
|
|
|
|
ep->temps = NULL;
|
|
|
|
e = ep;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-12-13 17:48:54 +01:00
|
|
|
quitenv(struct shf *shf)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
2004-10-28 13:03:24 +02:00
|
|
|
struct env *ep = e;
|
|
|
|
int fd;
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
if (ep->oenv && ep->oenv->loc != ep->loc)
|
|
|
|
popblock();
|
|
|
|
if (ep->savefd != NULL) {
|
|
|
|
for (fd = 0; fd < NUFILE; fd++)
|
|
|
|
/* if ep->savefd[fd] < 0, means fd was closed */
|
|
|
|
if (ep->savefd[fd])
|
|
|
|
restfd(fd, ep->savefd[fd]);
|
|
|
|
if (ep->savefd[2]) /* Clear any write errors */
|
|
|
|
shf_reopen(2, SHF_WR, shl_out);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Bottom of the stack.
|
|
|
|
* Either main shell is exiting or cleanup_parents_env() was called.
|
|
|
|
*/
|
|
|
|
if (ep->oenv == NULL) {
|
|
|
|
if (ep->type == E_NONE) { /* Main shell exiting? */
|
|
|
|
if (Flag(FTALKING))
|
|
|
|
hist_finish();
|
|
|
|
j_exit();
|
|
|
|
if (ep->flags & EF_FAKE_SIGDIE) {
|
|
|
|
int sig = exstat - 128;
|
|
|
|
|
|
|
|
/* ham up our death a bit (at&t ksh
|
|
|
|
* only seems to do this for SIGTERM)
|
|
|
|
* Don't do it for SIGQUIT, since we'd
|
|
|
|
* dump a core..
|
|
|
|
*/
|
2004-08-27 16:08:36 +02:00
|
|
|
if ((sig == SIGINT || sig == SIGTERM) &&
|
|
|
|
getpgrp() == kshpid) {
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
setsig(&sigtraps[sig], SIG_DFL,
|
|
|
|
SS_RESTORE_CURR|SS_FORCE);
|
|
|
|
kill(0, sig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef MEM_DEBUG
|
|
|
|
chmem_allfree();
|
|
|
|
#endif /* MEM_DEBUG */
|
|
|
|
}
|
2004-12-13 17:48:54 +01:00
|
|
|
if (shf)
|
|
|
|
shf_close(shf);
|
|
|
|
reclaim();
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
exit(exstat);
|
|
|
|
}
|
2004-12-13 17:48:54 +01:00
|
|
|
if (shf)
|
|
|
|
shf_close(shf);
|
|
|
|
reclaim();
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
|
|
|
|
e = e->oenv;
|
|
|
|
afree(ep, ATEMP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called after a fork to cleanup stuff left over from parents environment */
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
cleanup_parents_env(void)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
struct env *ep;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Don't clean up temporary files - parent will probably need them.
|
|
|
|
* Also, can't easily reclaim memory since variables, etc. could be
|
|
|
|
* anywhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* close all file descriptors hiding in savefd */
|
|
|
|
for (ep = e; ep; ep = ep->oenv) {
|
|
|
|
if (ep->savefd) {
|
|
|
|
for (fd = 0; fd < NUFILE; fd++)
|
|
|
|
if (ep->savefd[fd] > 0)
|
|
|
|
close(ep->savefd[fd]);
|
|
|
|
afree(ep->savefd, &ep->area);
|
|
|
|
ep->savefd = (short *) 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
e->oenv = (struct env *) 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called just before an execve cleanup stuff temporary files */
|
|
|
|
void
|
2004-10-28 13:53:44 +02:00
|
|
|
cleanup_proc_env(void)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
struct env *ep;
|
|
|
|
|
|
|
|
for (ep = e; ep; ep = ep->oenv)
|
|
|
|
remove_temps(ep->temps);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove temp files and free ATEMP Area */
|
|
|
|
static void
|
2004-10-28 13:53:44 +02:00
|
|
|
reclaim(void)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
remove_temps(e->temps);
|
|
|
|
e->temps = NULL;
|
|
|
|
afreeall(&e->area);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-10-28 13:53:44 +02:00
|
|
|
remove_temps(struct temp *tp)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
for (; tp != NULL; tp = tp->next)
|
2004-12-13 20:05:09 +01:00
|
|
|
if (tp->pid == procpid)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
unlink(tp->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns true if name refers to a restricted shell */
|
|
|
|
static int
|
2004-10-28 13:53:44 +02:00
|
|
|
is_restricted(char *name)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
char *p;
|
|
|
|
|
|
|
|
if ((p = ksh_strrchr_dirsep(name)))
|
|
|
|
name = p;
|
|
|
|
/* accepts rsh, rksh, rpdksh, pdrksh, etc. */
|
2004-04-27 21:59:57 +02:00
|
|
|
return (p = strchr(name, 'r')) && strstr(p, "sh")
|
|
|
|
&& !strstr(p-2, "mirbsdksh") && !strstr(p-2, "mirosksh");
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-10-28 13:03:24 +02:00
|
|
|
aerror(Area *ap GCC_FUNC_ATTR(unused), const char *msg)
|
Import OpenBSD 3.3 source repository from CTM 3132 the first time
This opens an OpenBSD-mirabile (aka MirBSD) repository.
### MirBSD is:
# Copyright (c) 1982-2003 by Thorsten "mirabile" Glaser <x86@ePost.de>
# Copyright © 1968-2003 The authors of And contributors to UNIX®, the
# C Language, BSD/Berkeley Unix; 386BSD, NetBSD 1.1 and OpenBSD.
#
# Anyone who obtained a copy of this work is hereby permitted to freely use,
# distribute, modify, merge, sublicence, give away or sell it as long as the
# authors are given due credit and the following notice is retained:
#
# This work is provided "as is", with no explicit or implicit warranty what-
# soever. Use it only at your own risk. In no event may an author or contri-
# butor be held liable for any damage, directly or indirectly, that origina-
# ted through or is caused by creation or modification of this work.
MirBSD is my private tree. MirBSD does not differ very much from OpenBSD
and intentionally tracks OpenBSD. That's why it _is_ OpenBSD, just not the
official one. It's like with DarrenBSD.
At time of this writing, no advertising for MirBSD must be done,
because the advertising clause has not yet been sorted out.
http://templeofhate.com/tglaser/MirBSD/index.php
2003-03-22 18:35:03 +01:00
|
|
|
{
|
|
|
|
internal_errorf(1, "alloc: %s", msg);
|
|
|
|
errorf(null); /* this is never executed - keeps gcc quiet */
|
|
|
|
/*NOTREACHED*/
|
|
|
|
}
|