Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
runcron
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
silver-platter
runcron
Commits
7bb4c623
Commit
7bb4c623
authored
10 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
improve command-line option handling
parent
928de6dc
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
runcron.c
+48
-2
48 additions, 2 deletions
runcron.c
with
48 additions
and
2 deletions
runcron.c
+
48
−
2
View file @
7bb4c623
...
...
@@ -28,9 +28,39 @@ char *lock_dir = "/var/tmp";
int
usage
()
{
fprintf
(
stderr
,
"%s v%s - a cron job wrapper
\n
"
"Usage: %s [<OPTIONS>] <COMMAND> [<ARGS>...]
\n
"
"%s v%s - a cron job wrapper
\n
"
,
PACKAGE
,
PACKAGE
,
PACKAGE_VERSION
"
\n
"
"Known options:
\n
"
"
\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
"
"
\n
"
"Options controlling the command output:
\n
"
"
\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
"
"
\n
"
"Options controlling locking behavior:
\n
"
"
\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
"
"
\n
"
,
PACKAGE
,
PACKAGE_VERSION
,
PACKAGE
);
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
"
);
exit
(
2
);
}
if
(
lock_timeout
>
0
)
{
fprintf
(
stderr
,
"Error: --no-lock and --lock-timeout should not be specified together
\n
"
);
exit
(
2
);
}
}
else
{
if
(
lock_timeout
>
0
)
{
lock_wait
=
1
;
}
}
if
(
optind
>=
argc
)
{
fprintf
(
stderr
,
"Error: no command specified
\n
"
);
exit
(
2
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment