mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 00:55:11 +00:00
Converted option parsing to getopt(). Also added some explanatory comments.
This commit is contained in:
parent
51154bacbe
commit
1ac435c15e
@ -23,9 +23,15 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "internal.h"
|
#include "internal.h"
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
#include <unistd.h> /* for getopt() */
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__)
|
||||||
@ -41,30 +47,23 @@ static int use_sync = 0;
|
|||||||
extern int update_main(int argc, char **argv)
|
extern int update_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
int opt;
|
||||||
|
|
||||||
argc--;
|
while ((opt = getopt(argc, argv, "Ss:f:")) > 0) {
|
||||||
argv++;
|
switch (opt) {
|
||||||
while (argc>0 && **argv == '-') {
|
|
||||||
while (*++(*argv)) {
|
|
||||||
switch (**argv) {
|
|
||||||
case 'S':
|
case 'S':
|
||||||
use_sync = 1;
|
use_sync = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (--argc < 1) usage(update_usage);
|
sync_duration = atoi(optarg);
|
||||||
sync_duration = atoi(*(++argv));
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (--argc < 1) usage(update_usage);
|
flush_duration = atoi(optarg);
|
||||||
flush_duration = atoi(*(++argv));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(update_usage);
|
usage(update_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
@ -79,6 +78,8 @@ extern int update_main(int argc, char **argv)
|
|||||||
* This is no longer necessary since 1.3.5x, but it will harmlessly
|
* This is no longer necessary since 1.3.5x, but it will harmlessly
|
||||||
* exit if that is the case.
|
* exit if that is the case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* set the program name that will show up in a 'ps' listing */
|
||||||
argv[0] = "bdflush (update)";
|
argv[0] = "bdflush (update)";
|
||||||
argv[1] = NULL;
|
argv[1] = NULL;
|
||||||
argv[2] = NULL;
|
argv[2] = NULL;
|
||||||
|
25
update.c
25
update.c
@ -23,9 +23,15 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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 "internal.h"
|
#include "internal.h"
|
||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/syslog.h>
|
#include <sys/syslog.h>
|
||||||
|
#include <unistd.h> /* for getopt() */
|
||||||
|
|
||||||
|
|
||||||
#if defined(__GLIBC__)
|
#if defined(__GLIBC__)
|
||||||
@ -41,30 +47,23 @@ static int use_sync = 0;
|
|||||||
extern int update_main(int argc, char **argv)
|
extern int update_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
|
int opt;
|
||||||
|
|
||||||
argc--;
|
while ((opt = getopt(argc, argv, "Ss:f:")) > 0) {
|
||||||
argv++;
|
switch (opt) {
|
||||||
while (argc>0 && **argv == '-') {
|
|
||||||
while (*++(*argv)) {
|
|
||||||
switch (**argv) {
|
|
||||||
case 'S':
|
case 'S':
|
||||||
use_sync = 1;
|
use_sync = 1;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
if (--argc < 1) usage(update_usage);
|
sync_duration = atoi(optarg);
|
||||||
sync_duration = atoi(*(++argv));
|
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
if (--argc < 1) usage(update_usage);
|
flush_duration = atoi(optarg);
|
||||||
flush_duration = atoi(*(++argv));
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
usage(update_usage);
|
usage(update_usage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
argc--;
|
|
||||||
argv++;
|
|
||||||
}
|
|
||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0)
|
if (pid < 0)
|
||||||
@ -79,6 +78,8 @@ extern int update_main(int argc, char **argv)
|
|||||||
* This is no longer necessary since 1.3.5x, but it will harmlessly
|
* This is no longer necessary since 1.3.5x, but it will harmlessly
|
||||||
* exit if that is the case.
|
* exit if that is the case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* set the program name that will show up in a 'ps' listing */
|
||||||
argv[0] = "bdflush (update)";
|
argv[0] = "bdflush (update)";
|
||||||
argv[1] = NULL;
|
argv[1] = NULL;
|
||||||
argv[2] = NULL;
|
argv[2] = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user