Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardobranco777 committed Mar 8, 2024
1 parent ac11c34 commit 99e41fb
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bsd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ PROG= restartable
WARNS= 3
CFLAGS+= -O2
LDFLAGS= -lutil
SRCS= restartable.c kinfo_getargv.c
SRCS= restartable.c kinfo_getargv.c util.c
HDRS= extern.h

BINDIR= /usr/local/bin
Expand All @@ -13,7 +13,7 @@ BINDIR= /usr/local/bin
BINDIR= /usr/pkg/bin
SRCS+= kinfo_getallproc.c
.elif ${OPSYS} == "DragonFly"
SRCS+= kinfo_getallproc.c
SRCS+= kinfo_getallproc.c kinfo_getvmmap.c
.endif

MK_DEBUG_FILES= no
Expand Down
16 changes: 16 additions & 0 deletions bsd/extern.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <sys/types.h>

int memnchr(const void *, int, size_t);
void free_argv(char **);
char **kinfo_getargv(pid_t pid);

Expand All @@ -9,3 +11,17 @@ char **kinfo_getargv(pid_t pid);
#if defined(__NetBSD__) || defined(__DragonFly__)
struct kinfo_proc *kinfo_getallproc(int *);
#endif

#ifdef __DragonFly__
struct kinfo_vmentry {
int kve_type; /* Type of map entry. */
int kve_protection; /* Protection bitmask. */
char kve_path[PATH_MAX]; /* Path to VM obj, if any. */
};

#define KVME_TYPE_VNODE 2
#define KVME_PROT_EXEC 4

struct kinfo_vmentry *kinfo_getvmmap(pid_t, int *);

#endif
9 changes: 9 additions & 0 deletions bsd/kinfo_getallproc.c
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#ifdef __DragonFly__
#include <sys/user.h>
#else
#include <sys/proc.h>
#endif

#include <stdlib.h>

#include "extern.h"

#ifdef __DragonFly__
#define p_pid kp_pid
#endif

/*
* Sort processes by pid
*/
Expand Down
17 changes: 5 additions & 12 deletions bsd/kinfo_getargv.c
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
#include <sys/cdefs.h>
#include <sys/param.h>
#include <sys/sysctl.h>
#ifdef __DragonFly__
#include <sys/user.h>
#else
#include <sys/proc.h>
#endif

#include <stdlib.h>
#include <string.h>

#include "extern.h"

static int
memnchr(const void *p, int c, size_t len)
{
int n = 0;

for (size_t i = 0; i < len; i++)
if (*((const unsigned char *)p + i) == c)
n++;

return n;
}

void
free_argv(char **argv)
{
Expand Down
14 changes: 14 additions & 0 deletions bsd/kinfo_getvmmap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <sys/types.h>

#include <limits.h>
#include <stdlib.h>

#include "extern.h"

struct kinfo_vmentry *
kinfo_getvmmap(pid_t pid, int *cntp)
{
struct kinfo_vmentry *kiv;

return (NULL);
}
13 changes: 13 additions & 0 deletions bsd/util.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include <stddef.h>

int
memnchr(const void *p, int c, size_t len)
{
int n = 0;

for (size_t i = 0; i < len; i++)
if (*((const unsigned char *)p + i) == c)
n++;

return n;
}

0 comments on commit 99e41fb

Please sign in to comment.