diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-03-04 21:19:32 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-03-04 21:19:32 +0000 |
commit | 029011b9eeaf491d00fda1d072c4c6094df96c3a (patch) | |
tree | 7c49f1fc1547a2f9cee812472f422a5c1a5c448b /miscutils/update.c | |
parent | 7c4b2f3fe5cb6b9a5c6bd089c18279c5ce29dc21 (diff) | |
download | busybox-w32-029011b9eeaf491d00fda1d072c4c6094df96c3a.tar.gz busybox-w32-029011b9eeaf491d00fda1d072c4c6094df96c3a.tar.bz2 busybox-w32-029011b9eeaf491d00fda1d072c4c6094df96c3a.zip |
A few updates (including the cp fix the Craig has been looking for)
-Erik
Diffstat (limited to 'miscutils/update.c')
-rw-r--r-- | miscutils/update.c | 86 |
1 files changed, 66 insertions, 20 deletions
diff --git a/miscutils/update.c b/miscutils/update.c index fef188bba..bb77c5f1f 100644 --- a/miscutils/update.c +++ b/miscutils/update.c | |||
@@ -1,9 +1,11 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * Mini update implementation for busybox | 3 | * Mini update implementation for busybox; much pasted from update-2.11 |
4 | * | 4 | * |
5 | * | 5 | * |
6 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. | 6 | * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>. |
7 | * Copyright (c) 1996, 1997, 1999 Torsten Poulin. | ||
8 | * Copyright (c) 2000 by Karl M. Hegbloom <karlheg@debian.org> | ||
7 | * | 9 | * |
8 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
@@ -23,6 +25,8 @@ | |||
23 | 25 | ||
24 | #include "internal.h" | 26 | #include "internal.h" |
25 | #include <linux/unistd.h> | 27 | #include <linux/unistd.h> |
28 | #include <sys/param.h> | ||
29 | #include <sys/syslog.h> | ||
26 | 30 | ||
27 | #if defined(__GLIBC__) | 31 | #if defined(__GLIBC__) |
28 | #include <sys/kdaemon.h> | 32 | #include <sys/kdaemon.h> |
@@ -30,37 +34,79 @@ | |||
30 | _syscall2(int, bdflush, int, func, int, data); | 34 | _syscall2(int, bdflush, int, func, int, data); |
31 | #endif /* __GLIBC__ */ | 35 | #endif /* __GLIBC__ */ |
32 | 36 | ||
37 | static char update_usage[] = | ||
38 | "update [options]\n" | ||
39 | " -S\tforce use of sync(2) instead of flushing\n" | ||
40 | " -s SECS\tcall sync this often (default 30)\n" | ||
41 | " -f SECS\tflush some buffers this often (default 5)\n"; | ||
42 | |||
43 | static unsigned int sync_duration = 30; | ||
44 | static unsigned int flush_duration = 5; | ||
45 | static int use_sync = 0; | ||
46 | |||
33 | extern int update_main(int argc, char **argv) | 47 | extern int update_main(int argc, char **argv) |
34 | { | 48 | { |
35 | /* | ||
36 | * Update is actually two daemons, bdflush and update. | ||
37 | */ | ||
38 | int pid; | 49 | int pid; |
39 | 50 | ||
51 | while (**argv == '-') { | ||
52 | while (*++(*argv)) { | ||
53 | switch (**argv) { | ||
54 | case 'S': | ||
55 | use_sync = 1; | ||
56 | break; | ||
57 | case 's': | ||
58 | if (--argc < 1) usage(update_usage); | ||
59 | sync_duration = atoi(*(++argv)); | ||
60 | break; | ||
61 | case 'f': | ||
62 | if (--argc < 1) usage(update_usage); | ||
63 | flush_duration = atoi(*(++argv)); | ||
64 | break; | ||
65 | } | ||
66 | } | ||
67 | argc--; | ||
68 | argv++; | ||
69 | } | ||
70 | |||
40 | pid = fork(); | 71 | pid = fork(); |
41 | if (pid < 0) | 72 | if (pid < 0) |
42 | return pid; | 73 | exit(FALSE); |
43 | else if (pid == 0) { | 74 | else if (pid == 0) { |
75 | /* Become a proper daemon */ | ||
76 | setsid(); | ||
77 | chdir("/"); | ||
78 | for (pid = 0; pid < OPEN_MAX; pid++) close(pid); | ||
79 | |||
44 | /* | 80 | /* |
45 | * This is no longer necessary since 1.3.5x, but it will harmlessly | 81 | * This is no longer necessary since 1.3.5x, but it will harmlessly |
46 | * exit if that is the case. | 82 | * exit if that is the case. |
47 | */ | 83 | */ |
48 | strcpy(argv[0], "bdflush (update)"); | 84 | argv[0] = "bdflush (update)"; |
49 | argv[1] = 0; | 85 | argv[1] = NULL; |
50 | argv[2] = 0; | 86 | argv[2] = NULL; |
51 | bdflush(1, 0); | ||
52 | _exit(0); | ||
53 | } | ||
54 | pid = fork(); | ||
55 | if (pid < 0) | ||
56 | return pid; | ||
57 | else if (pid == 0) { | ||
58 | argv[0] = "update"; | ||
59 | for (;;) { | 87 | for (;;) { |
60 | sync(); | 88 | if (use_sync) { |
61 | sleep(30); | 89 | sleep(sync_duration); |
90 | sync(); | ||
91 | } else { | ||
92 | sleep(flush_duration); | ||
93 | if (bdflush(1, 0) < 0) { | ||
94 | openlog("update", LOG_CONS, LOG_DAEMON); | ||
95 | syslog(LOG_INFO, | ||
96 | "This kernel does not need update(8). Exiting."); | ||
97 | closelog(); | ||
98 | exit(TRUE); | ||
99 | } | ||
100 | } | ||
62 | } | 101 | } |
63 | } | 102 | } |
64 | 103 | return TRUE; | |
65 | return 0; | ||
66 | } | 104 | } |
105 | |||
106 | /* | ||
107 | Local Variables: | ||
108 | c-file-style: "linux" | ||
109 | c-basic-offset: 4 | ||
110 | tab-width: 4 | ||
111 | End: | ||
112 | */ | ||