Esempio n. 1
0
int
fgcmd(int argc, char **argv)
{
	struct job *jp;
	int i;
	int status;

	nextopt("");
	jp = getjob(*argptr, 0);
	if (jp->jobctl == 0)
		error("job not created under job control");
	out1fmt("%s", jp->ps[0].cmd);
	for (i = 1; i < jp->nprocs; i++)
		out1fmt(" | %s", jp->ps[i].cmd );
	out1c('\n');
	flushall();

	for (i = 0; i < jp->nprocs; i++)
	    if (tcsetpgrp(ttyfd, jp->ps[i].pid) != -1)
		    break;

	if (i >= jp->nprocs) {
		error("Cannot set tty process group (%s) at %d",
		    strerror(errno), __LINE__);
	}
	restartjob(jp);
	INTOFF;
	status = waitforjob(jp);
	INTON;
	return status;
}
Esempio n. 2
0
static void
printalias(const struct alias *a)
{
	out1fmt("%s=", a->name);
	out1qstr(a->val);
	out1c('\n');
}
Esempio n. 3
0
File: var.c Progetto: dezelin/kBuild
int
showvars(shinstance *psh, const char *name, int flag, int show_value)
{
    struct var **vpp;
    struct var *vp;
    const char *p;

    static struct var **list;	/* static in case we are interrupted */
    static int list_len;
    int count = 0;

    if (!list) {
        list_len = 32;
        list = ckmalloc(psh, list_len * sizeof(*list));
    }

    for (vpp = psh->vartab ; vpp < psh->vartab + VTABSIZE ; vpp++) {
        for (vp = *vpp ; vp ; vp = vp->next) {
            if (flag && !(vp->flags & flag))
                continue;
            if (vp->flags & VUNSET && !(show_value & 2))
                continue;
            if (count >= list_len) {
                list = ckrealloc(psh, list,
                                 (list_len << 1) * sizeof(*list));
                list_len <<= 1;
            }
            list[count++] = vp;
        }
    }

    qsort(list, count, sizeof(*list), sort_var);

    for (vpp = list; count--; vpp++) {
        vp = *vpp;
        if (name)
            out1fmt(psh, "%s ", name);
        for (p = vp->text ; *p != '=' ; p++)
            out1c(psh, *p);
        if (!(vp->flags & VUNSET) && show_value) {
            out1fmt(psh, "=");
            print_quoted(psh, ++p);
        }
        out1c(psh, '\n');
    }
    return 0;
}
Esempio n. 4
0
int
wordexpcmd(int argc, char **argv)
{
	size_t len;
	int i;

	out1fmt("%d", argc - 1);
	out1c('\0');
	for (i = 1, len = 0; i < argc; i++)
		len += strlen(argv[i]);
	out1fmt("%zu", len);
	out1c('\0');
	for (i = 1; i < argc; i++) {
		out1str(argv[i]);
		out1c('\0');
	}
	return (0);
}
Esempio n. 5
0
int
wordexpcmd(shinstance *psh, int argc, char **argv)
{
	size_t len;
	int i;

	out1fmt(psh, "%d", argc - 1);
	out1c(psh, '\0');
	for (i = 1, len = 0; i < argc; i++)
		len += strlen(argv[i]);
	out1fmt(psh, "%zd", len);
	out1c(psh, '\0');
	for (i = 1; i < argc; i++) {
		out1str(psh, argv[i]);
		out1c(psh, '\0');
	}
	return (0);
}
Esempio n. 6
0
static void
printjobcmd(struct job *jp)
{
	struct procstat *ps;
	int i;

	for (ps = jp->ps, i = jp->nprocs ; --i >= 0 ; ps++) {
		out1str(ps->cmd);
		if (i > 0)
			out1str(" | ");
	}
	out1c('\n');
}
Esempio n. 7
0
File: jobs.c Progetto: 0xffea/MINIX3
int
jobidcmd(int argc __unused, char **argv)
{
	struct job *jp;
	int i;

	jp = getjob(argv[1]);
	for (i = 0 ; i < jp->nprocs ; ) {
		out1fmt("%d", (int)jp->ps[i].pid);
		out1c(++i < jp->nprocs? ' ' : '\n');
	}
	return 0;
}
Esempio n. 8
0
static void
printalias(const struct alias *a)
{
	char *p;

	out1fmt("%s=", a->name);
	/* Don't print the space added above. */
	p = a->val + strlen(a->val) - 1;
	*p = '\0';
	out1qstr(a->val);
	*p = ' ';
	out1c('\n');
}
Esempio n. 9
0
/*
 * TODO - sort output
 */
int
aliascmd(int argc, char **argv)
{
	char *n, *v;
	int ret = 0;
	struct alias *ap;

	if (argc == 1) {
		int i;

		for (i = 0; i < ATABSIZE; i++)
			for (ap = atab[i]; ap; ap = ap->next) {
				if (*ap->name != '\0') {
					out1fmt("alias %s=", ap->name);
					print_quoted(ap->val);
					out1c('\n');
				}
			}
		return (0);
	}
	while ((n = *++argv) != NULL) {
		if ((v = strchr(n+1, '=')) == NULL) { /* n+1: funny ksh stuff */
			if ((ap = lookupalias(n, 0)) == NULL) {
				outfmt(out2, "alias: %s not found\n", n);
				ret = 1;
			} else {
				out1fmt("alias %s=", n);
				print_quoted(ap->val);
				out1c('\n');
			}
		} else {
			*v++ = '\0';
			setalias(n, v);
		}
	}

	return (ret);
}
Esempio n. 10
0
int
jobidcmd(int argc, char **argv)
{
	struct job *jp;
	int i;

	nextopt("");
	jp = getjob(*argptr, 0);
	for (i = 0 ; i < jp->nprocs ; ) {
		out1fmt("%ld", (long)jp->ps[i].pid);
		out1c(++i < jp->nprocs ? ' ' : '\n');
	}
	return 0;
}
Esempio n. 11
0
/*
 * Print a list of valid signal names
 */
static void
printsignals(void)
{
	int n;

	out1str("EXIT ");

	for (n = 1; n < NSIG; n++) {
		out1fmt("%s", sys_signame[n]);
		if ((n == NSIG/2) ||  n == (NSIG - 1))
			out1str("\n");
		else
			out1c(' ');
	}
}
Esempio n. 12
0
/*
 * Print a list of valid signal names
 */
static void
printsignals(void)
{
	int n;

	out1str("EXIT ");
#ifndef HAVE_SYS_SIGNAME
	init_sys_signame();
#endif

	for (n = 1; n < NSIG; n++) {
		out1fmt("%s", sys_signame[n]);
		if ((n == NSIG/2) ||  n == (NSIG - 1))
			out1str("\n");
		else
			out1c(' ');
	}
}
Esempio n. 13
0
File: jobs.c Progetto: 0xffea/MINIX3
int
bgcmd(int argc, char **argv)
{
	char s[64];
	struct job *jp;

	do {
		jp = getjob(*++argv);
		if (jp->jobctl == 0)
			error("job not created under job control");
		if (jp->state == JOBDONE)
			continue;
		restartjob(jp);
		jp->foreground = 0;
		fmtstr(s, 64, "[%td] ", jp - jobtab + 1);
		out1str(s);
		out1str(jp->ps[0].cmd);
		out1c('\n');
	} while (--argc > 1);
	return 0;
}
Esempio n. 14
0
int
bgcmd(int argc, char **argv)
{
	struct job *jp;
	int i;

	nextopt("");
	do {
		jp = getjob(*argptr, 0);
		if (jp->jobctl == 0)
			error("job not created under job control");
		set_curjob(jp, 1);
		out1fmt("[%ld] %s", (long)(jp - jobtab + 1), jp->ps[0].cmd);
		for (i = 1; i < jp->nprocs; i++)
			out1fmt(" | %s", jp->ps[i].cmd );
		out1c('\n');
		flushall();
		restartjob(jp);
	} while (*argptr && *++argptr);
	return 0;
}
Esempio n. 15
0
File: jobs.c Progetto: 0xffea/MINIX3
int
fgcmd(int argc __unused, char **argv)
{
	struct job *jp;
	pid_t pgrp;
	int status;

	jp = getjob(argv[1]);
	if (jp->jobctl == 0)
		error("job not created under job control");
	out1str(jp->ps[0].cmd);
	out1c('\n');
	flushout(&output);
	pgrp = jp->ps[0].pid;
	tcsetpgrp(ttyfd, pgrp);
	restartjob(jp);
	jp->foreground = 1;
	INTOFF;
	status = waitforjob(jp, (int *)NULL);
	INTON;
	return status;
}
Esempio n. 16
0
STATIC void
minus_o(char *name, int val)
{
	int doneset, i;

	if (name == NULL) {
		if (val) {
			/* "Pretty" output. */
			out1str("Current option settings\n");
			for (i = 0; i < NOPTS; i++)
				out1fmt("%-16s%s\n", optlist[i].name,
					optlist[i].val ? "on" : "off");
		} else {
			/* Output suitable for re-input to shell. */
			for (doneset = i = 0; i < NOPTS; i++)
				if (optlist[i].val) {
					if (!doneset) {
						out1str("set");
						doneset = 1;
					}
					out1fmt(" -o %s", optlist[i].name);
				}
			if (doneset)
				out1c('\n');
		}
	} else {
		for (i = 0; i < NOPTS; i++)
			if (equal(name, optlist[i].name)) {
				if (!val && privileged && equal(name, "privileged")) {
					(void) setuid(getuid());
					(void) setgid(getgid());
				}
				setoption(optlist[i].letter, val);
				return;
			}
		error("Illegal option -o %s", name);
	}
}
Esempio n. 17
0
/*
 * Print a list of valid signal names.
 */
static void
printsignals(void)
{
	int n, outlen;

	outlen = 0;
	for (n = 1; n < sys_nsig; n++) {
		if (sys_signame[n]) {
			out1fmt("%s", sys_signame[n]);
			outlen += strlen(sys_signame[n]);
		} else {
			out1fmt("%d", n);
			outlen += 3;	/* good enough */
		}
		++outlen;
		if (outlen > 71 || n == sys_nsig - 1) {
			out1str("\n");
			outlen = 0;
		} else {
			out1c(' ');
		}
	}
}
Esempio n. 18
0
/*
 * Print a list of valid signal names.
 */
static void
printsignals(void)
{
	int n, outlen;

	outlen = 0;
	for (n = 1; n < _NSIG; n++) {
		if (strsigname(n)) {
			out1fmt("%s", strsigname(n));
			outlen += strlen(strsigname(n));
		} else {
			out1fmt("%d", n);
			outlen += 3;	/* good enough */
		}
		++outlen;
		if (outlen > 70 || n == _NSIG - 1) {
			out1str("\n");
			outlen = 0;
		} else {
			out1c(' ');
		}
	}
}
Esempio n. 19
0
File: jobs.c Progetto: 0xffea/MINIX3
STATIC void
showjob(struct job *jp, pid_t pid, int sformat, int lformat)
{
	char s[64];
	struct procstat *ps;
	struct job *j;
	int col, curr, i, jobno, prev, procno;
	char c;

	procno = jp->nprocs;
	jobno = jp - jobtab + 1;
	curr = prev = 0;
#if JOBS
	if ((j = getcurjob(NULL)) != NULL) {
		curr = j - jobtab + 1;
		if ((j = getcurjob(j)) != NULL)
			prev = j - jobtab + 1;
	}
#endif
	for (ps = jp->ps ; ; ps++) {	/* for each process */
		if (sformat) {
			out1fmt("%d\n", (int)ps->pid);
			goto skip;
		}
		if (!lformat && ps != jp->ps && pid == 0)
			goto skip;
		if (pid != 0 && pid != ps->pid)
			goto skip;
		if (jobno == curr && ps == jp->ps)
			c = '+';
		else if (jobno == prev && ps == jp->ps)
			c = '-';
		else
			c = ' ';
		if (ps == jp->ps)
			fmtstr(s, 64, "[%d] %c ", jobno, c);
		else
			fmtstr(s, 64, "    %c ", c);
		out1str(s);
		col = strlen(s);
		if (lformat) {
			fmtstr(s, 64, "%d ", (int)ps->pid);
			out1str(s);
			col += strlen(s);
		}
		s[0] = '\0';
		if (ps != jp->ps) {
			*s = '\0';
		} else if (ps->status == -1) {
			strcpy(s, "Running");
		} else if (WIFEXITED(ps->status)) {
			if (WEXITSTATUS(ps->status) == 0)
				strcpy(s, "Done");
			else
				fmtstr(s, 64, "Done (%d)",
				    WEXITSTATUS(ps->status));
		} else {
#if JOBS
			if (WIFSTOPPED(ps->status)) 
				i = WSTOPSIG(ps->status);
			else
#endif
				i = WTERMSIG(ps->status);
			if ((i & 0x7F) < _NSIG && strsiglist(i & 0x7F))
				scopy(strsiglist(i & 0x7F), s);
			else
				fmtstr(s, 64, "Signal %d", i & 0x7F);
			if (WCOREDUMP(ps->status))
				strcat(s, " (core dumped)");
		}
		out1str(s);
		col += strlen(s);
		do {
			out1c(' ');
			col++;
		} while (col < 30);
		out1str(ps->cmd);
		out1c('\n');
skip:		if (--procno <= 0)
			break;
	}
}
Esempio n. 20
0
static void
showjob(struct job *jp, int mode)
{
	char s[64];
	char statestr[64];
	struct procstat *ps;
	struct job *j;
	int col, curr, i, jobno, prev, procno;
	char c;

	procno = (mode == SHOWJOBS_PGIDS) ? 1 : jp->nprocs;
	jobno = jp - jobtab + 1;
	curr = prev = 0;
#if JOBS
	if ((j = getcurjob(NULL)) != NULL) {
		curr = j - jobtab + 1;
		if ((j = getcurjob(j)) != NULL)
			prev = j - jobtab + 1;
	}
#endif
	ps = jp->ps + jp->nprocs - 1;
	if (jp->state == 0) {
		strcpy(statestr, "Running");
#if JOBS
	} else if (jp->state == JOBSTOPPED) {
		while (!WIFSTOPPED(ps->status) && ps > jp->ps)
			ps--;
		if (WIFSTOPPED(ps->status))
			i = WSTOPSIG(ps->status);
		else
			i = -1;
		if (i > 0 && i < sys_nsig && sys_siglist[i])
			strcpy(statestr, sys_siglist[i]);
		else
			strcpy(statestr, "Suspended");
#endif
	} else if (WIFEXITED(ps->status)) {
		if (WEXITSTATUS(ps->status) == 0)
			strcpy(statestr, "Done");
		else
			fmtstr(statestr, 64, "Done(%d)",
			    WEXITSTATUS(ps->status));
	} else {
		i = WTERMSIG(ps->status);
		if (i > 0 && i < sys_nsig && sys_siglist[i])
			strcpy(statestr, sys_siglist[i]);
		else
			fmtstr(statestr, 64, "Signal %d", i);
		if (WCOREDUMP(ps->status))
			strcat(statestr, " (core dumped)");
	}

	for (ps = jp->ps ; ; ps++) {	/* for each process */
		if (mode == SHOWJOBS_PIDS || mode == SHOWJOBS_PGIDS) {
			out1fmt("%d\n", (int)ps->pid);
			goto skip;
		}
		if (mode != SHOWJOBS_VERBOSE && ps != jp->ps)
			goto skip;
		if (jobno == curr && ps == jp->ps)
			c = '+';
		else if (jobno == prev && ps == jp->ps)
			c = '-';
		else
			c = ' ';
		if (ps == jp->ps)
			fmtstr(s, 64, "[%d] %c ", jobno, c);
		else
			fmtstr(s, 64, "    %c ", c);
		out1str(s);
		col = strlen(s);
		if (mode == SHOWJOBS_VERBOSE) {
			fmtstr(s, 64, "%d ", (int)ps->pid);
			out1str(s);
			col += strlen(s);
		}
		if (ps == jp->ps) {
			out1str(statestr);
			col += strlen(statestr);
		}
		do {
			out1c(' ');
			col++;
		} while (col < 30);
		if (mode == SHOWJOBS_VERBOSE) {
			out1str(ps->cmd);
			out1c('\n');
		} else
			printjobcmd(jp);
skip:		if (--procno <= 0)
			break;
	}
}