X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=update.c;h=7279d83a87981c3d47ddd370c76b597d41080600;hb=d58ff8731ce635a75406cc8b9629f1041bb4ed32;hp=14f1d3c2081dcfaa3268b167a55f72fe821665f3;hpb=7ab9c7ee52db8759d457819f5480378fa3aa97cc;p=oweals%2Fbusybox.git diff --git a/update.c b/update.c index 14f1d3c20..7279d83a8 100644 --- a/update.c +++ b/update.c @@ -23,27 +23,22 @@ * */ -#include "internal.h" -#include +/* + * Note: This program is only necessary if you are running a 2.0.x (or + * earlier) kernel. 2.2.x and higher flush filesystem buffers automatically. + */ + +#include "busybox.h" #include #include +#include /* for getopt() */ + #if defined(__GLIBC__) #include #else -_syscall2(int, bdflush, int, func, int, data); -#endif /* __GLIBC__ */ - -static char update_usage[] = - "update [options]\n" -#ifndef BB_FEATURE_TRIVIAL_HELP - "\nPeriodically flushes filesystem buffers.\n\n" - "Options:\n" - "\t-S\tforce use of sync(2) instead of flushing\n" - "\t-s SECS\tcall sync this often (default 30)\n" - "\t-f SECS\tflush some buffers this often (default 5)\n" -#endif - ; +static _syscall2(int, bdflush, int, func, int, data); +#endif /* __GLIBC__ */ static unsigned int sync_duration = 30; static unsigned int flush_duration = 5; @@ -52,29 +47,22 @@ static int use_sync = 0; extern int update_main(int argc, char **argv) { int pid; + int opt; - argc--; - argv++; - while (argc>0 && **argv == '-') { - while (*++(*argv)) { - switch (**argv) { + while ((opt = getopt(argc, argv, "Ss:f:")) > 0) { + switch (opt) { case 'S': use_sync = 1; break; case 's': - if (--argc < 1) usage(update_usage); - sync_duration = atoi(*(++argv)); + sync_duration = atoi(optarg); break; case 'f': - if (--argc < 1) usage(update_usage); - flush_duration = atoi(*(++argv)); + flush_duration = atoi(optarg); break; default: usage(update_usage); - } } - argc--; - argv++; } pid = fork(); @@ -84,12 +72,19 @@ extern int update_main(int argc, char **argv) /* Become a proper daemon */ setsid(); chdir("/"); +#ifdef OPEN_MAX for (pid = 0; pid < OPEN_MAX; pid++) close(pid); +#else + /* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */ + for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid); +#endif /* * This is no longer necessary since 1.3.5x, but it will harmlessly * exit if that is the case. */ + + /* set the program name that will show up in a 'ps' listing */ argv[0] = "bdflush (update)"; argv[1] = NULL; argv[2] = NULL; @@ -109,7 +104,7 @@ extern int update_main(int argc, char **argv) } } } - exit( TRUE); + return( TRUE); } /*