Replace hard-coded exit status bitmask values with named constants.
This commit is contained in:
@@ -23,6 +23,17 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Exit status bitmask values.
|
||||
*/
|
||||
#define PV_ERROREXIT_REMOTE 1
|
||||
#define PV_ERROREXIT_ACCESS 2
|
||||
#define PV_ERROREXIT_OUROBOROS 4
|
||||
#define PV_ERROREXIT_TRANSITION 8
|
||||
#define PV_ERROREXIT_TRANSFER 16
|
||||
#define PV_ERROREXIT_SIGNAL 32
|
||||
#define PV_ERROREXIT_MEMORY 64
|
||||
|
||||
/*
|
||||
* Opaque structure for PV internal state.
|
||||
*/
|
||||
|
||||
+1
-1
@@ -748,7 +748,7 @@ static bool pv__format(pvstate_t state, long double elapsed_sec, off_t bytes_sin
|
||||
new_buffer = malloc(new_size + 16);
|
||||
if (NULL == new_buffer) {
|
||||
pv_error(state, "%s: %s", _("buffer allocation failed"), strerror(errno));
|
||||
state->status.exit_status |= 64;
|
||||
state->status.exit_status |= PV_ERROREXIT_MEMORY;
|
||||
state->display.display_buffer = NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
* suspended. See clock_gettime(2) with CLOCK_MONOTONIC.
|
||||
*
|
||||
* The read should not fail; if it does, the program is aborted with exit
|
||||
* status 16.
|
||||
* status 16 (transfer error).
|
||||
*/
|
||||
void pv_elapsedtime_read(struct timespec *return_time)
|
||||
{
|
||||
@@ -29,7 +29,7 @@ void pv_elapsedtime_read(struct timespec *return_time)
|
||||
if (0 != clock_gettime(CLOCK_MONOTONIC, return_time)) {
|
||||
fprintf(stderr, "%s: %s: %s\n", PACKAGE_NAME, "clock_gettime", strerror(errno));
|
||||
/*@-exitarg@ *//* we explicitly want a special exit status */
|
||||
exit(16);
|
||||
exit(PV_ERROREXIT_TRANSFER);
|
||||
/*@+exitarg@ */
|
||||
}
|
||||
/*@+unrecog@ */
|
||||
|
||||
+9
-9
@@ -147,7 +147,7 @@ static off_t pv_calc_total_bytes(pvstate_t state)
|
||||
pv_error(state, "%s: %s: %s",
|
||||
NULL == state->control.output_name ? "(null)" : state->control.output_name,
|
||||
_("failed to seek to start of output"), strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
/*
|
||||
* If we worked out a size, then set the
|
||||
@@ -229,7 +229,7 @@ static off_t pv_calc_total_lines(pvstate_t state)
|
||||
*/
|
||||
if (numread < 0) {
|
||||
pv_error(state, "%s: %s", state->files.filename[file_idx], strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
break;
|
||||
} else if (0 == numread) {
|
||||
break;
|
||||
@@ -247,7 +247,7 @@ static off_t pv_calc_total_lines(pvstate_t state)
|
||||
|
||||
if (0 != lseek(fd, 0, SEEK_SET)) {
|
||||
pv_error(state, "%s: %s", state->files.filename[file_idx], strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
|
||||
(void) close(fd);
|
||||
@@ -292,14 +292,14 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
if (oldfd >= 0) {
|
||||
if (0 != close(oldfd)) {
|
||||
pv_error(state, "%s: %s", _("failed to close file"), strerror(errno));
|
||||
state->status.exit_status |= 8;
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSITION;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (filenum >= state->files.file_count) {
|
||||
debug("%s: %d >= %d", "filenum too large", filenum, state->files.file_count);
|
||||
state->status.exit_status |= 8;
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSITION;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
if (fd < 0) {
|
||||
pv_error(state, "%s: %s: %s",
|
||||
_("failed to read file"), state->files.filename[filenum], strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -324,14 +324,14 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
pv_error(state, "%s: %s: %s", _("failed to stat file"),
|
||||
NULL == state->files.filename ? "-" : state->files.filename[filenum], strerror(errno));
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (0 != fstat(state->control.output_fd, &osb)) {
|
||||
pv_error(state, "%s: %s", _("failed to stat output file"), strerror(errno));
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
|
||||
pv_error(state, "%s: %s", _("input file is output file"),
|
||||
NULL == state->files.filename ? "-" : state->files.filename[filenum]);
|
||||
(void) close(fd);
|
||||
state->status.exit_status |= 4;
|
||||
state->status.exit_status |= PV_ERROREXIT_OUROBOROS;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -358,7 +358,7 @@ int pv_main_loop(pvstate_t state)
|
||||
}
|
||||
|
||||
if (1 == state->flag.trigger_exit)
|
||||
state->status.exit_status |= 32;
|
||||
state->status.exit_status |= PV_ERROREXIT_SIGNAL;
|
||||
|
||||
if (fd >= 0)
|
||||
(void) close(fd);
|
||||
@@ -389,7 +389,7 @@ int pv_watchfd_loop(pvstate_t state)
|
||||
info.watch_fd = state->control.watch_fd;
|
||||
rc = pv_watchfd_info(state, &info, false);
|
||||
if (0 != rc) {
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
/*@-compdestroy@ */
|
||||
return state->status.exit_status;
|
||||
/*@+compdestroy@ */
|
||||
@@ -520,7 +520,7 @@ int pv_watchfd_loop(pvstate_t state)
|
||||
pv_write_retry(STDERR_FILENO, "\n", 1);
|
||||
|
||||
if (1 == state->flag.trigger_exit)
|
||||
state->status.exit_status |= 32;
|
||||
state->status.exit_status |= PV_ERROREXIT_SIGNAL;
|
||||
|
||||
/*
|
||||
* Free the state structure specific to this file descriptor.
|
||||
@@ -573,8 +573,8 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
*/
|
||||
if (kill(state->control.watch_pid, 0) != 0) {
|
||||
pv_error(state, "%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
return 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
return PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -624,10 +624,10 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
if (kill(state->control.watch_pid, 0) != 0) {
|
||||
if (first_pass) {
|
||||
pv_error(state, "%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
if (NULL != info_array)
|
||||
free(info_array);
|
||||
return 2;
|
||||
return PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -665,10 +665,10 @@ int pv_watchpid_loop(pvstate_t state)
|
||||
if (rc != 0) {
|
||||
if (first_pass) {
|
||||
pv_error(state, "%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
|
||||
state->status.exit_status |= 2;
|
||||
state->status.exit_status |= PV_ERROREXIT_ACCESS;
|
||||
if (NULL != info_array)
|
||||
free(info_array);
|
||||
return 2;
|
||||
return PV_ERROREXIT_ACCESS;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
+5
-5
@@ -446,7 +446,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
|
||||
* exit status, regardless of whether we're skipping errors, and
|
||||
* increment the error counter.
|
||||
*/
|
||||
state->status.exit_status |= 16;
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
|
||||
state->transfer.read_errors_in_a_row++;
|
||||
|
||||
/*
|
||||
@@ -633,7 +633,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
|
||||
|
||||
if (NULL == state->transfer.transfer_buffer) {
|
||||
pv_error(state, "%s", _("no transfer buffer allocated"));
|
||||
state->status.exit_status |= 64;
|
||||
state->status.exit_status |= PV_ERROREXIT_MEMORY;
|
||||
*eof_out = true;
|
||||
state->transfer.written = -1;
|
||||
return 1;
|
||||
@@ -820,7 +820,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
|
||||
}
|
||||
|
||||
pv_error(state, "%s: %s", _("write failed"), strerror(errno));
|
||||
state->status.exit_status |= 16;
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
|
||||
*eof_out = true;
|
||||
state->transfer.written = -1;
|
||||
|
||||
@@ -959,7 +959,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
|
||||
pv__allocate_aligned_buffer(state->control.output_fd, fd, state->control.target_buffer_size + 32);
|
||||
if (NULL == state->transfer.transfer_buffer) {
|
||||
pv_error(state, "%s: %s", _("buffer allocation failed"), strerror(errno));
|
||||
state->status.exit_status |= 64;
|
||||
state->status.exit_status |= PV_ERROREXIT_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
state->transfer.buffer_size = state->control.target_buffer_size;
|
||||
@@ -1061,7 +1061,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
|
||||
/*@+compdef@ */
|
||||
/* splint - see previous pv_current_file_name() calls. */
|
||||
|
||||
state->status.exit_status |= 16;
|
||||
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user