FDD-book/examples/part-07/ch30-virtualisation/lab03-jaildev/testclient.c
Edson Brandi 6e6dac94fe Add book companion files under examples/
Organize companion code and materials by book part:

  part-01/      Foundations
  part-02/      Kernel & driver fundamentals
  part-03/      Character & block devices
  part-04/      Networking & storage
  part-05/      Buses & advanced topics
  part-06/      Debugging & performance
  part-07/      Real-world drivers
  appendices/   Supplementary material
  README.md     Overview and build instructions
2026-04-25 16:51:00 +00:00

44 lines
735 B
C

/*
* testclient.c - A small user-space test for jaildev.
*
* Compile:
* cc -Wall -o testclient testclient.c
* Run (as root on the host, and as root inside a jail):
* ./testclient
*/
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <err.h>
#define JAILDEV_IOC_PRIVOP _IO('J', 1)
int
main(void)
{
char buf[64];
ssize_t n;
int fd;
fd = open("/dev/jaildev", O_RDONLY);
if (fd < 0)
err(1, "open /dev/jaildev");
n = read(fd, buf, sizeof(buf) - 1);
if (n < 0) {
warn("read");
} else {
buf[n] = '\0';
printf("read: %s", buf);
}
if (ioctl(fd, JAILDEV_IOC_PRIVOP) < 0)
warn("ioctl PRIVOP");
else
printf("privileged ioctl succeeded\n");
close(fd);
return (0);
}