From 80d4ce3a11e28394724cff32073302265933c06d Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Fri, 13 Nov 2009 21:31:09 +0000 Subject: Add a --warn option to just warn when reference file does not exist. Fixes Gentoo #291894. --- src/rc/swclock.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src/rc') diff --git a/src/rc/swclock.c b/src/rc/swclock.c index 39d65631..e4e0068a 100644 --- a/src/rc/swclock.c +++ b/src/rc/swclock.c @@ -52,13 +52,15 @@ extern const char *applet; #include "_usage.h" #define extraopts "file" -#define getoptstring "s" getoptstring_COMMON +#define getoptstring "sw" getoptstring_COMMON static const struct option longopts[] = { { "save", 0, NULL, 's' }, + { "warn", 0, NULL, 'w' }, longopts_COMMON }; static const char * const longopts_help[] = { "saves the time", + "no error if no reference file", longopts_help_COMMON }; #include "_usage.c" @@ -66,10 +68,11 @@ static const char * const longopts_help[] = { int swclock(int argc, char **argv) { - int opt, sflag = 0; + int opt, sflag = 0, wflag = 0; const char *file = RC_SHUTDOWNTIME; struct stat sb; struct timeval tv; + void (*e)(const char * __EINFO_RESTRICT, ...) EINFO_XPRINTF(1, 2); while ((opt = getopt_long(argc, argv, getoptstring, longopts, (int *) 0)) != -1) @@ -78,6 +81,9 @@ swclock(int argc, char **argv) case 's': sflag = 1; break; + case 'w': + wflag = 1; + break; case_RC_COMMON_GETOPT; } } @@ -97,8 +103,13 @@ swclock(int argc, char **argv) return 0; } - if (stat(file, &sb) == -1) - eerrorx("swclock: `%s': %s", file, strerror(errno)); + if (stat(file, &sb) == -1) { + 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_usec = 0; -- cgit v1.2.3