On Fri, Jan 05 2018, "Theo de Raadt" <dera...@openbsd.org> wrote:
>> On Fri, 05 Jan 2018 08:20:03 +0100, Jeremie Courreges-Anglas wrote:
>> 
>> > I kinda take job control in my shell for granted.  Todd, would it make
>> > sense to just delete the #ifdefs?  I doubt that we'll want to ship a ksh
>> > with no job control in space-constrained installers.
>> 
>> I don't see any reason to support building ksh without job control.
>> I'd rather just delete the #ifdefs.
>
> Yep.

Cool, here's the diff.  unifdef gives me the same result on jobs.c,
except for the indentation change in two conditionals.  ok?


Index: c_ksh.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/c_ksh.c,v
retrieving revision 1.54
diff -u -p -r1.54 c_ksh.c
--- c_ksh.c     4 Jan 2018 19:06:16 -0000       1.54
+++ c_ksh.c     5 Jan 2018 15:07:03 -0000
@@ -1068,7 +1068,6 @@ c_jobs(char **wp)
        return rv;
 }
 
-#ifdef JOBS
 int
 c_fgbg(char **wp)
 {
@@ -1092,7 +1091,6 @@ c_fgbg(char **wp)
         */
        return (bg || Flag(FPOSIX)) ? 0 : rv;
 }
-#endif
 
 struct kill_info {
        int num_width;
@@ -1398,10 +1396,8 @@ const struct builtin kshbuiltins [] = {
        {"=typeset", c_typeset},
        {"+unalias", c_unalias},
        {"whence", c_whence},
-#ifdef JOBS
        {"+bg", c_fgbg},
        {"+fg", c_fgbg},
-#endif
 #ifdef EMACS
        {"bind", c_bind},
 #endif
Index: config.h
===================================================================
RCS file: /d/cvs/src/bin/ksh/config.h,v
retrieving revision 1.16
diff -u -p -r1.16 config.h
--- config.h    1 Aug 2017 14:30:05 -0000       1.16
+++ config.h    5 Jan 2018 15:07:03 -0000
@@ -11,9 +11,6 @@
 #ifndef CONFIG_H
 #define CONFIG_H
 
-/* Include job control? */
-#define JOBS 1
-
 /* Include brace-expansion? */
 #define BRACE_EXPAND 1
 
Index: jobs.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/jobs.c,v
retrieving revision 1.55
diff -u -p -r1.55 jobs.c
--- jobs.c      17 Mar 2016 23:33:23 -0000      1.55
+++ jobs.c      5 Jan 2018 15:07:03 -0000
@@ -86,10 +86,8 @@ struct job {
        Proc    *proc_list;     /* process list */
        Proc    *last_proc;     /* last process in list */
        Coproc_id coproc_id;    /* 0 or id of coprocess output pipe */
-#ifdef JOBS
        struct termios ttystate;/* saved tty state for stopped jobs */
        pid_t   saved_ttypgrp;  /* saved tty process group for stopped jobs */
-#endif /* JOBS */
 };
 
 /* Flags for j_waitj() */
@@ -127,13 +125,11 @@ static int                child_max;      /* CHILD_MAX */
 /* held_sigchld is set if sigchld occurs before a job is completely started */
 static volatile sig_atomic_t held_sigchld;
 
-#ifdef JOBS
 static struct shf      *shl_j;
 static int             ttypgrp_ok;     /* set if can use tty pgrps */
 static pid_t           restore_ttypgrp = -1;
 static pid_t           our_pgrp;
 static int const       tt_sigs[] = { SIGTSTP, SIGTTIN, SIGTTOU };
-#endif /* JOBS */
 
 static void            j_set_async(Job *);
 static void            j_startjob(Job *);
@@ -163,7 +159,6 @@ j_init(int mflagset)
        setsig(&sigtraps[SIGCHLD], j_sigchld,
            SS_RESTORE_ORIG|SS_FORCE|SS_SHTRAP);
 
-#ifdef JOBS
        if (!mflagset && Flag(FTALKING))
                Flag(FMONITOR) = 1;
 
@@ -189,10 +184,8 @@ j_init(int mflagset)
        /* j_change() calls tty_init() */
        if (Flag(FMONITOR))
                j_change();
-       else
-#endif /* JOBS */
-               if (Flag(FTALKING))
-                       tty_init(true);
+       else if (Flag(FTALKING))
+               tty_init(true);
 }
 
 /* suspend the shell */
@@ -267,21 +260,18 @@ j_exit(void)
                                kill_job(j, SIGHUP);
                        else
                                killpg(j->pgrp, SIGHUP);
-#ifdef JOBS
                        if (j->state == PSTOPPED) {
                                if (j->pgrp == 0)
                                        kill_job(j, SIGCONT);
                                else
                                        killpg(j->pgrp, SIGCONT);
                        }
-#endif /* JOBS */
                }
        }
        if (killed)
                sleep(1);
        j_notify();
 
-#ifdef JOBS
        if (kshpid == procpid && restore_ttypgrp >= 0) {
                /* Need to restore the tty pgrp to what it was when the
                 * shell started up, so that the process that started us
@@ -297,10 +287,8 @@ j_exit(void)
                Flag(FMONITOR) = 0;
                j_change();
        }
-#endif /* JOBS */
 }
 
-#ifdef JOBS
 /* turn job control on or off according to Flag(FMONITOR) */
 void
 j_change(void)
@@ -389,7 +377,6 @@ j_change(void)
                        tty_close();
        }
 }
-#endif /* JOBS */
 
 /* execute tree in child subprocess */
 int
@@ -472,7 +459,6 @@ exchild(struct op *t, int flags, volatil
        else
                p->pid = i;
 
-#ifdef JOBS
        /* job control set up */
        if (Flag(FMONITOR) && !(flags&XXCOM)) {
                int     dotty = 0;
@@ -493,7 +479,6 @@ exchild(struct op *t, int flags, volatil
                if (ttypgrp_ok && dotty && !(flags & XBGND))
                        tcsetpgrp(tty_fd, j->pgrp);
        }
-#endif /* JOBS */
 
        /* used to close pipe input fd */
        if (close_fd >= 0 && (((flags & XPCLOSE) && !ischild) ||
@@ -505,7 +490,6 @@ exchild(struct op *t, int flags, volatil
                        coproc_cleanup(false);
                sigprocmask(SIG_SETMASK, &omask, NULL);
                cleanup_parents_env();
-#ifdef JOBS
                /* If FMONITOR or FTALKING is set, these signals are ignored,
                 * if neither FMONITOR nor FTALKING are set, the signals have
                 * their inherited values.
@@ -515,7 +499,6 @@ exchild(struct op *t, int flags, volatil
                                setsig(&sigtraps[tt_sigs[i]], SIG_DFL,
                                    SS_RESTORE_DFL|SS_FORCE);
                }
-#endif /* JOBS */
                if (Flag(FBGNICE) && (flags & XBGND))
                        nice(4);
                if ((flags & XBGND) && !Flag(FMONITOR)) {
@@ -533,10 +516,8 @@ exchild(struct op *t, int flags, volatil
                }
                remove_job(j, "child"); /* in case of `jobs` command */
                nzombie = 0;
-#ifdef JOBS
                ttypgrp_ok = 0;
                Flag(FMONITOR) = 0;
-#endif /* JOBS */
                Flag(FTALKING) = 0;
                tty_close();
                cleartraps();
@@ -550,12 +531,10 @@ exchild(struct op *t, int flags, volatil
        /* Ensure next child gets a (slightly) different $RANDOM sequence */
        change_random();
        if (!(flags & XPIPEO)) {        /* last process in a job */
-#ifdef JOBS
                /* YYY: Is this needed? (see also YYY above)
                   if (Flag(FMONITOR) && !(flags&(XXCOM|XBGND)))
                        tcsetpgrp(tty_fd, j->pgrp);
                */
-#endif /* JOBS */
                j_startjob(j);
                if (flags & XCOPROC) {
                        j->coproc_id = coproc.id;
@@ -697,10 +676,8 @@ j_kill(const char *cp, int sig)
                        rv = 1;
                }
        } else {
-#ifdef JOBS
                if (j->state == PSTOPPED && (sig == SIGTERM || sig == SIGHUP))
                        (void) killpg(j->pgrp, SIGCONT);
-#endif /* JOBS */
                if (killpg(j->pgrp, sig) < 0) {
                        bi_errorf("%s: %s", cp, strerror(errno));
                        rv = 1;
@@ -712,7 +689,6 @@ j_kill(const char *cp, int sig)
        return rv;
 }
 
-#ifdef JOBS
 /* fg and bg built-ins: called only if Flag(FMONITOR) set */
 int
 j_resume(const char *cp, int bg)
@@ -759,7 +735,6 @@ j_resume(const char *cp, int bg)
        if (bg)
                j_set_async(j);
        else {
-# ifdef JOBS
                /* attach tty to job */
                if (j->state == PRUNNING) {
                        if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
@@ -779,7 +754,6 @@ j_resume(const char *cp, int bg)
                                return 1;
                        }
                }
-# endif /* JOBS */
                j->flags |= JF_FG;
                j->flags &= ~JF_KNOWN;
                if (j == async_job)
@@ -791,7 +765,6 @@ j_resume(const char *cp, int bg)
 
                if (!bg) {
                        j->flags &= ~JF_FG;
-# ifdef JOBS
                        if (ttypgrp_ok && (j->flags & JF_SAVEDTTY))
                                tcsetattr(tty_fd, TCSADRAIN, &tty_state);
                        if (ttypgrp_ok && tcsetpgrp(tty_fd, our_pgrp) < 0) {
@@ -800,7 +773,6 @@ j_resume(const char *cp, int bg)
                                    tty_fd, (int) our_pgrp,
                                    strerror(errno));
                        }
-# endif /* JOBS */
                }
                sigprocmask(SIG_SETMASK, &omask, NULL);
                bi_errorf("cannot continue job %s: %s",
@@ -808,17 +780,14 @@ j_resume(const char *cp, int bg)
                return 1;
        }
        if (!bg) {
-# ifdef JOBS
                if (ttypgrp_ok) {
                        j->flags &= ~(JF_SAVEDTTY | JF_SAVEDTTYPGRP);
                }
-# endif /* JOBS */
                rv = j_waitj(j, JW_NONE, "jw:resume");
        }
        sigprocmask(SIG_SETMASK, &omask, NULL);
        return rv;
 }
-#endif /* JOBS */
 
 /* are there any running or stopped jobs ? */
 int
@@ -828,10 +797,8 @@ j_stopped_running(void)
        int     which = 0;
 
        for (j = job_list; j != NULL; j = j->next) {
-#ifdef JOBS
                if (j->ppid == procpid && j->state == PSTOPPED)
                        which |= 1;
-#endif /* JOBS */
                if (Flag(FLOGIN) && !Flag(FNOHUP) && procpid == kshpid &&
                    j->ppid == procpid && j->state == PRUNNING)
                        which |= 2;
@@ -919,10 +886,8 @@ j_notify(void)
 
        sigprocmask(SIG_BLOCK, &sm_sigchld, &omask);
        for (j = job_list; j; j = j->next) {
-#ifdef JOBS
                if (Flag(FMONITOR) && (j->flags & JF_CHANGED))
                        j_print(j, JP_MEDIUM, shl_out);
-#endif /* JOBS */
                /* Remove job after doing reports so there aren't
                 * multiple +/- jobs.
                 */
@@ -1053,7 +1018,6 @@ j_waitj(Job *j,
                int     status;
 
                j->flags &= ~JF_FG;
-#ifdef JOBS
                if (Flag(FMONITOR) && ttypgrp_ok && j->pgrp) {
                        /*
                         * Save the tty's current pgrp so it can be restored
@@ -1080,7 +1044,6 @@ j_waitj(Job *j,
                                tcgetattr(tty_fd, &j->ttystate);
                        }
                }
-#endif /* JOBS */
                if (tty_fd >= 0) {
                        /* Only restore tty settings if job was originally
                         * started in the foreground.  Problems can be
@@ -1110,7 +1073,6 @@ j_waitj(Job *j,
                                        j->flags &= ~JF_USETTYMODE;
                        }
                }
-#ifdef JOBS
                /* If it looks like user hit ^C to kill a job, pretend we got
                 * one too to break out of for loops, etc.  (at&t ksh does this
                 * even when not monitoring, but this doesn't make sense since
@@ -1121,7 +1083,6 @@ j_waitj(Job *j,
                    WIFSIGNALED(status) &&
                    (sigtraps[WTERMSIG(status)].flags & TF_TTY_INTR))
                        trapsig(WTERMSIG(status));
-#endif /* JOBS */
        }
 
        j_usrtime = j->usrtime;
@@ -1195,12 +1156,9 @@ found:
                timersub(&j->systime, &ru0.ru_stime, &j->systime);
                ru0 = ru1;
                p->status = status;
-#ifdef JOBS
                if (WIFSTOPPED(status))
                        p->state = PSTOPPED;
-               else
-#endif /* JOBS */
-               if (WIFSIGNALED(status))
+               else if (WIFSIGNALED(status))
                        p->state = PSIGNALLED;
                else
                        p->state = PEXITED;
@@ -1278,7 +1236,6 @@ check_job(Job *j)
        }
 
        j->flags |= JF_CHANGED;
-#ifdef JOBS
        if (Flag(FMONITOR) && !(j->flags & JF_XXCOM)) {
                /* Only put stopped jobs at the front to avoid confusing
                 * the user (don't want finished jobs effecting %+ or %-)
@@ -1307,7 +1264,6 @@ check_job(Job *j)
                                remove_job(j, "notify");
                }
        }
-#endif /* JOBS */
        if (!Flag(FMONITOR) && !(j->flags & (JF_WAITING|JF_FG)) &&
            j->state != PSTOPPED) {
                if (j == async_job || (j->flags & JF_KNOWN)) {
Index: main.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/main.c,v
retrieving revision 1.85
diff -u -p -r1.85 main.c
--- main.c      12 Dec 2017 00:18:58 -0000      1.85
+++ main.c      5 Jan 2018 15:07:03 -0000
@@ -91,9 +91,7 @@ static const char *initcoms [] = {
         /* Standard ksh aliases */
          "hash=alias -t",      /* not "alias -t --": hash -r needs to work */
          "type=whence -v",
-#ifdef JOBS
          "stop=kill -STOP",
-#endif
          "autoload=typeset -fu",
          "functions=typeset -f",
 #ifdef HISTORY
Index: misc.c
===================================================================
RCS file: /d/cvs/src/bin/ksh/misc.c,v
retrieving revision 1.63
diff -u -p -r1.63 misc.c
--- misc.c      4 Jan 2018 19:06:16 -0000       1.63
+++ misc.c      5 Jan 2018 15:07:03 -0000
@@ -139,19 +139,13 @@ const struct option sh_options[] = {
        { "keyword",    'k',            OF_ANY },
        { "login",      'l',        OF_CMDLINE },
        { "markdirs",   'X',            OF_ANY },
-#ifdef JOBS
        { "monitor",    'm',            OF_ANY },
-#else /* JOBS */
-       { NULL, 'm',                 0 }, /* so FMONITOR not ifdef'd */
-#endif /* JOBS */
        { "noclobber",  'C',            OF_ANY },
        { "noexec",     'n',            OF_ANY },
        { "noglob",     'f',            OF_ANY },
        { "nohup",        0,            OF_ANY },
        { "nolog",        0,            OF_ANY }, /* no effect */
-#ifdef JOBS
        { "notify",     'b',            OF_ANY },
-#endif /* JOBS */
        { "nounset",    'u',            OF_ANY },
        { "physical",     0,            OF_ANY }, /* non-standard */
        { "posix",        0,            OF_ANY }, /* non-standard */
@@ -273,12 +267,10 @@ change_flag(enum sh_flag f,
 
        oldval = Flag(f);
        Flag(f) = newval;
-#ifdef JOBS
        if (f == FMONITOR) {
                if (what != OF_CMDLINE && newval != oldval)
                        j_change();
        } else
-#endif /* JOBS */
 #ifdef EDIT
        if (0
 # ifdef VI
Index: sh.h
===================================================================
RCS file: /d/cvs/src/bin/ksh/sh.h,v
retrieving revision 1.66
diff -u -p -r1.66 sh.h
--- sh.h        27 Dec 2017 13:02:57 -0000      1.66
+++ sh.h        5 Jan 2018 15:07:03 -0000
@@ -155,9 +155,7 @@ enum sh_flag {
        FNOGLOB,        /* -f: don't do file globbing */
        FNOHUP,         /* -H: don't kill running jobs when login shell exits */
        FNOLOG,         /* don't save functions in history (ignored) */
-#ifdef JOBS
        FNOTIFY,        /* -b: asynchronous job completion notification */
-#endif
        FNOUNSET,       /* -u: using an unset var is an error */
        FPHYSICAL,      /* -o physical: don't do logical cd's/pwd's */
        FPOSIX,         /* -o posix: be posixly correct */


-- 
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE

Reply via email to