aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-11-13 21:31:09 +0000
committerRoy Marples <roy@marples.name>2009-11-13 21:31:09 +0000
commit80d4ce3a11e28394724cff32073302265933c06d (patch)
tree53b45a5926eed8b44b6206b8a611c3aef83ca977 /src
parentd21177e5c786b5684365c4a323c1ec904c2e0a6e (diff)
Add a --warn option to just warn when reference file does not exist.
Fixes Gentoo #291894.
Diffstat (limited to 'src')
-rw-r--r--src/rc/swclock.c19
1 files changed, 15 insertions, 4 deletions
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;