-
Notifications
You must be signed in to change notification settings - Fork 0
/
wakemeup.c
57 lines (45 loc) · 1 KB
/
wakemeup.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
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <err.h>
#include <sysexits.h>
#include <sys/wait.h>
#include <signal.h>
#include <stdlib.h>
#include <time.h>
/* Compile with -DDEBUG flag after gcc to print and not cast */
extern char **environ;
int main(int argc, char *argv[])
{
pid_t child_pid;
time_t tt;
struct tm *t1;
child_pid= fork();
if (child_pid > 0)
{
tt = time(0);
t1 = (localtime) (&tt);
while ((t1->tm_hour != atoi(argv[2])) || (t1->tm_min != atoi(argv[3])))
{
sleep(60);
tt = time(0);
t1 = (localtime) (&tt);
}
kill(child_pid, SIGTERM);
main(argc, argv);
}
else
tt = time(0);
t1 = (localtime) (&tt);
if (child_pid == 0)
{
#ifdef DEBUG
printf("Casting now @ %d : %02d : %02d\n", t1->tm_hour, t1->tm_min, t1->tm_sec);
#else
execle("/usr/local/bin/castnow", "castnow", argv[1], "&", NULL, environ);
#endif
}
else
err(EX_OSERR, "fork error");
return 0;
}