From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists.gentoo.org ([140.105.134.102] helo=robin.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1IXVfK-00055L-2p for garchives@archives.gentoo.org; Tue, 18 Sep 2007 05:30:30 +0000 Received: from robin.gentoo.org (localhost [127.0.0.1]) by robin.gentoo.org (8.14.0/8.14.0) with SMTP id l8I5Mo6m012525; Tue, 18 Sep 2007 05:22:50 GMT Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by robin.gentoo.org (8.14.0/8.14.0) with ESMTP id l8I5Mi7a012463 for ; Tue, 18 Sep 2007 05:22:50 GMT Received: from stork.gentoo.org (stork.gentoo.org [64.127.104.133]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTP id D96EB652BE for ; Tue, 18 Sep 2007 05:22:49 +0000 (UTC) Received: from solar by stork.gentoo.org with local (Exim 4.60) (envelope-from ) id 1IXVXt-0006Bf-6R for gentoo-commits@lists.gentoo.org; Tue, 18 Sep 2007 05:22:49 +0000 From: "gecos missing (solar)" To: gentoo-commits@lists.gentoo.org Subject: [gentoo-commits] gentoo-projects commit in pax-utils: pspax.c X-VCS-Repository: gentoo-projects X-VCS-Files: pspax.c X-VCS-Directories: pax-utils X-VCS-Committer: solar X-VCS-Committer-Name: gecos missing Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Message-Id: Sender: Date: Tue, 18 Sep 2007 05:22:49 +0000 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@gentoo.org Reply-To: gentoo-dev@lists.gentoo.org X-Archives-Salt: e73d1400-b7f6-4df3-aa25-e4269adf6216 X-Archives-Hash: 23889231965aa77d0028979121dd6bb8 solar 07/09/18 05:22:49 Modified: pspax.c Log: - add /proc/pid/ipaddr support with the -i flag (grsec kernels only) Revision Changes Path 1.39 pax-utils/pspax.c file : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&view=markup plain: http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?rev=1.39&content-type=text/plain diff : http://sources.gentoo.org/viewcvs.py/gentoo-projects/pax-utils/pspax.c?r1=1.38&r2=1.39 Index: pspax.c =================================================================== RCS file: /var/cvsroot/gentoo-projects/pax-utils/pspax.c,v retrieving revision 1.38 retrieving revision 1.39 diff -u -r1.38 -r1.39 --- pspax.c 20 Aug 2007 09:54:15 -0000 1.38 +++ pspax.c 18 Sep 2007 05:22:48 -0000 1.39 @@ -12,7 +12,7 @@ * cc -o pspax pspax.c -DWANT_SYSCAP -lcap */ -static const char *rcsid = "$Id: pspax.c,v 1.38 2007/08/20 09:54:15 vapier Exp $"; +static const char *rcsid = "$Id: pspax.c,v 1.39 2007/09/18 05:22:48 solar Exp $"; const char * const argv0 = "pspax"; #include "paxinc.h" @@ -35,6 +35,7 @@ static char verbose = 0; static char show_banner = 1; static char show_phdr = 0; +static char show_addr = 0; static char noexec = 1; static char writeexec = 1; @@ -201,6 +202,25 @@ return buf; } +static char *get_pid_addr(pid_t pid) +{ + FILE *fp; + char *p; + char str[32]; + static char buf[BUFSIZ]; + + memset(buf, 0, sizeof(buf)); + + snprintf(str, sizeof(str), PROC_DIR "/%u/ipaddr", pid); + if ((fp = fopen(str, "r")) == NULL) + return NULL; + if (fgets(buf, sizeof(buf), fp) != NULL) + if ((p = strchr(buf, '\n')) != NULL) + *p = 0; + fclose(fp); + return buf; +} + static const char *get_proc_type(pid_t pid) { char fname[32]; @@ -273,10 +293,10 @@ register struct dirent *de; pid_t pid; pid_t ppid = show_pid; - int have_attr, wx; + int have_attr, have_addr, wx; struct passwd *pwd; struct stat st; - const char *pax, *type, *name, *caps, *attr; + const char *pax, *type, *name, *caps, *attr, *addr; WRAP_SYSCAP(ssize_t length; cap_t cap_d;); WRAP_SYSCAP(cap_d = cap_init()); @@ -294,9 +314,15 @@ else have_attr = 0; + if ((access("/proc/self/ipaddr", R_OK) != (-1)) && show_addr) + have_addr = 1; + else + have_addr = 0; + if (show_banner) - printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s\n", - "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", "ATTR", show_phdr ? "STACK LOAD" : ""); + printf("%-8s %-6s %-6s %-4s %-10s %-16s %-4s %-4s %s %s\n", + "USER", "PID", "PAX", "MAPS", "ETYPE", "NAME", "CAPS", have_attr ? "ATTR" : "", + have_addr ? "IPADDR" : "", show_phdr ? "STACK LOAD" : ""); while ((de = readdir(dir))) { errno = 0; @@ -327,6 +353,7 @@ type = get_proc_type(pid); name = get_proc_name(pid); attr = (have_attr ? get_pid_attr(pid) : NULL); + addr = (have_addr ? get_pid_addr(pid) : NULL); if (show_uid != (-1) && pwd) if (pwd->pw_uid != show_uid) @@ -341,7 +368,7 @@ WRAP_SYSCAP(caps = cap_to_text(cap_d, &length)); if (show_all || type) { - printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s\n", + printf("%-8s %-6d %-6s %-4s %-10s %-16s %-4s %s %s %s\n", pwd ? pwd->pw_name : "--------", pid, pax ? pax : "---", @@ -349,7 +376,9 @@ type ? type : "-------", name ? name : "-----", caps ? caps : " = ", - attr ? attr : "-", show_phdr ? get_proc_phdr(pid) : ""); + attr ? attr : "", + addr ? addr : "", + show_phdr ? get_proc_phdr(pid) : ""); if (verbose && wx) print_executable_mappings(pid); } @@ -366,11 +395,12 @@ /* usage / invocation handling functions */ -#define PARSE_FLAGS "aep:u:g:nwvBhV" +#define PARSE_FLAGS "aeip:u:g:nwvBhV" #define a_argument required_argument static struct option const long_opts[] = { {"all", no_argument, NULL, 'a'}, {"header", no_argument, NULL, 'e'}, + {"ipaddr", no_argument, NULL, 'i'}, {"pid", a_argument, NULL, 'p'}, {"user", a_argument, NULL, 'u'}, {"group", a_argument, NULL, 'g'}, @@ -385,6 +415,7 @@ static const char *opts_help[] = { "Show all processes", "Print GNU_STACK/PT_LOAD markings", + "Print ipaddr info if supported", "Process ID/pid #", "Process user/uid #", "Process group/gid #", @@ -437,6 +468,7 @@ case 'B': show_banner = 0; break; case 'a': show_all = 1; break; case 'e': show_phdr = 1; break; + case 'i': show_addr = 1; break; case 'p': show_pid = atoi(optarg); break; case 'n': noexec = 1; writeexec = 0; break; case 'w': noexec = 0; writeexec = 1; break; -- gentoo-commits@gentoo.org mailing list