summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Adrien Schildknecht <adrien+dev@schischi.me>2013-09-29 12:23:44 -0700
committerGravatar Adrien Schildknecht <adrien+dev@schischi.me>2013-09-29 12:23:44 -0700
commitdf3f1d8e4df35b23b8e94edc527dbae6446eef43 (patch)
treea8ec3339eddc44b319580381bfe492de3e6bca2c
parent068872e0c86217894513cc380dc8aa7b32fe2f63 (diff)
parenta625a378cb45d0b4734007eef950383946abd801 (diff)
Merge pull request #5 from kushou/master
Bugfix: xcwd always failing to fetch processes.
-rw-r--r--xcwd.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/xcwd.c b/xcwd.c
index 52132f0..ff50bce 100644
--- a/xcwd.c
+++ b/xcwd.c
@@ -155,7 +155,8 @@ static processes_t getProcesses(void)
processes_t p = NULL;
#ifdef LINUX
glob_t globbuf;
- unsigned int i, j;
+ unsigned int i, j, k;
+ char line[201] = {0};
glob("/proc/[0-9]*", GLOB_NOSORT, NULL, &globbuf);
p = malloc(sizeof(struct processes_s));
@@ -172,9 +173,12 @@ static processes_t getProcesses(void)
tn = fopen(name, "r");
if (tn == NULL)
continue;
- if(fscanf(tn, "%ld (%32[^)] %*3c %ld", &p->ps[j].pid,
- p->ps[j].name, &p->ps[j].ppid) != 3)
- return NULL;
+ fread(line, 200, 1, tn);
+ p->ps[j].pid = atoi(strtok(line, " "));
+ k = snprintf(p->ps[j].name, 32, "%s", strtok(NULL, " ") + 1);
+ p->ps[j].name[k - 1] = 0;
+ strtok(NULL, " "); // discard process state
+ p->ps[j].ppid = atoi(strtok(NULL, " "));
LOG("\t%-20s\tpid=%6ld\tppid=%6ld\n", p->ps[j].name, p->ps[j].pid,
p->ps[j].ppid);
fclose(tn);