FDD-book/examples/part-07/ch31-security/lab06-detach/test/spin.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

37 lines
667 B
C

/*
* spin.c - companion test program for Chapter 31 Lab 6.
*
* Opens /dev/secdev and hammers the SECDEV_SLEEP ioctl in a loop.
* Running this while another terminal issues `kldunload secdev`
* exercises the detach race.
*
* Build: cc -Wall -O2 -o spin spin.c
* Usage: sudo ./spin
*/
#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#define SECDEV_SLEEP _IO('S', 2)
int
main(void)
{
int fd;
fd = open("/dev/secdev", O_RDWR);
if (fd < 0) {
perror("open /dev/secdev");
return (1);
}
for (;;) {
if (ioctl(fd, SECDEV_SLEEP, NULL) < 0) {
perror("ioctl SECDEV_SLEEP");
break;
}
}
close(fd);
return (0);
}