More stuff
[oweals/busybox.git] / update.c
1 #include "internal.h"
2 #include <linux/unistd.h>
3
4 #if defined(__GLIBC__)
5 #include <sys/kdaemon.h>
6 #else
7 _syscall2(int, bdflush, int, func, int, data);
8 #endif /* __GLIBC__ */
9
10 extern int
11 update_main(int argc, char** argv)
12 {
13         /*
14          * Update is actually two daemons, bdflush and update.
15          */
16         int     pid;
17
18         pid = fork();
19         if ( pid < 0 )
20                 return pid;
21         else if ( pid == 0 ) {
22                 /*
23                  * This is no longer necessary since 1.3.5x, but it will harmlessly
24                  * exit if that is the case.
25                  */
26                 strcpy(argv[0], "bdflush (update)");
27                 argv[1] = 0;
28                 argv[2] = 0;
29                 bdflush(1, 0);
30                 _exit(0);
31         }
32         pid = fork();
33         if ( pid < 0 )
34                 return pid;
35         else if ( pid == 0 ) {
36                 argv[0] = "update";
37                 for ( ; ; ) {
38                         sync();
39                         sleep(30);
40                 }
41         }
42
43         return 0;
44 }