The other kevent calls I use seem to work alright, but when run as root,
this fails.
#include <err.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/event.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int
main()
{
pid_t pid;
int kq;
struct kevent ke;
printf("\nUID: %u\n", getuid());
setuid(1000);
printf("UID: %u\n\n", getuid(), geteuid());
kq = kqueue();
if (kq == -1)
errx(1, "kq!");
pid = fork();
if (pid == (pid_t) 0) {
sleep(2);
printf("done\n");
_exit(0);
}
if (pid == -1)
err(1, NULL);
EV_SET(&ke, pid, EVFILT_PROC, EV_ADD | EV_ONESHOT,
NOTE_EXIT, 0, NULL);
if (kevent(kq, &ke, 1, NULL, 0, NULL) == -1) {
kill(pid, SIGKILL);
err(EXIT_FAILURE, "kevent register fail.");
}
wait(0);
return 0;
}
-Luke