Merge pull request #74 from aajonusonline/patch-1
swallow patch: add FreeBSD support
This commit is contained in:
commit
86aba1a368
1 changed files with 11 additions and 4 deletions
15
dwm.c
15
dwm.c
|
@ -2412,18 +2412,25 @@ getparentprocess(pid_t p)
|
||||||
{
|
{
|
||||||
unsigned int v = 0;
|
unsigned int v = 0;
|
||||||
|
|
||||||
#ifdef __linux__
|
#if defined(__linux__)
|
||||||
FILE *f;
|
FILE *f;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
|
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
|
||||||
|
|
||||||
if (!(f = fopen(buf, "r")))
|
if (!(f = fopen(buf, "r")))
|
||||||
return 0;
|
return (pid_t)0;
|
||||||
|
|
||||||
fscanf(f, "%*u %*s %*c %u", &v);
|
if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
|
||||||
|
v = (pid_t)0;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
#endif /* __linux__ */
|
#elif defined(__FreeBSD__)
|
||||||
|
struct kinfo_proc *proc = kinfo_getproc(p);
|
||||||
|
if (!proc)
|
||||||
|
return (pid_t)0;
|
||||||
|
|
||||||
|
v = proc->ki_ppid;
|
||||||
|
free(proc);
|
||||||
|
#endif
|
||||||
return (pid_t)v;
|
return (pid_t)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue