mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
swallow: upgrading to latest version with OpenBSD support
This commit is contained in:
parent
4a35cd2704
commit
dc9e57a6b6
4
dwm.c
4
dwm.c
@ -4394,7 +4394,11 @@ main(int argc, char *argv[])
|
|||||||
#endif // COOL_AUTOSTART_PATCH
|
#endif // COOL_AUTOSTART_PATCH
|
||||||
setup();
|
setup();
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
|
#if SWALLOW_PATCH
|
||||||
|
if (pledge("stdio rpath proc exec ps", NULL) == -1)
|
||||||
|
#else
|
||||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||||
|
#endif // SWALLOW_PATCH
|
||||||
die("pledge");
|
die("pledge");
|
||||||
#endif /* __OpenBSD__ */
|
#endif /* __OpenBSD__ */
|
||||||
scan();
|
scan();
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
#include <X11/Xlib-xcb.h>
|
#include <X11/Xlib-xcb.h>
|
||||||
#include <xcb/res.h>
|
#include <xcb/res.h>
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <kvm.h>
|
||||||
|
#endif /* __OpenBSD__ */
|
||||||
|
|
||||||
static int scanner;
|
static int scanner;
|
||||||
static xcb_connection_t *xcon;
|
static xcb_connection_t *xcon;
|
||||||
@ -64,6 +68,7 @@ winpid(Window w)
|
|||||||
{
|
{
|
||||||
pid_t result = 0;
|
pid_t result = 0;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
xcb_res_client_id_spec_t spec = {0};
|
xcb_res_client_id_spec_t spec = {0};
|
||||||
spec.client = w;
|
spec.client = w;
|
||||||
spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
|
spec.mask = XCB_RES_CLIENT_ID_MASK_LOCAL_CLIENT_PID;
|
||||||
@ -89,6 +94,23 @@ winpid(Window w)
|
|||||||
|
|
||||||
if (result == (pid_t)-1)
|
if (result == (pid_t)-1)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
|
#endif /* __linux__ */
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
Atom type;
|
||||||
|
int format;
|
||||||
|
unsigned long len, bytes;
|
||||||
|
unsigned char *prop;
|
||||||
|
pid_t ret;
|
||||||
|
|
||||||
|
if (XGetWindowProperty(dpy, w, XInternAtom(dpy, "_NET_WM_PID", 1), 0, 1, False, AnyPropertyType, &type, &format, &len, &bytes, &prop) != Success || !prop)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = *(pid_t*)prop;
|
||||||
|
XFree(prop);
|
||||||
|
result = ret;
|
||||||
|
#endif /* __OpenBSD__ */
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,7 +119,7 @@ getparentprocess(pid_t p)
|
|||||||
{
|
{
|
||||||
unsigned int v = 0;
|
unsigned int v = 0;
|
||||||
|
|
||||||
#if defined(__linux__)
|
#ifdef __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);
|
||||||
@ -108,14 +130,19 @@ getparentprocess(pid_t p)
|
|||||||
if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
|
if (fscanf(f, "%*u %*s %*c %u", (unsigned *)&v) != 1)
|
||||||
v = (pid_t)0;
|
v = (pid_t)0;
|
||||||
fclose(f);
|
fclose(f);
|
||||||
#elif defined(__FreeBSD__)
|
#endif /* __linux__ */
|
||||||
struct kinfo_proc *proc = kinfo_getproc(p);
|
#ifdef __OpenBSD__
|
||||||
if (!proc)
|
int n;
|
||||||
return (pid_t)0;
|
kvm_t *kd;
|
||||||
|
struct kinfo_proc *kp;
|
||||||
|
|
||||||
v = proc->ki_ppid;
|
kd = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, NULL);
|
||||||
free(proc);
|
if (!kd)
|
||||||
#endif
|
return 0;
|
||||||
|
|
||||||
|
kp = kvm_getprocs(kd, KERN_PROC_PID, p, sizeof(*kp), &n);
|
||||||
|
v = kp->p_ppid;
|
||||||
|
#endif /* __OpenBSD__ */
|
||||||
return (pid_t)v;
|
return (pid_t)v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user