OSDN Git Service

Upgrade to mksh R56b.
[android-x86/external-mksh.git] / src / jobs.c
index 0366004..4df98b7 100644 (file)
@@ -23,7 +23,7 @@
 
 #include "sh.h"
 
-__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.121 2016/07/25 00:04:44 tg Exp $");
+__RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.124 2017/08/08 14:30:10 tg Exp $");
 
 #if HAVE_KILLPG
 #define mksh_killpg            killpg
@@ -39,14 +39,27 @@ __RCSID("$MirOS: src/bin/mksh/jobs.c,v 1.121 2016/07/25 00:04:44 tg Exp $");
 #define PSTOPPED       3
 
 typedef struct proc Proc;
+/* to take alignment into consideration */
+struct proc_dummy {
+       Proc *next;
+       pid_t pid;
+       int state;
+       int status;
+       char command[128];
+};
+/* real structure */
 struct proc {
-       Proc *next;             /* next process in pipeline (if any) */
-       pid_t pid;              /* process id */
+       /* next process in pipeline (if any) */
+       Proc *next;
+       /* process id of this Unix process in the job */
+       pid_t pid;
+       /* one of the four P… above */
        int state;
-       int status;             /* wait status */
+       /* wait status */
+       int status;
        /* process command string from vistree */
-       char command[256 - (ALLOC_OVERHEAD + sizeof(Proc *) +
-           sizeof(pid_t) + 2 * sizeof(int))];
+       char command[256 - (ALLOC_OVERHEAD +
+           offsetof(struct proc_dummy, command[0]))];
 };
 
 /* Notify/print flag - j_print() argument */
@@ -1009,8 +1022,14 @@ j_notify(void)
        }
        for (j = job_list; j; j = tmp) {
                tmp = j->next;
-               if (j->flags & JF_REMOVE)
-                       remove_job(j, "notify");
+               if (j->flags & JF_REMOVE) {
+                       if (j == async_job || (j->flags & JF_KNOWN)) {
+                               j->flags = (j->flags & ~JF_REMOVE) | JF_ZOMBIE;
+                               j->job = -1;
+                               nzombie++;
+                       } else
+                               remove_job(j, "notify");
+               }
        }
        shf_flush(shl_out);
 #ifndef MKSH_NOPROSPECTOFWORK
@@ -1651,7 +1670,7 @@ j_lookup(const char *cp, int *ecodep)
        size_t len;
        int job = 0;
 
-       if (ksh_isdigit(*cp) && getn(cp, &job)) {
+       if (ctype(*cp, C_DIGIT) && getn(cp, &job)) {
                /* Look for last_proc->pid (what $! returns) first... */
                for (j = job_list; j != NULL; j = j->next)
                        if (j->last_proc && j->last_proc->pid == job)