Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=pacman-g2.git;a=commitdiff;h=a58e9fbe2e87769832d136e8857b307d118d86de
commit a58e9fbe2e87769832d136e8857b307d118d86de Author: Miklos Vajna <[email protected]> Date: Sun May 15 02:11:10 2011 +0200 pacman -P: display cgroups so that a user will know what service to restart diff --git a/src/pacman-g2/ps.c b/src/pacman-g2/ps.c index 8ce6f06..e18736c 100644 --- a/src/pacman-g2/ps.c +++ b/src/pacman-g2/ps.c @@ -26,6 +26,7 @@ #include <limits.h> #include <libintl.h> #include <sys/wait.h> +#include <sys/stat.h> /* pacman-g2 */ #include "util.h" @@ -98,6 +99,7 @@ static int ps_free(ps_t *ps) FREE(ps->cmd); FREE(ps->user); FREELIST(ps->files); + FREELIST(ps->cgroups); return 0; } @@ -112,6 +114,30 @@ static list_t* add_or_free(list_t* l, ps_t* ps) return l; } +static list_t *ps_cgroup(pid_t pid) { + struct stat buf; + char *ptr, path[PATH_MAX+1], line[PATH_MAX+1]; + list_t *ret = NULL; + + snprintf(path, PATH_MAX, "/proc/%d/cgroup", pid); + if(!stat(path, &buf)) { + FILE *fp = fopen(path, "r"); + if (!fp) + return ret; + while(!feof(fp)) { + if(fgets(line, PATH_MAX, fp) == NULL) + break; + if (line[strlen(line)-2] == '/') + continue; + // drop newline + line[strlen(line)-1] = 0; + if ((ptr = strchr(line, ':'))) + ret = list_add(ret, strdup(ptr+1)); + } + } + return ret; +} + static list_t* ps_parse(FILE *fp) { char buf[PATH_MAX+1], *ptr; @@ -127,6 +153,7 @@ static list_t* ps_parse(FILE *fp) ps = ps_new(); ps->pid = atoi(buf+1); + ps->cgroups = ps_cgroup(ps->pid); ptr = buf+strlen(buf)+1; ps->cmd = strdup(ptr+1); ptr = ptr + strlen(ptr)+1; @@ -187,6 +214,7 @@ int pspkg() printf( _("PID : %d\n"), ps->pid); printf( _("Command : %s\n"), ps->cmd); list_display(_("Files :"), ps->files); + list_display(_("CGroups :"), ps->cgroups); ps_free(ps); printf("\n"); } diff --git a/src/pacman-g2/ps.h b/src/pacman-g2/ps.h index 230d68d..dcaec9e 100644 --- a/src/pacman-g2/ps.h +++ b/src/pacman-g2/ps.h @@ -26,6 +26,7 @@ typedef struct __ps_t { char *cmd; char *user; list_t *files; + list_t *cgroups; } ps_t; int pspkg(); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
