2000-02-09 01:28:47 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
1999-10-21 03:38:37 +05:30
|
|
|
/*
|
2000-03-05 02:49:32 +05:30
|
|
|
* Mini update implementation for busybox; much pasted from update-2.11
|
1999-10-21 03:38:37 +05:30
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
2000-03-05 02:49:32 +05:30
|
|
|
* Copyright (c) 1996, 1997, 1999 Torsten Poulin.
|
|
|
|
* Copyright (c) 2000 by Karl M. Hegbloom <karlheg@debian.org>
|
1999-10-21 03:38:37 +05:30
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1999-10-05 21:54:54 +05:30
|
|
|
#include "internal.h"
|
2000-07-11 01:38:44 +05:30
|
|
|
#include <sys/syscall.h>
|
2000-03-05 02:49:32 +05:30
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/syslog.h>
|
1999-10-05 21:54:54 +05:30
|
|
|
|
2000-06-19 23:44:20 +05:30
|
|
|
|
1999-10-05 21:54:54 +05:30
|
|
|
#if defined(__GLIBC__)
|
|
|
|
#include <sys/kdaemon.h>
|
|
|
|
#else
|
2000-06-19 23:44:20 +05:30
|
|
|
static _syscall2(int, bdflush, int, func, int, data);
|
2000-02-09 01:28:47 +05:30
|
|
|
#endif /* __GLIBC__ */
|
1999-10-05 21:54:54 +05:30
|
|
|
|
2000-06-19 23:44:20 +05:30
|
|
|
|
2000-03-05 02:49:32 +05:30
|
|
|
static char update_usage[] =
|
2000-05-13 01:11:47 +05:30
|
|
|
"update [options]\n"
|
|
|
|
#ifndef BB_FEATURE_TRIVIAL_HELP
|
|
|
|
"\nPeriodically flushes filesystem buffers.\n\n"
|
2000-04-17 21:46:10 +05:30
|
|
|
"Options:\n"
|
|
|
|
"\t-S\tforce use of sync(2) instead of flushing\n"
|
|
|
|
"\t-s SECS\tcall sync this often (default 30)\n"
|
2000-05-13 01:11:47 +05:30
|
|
|
"\t-f SECS\tflush some buffers this often (default 5)\n"
|
|
|
|
#endif
|
|
|
|
;
|
2000-03-05 02:49:32 +05:30
|
|
|
|
|
|
|
static unsigned int sync_duration = 30;
|
|
|
|
static unsigned int flush_duration = 5;
|
|
|
|
static int use_sync = 0;
|
|
|
|
|
2000-02-09 01:28:47 +05:30
|
|
|
extern int update_main(int argc, char **argv)
|
1999-10-05 21:54:54 +05:30
|
|
|
{
|
2000-02-09 01:28:47 +05:30
|
|
|
int pid;
|
1999-10-05 21:54:54 +05:30
|
|
|
|
2000-04-17 21:46:10 +05:30
|
|
|
argc--;
|
|
|
|
argv++;
|
2000-04-29 03:40:34 +05:30
|
|
|
while (argc>0 && **argv == '-') {
|
2000-03-05 02:49:32 +05:30
|
|
|
while (*++(*argv)) {
|
|
|
|
switch (**argv) {
|
|
|
|
case 'S':
|
|
|
|
use_sync = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
if (--argc < 1) usage(update_usage);
|
|
|
|
sync_duration = atoi(*(++argv));
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
if (--argc < 1) usage(update_usage);
|
|
|
|
flush_duration = atoi(*(++argv));
|
|
|
|
break;
|
2000-04-17 21:46:10 +05:30
|
|
|
default:
|
|
|
|
usage(update_usage);
|
2000-03-05 02:49:32 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
argc--;
|
|
|
|
argv++;
|
|
|
|
}
|
|
|
|
|
1999-10-05 21:54:54 +05:30
|
|
|
pid = fork();
|
2000-02-09 01:28:47 +05:30
|
|
|
if (pid < 0)
|
2000-03-05 02:49:32 +05:30
|
|
|
exit(FALSE);
|
2000-02-09 01:28:47 +05:30
|
|
|
else if (pid == 0) {
|
2000-03-05 02:49:32 +05:30
|
|
|
/* Become a proper daemon */
|
|
|
|
setsid();
|
|
|
|
chdir("/");
|
|
|
|
for (pid = 0; pid < OPEN_MAX; pid++) close(pid);
|
|
|
|
|
1999-10-05 21:54:54 +05:30
|
|
|
/*
|
|
|
|
* This is no longer necessary since 1.3.5x, but it will harmlessly
|
|
|
|
* exit if that is the case.
|
|
|
|
*/
|
2000-03-05 02:49:32 +05:30
|
|
|
argv[0] = "bdflush (update)";
|
|
|
|
argv[1] = NULL;
|
|
|
|
argv[2] = NULL;
|
2000-02-09 01:28:47 +05:30
|
|
|
for (;;) {
|
2000-03-05 02:49:32 +05:30
|
|
|
if (use_sync) {
|
|
|
|
sleep(sync_duration);
|
|
|
|
sync();
|
|
|
|
} else {
|
|
|
|
sleep(flush_duration);
|
|
|
|
if (bdflush(1, 0) < 0) {
|
|
|
|
openlog("update", LOG_CONS, LOG_DAEMON);
|
|
|
|
syslog(LOG_INFO,
|
|
|
|
"This kernel does not need update(8). Exiting.");
|
|
|
|
closelog();
|
|
|
|
exit(TRUE);
|
|
|
|
}
|
|
|
|
}
|
1999-10-05 21:54:54 +05:30
|
|
|
}
|
|
|
|
}
|
2000-06-19 23:44:20 +05:30
|
|
|
return( TRUE);
|
1999-10-05 21:54:54 +05:30
|
|
|
}
|
2000-03-05 02:49:32 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
Local Variables:
|
|
|
|
c-file-style: "linux"
|
|
|
|
c-basic-offset: 4
|
|
|
|
tab-width: 4
|
|
|
|
End:
|
|
|
|
*/
|