Skip to content

Commit

Permalink
Implment ignoring itself by default, adds -s option to allow showing …
Browse files Browse the repository at this point in the history
…itself
  • Loading branch information
jduck committed May 14, 2013
1 parent 6f3d51c commit 2487767
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 0 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
support searching by real/effective/saved/fs uid/gid specifically
ignore our own process by default? maybe allow showing it
print better error messages when things fail

11 changes: 10 additions & 1 deletion privmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pid_t search_pid = -1;
uid_t search_uid = -1;
gid_t search_gid = -1;
char *search_cmd = NULL;
int ignore_self = 1;


void perror_str(const char *fmt, ...);
Expand Down Expand Up @@ -81,7 +82,7 @@ main(int argc, char *argv[])
}

/* process args */
while ((c = getopt(argc, argv, "g:p:u:")) != -1) {
while ((c = getopt(argc, argv, "g:p:su:")) != -1) {
char *end = NULL;
int num;

Expand Down Expand Up @@ -139,6 +140,10 @@ main(int argc, char *argv[])
search_uid = num;
break;

case 's':
ignore_self = !ignore_self;
break;

default:
usage(argv);
return 1;
Expand Down Expand Up @@ -254,6 +259,9 @@ get_process_info(process_t *pp, const char *pidstr)
FILE *fp;
size_t len;

if (ignore_self && pp->pid == getpid())
return 0;

/* first, extract the cmdline, if possible. */
fp = open_proc_entry(pp->pid, pidstr, "cmdline");
if (fp) {
Expand Down Expand Up @@ -447,5 +455,6 @@ usage(char *argv[])
"-g <gid> \tshow only processes with the specified group id or name\n"
"-p <pid> \tshow only processes with the specified process id or name\n"
"-u <uid> \tshow only processes with the specified user id or name\n"
"-s \tshow privileges for itself too (defaults to hiding itself)\n"
, cmd);
}

0 comments on commit 2487767

Please sign in to comment.