-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.c
More file actions
34 lines (28 loc) · 720 Bytes
/
user.c
File metadata and controls
34 lines (28 loc) · 720 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include "common.h"
int main(int argc, char *argv[]) {
int fd;
unsigned long pid;
if (argc != 2) {
fprintf(stderr, "Usage: %s <pid>\n", argv[0]);
return EXIT_FAILURE;
}
pid = strtoul(argv[1], NULL, 10);
fd = open(DEVICE_PATH, O_RDWR);
if (fd < 0) {
perror("Failed to open device");
return EXIT_FAILURE;
}
if (ioctl(fd, IOCTL_CHANGE_PID, pid) < 0) {
perror("Failed to issue ioctl");
close(fd);
return EXIT_FAILURE;
}
printf("ioctl sent PID %lu to kernel module.\n", pid);
close(fd);
return EXIT_SUCCESS;
}