Example #1
0
static void
pr_args(struct kinfo_proc *kp)
{
	char **argv, *str;
	int left;

	if (kp == NULL)
		goto nothing;		/* XXX - can this happen? */
	left = argwidth;
	argv = kvm_getargv(kd, kp, argwidth+60);  /* +60 for ftpd snip */
	if (argv == NULL)
		goto nothing;

	if (*argv == NULL || **argv == '\0') {
		/* Process has zeroed argv[0], display executable name. */
		fmt_putc('(', &left);
		fmt_puts(kp->p_comm, &left);
		fmt_putc(')', &left);
	}
	while (*argv) {
		/*
		 * ftp argv[0] is in the following format:
		 * ftpd: HOSTNAME: [USER/PASS: ]CMD args (ftpd)
		 */
		if (strncmp(*argv, "ftpd:", 5) == 0) {
			if ((str = strchr(*argv + 5, ':')) != NULL)
				str = strchr(str + 1, ':');
			if (str != NULL) {
				if ((str[0] == ':') &&
				    isspace((unsigned char)str[1]))
					str += 2;
				fmt_puts(str, &left);
			} else
				fmt_puts(*argv, &left);
		} else
			fmt_puts(*argv, &left);
		argv++;
		fmt_putc(' ', &left);
	}
	return;
nothing:
	putchar('-');
}
Example #2
0
void
command(const struct kinfo_proc *kp, VARENT *ve)
{
	VAR *v;
	int left, wantspace = 0;
	char **argv, **p;

	v = ve->var;
	if (ve->next != NULL || termwidth != UNLIMITED) {
		if (ve->next == NULL) {
			left = termwidth - (totwidth - v->width);
			if (left < 1) /* already wrapped, just use std width */
				left = v->width;
		} else
			left = v->width;
	} else
		left = -1;
	if (needenv && kd != NULL) {
		argv = kvm_getenvv(kd, kp, termwidth);
		if ((p = argv) != NULL) {
			while (*p) {
				fmt_puts(*p, &left);
				p++;
				if (*p)
					fmt_putc(' ', &left);
				else
					wantspace = 1;
			}
		}
	} else
		argv = NULL;
	if (needcomm) {
		if (!commandonly) {
			if (kd != NULL) {
				argv = kvm_getargv(kd, kp, termwidth);
				if ((p = argv) != NULL) {
					if (wantspace) {
						fmt_putc(' ', &left);
						wantspace = 0;
					}
					while (*p) {
						fmt_puts(*p, &left);
						p++;
						if (*p)
							fmt_putc(' ', &left);
						else
							wantspace = 1;
					}
				}
			}
			if (argv == NULL || argv[0] == '\0' ||
			    strcmp(cmdpart(argv[0]), kp->p_comm)) {
				if (wantspace) {
					fmt_putc(' ', &left);
					wantspace = 0;
				}
				fmt_putc('(', &left);
				fmt_puts(kp->p_comm, &left);
				fmt_putc(')', &left);
			}
		} else {
			if (wantspace) {
				fmt_putc(' ', &left);
				wantspace = 0;
			}
			fmt_puts(kp->p_comm, &left);
		}
	}
	if (ve->next && left > 0) {
		if (wantspace) {
			fmt_putc(' ', &left);
			wantspace = 0;
		}
		printf("%*s", left, "");
	}
}