flock: use sysexit.h for all exit values

Additionally enhance readability of complex double "if shorthand's" by
making the segment to be few normal "if's".

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Sami Kerola 2011-09-21 21:56:45 +02:00
parent e8cea66966
commit 56d45cfabe
1 changed files with 14 additions and 9 deletions

View File

@ -166,7 +166,7 @@ int main(int argc, char *argv[])
break; break;
case 'V': case 'V':
printf("flock (%s)\n", PACKAGE_STRING); printf("flock (%s)\n", PACKAGE_STRING);
exit(0); exit(EX_OK);
default: default:
/* optopt will be set if this was an unrecognized /* optopt will be set if this was an unrecognized
* option, i.e. *not* 'h' or '? * option, i.e. *not* 'h' or '?
@ -209,11 +209,11 @@ int main(int argc, char *argv[])
if (fd < 0) { if (fd < 0) {
warn(_("cannot open lock file %s"), argv[optind]); warn(_("cannot open lock file %s"), argv[optind]);
exit((errno == ENOMEM || errno == EMFILE if (errno == ENOMEM || errno == EMFILE || errno == ENFILE)
|| errno == ENFILE) ? EX_OSERR : (errno == EROFS exit(EX_OSERR);
|| errno == if (errno == EROFS || errno == ENOSPC)
ENOSPC) ? exit(EX_CANTCREAT);
EX_CANTCREAT : EX_NOINPUT); exit(EX_NOINPUT);
} }
} else if (optind < argc) { } else if (optind < argc) {
/* Use provided file descriptor */ /* Use provided file descriptor */
@ -247,12 +247,17 @@ int main(int argc, char *argv[])
while (flock(fd, type | block)) { while (flock(fd, type | block)) {
switch (errno) { switch (errno) {
case EWOULDBLOCK: case EWOULDBLOCK:
/* -n option set and failed to lock */ /* -n option set and failed to lock. The numeric
* exit value is specified in man flock.1
*/
exit(1); exit(1);
case EINTR: case EINTR:
/* Signal received */ /* Signal received */
if (timeout_expired) if (timeout_expired)
/* -w option set and failed to lock */ /* -w option set and failed to lock. The
* numeric exit value is specified in man
* flock.1
*/
exit(1); exit(1);
/* otherwise try again */ /* otherwise try again */
continue; continue;
@ -274,7 +279,7 @@ int main(int argc, char *argv[])
sigaction(SIGALRM, &old_sa, NULL); sigaction(SIGALRM, &old_sa, NULL);
} }
status = 0; status = EX_OK;
if (cmd_argv) { if (cmd_argv) {
pid_t w, f; pid_t w, f;