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
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2000-07-21 04:36:27 +05:30
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-03-05 02:49:32 +05:30
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/syslog.h>
|
2000-07-21 04:36:27 +05:30
|
|
|
#include <unistd.h> /* for getopt() */
|
2001-01-27 13:54:39 +05:30
|
|
|
#include <stdlib.h>
|
1999-10-05 21:54:54 +05:30
|
|
|
|
2001-04-10 05:22:18 +05:30
|
|
|
#if __GNU_LIBRARY__ > 5
|
|
|
|
#include <sys/kdaemon.h>
|
1999-10-05 21:54:54 +05:30
|
|
|
#else
|
2001-04-10 05:22:18 +05:30
|
|
|
extern int bdflush (int func, long int data);
|
|
|
|
#endif
|
2001-04-05 08:44:39 +05:30
|
|
|
|
2001-02-20 11:44:08 +05:30
|
|
|
#include "busybox.h"
|
1999-10-05 21:54:54 +05:30
|
|
|
|
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;
|
2000-07-21 04:36:27 +05:30
|
|
|
int opt;
|
1999-10-05 21:54:54 +05:30
|
|
|
|
2000-07-21 04:36:27 +05:30
|
|
|
while ((opt = getopt(argc, argv, "Ss:f:")) > 0) {
|
|
|
|
switch (opt) {
|
2000-03-05 02:49:32 +05:30
|
|
|
case 'S':
|
|
|
|
use_sync = 1;
|
|
|
|
break;
|
|
|
|
case 's':
|
2000-07-21 04:36:27 +05:30
|
|
|
sync_duration = atoi(optarg);
|
2000-03-05 02:49:32 +05:30
|
|
|
break;
|
|
|
|
case 'f':
|
2000-07-21 04:36:27 +05:30
|
|
|
flush_duration = atoi(optarg);
|
2000-03-05 02:49:32 +05:30
|
|
|
break;
|
2000-04-17 21:46:10 +05:30
|
|
|
default:
|
2003-03-19 14:43:01 +05:30
|
|
|
bb_show_usage();
|
2000-03-05 02:49:32 +05:30
|
|
|
}
|
|
|
|
}
|
2001-07-20 03:58:02 +05:30
|
|
|
|
|
|
|
if (daemon(0, 1) < 0)
|
2003-03-19 14:43:01 +05:30
|
|
|
bb_perror_msg_and_die("daemon");
|
2000-03-05 02:49:32 +05:30
|
|
|
|
2000-09-29 02:22:55 +05:30
|
|
|
#ifdef OPEN_MAX
|
2001-07-20 03:58:02 +05:30
|
|
|
for (pid = 0; pid < OPEN_MAX; pid++) close(pid);
|
2000-09-29 02:22:55 +05:30
|
|
|
#else
|
2001-07-20 03:58:02 +05:30
|
|
|
/* glibc 2.1.92 requires using sysconf(_SC_OPEN_MAX) */
|
|
|
|
for (pid = 0; pid < sysconf(_SC_OPEN_MAX); pid++) close(pid);
|
2000-09-29 02:22:55 +05:30
|
|
|
#endif
|
2000-03-05 02:49:32 +05:30
|
|
|
|
2001-07-20 03:58:02 +05:30
|
|
|
/* This is no longer necessary since 1.3.5x, but it will harmlessly
|
|
|
|
* exit if that is the case.
|
|
|
|
*/
|
2000-07-21 04:36:27 +05:30
|
|
|
|
2001-07-20 03:58:02 +05:30
|
|
|
/* set the program name that will show up in a 'ps' listing */
|
|
|
|
argv[0] = "bdflush (update)";
|
|
|
|
argv[1] = NULL;
|
|
|
|
argv[2] = NULL;
|
|
|
|
for (;;) {
|
|
|
|
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();
|
|
|
|
return EXIT_SUCCESS;
|
2000-03-05 02:49:32 +05:30
|
|
|
}
|
1999-10-05 21:54:54 +05:30
|
|
|
}
|
|
|
|
}
|
2001-07-20 03:58:02 +05:30
|
|
|
|
2000-12-01 08:25:13 +05:30
|
|
|
return EXIT_SUCCESS;
|
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:
|
|
|
|
*/
|