diff options
author | Luke Smith <luke@lukesmith.xyz> | 2020-08-27 14:33:23 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-27 14:33:23 -0400 |
commit | 86aba1a368d827dd33317af92821a0425068aac5 (patch) | |
tree | 873efa59ba8de3543ddf3fbffb48231070a32835 /dwm.c | |
parent | 90eb5e6238ee5a5675239feba6ff29e2008443dd (diff) | |
parent | 12c731865e92d524f91163fa0dd54bd96aa9e6ab (diff) |
Merge pull request #74 from aajonusonline/patch-1
swallow patch: add FreeBSD support
Diffstat (limited to 'dwm.c')
-rw-r--r-- | dwm.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -2412,18 +2412,25 @@ getparentprocess(pid_t p) { unsigned int v = 0; -#ifdef __linux__ +#if defined(__linux__) FILE *f; char buf[256]; snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p); 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); -#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; } |