diff options
author | Roland McGrath <roland@gnu.org> | 1994-10-01 07:44:49 +0000 |
---|---|---|
committer | Roland McGrath <roland@gnu.org> | 1994-10-01 07:44:49 +0000 |
commit | cbd8b271600173af776928e0316838d1b2f97cb2 (patch) | |
tree | 9f76b52a18611709eb12b97a76e5ce35bfcdf885 /sutils | |
parent | b30758c5f344ce10e860c26a606fb505cedda1ea (diff) |
Formerly update.c.~3~
Diffstat (limited to 'sutils')
-rw-r--r-- | sutils/update.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/sutils/update.c b/sutils/update.c index 07e38e41..3c0790c6 100644 --- a/sutils/update.c +++ b/sutils/update.c @@ -20,44 +20,34 @@ #include <unistd.h> #include <stdio.h> -#include <fcntl.h> int -main () +main (int argc, char **argv) { - int fd; - - switch (fork ()) + int interval; + + switch (argc) { - case -1: - perror ("Cannot fork"); - exit (1); - case 0: + case 1: + interval = 30; + break; + case 2: + interval = atoi (argv[1]); break; default: - _exit (0); - } - - if (setsid () == -1) - { - perror ("Cannot setsid"); + fprintf (stderr, "Usage: %s [SECONDS]\n", argv[0]); exit (1); } - chdir ("/"); - fd = open ("/dev/null", O_RDWR, 0); - if (fd != -1) + if (daemon (0, 0)) { - dup2 (fd, STDIN_FILENO); - dup2 (fd, STDOUT_FILENO); - dup2 (fd, STDERR_FILENO); - if (fd < STDERR_FILENO) - close (fd); + perror ("daemon"); + exit (1); } - + for (;;) { sync (); - sleep (30); + sleep (interval); } } |