/*-
* Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011,
- * 2012, 2013, 2014, 2015, 2016
+ * 2012, 2013, 2014, 2015, 2016, 2018
* mirabilos <m@mirbsd.org>
*
* Provided that these terms and disclaimer and all copyright notices
#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.127 2018/07/15 16:23:10 tg Exp $");
#if HAVE_KILLPG
#define mksh_killpg killpg
#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 */
void
j_init(void)
{
-#ifndef MKSH_UNEMPLOYED
- bool mflagset = Flag(FMONITOR) != 127;
-
- Flag(FMONITOR) = 0;
-#endif
-
#ifndef MKSH_NOPROSPECTOFWORK
(void)sigemptyset(&sm_default);
sigprocmask(SIG_SETMASK, &sm_default, NULL);
#endif
#ifndef MKSH_UNEMPLOYED
- if (!mflagset && Flag(FTALKING))
- Flag(FMONITOR) = 1;
+ if (Flag(FMONITOR) == 127)
+ Flag(FMONITOR) = Flag(FTALKING);
/*
* shl_j is used to do asynchronous notification (used in
}
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
Proc *p;
int state;
int status;
+#ifdef WCOREDUMP
bool coredumped;
+#endif
char jobchar = ' ';
char buf[64];
const char *filler;
jobchar = '-';
for (p = j->proc_list; p != NULL;) {
+#ifdef WCOREDUMP
coredumped = false;
+#endif
switch (p->state) {
case PRUNNING:
memcpy(buf, "Running", 8);
* kludge for not reporting 'normal termination
* signals' (i.e. SIGINT, SIGPIPE)
*/
- if (how == JP_SHORT && !coredumped &&
+ if (how == JP_SHORT &&
+#ifdef WCOREDUMP
+ !coredumped &&
+#endif
(termsig == SIGINT || termsig == SIGPIPE)) {
buf[0] = '\0';
} else
if (how == JP_SHORT) {
if (buf[0]) {
output = 1;
+#ifdef WCOREDUMP
shf_fprintf(shf, "%s%s ",
buf, coredumped ? " (core dumped)" : null);
+#else
+ shf_puts(buf, shf);
+ shf_putchar(' ', shf);
+#endif
}
} else {
output = 1;
shf_fprintf(shf, "%-20s %s%s%s", buf, p->command,
p->next ? "|" : null,
- coredumped ? " (core dumped)" : null);
+#ifdef WCOREDUMP
+ coredumped ? " (core dumped)" :
+#endif
+ null);
}
state = p->state;
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)
break;
case 2:
#ifndef MKSH_DISABLE_TTY_WARNING
- warningf(false, Tf_sD_s_s, Tcant_find, Ttty_fd,
+ warningf(false, Tf_s_sD_s, Tcant_find, Ttty_fd,
cstrerror(errno));
#endif
break;