diff --git a/unix/Makefile b/unix/Makefile index 1c5a9b8..07fccb8 100644 --- a/unix/Makefile +++ b/unix/Makefile @@ -3,18 +3,15 @@ CFLAGS = -Wall -Wextra OS != uname -s BIN = restartable -.if $(OS) != "FreeBSD" && $(OS) != "NetBSD" -OBJS = kinfo_getvmmap.o -.else +#.if $(OS) != "FreeBSD" && $(OS) != "NetBSD" +#OBJS = kinfo_getvmmap.o +#.else OBJS = -.endif +#.endif $(BIN): restartable.c $(OBJS) $(CC) $(CFLAGS) -o $@ $< $(OBJS) -lutil -lkvm -kinfo_getvmmap.o: kinfo_getvmmap.c - $(CC) $(CFLAGS) -o $@ $< - .PHONY: clean clean: rm -f $(BIN) $(OBJS) diff --git a/unix/kinfo_getvmmap.c b/unix/kinfo_getvmmap.c deleted file mode 100644 index 4766b73..0000000 --- a/unix/kinfo_getvmmap.c +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Adapted from NetBSD lib/libutil/kinfo_getvmmap.c - */ - -#include - -#include -#include -#include -#include -#include -#include - -struct kinfo_vmentry * -kinfo_getvmmap(pid_t pid, size_t *cntp) -{ - int mib[5]; - int error; - size_t len; - struct kinfo_vmentry *kiv; - - *cntp = 0; - len = 0; - mib[0] = CTL_VM; - mib[1] = KERN_PROC; - mib[2] = KERN_PROC_VMMAP; - mib[3] = pid; - mib[4] = sizeof(*kiv); - - error = sysctl(mib, nitems(mib), NULL, &len, NULL, 0); - if (error) - return NULL; - - len = len * 4 / 3; - - kiv = malloc(len); - if (kiv == NULL) - return NULL; - - error = sysctl(mib, nitems(mib), kiv, &len, NULL, 0); - if (error) { - free(kiv); - return NULL; - } - - *cntp = len / sizeof(*kiv); - return kiv; /* Caller must free() return value */ -} diff --git a/unix/restartable.c b/unix/restartable.c index 683182d..6c5c9d7 100644 --- a/unix/restartable.c +++ b/unix/restartable.c @@ -40,32 +40,30 @@ #else #include #include +#if defined(__NetBSD__) #include -#ifdef __OpenBSD__ -#include +#elif defined(__DragonFly__) +#include #endif #endif #include #include /* _POSIX2_LINE_MAX */ -#if defined(__NetBSD__) || defined(__OpenBSD__) -#ifdef __NetBSD__ +#if defined(__NetBSD__) #define kinfo_proc kinfo_proc2 #define kvm_getargv kvm_getargv2 -#endif #define ki_comm p_comm #define ki_login p_login #define ki_pid p_pid #define ki_ppid p_ppid #define ki_ruid p_ruid -#endif - -#if defined(__OpenBSD__) -struct kinfo_vmentry *kinfo_getvmmap(pid_t, size_t *); -#define KVME_PROT_EXEC KVE_PROT_EXEC -#define KVME_TYPE_VNODE DTYPE_VNODE -#define kve_type kve_etype +#elif defined(__DragonFly__) +#define ki_comm kp_comm +#define ki_login kp_login +#define ki_pid kp_pid +#define ki_ppid kp_ppid +#define ki_ruid kp_ruid #endif static int verbose = 0; @@ -104,10 +102,9 @@ print_argv(kvm_t *kd, const struct kinfo_proc *kp) { static void print_proc(kvm_t *kd, const struct kinfo_proc *kp) { - struct kinfo_vmentry *vmmap; #if defined(__FreeBSD__) int i, count; -#elif defined(__NetBSD__) || defined(__OpenBSD__) +#elif defined(__NetBSD__) unsigned int i; size_t count; #endif @@ -115,7 +112,8 @@ print_proc(kvm_t *kd, const struct kinfo_proc *kp) { if (kp->ki_pid == 0) return; - vmmap = kinfo_getvmmap(kp->ki_pid, &count); +#if defined(__FreeBSD__) || defined(__NetBSD__) + struct kinfo_vmentry *vmmap = kinfo_getvmmap(kp->ki_pid, &count); if (vmmap == NULL) err(1, "kinfo_getvmmap(): %d", kp->ki_pid); @@ -128,6 +126,7 @@ print_proc(kvm_t *kd, const struct kinfo_proc *kp) { } free(vmmap); +#endif } static int @@ -147,10 +146,8 @@ print_all(void) { err(1, "kinfo_getallproc()"); #elif defined(__NetBSD__) procs = kvm_getproc2(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc2), &count); -#elif defined(__OpenBSD__) - procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, sizeof(struct kinfo_proc), &count); #else - procs = kvm_getprocs(kd, KERN_PROC_ALL, &count); + procs = kvm_getprocs(kd, KERN_PROC_ALL, 0, &count); #endif if (procs == NULL) err(1, "kvm_getprocs(): %s", kvm_geterr(kd));