#ifdef WITH_SELINUX
#include <selinux/selinux.h>
+#else
+typedef void* security_context_t; /* DUMMY to remove most ifdefs */
#endif /*WITH_SELINUX */
extern const char *__progname;
pid_t pid;
pid_t pgid;
uid_t uid;
-#ifdef WITH_SELINUX
security_context_t scontext;
-#endif /*WITH_SELINUX */
char flags;
struct _child *children;
struct _proc *parent;
static int print_args = 0, compact = 1, user_change = 0, pids = 0, pgids = 0,
show_parents = 0, by_pid = 0, trunc = 1, wait_end = 0;
-#ifdef WITH_SELINUX
static int show_scontext = 0;
-#endif /*WITH_SELINUX */
static int output_width = 132;
static int cur_x = 1;
static char last_char = 0;
static int dumped = 0; /* used by dump_by_user */
static int charlen = 0; /* length of character */
-static void fix_orphans(void);
+static void fix_orphans(security_context_t scontext);
/*
* Allocates additional buffer space for width and more as needed.
* The first call will allocate the first buffer.
return digits;
}
-#ifdef WITH_SELINUX
static void out_scontext(security_context_t scontext)
{
out_string("`");
out_string(scontext);
out_string("'");
}
-#endif /*WITH_SELINUX */
-
static void out_newline(void)
{
return NULL;
}
-#ifdef WITH_SELINUX
static PROC *new_proc(const char *comm, pid_t pid, uid_t uid,
security_context_t scontext)
-#else /*WITH_SELINUX */
-static PROC *new_proc(const char *comm, pid_t pid, uid_t uid)
-#endif /*WITH_SELINUX */
{
PROC *new;
new->flags = 0;
new->argc = 0;
new->argv = NULL;
-#ifdef WITH_SELINUX
new->scontext = scontext;
-#endif /*WITH_SELINUX */
new->children = NULL;
new->parent = NULL;
new->next = list;
}
}
}
-#ifdef WITH_SELINUX
static void
add_proc(const char *comm, pid_t pid, pid_t ppid, pid_t pgid, uid_t uid,
const char *args, int size, char isthread, security_context_t scontext)
-#else /*WITH_SELINUX */
-static void
-add_proc(const char *comm, pid_t pid, pid_t ppid, pid_t pgid, uid_t uid,
- const char *args, int size, char isthread)
-#endif /*WITH_SELINUX */
{
PROC *this, *parent;
if (!(this = find_proc(pid)))
-#ifdef WITH_SELINUX
this = new_proc(comm, pid, uid, scontext);
-#else /*WITH_SELINUX */
- this = new_proc(comm, pid, uid);
-#endif /*WITH_SELINUX */
else {
rename_proc(this, comm, uid);
}
if (isthread)
this->flags |= PFLAG_THREAD;
if (!(parent = find_proc(ppid))) {
-#ifdef WITH_SELINUX
parent = new_proc("?", ppid, 0, scontext);
-#else /*WITH_SELINUX */
- parent = new_proc("?", ppid, 0);
-#endif
}
if (pid != 0) {
add_child(parent, this);
else
(void) out_int(current->uid);
}
-#ifdef WITH_SELINUX
if (show_scontext) {
out_char(info++ ? ',' : '(');
out_scontext(current->scontext);
}
-#endif /*WITH_SELINUX */
if ((swapped && print_args && current->argc < 0) || (!swapped && info))
out_char(')');
if ((current->flags & PFLAG_HILIGHT) && (tmp = tgetstr("me", NULL)))
}
}
}
-#ifdef WITH_SELINUX
if (show_scontext || print_args || !current->children)
-#else /*WITH_SELINUX */
- if (print_args || !current->children)
-#endif /*WITH_SELINUX */
{
while (closing--)
out_char(']');
ensure_buffer_capacity(level);
more[level] = !last;
-#ifdef WITH_SELINUX
if (show_scontext || print_args)
-#else /*WITH_SELINUX */
- if (print_args)
-#endif /*WITH_SELINUX */
{
width[level] = swapped + (comm_len > 1 ? 0 : -1);
count=0;
pid_t pid, ppid, pgid;
int fd, size;
int empty;
-#ifdef WITH_SELINUX
security_context_t scontext = NULL;
+#ifdef WITH_SELINUX
int selinux_enabled = is_selinux_enabled() > 0;
#endif /*WITH_SELINUX */
while ((dt = readdir(taskdir)) != NULL) {
if ((thread = atoi(dt->d_name)) != 0) {
if (thread != pid) {
-#ifdef WITH_SELINUX
if (print_args)
add_proc(threadname, thread, pid, pgid, st.st_uid,
threadname, strlen (threadname) + 1, 1,scontext);
else
add_proc(threadname, thread, pid, pgid, st.st_uid,
NULL, 0, 1, scontext);
-#else /*WITH_SELINUX */
- if (print_args)
- add_proc(threadname, thread, pid, pgid, st.st_uid,
- threadname, strlen (threadname) + 1, 1);
- else
- add_proc(threadname, thread, pid, pgid, st.st_uid,
- NULL, 0, 1);
-#endif /*WITH_SELINUX */
}
}
}
}
free(taskpath);
if (!print_args)
-#ifdef WITH_SELINUX
add_proc(comm, pid, ppid, pgid, st.st_uid, NULL, 0, 0, scontext);
-#else /*WITH_SELINUX */
- add_proc(comm, pid, ppid, pgid, st.st_uid, NULL, 0, 0);
-#endif /*WITH_SELINUX */
else {
sprintf(path, "%s/%d/cmdline", PROC_BASE, pid);
if ((fd = open(path, O_RDONLY)) < 0) {
size--;
if (size)
buffer[size++] = 0;
-#ifdef WITH_SELINUX
add_proc(comm, pid, ppid, pgid, st.st_uid,
buffer, size, 0, scontext);
-#else /*WITH_SELINUX */
- add_proc(comm, pid, ppid, pgid, st.st_uid,
- buffer, size, 0);
-#endif /*WITH_SELINUX */
}
}
}
}
}
(void) closedir(dir);
- fix_orphans();
+ fix_orphans(scontext);
if (print_args)
free(buffer);
if (empty) {
}
}
-static void fix_orphans(void)
+static void fix_orphans(security_context_t scontext)
{
/* When using kernel 3.3 with hidepid feature enabled on /proc
* then we need fake root pid and gather all the orphan processes
PROC *root, *walk;
if (!(root = find_proc(ROOT_PID))) {
-#ifdef WITH_SELINUX
root = new_proc("?", ROOT_PID, 0, scontext);
-#else /*WITH_SELINUX */
- root = new_proc("?", ROOT_PID, 0);
-#endif
}
for (walk = list; walk; walk = walk->next) {
if (walk->pid == 1 || walk->pid == 0)