-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdwmguard.c
46 lines (40 loc) · 929 Bytes
/
dwmguard.c
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
35
36
37
38
39
40
41
42
43
44
45
46
/*
* dwmguard.c
* author: Aleksei Kozadaev (2016)
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#define DWM "/usr/local/bin/dwm"
int
main(void)
{
int running = 1, status;
pid_t pid;
while (running) {
pid = fork();
switch(pid) {
case -1:
perror("fork");
exit(1);
case 0:
execl(DWM, DWM, NULL);
perror("execl");
exit(1);
}
if (wait(&status) < 0) {
perror("wait");
exit(1);
}
if (WIFEXITED(status)) {
running = (WEXITSTATUS(status) != 0);
} else if (WIFSIGNALED(status)) {
printf("process %d killed: signal %d\n", pid,
WTERMSIG(status));
exit(WTERMSIG(status));
}
}
return EXIT_SUCCESS;
}