Skip to content

Commit

Permalink
Add support for DragonFly
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Jan 12, 2024
1 parent 5046026 commit 91e8faf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 73 deletions.
11 changes: 4 additions & 7 deletions unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
48 changes: 0 additions & 48 deletions unix/kinfo_getvmmap.c

This file was deleted.

33 changes: 15 additions & 18 deletions unix/restartable.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,30 @@
#else
#include <sys/param.h>
#include <sys/sysctl.h>
#if defined(__NetBSD__)
#include <util.h>
#ifdef __OpenBSD__
#include <sys/file.h>
#elif defined(__DragonFly__)
#include <sys/user.h>
#endif
#endif

#include <fcntl.h>
#include <limits.h> /* _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;
Expand Down Expand Up @@ -104,18 +102,18 @@ 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

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);

Expand All @@ -128,6 +126,7 @@ print_proc(kvm_t *kd, const struct kinfo_proc *kp) {
}

free(vmmap);
#endif
}

static int
Expand All @@ -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));
Expand Down

0 comments on commit 91e8faf

Please sign in to comment.