diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2004-12-18 20:55:53 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2004-12-18 20:55:53 +0000 |
commit | 62c19679be069ef2770e79fb05fdbc3a9749c612 (patch) | |
tree | bbdc0d9152836bab35763618d41fe24d089c34d0 /bin/ksh/main.c | |
parent | 220f5907de5bdc773b687af762aa5d835e26025c (diff) |
Remove unused OS dependent #ifdef blocks, #defines and macro abstraction.
First step in making the ksh code easier to read. From Matthias Kilian
Diffstat (limited to 'bin/ksh/main.c')
-rw-r--r-- | bin/ksh/main.c | 114 |
1 files changed, 11 insertions, 103 deletions
diff --git a/bin/ksh/main.c b/bin/ksh/main.c index 8c7b8b95469..361d40478c7 100644 --- a/bin/ksh/main.c +++ b/bin/ksh/main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: main.c,v 1.28 2004/08/23 14:56:32 millert Exp $ */ +/* $OpenBSD: main.c,v 1.29 2004/12/18 20:55:52 millert Exp $ */ /* * startup, main loop, environments and error handling @@ -7,8 +7,7 @@ #define EXTERN /* define EXTERNs in sh.h */ #include "sh.h" -#include "ksh_stat.h" -#include "ksh_time.h" +#include <sys/stat.h> extern char **environ; @@ -16,9 +15,9 @@ 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(void); +static void remove_temps(struct temp *tp); +static int is_restricted(char *name); /* * shell initialization @@ -66,9 +65,6 @@ static const char *const initcoms [] = { #ifdef KSH /* Aliases that are builtin commands in at&t */ "login=exec login", -#ifndef __OpenBSD__ - "newgrp=exec newgrp", -#endif /* __OpenBSD__ */ #endif /* KSH */ NULL, /* this is what at&t ksh seems to track, with the addition of emacs */ @@ -76,9 +72,6 @@ static const char *const initcoms [] = { "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 }; @@ -94,16 +87,6 @@ main(int argc, char *argv[]) struct env env; pid_t ppid; -#ifdef MEM_DEBUG - chmem_set_defaults("ct", 1); - /* chmem_push("+c", 1); */ -#endif /* MEM_DEBUG */ - -#ifdef OS2 - setmode (0, O_BINARY); - setmode (1, O_TEXT); -#endif - /* make sure argv[] is sane */ if (!*argv) { static const char *empty_argv[] = { @@ -154,8 +137,7 @@ main(int argc, char *argv[]) init_histvec(); - def_path = DEFAULT__PATH; -#if defined(HAVE_CONFSTR) && defined(_CS_PATH) + def_path = _PATH_DEFPATH; { size_t len = confstr(_CS_PATH, (char *) 0, 0); char *new; @@ -165,7 +147,6 @@ main(int argc, char *argv[]) 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). @@ -237,7 +218,7 @@ main(int argc, char *argv[]) char *pwdx = pwd; /* Try to use existing $PWD if it is valid */ - if (!ISABSPATH(pwd) + if (pwd[0] != '/' || 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) @@ -254,9 +235,6 @@ main(int argc, char *argv[]) } ppid = getppid(); setint(global("PPID"), (long) ppid); -#if defined(KSH) && !defined(__OpenBSD__) - setint(global("RANDOM"), (long) (time((time_t *)0) * kshpid * ppid)); -#endif /* KSH */ /* setstr can't fail here */ setstr(global(version_param), ksh_version, KSH_RETURN_ERROR); @@ -299,18 +277,7 @@ main(int argc, char *argv[]) kshname = argv[argi++]; } else if (argi < argc && !Flag(FSTDIN)) { s = pushs(SFILE, ATEMP); -#ifdef OS2 - /* a bug in os2 extproc shell processing doesn't - * pass full pathnames so we have to search for it. - * This changes the behavior of 'ksh arg' to search - * the users search path but it can't be helped. - */ - s->file = search(argv[argi++], path, R_OK, (int *) 0); - if (!s->file || !*s->file) - s->file = argv[argi - 1]; -#else s->file = argv[argi++]; -#endif /* OS2 */ s->u.shf = shf_open(s->file, O_RDONLY, 0, SHF_MAPHI|SHF_CLEXEC); if (s->u.shf == NULL) { exstat = 127; /* POSIX */ @@ -370,27 +337,10 @@ main(int argc, char *argv[]) warningf(FALSE, "Cannot determine current working directory"); if (Flag(FLOGIN)) { -#ifdef OS2 - char *profile; - - /* Try to find a profile - first see if $INIT has a value, - * then try /etc/profile.ksh, then c:/usr/etc/profile.ksh. - */ - if (!Flag(FPRIVILEGED) - && strcmp(profile = substitute("$INIT/profile.ksh", 0), - "/profile.ksh")) - include(profile, 0, (char **) 0, 1); - else if (include("/etc/profile.ksh", 0, (char **) 0, 1) < 0) - include("c:/usr/etc/profile.ksh", 0, (char **) 0, 1); - if (!Flag(FPRIVILEGED)) - include(substitute("$HOME/profile.ksh", 0), 0, - (char **) 0, 1); -#else /* OS2 */ include(KSH_SYSTEM_PROFILE, 0, (char **) 0, 1); if (!Flag(FPRIVILEGED)) include(substitute("$HOME/.profile", 0), 0, (char **) 0, 1); -#endif /* OS2 */ } if (Flag(FPRIVILEGED)) @@ -414,11 +364,6 @@ main(int argc, char *argv[]) env_file = substitute(env_file, DOTILDE); if (*env_file != '\0') include(env_file, 0, (char **) 0, 1); -#ifdef OS2 - else if (Flag(FTALKING)) - include(substitute("$HOME/kshrc.ksh", 0), 0, - (char **) 0, 1); -#endif /* OS2 */ } if (is_restricted(argv[0]) || is_restricted(str_val(global("SHELL")))) @@ -473,7 +418,7 @@ include(name, argc, argv, intr_ok) old_argc = 0; } newenv(E_INCL); - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { if (s) /* Do this before quitenv(), which frees the memory */ shf_close(s->u.shf); @@ -549,7 +494,7 @@ shell(s, toplevel) newenv(E_PARSE); if (interactive) really_exit = 0; - i = ksh_sigsetjmp(e->jbuf, 0); + i = sigsetjmp(e->jbuf, 0); if (i) { switch (i) { case LINTR: /* we get here if SIGINT not caught or ignored */ @@ -666,7 +611,7 @@ unwind(i) case E_INCL: case E_LOOP: case E_ERRH: - ksh_siglongjmp(e->jbuf, i); + siglongjmp(e->jbuf, i); /*NOTREACHED*/ case E_NONE: @@ -738,9 +683,6 @@ quitenv() kill(0, sig); } } -#ifdef MEM_DEBUG - chmem_allfree(); -#endif /* MEM_DEBUG */ } exit(exstat); } @@ -797,44 +739,10 @@ static void remove_temps(tp) struct temp *tp; { -#ifdef OS2 - 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) { -#ifdef OS2 - /* 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)); - t->name = (char *) &t[1]; - strlcpy(t->name, tp->name, strlen(tp->name) + 1); - t->next = delayed_remove; - delayed_remove = t; - } -#else /* OS2 */ unlink(tp->name); -#endif /* OS2 */ } } @@ -845,7 +753,7 @@ is_restricted(name) { char *p; - if ((p = ksh_strrchr_dirsep(name))) + if ((p = strrchr(name, '/'))) name = p; /* accepts rsh, rksh, rpdksh, pdrksh, etc. */ return (p = strchr(name, 'r')) && strstr(p, "sh"); |