Add OpenBSD support to DetermineClientCmd()
Uses kvm_getargv() from libkvm. Signed-off-by: Matthieu Herrb <matthieu.herrb@laas.fr> Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
parent
a55214d119
commit
6d6d4cb604
|
@ -1024,6 +1024,13 @@ if test "x$RES" = xyes && test "x$CLIENTIDS" = xyes; then
|
||||||
else
|
else
|
||||||
CLIENTIDS=no
|
CLIENTIDS=no
|
||||||
fi
|
fi
|
||||||
|
if test "x$CLIENTIDS" = xyes; then
|
||||||
|
case $host_os in
|
||||||
|
openbsd*)
|
||||||
|
SYS_LIBS="$SYS_LIBS -lkvm"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
AC_MSG_RESULT([$CLIENTIDS])
|
AC_MSG_RESULT([$CLIENTIDS])
|
||||||
AM_CONDITIONAL(CLIENTIDS, [test "x$CLIENTIDS" = xyes])
|
AM_CONDITIONAL(CLIENTIDS, [test "x$CLIENTIDS" = xyes])
|
||||||
|
|
||||||
|
|
43
os/client.c
43
os/client.c
|
@ -64,6 +64,15 @@
|
||||||
#include <procfs.h>
|
#include <procfs.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef __OpenBSD__
|
||||||
|
#include <sys/param.h>
|
||||||
|
#include <sys/sysctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
#include <kvm.h>
|
||||||
|
#include <limits.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try to determine a PID for a client from its connection
|
* Try to determine a PID for a client from its connection
|
||||||
* information. This should be called only once when new client has
|
* information. This should be called only once when new client has
|
||||||
|
@ -172,7 +181,39 @@ void DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
|
||||||
if (cmdargs && sp)
|
if (cmdargs && sp)
|
||||||
*cmdargs = strdup(sp);
|
*cmdargs = strdup(sp);
|
||||||
}
|
}
|
||||||
#else /* not Solaris */
|
#elif defined(__OpenBSD__)
|
||||||
|
/* on OpenBSD use kvm_getargv() */
|
||||||
|
{
|
||||||
|
kvm_t *kd;
|
||||||
|
char errbuf[_POSIX2_LINE_MAX];
|
||||||
|
char **argv;
|
||||||
|
struct kinfo_proc *kp;
|
||||||
|
size_t len = 0;
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
kd = kvm_open(NULL, NULL, NULL, KVM_NO_FILES, errbuf);
|
||||||
|
if (kd == NULL)
|
||||||
|
return;
|
||||||
|
kp = kvm_getprocs(kd, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &n);
|
||||||
|
if (n != 1)
|
||||||
|
return;
|
||||||
|
argv = kvm_getargv(kd, kp, 0);
|
||||||
|
*cmdname = strdup(argv[0]);
|
||||||
|
i = 1;
|
||||||
|
while (argv[i] != NULL) {
|
||||||
|
len += strlen(argv[i]) + 1;
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
*cmdargs = calloc(1, len);
|
||||||
|
i = 1;
|
||||||
|
while (argv[i] != NULL) {
|
||||||
|
strlcat(*cmdargs, argv[i], len);
|
||||||
|
strlcat(*cmdargs, " ", len);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
kvm_close(kd);
|
||||||
|
}
|
||||||
|
#else /* Linux using /proc/pid/cmdline */
|
||||||
|
|
||||||
/* Check if /proc/pid/cmdline exists. It's not supported on all
|
/* Check if /proc/pid/cmdline exists. It's not supported on all
|
||||||
* operating systems. */
|
* operating systems. */
|
||||||
|
|
Loading…
Reference in New Issue