From cbc4c398d44760649fc29143cd80d3d2b15442ed Mon Sep 17 00:00:00 2001 From: jilles Date: Sun, 20 Jan 2013 12:44:50 +0000 Subject: sh: Remove mkinit's initialization routine. Instead, call the only init function left directly from main(). --- bin/sh/TOUR | 4 ---- bin/sh/init.h | 1 - bin/sh/main.c | 2 +- bin/sh/mkinit.c | 8 +------- bin/sh/var.c | 32 ++++++++++---------------------- 5 files changed, 12 insertions(+), 35 deletions(-) diff --git a/bin/sh/TOUR b/bin/sh/TOUR index 4b61bdf..13438b5 100644 --- a/bin/sh/TOUR +++ b/bin/sh/TOUR @@ -33,10 +33,6 @@ programs is: There are undoubtedly too many of these. Mkinit searches all the C source files for entries looking like: - INIT { - x = 1; /* executed during initialization */ - } - RESET { x = 2; /* executed when the shell does a longjmp back to the main command loop */ diff --git a/bin/sh/init.h b/bin/sh/init.h index dd0c4a8..384bb69 100644 --- a/bin/sh/init.h +++ b/bin/sh/init.h @@ -33,5 +33,4 @@ * $FreeBSD$ */ -void init(void); void reset(void); diff --git a/bin/sh/main.c b/bin/sh/main.c index b93f04e..66e1335 100644 --- a/bin/sh/main.c +++ b/bin/sh/main.c @@ -139,7 +139,7 @@ main(int argc, char *argv[]) #endif rootpid = getpid(); rootshell = 1; - init(); + initvar(); setstackmark(&smark); setstackmark(&smark2); procargs(argc, argv); diff --git a/bin/sh/mkinit.c b/bin/sh/mkinit.c index 1d1d93e..d73e0e2 100644 --- a/bin/sh/mkinit.c +++ b/bin/sh/mkinit.c @@ -101,7 +101,7 @@ struct block { */ struct event { - const char *name; /* name of event (e.g. INIT) */ + const char *name; /* name of event (e.g. RESET) */ const char *routine; /* name of routine called on event */ const char *comment; /* comment describing routine */ struct text code; /* code for handling event */ @@ -114,11 +114,6 @@ char writer[] = "\ */\n\ \n"; -char init[] = "\ -/*\n\ - * Initialization code.\n\ - */\n"; - char reset[] = "\ /*\n\ * This routine is called when an error or an interrupt occurs in an\n\ @@ -127,7 +122,6 @@ char reset[] = "\ struct event event[] = { - { "INIT", "init", init, { NULL, 0, NULL, NULL } }, { "RESET", "reset", reset, { NULL, 0, NULL, NULL } }, { NULL, NULL, NULL, { NULL, 0, NULL, NULL } } }; diff --git a/bin/sh/var.c b/bin/sh/var.c index 48a0dc5..3f29a48 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -146,29 +146,11 @@ static int varequal(const char *, const char *); static struct var *find_var(const char *, struct var ***, int *); static int localevar(const char *); -/* - * Initialize the variable symbol tables and import the environment. - */ - -#ifdef mkinit -INCLUDE "var.h" -MKINIT char **environ; -INIT { - char **envp; - - initvar(); - for (envp = environ ; *envp ; envp++) { - if (strchr(*envp, '=')) { - setvareq(*envp, VEXPORT|VTEXTFIXED); - } - } -} -#endif - +extern char **environ; /* - * This routine initializes the builtin variables. It is called when the - * shell is initialized. + * This routine initializes the builtin variables and imports the environment. + * It is called when the shell is initialized. */ void @@ -178,6 +160,7 @@ initvar(void) const struct varinit *ip; struct var *vp; struct var **vpp; + char **envp; for (ip = varinit ; (vp = ip->var) != NULL ; ip++) { if (find_var(ip->text, &vpp, &vp->name_len) != NULL) @@ -201,6 +184,11 @@ initvar(void) fmtstr(ppid, sizeof(ppid), "%d", (int)getppid()); setvarsafe("PPID", ppid, 0); } + for (envp = environ ; *envp ; envp++) { + if (strchr(*envp, '=')) { + setvareq(*envp, VEXPORT|VTEXTFIXED); + } + } } /* @@ -356,7 +344,7 @@ setvareq(char *s, int flags) * a regular variable function callback, but why bother? * * Note: this assumes iflag is not set to 1 initially. - * As part of init(), this is called before arguments + * As part of initvar(), this is called before arguments * are looked at. */ if ((vp == &vmpath || (vp == &vmail && ! mpathset())) && -- cgit v1.1