Commit 7bb4c623 authored by ale's avatar ale

improve command-line option handling

parent 928de6dc
......@@ -28,9 +28,39 @@ char *lock_dir = "/var/tmp";
int usage() {
"%s v%s - a cron job wrapper\n"
"Usage: %s [<OPTIONS>] <COMMAND> [<ARGS>...]\n"
"%s v%s - a cron job wrapper\n",
"Known options:\n"
" --help Show this help message\n"
" --splay SECONDS Wait a random amount of time between 0 and SECONDS before\n"
" actually starting the command.\n"
" --timeout SECONDS\n"
" If the command runs for more than the specified amount of\n"
" time, terminate it. By default commands can run forever.\n"
"Options controlling the command output:\n"
" --quiet Only show output from the command if it fails, suppress\n"
" all output if the exit status is 0.\n"
" --syslog Log command output to syslog, instead of stderr.\n"
"Options controlling locking behavior:\n"
" -n, --name NAME Set the job name. By default, the basename of COMMAND will\n"
" be used.\n"
" --no-lock Disable locking, allow running multiple instances at once.\n"
" --wait Wait for the lock to be released. If another instance of\n"
" this command is running, wait until it terminates (or\n"
" until the lock timeout expires).\n"
" --lock-timeout SECONDS\n"
" Wait at most the specified amount of time for the instance\n"
" lock to be released, failing with an error if after SECONDS\n"
" the lock could not be obtained. If set to 0 (the default),\n"
" wait forever. Specifying this option implies --wait.\n"
return 2;
......@@ -298,6 +328,22 @@ int main(int argc, char **argv) {
/* Check for option consistency. */
if (!locking) {
if (lock_wait) {
fprintf(stderr, "Error: --wait and --no-lock should not be specified together\n");
if (lock_timeout > 0) {
fprintf(stderr, "Error: --no-lock and --lock-timeout should not be specified together\n");
} else {
if (lock_timeout > 0) {
lock_wait = 1;
if (optind >= argc) {
fprintf(stderr, "Error: no command specified\n");
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment