swallow patch: add FreeBSD support

patch from this commit:
42a798c34b
This commit is contained in:
aajonusonline 2020-05-18 23:30:49 +03:00 committed by GitHub
parent 1c7d57451b
commit 12c731865e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

15
dwm.c
View file

@ -2405,18 +2405,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;
}