mirror of
https://github.com/sheumann/hush.git
synced 2024-07-06 04:28:58 +00:00
ps: reduce #ifdef forest
This commit is contained in:
parent
966ec7c067
commit
d3ada32285
38
procps/ps.c
38
procps/ps.c
@ -13,31 +13,19 @@ int ps_main(int argc, char **argv)
|
|||||||
{
|
{
|
||||||
procps_status_t * p;
|
procps_status_t * p;
|
||||||
int i, len;
|
int i, len;
|
||||||
|
SKIP_SELINUX(const) int use_selinux = 0;
|
||||||
#if ENABLE_SELINUX
|
USE_SELINUX(security_context_t sid = NULL;)
|
||||||
int use_selinux = 0;
|
#if !ENABLE_FEATURE_PS_WIDE
|
||||||
security_context_t sid = NULL;
|
enum { terminal_width = 79 };
|
||||||
#endif
|
#else
|
||||||
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE
|
|
||||||
int terminal_width;
|
int terminal_width;
|
||||||
int w_count = 0;
|
int w_count = 0;
|
||||||
|
|
||||||
opt_complementary = "-:ww";
|
|
||||||
#else
|
|
||||||
# define terminal_width 79
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
#if ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX
|
||||||
/* handle arguments */
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX
|
|
||||||
i = getopt32(argc, argv, "wc", &w_count);
|
|
||||||
#elif ENABLE_FEATURE_PS_WIDE && !ENABLE_SELINUX
|
|
||||||
getopt32(argc, argv, "w", &w_count);
|
|
||||||
#else /* !ENABLE_FEATURE_PS_WIDE && ENABLE_SELINUX */
|
|
||||||
i = getopt32(argc, argv, "c");
|
|
||||||
#endif
|
|
||||||
#if ENABLE_FEATURE_PS_WIDE
|
#if ENABLE_FEATURE_PS_WIDE
|
||||||
|
opt_complementary = "-:ww";
|
||||||
|
USE_SELINUX(i =) getopt32(argc, argv, "w" USE_SELINUX("c"), &w_count);
|
||||||
/* if w is given once, GNU ps sets the width to 132,
|
/* if w is given once, GNU ps sets the width to 132,
|
||||||
* if w is given more than once, it is "unlimited"
|
* if w is given more than once, it is "unlimited"
|
||||||
*/
|
*/
|
||||||
@ -48,18 +36,18 @@ int ps_main(int argc, char **argv)
|
|||||||
/* Go one less... */
|
/* Go one less... */
|
||||||
terminal_width--;
|
terminal_width--;
|
||||||
}
|
}
|
||||||
|
#else /* only ENABLE_SELINUX */
|
||||||
|
i = getopt32(argc, argv, "c");
|
||||||
#endif
|
#endif
|
||||||
#if ENABLE_SELINUX
|
#if ENABLE_SELINUX
|
||||||
if ((i & (1+ENABLE_FEATURE_PS_WIDE)) && is_selinux_enabled())
|
if ((i & (1+ENABLE_FEATURE_PS_WIDE)) && is_selinux_enabled())
|
||||||
use_selinux = 1;
|
use_selinux = 1;
|
||||||
#endif
|
#endif
|
||||||
#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
|
#endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */
|
||||||
|
|
||||||
#if ENABLE_SELINUX
|
|
||||||
if (use_selinux)
|
if (use_selinux)
|
||||||
puts(" PID Context Stat Command");
|
puts(" PID Context Stat Command");
|
||||||
else
|
else
|
||||||
#endif
|
|
||||||
puts(" PID Uid VmSize Stat Command");
|
puts(" PID Uid VmSize Stat Command");
|
||||||
|
|
||||||
while ((p = procps_scan(1)) != 0) {
|
while ((p = procps_scan(1)) != 0) {
|
||||||
@ -75,7 +63,7 @@ int ps_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (sid) {
|
if (sid) {
|
||||||
/* I assume sid initilized with NULL */
|
/* I assume sid initialized with NULL */
|
||||||
len = strlen(sid)+1;
|
len = strlen(sid)+1;
|
||||||
safe_strncpy(sbuf, sid, len);
|
safe_strncpy(sbuf, sid, len);
|
||||||
freecon(sid);
|
freecon(sid);
|
||||||
@ -99,7 +87,7 @@ int ps_main(int argc, char **argv)
|
|||||||
i = 0;
|
i = 0;
|
||||||
if (strlen(namecmd) > (size_t)i)
|
if (strlen(namecmd) > (size_t)i)
|
||||||
namecmd[i] = 0;
|
namecmd[i] = 0;
|
||||||
printf("%s\n", namecmd);
|
puts(namecmd);
|
||||||
} else {
|
} else {
|
||||||
namecmd = p->short_cmd;
|
namecmd = p->short_cmd;
|
||||||
if (i < 2)
|
if (i < 2)
|
||||||
@ -108,7 +96,7 @@ int ps_main(int argc, char **argv)
|
|||||||
namecmd[i-2] = 0;
|
namecmd[i-2] = 0;
|
||||||
printf("[%s]\n", namecmd);
|
printf("[%s]\n", namecmd);
|
||||||
}
|
}
|
||||||
/* no check needed, but to make valgrind happy.. */
|
/* no check needed, but to make valgrind happy.. */
|
||||||
if (ENABLE_FEATURE_CLEAN_UP && p->cmd)
|
if (ENABLE_FEATURE_CLEAN_UP && p->cmd)
|
||||||
free(p->cmd);
|
free(p->cmd);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user