1 /* vi: set sw=4 ts=4: */
3 * Mini ps implementation(s) for busybox
5 * Copyright (C) 1999,2000 by Lineo, inc. and Erik Andersen
6 * Copyright (C) 1999,2000,2001 by Erik Andersen <andersee@debian.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 * Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <sys/ioctl.h>
35 #include <fs_secure.h>
37 #include <flask_util.h> /* for is_flask_enabled() */
40 static const int TERMINAL_WIDTH = 79; /* not 80 in case terminal has linefold bug */
44 extern int ps_main(int argc, char **argv)
48 #ifdef CONFIG_FEATURE_AUTOWIDTH
49 struct winsize win = { 0, 0, 0, 0 };
50 int terminal_width = TERMINAL_WIDTH;
52 #define terminal_width TERMINAL_WIDTH
58 if(is_flask_enabled() && argv[1] && !strcmp(argv[1], "-c") )
63 #ifdef CONFIG_FEATURE_AUTOWIDTH
64 ioctl(fileno(stdout), TIOCGWINSZ, &win);
66 terminal_width = win.ws_col - 1;
71 printf(" PID Context Stat Command\n");
74 printf(" PID Uid VmSize Stat Command\n");
76 while ((p = procps_scan(1, use_selinux, &sid)) != 0) {
78 while ((p = procps_scan(1)) != 0) {
80 char *namecmd = p->cmd;
87 if(security_sid_to_context(sid, (security_context_t)&sbuf, &len))
88 strcpy(sbuf, "unknown");
90 len = printf("%5d %-32s %s ", p->pid, sbuf, p->state);
95 len = printf("%5d %-8s %s ", p->pid, p->user, p->state);
97 len = printf("%5d %-8s %6ld %s ", p->pid, p->user, p->rss, p->state);
98 i = terminal_width-len;
100 if(namecmd != 0 && namecmd[0] != 0) {
103 if(strlen(namecmd) > i)
105 printf("%s\n", namecmd);
107 namecmd = p->short_cmd;
110 if(strlen(namecmd) > (i-2))
112 printf("[%s]\n", namecmd);