summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2011-07-08 09:49:46 +0200
committerDaniel Friesel <derf@finalrewind.org>2011-07-08 09:49:46 +0200
commit0e80b23b5efd17fcc12a79485b2bd55186b8500a (patch)
tree0a688ccd130117e11daad69b4fd4761e4eca3b7e
parent1f28f34dade2276b42c4a11bd8f81945473fce5f (diff)
Make command argument optional
-rw-r--r--src/randsleep.111
-rw-r--r--src/randsleep.c12
2 files changed, 18 insertions, 5 deletions
diff --git a/src/randsleep.1 b/src/randsleep.1
index 41d2fac..d051b73 100644
--- a/src/randsleep.1
+++ b/src/randsleep.1
@@ -12,7 +12,8 @@
.Sh SYNOPSIS
.
.Nm
-.Ar time command args ...
+.Ar time
+.Op Ar command args ...
.
.
.Sh VERSION
@@ -32,6 +33,14 @@ after sleeping for up to
seconds.
It is intended for use in cronjobs and similar.
.
+.Pp
+.
+If
+.Ar command
+is not specified,
+.Nm
+will simply return after sleeping.
+.
.
.Sh RATIONALE
.
diff --git a/src/randsleep.c b/src/randsleep.c
index 389e3a7..ea9c588 100644
--- a/src/randsleep.c
+++ b/src/randsleep.c
@@ -7,8 +7,8 @@ int main (int argc, char **argv) {
long maxsleep;
struct timespec ntime;
- if (argc <= 2) {
- fputs("Usage: randsleep <max> <cmd>\n", stdout);
+ if (argc < 2) {
+ fputs("Usage: randsleep <max> [<cmd>]\n", stdout);
return 1;
}
@@ -21,6 +21,10 @@ int main (int argc, char **argv) {
sleep(rand() % maxsleep);
- execvp(argv[2], argv + 2);
- perror("execvp");
+ if (argc > 2) {
+ execvp(argv[2], argv + 2);
+ perror("execvp");
+ }
+
+ return 0;
}