Add a --warn option to just warn when reference file does not exist.

Fixes Gentoo #291894.
This commit is contained in:
Roy Marples 2009-11-13 21:31:09 +00:00
parent d21177e5c7
commit 80d4ce3a11
2 changed files with 16 additions and 5 deletions

View File

@ -16,7 +16,7 @@ depend()
start() start()
{ {
ebegin "Setting the local clock based on last shutdown time" ebegin "Setting the local clock based on last shutdown time"
swclock swclock --warn
eend $? eend $?
} }

View File

@ -52,13 +52,15 @@ extern const char *applet;
#include "_usage.h" #include "_usage.h"
#define extraopts "file" #define extraopts "file"
#define getoptstring "s" getoptstring_COMMON #define getoptstring "sw" getoptstring_COMMON
static const struct option longopts[] = { static const struct option longopts[] = {
{ "save", 0, NULL, 's' }, { "save", 0, NULL, 's' },
{ "warn", 0, NULL, 'w' },
longopts_COMMON longopts_COMMON
}; };
static const char * const longopts_help[] = { static const char * const longopts_help[] = {
"saves the time", "saves the time",
"no error if no reference file",
longopts_help_COMMON longopts_help_COMMON
}; };
#include "_usage.c" #include "_usage.c"
@ -66,10 +68,11 @@ static const char * const longopts_help[] = {
int int
swclock(int argc, char **argv) swclock(int argc, char **argv)
{ {
int opt, sflag = 0; int opt, sflag = 0, wflag = 0;
const char *file = RC_SHUTDOWNTIME; const char *file = RC_SHUTDOWNTIME;
struct stat sb; struct stat sb;
struct timeval tv; struct timeval tv;
void (*e)(const char * __EINFO_RESTRICT, ...) EINFO_XPRINTF(1, 2);
while ((opt = getopt_long(argc, argv, getoptstring, while ((opt = getopt_long(argc, argv, getoptstring,
longopts, (int *) 0)) != -1) longopts, (int *) 0)) != -1)
@ -78,6 +81,9 @@ swclock(int argc, char **argv)
case 's': case 's':
sflag = 1; sflag = 1;
break; break;
case 'w':
wflag = 1;
break;
case_RC_COMMON_GETOPT; case_RC_COMMON_GETOPT;
} }
} }
@ -97,8 +103,13 @@ swclock(int argc, char **argv)
return 0; return 0;
} }
if (stat(file, &sb) == -1) if (stat(file, &sb) == -1) {
eerrorx("swclock: `%s': %s", file, strerror(errno)); if (wflag != 0 && errno == EEXIST)
e = ewarnx;
else
e = eerrorx;
e("swclock: `%s': %s", file, strerror(errno));
}
tv.tv_sec = sb.st_mtime; tv.tv_sec = sb.st_mtime;
tv.tv_usec = 0; tv.tv_usec = 0;