summaryrefslogtreecommitdiff
path: root/bin/pdksh/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'bin/pdksh/main.c')
-rw-r--r--bin/pdksh/main.c71
1 files changed, 49 insertions, 22 deletions
diff --git a/bin/pdksh/main.c b/bin/pdksh/main.c
index ad3cce92323..e8425e1fab8 100644
--- a/bin/pdksh/main.c
+++ b/bin/pdksh/main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: main.c,v 1.3 1996/10/01 02:05:45 downsj Exp $ */
+/* $OpenBSD: main.c,v 1.4 1996/11/21 07:59:33 downsj Exp $ */
/*
* startup, main loop, enviroments and error handling
@@ -16,17 +16,17 @@ extern char **environ;
* global data
*/
-static void reclaim ARGS((void));
-static void remove_temps ARGS((struct temp *tp));
-static int is_restricted ARGS((char *name));
+static void reclaim ARGS((void));
+static void remove_temps ARGS((struct temp *tp));
+static int is_restricted ARGS((char *name));
/*
* shell initialization
*/
-static const char initifs [] = "IFS= \t\n"; /* must be R/W */
+static const char initifs [] = "IFS= \t\n"; /* must be R/W */
-static const char initsubs [] =
+static const char initsubs [] =
"${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char version_param[] =
@@ -37,7 +37,7 @@ static const char version_param[] =
#endif /* KSH */
;
-static const char *const initcoms [] = {
+static const char *const initcoms [] = {
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-r", version_param, NULL,
"typeset", "-ri", "PPID", NULL,
@@ -120,11 +120,9 @@ main(argc, argv)
ainit(&aperm); /* initialize permanent Area */
/* set up base enviroment */
+ memset(&env, 0, sizeof(env));
env.type = E_NONE;
ainit(&env.area);
- env.savefd = NULL;
- env.oenv = NULL;
- env.loc = (struct block *) 0;
e = &env;
newblock(); /* set up global l->vars and l->funs */
@@ -729,6 +727,17 @@ cleanup_parents_env()
e->oenv = (struct env *) 0;
}
+/* Called just before an execve cleanup stuff temporary files */
+void
+cleanup_proc_env()
+{
+ struct env *ep;
+
+ for (ep = e; ep; ep = ep->oenv)
+ remove_temps(ep->temps);
+ remove_temps(func_heredocs);
+}
+
/* remove temp files and free ATEMP Area */
static void
reclaim()
@@ -743,25 +752,43 @@ remove_temps(tp)
struct temp *tp;
{
#ifdef OS2
- static char tmpfile[30];
- int status;
-
- if (strlen (tmpfile) > 0 ) {
- unlink(tmpfile);
- *tmpfile=0;
- }
+ static struct temp *delayed_remove;
+ struct temp *t, **tprev;
+
+ if (delayed_remove) {
+ for (tprev = &delayed_remove, t = delayed_remove; t; t = *tprev)
+ /* No need to check t->pid here... */
+ if (unlink(t->name) >= 0 || errno == ENOENT) {
+ *tprev = t->next;
+ afree(t, APERM);
+ } else
+ tprev = &t->next;
+ }
#endif /* OS2 */
for (; tp != NULL; tp = tp->next)
- if (tp->pid == procpid)
+ if (tp->pid == procpid) {
#ifdef OS2
- { status=unlink(tp->name);
- if (status < 0)
- strcpy(tmpfile, tp->name);
- }
+ /* OS/2 (and dos) do not allow files that are currently
+ * open to be removed, so we cache it away for future
+ * removal.
+ * XXX should only do this if errno
+ * is Efile-still-open-can't-remove
+ * (but I don't know what that is...)
+ */
+ if (unlink(tp->name) < 0 && errno != ENOENT) {
+ t = (struct temp *) alloc(
+ sizeof(struct temp) + strlen(tp->name) + 1,
+ APERM);
+ memset(t, 0, sizeof(struct temp));
+ strcpy(t->name, tp->name);
+ t->next = delayed_remove;
+ delayed_remove = t;
+ }
#else /* OS2 */
unlink(tp->name);
#endif /* OS2 */
+ }
}
/* Returns true if name refers to a restricted shell */