Remove the state from the pv_error arguments, by adding a new function pv_set_error_prefix to call on startup, eliminating the need for a state program_name string; and add a private boolean to track whether there has been any output which means errors need preceding by a newline, which is updated by pv_display directly (#165).

This commit is contained in:
Andrew Wood
2025-07-27 00:22:57 +01:00
parent 005bc2f841
commit da2a2e6fd2
11 changed files with 114 additions and 90 deletions
+1 -2
View File
@@ -142,7 +142,6 @@ struct pvstate_s {
* Program status *
******************/
struct pvprogramstatus_s {
/*@only@*/ char *program_name; /* program name for error reporting */
char cwd[PV_SIZEOF_CWD]; /* current working directory for relative path */
int current_input_file; /* index of current file being read */
int exit_status; /* exit status to give (0=OK) */
@@ -505,7 +504,7 @@ struct pvwatchfd_s {
};
typedef struct pvwatchfd_s *pvwatchfd_t;
void pv_error(pvstate_t, char *, ...);
void pv_error(char *, ...);
int pv_main_loop(pvstate_t);
void pv_calculate_transfer_rate(pvtransfercalc_t, readonly_pvtransferstate_t, readonly_pvcontrol_t, readonly_pvdisplay_t, bool);
+6 -1
View File
@@ -175,10 +175,15 @@ void pv_nanosleep(long long);
* Main PV functions.
*/
/*
* Set the prefix (program name) for any PV error messages.
*/
extern void pv_set_error_prefix(/*@unique@ */ const char *);
/*
* Create a new state structure, and return it, or 0 (NULL) on error.
*/
extern /*@null@*/ /*@only@*/ pvstate_t pv_state_alloc(const char *);
extern /*@null@*/ /*@only@*/ pvstate_t pv_state_alloc(void);
/*
* Clear the calculated parts of a state structure.
+4 -1
View File
@@ -314,10 +314,13 @@ int main(int argc, char **argv)
return 0;
}
/* Set the error message prefix. */
pv_set_error_prefix(opts->program_name);
/*
* Allocate our internal state buffer.
*/
state = pv_state_alloc(opts->program_name);
state = pv_state_alloc();
if (NULL == state) {
/*@-mustfreefresh@ */
/*
+11 -11
View File
@@ -22,7 +22,7 @@
#include <sys/stat.h>
#ifdef PV_REMOTE_CONTROL
void pv_error(pvstate_t, char *, ...);
void pv_error(char *, ...);
struct remote_msg {
bool progress; /* progress bar flag */
@@ -161,7 +161,7 @@ int pv_remote_set(opts_t opts, pvstate_t state)
* Check that the remote process exists.
*/
if (kill((pid_t) (opts->remote), 0) != 0) {
pv_error(state, "%u: %s", opts->remote, strerror(errno));
pv_error("%u: %s", opts->remote, strerror(errno));
return PV_ERROREXIT_REMOTE_OR_PID;
}
@@ -225,7 +225,7 @@ int pv_remote_set(opts_t opts, pvstate_t state)
memset(control_filename, 0, sizeof(control_filename));
control_fptr = pv__control_file(control_filename, sizeof(control_filename), (pid_t) getpid(), true);
if (NULL == control_fptr) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
return PV_ERROREXIT_REMOTE_OR_PID;
}
@@ -234,14 +234,14 @@ int pv_remote_set(opts_t opts, pvstate_t state)
* it.
*/
if (1 != fwrite(&msgbuf, sizeof(msgbuf), 1, control_fptr)) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
(void) fclose(control_fptr);
(void) remove(control_filename);
return PV_ERROREXIT_REMOTE_OR_PID;
}
if (0 != fclose(control_fptr)) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
(void) remove(control_filename);
return PV_ERROREXIT_REMOTE_OR_PID;
}
@@ -253,7 +253,7 @@ int pv_remote_set(opts_t opts, pvstate_t state)
signal_sender = 0;
(void) pv_sigusr2_received(state, &signal_sender);
if (kill((pid_t) (opts->remote), SIGUSR2) != 0) {
pv_error(state, "%u: %s", opts->remote, strerror(errno));
pv_error("%u: %s", opts->remote, strerror(errno));
(void) remove(control_filename);
return PV_ERROREXIT_REMOTE_OR_PID;
}
@@ -291,7 +291,7 @@ int pv_remote_set(opts_t opts, pvstate_t state)
* Remove the remote control file.
*/
if (0 != remove(control_filename)) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
}
/*
@@ -306,7 +306,7 @@ int pv_remote_set(opts_t opts, pvstate_t state)
* warnings, but in this case it's unavoidable, and mitigated by the
* fact we only translate each string once.
*/
pv_error(state, "%u: %s", opts->remote, _("message not received"));
pv_error("%u: %s", opts->remote, _("message not received"));
return PV_ERROREXIT_REMOTE_OR_PID;
/*@+mustfreefresh @ */
}
@@ -338,7 +338,7 @@ void pv_remote_check(pvstate_t state)
memset(control_filename, 0, sizeof(control_filename));
control_fptr = pv__control_file(control_filename, sizeof(control_filename), signal_sender, false);
if (NULL == control_fptr) {
pv_error(state, "%s: %s", control_filename, strerror(errno));
pv_error("%s: %s", control_filename, strerror(errno));
return;
}
@@ -347,13 +347,13 @@ void pv_remote_check(pvstate_t state)
* it.
*/
if (1 != fread(&msgbuf, sizeof(msgbuf), 1, control_fptr)) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
(void) fclose(control_fptr);
return;
}
if (0 != fclose(control_fptr)) {
pv_error(state, "%s", strerror(errno));
pv_error("%s", strerror(errno));
return;
}
+4 -4
View File
@@ -58,7 +58,7 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd)
ttydev = ttyname(fd);
if (!ttydev) {
if (!state->control.force) {
pv_error(state, "%s: %s", _("failed to get terminal name"), strerror(errno));
pv_error("%s: %s", _("failed to get terminal name"), strerror(errno));
}
/*
* If we don't know our terminal name, we can neither do IPC
@@ -103,7 +103,7 @@ static void pv_crs_open_lockfile(pvstate_t state, int fd)
*/
if (state->cursor.lock_fd < 0) {
pv_error(state, "%s: %s: %s", state->cursor.lock_file, _("failed to open lock file"), strerror(errno));
pv_error("%s: %s: %s", state->cursor.lock_file, _("failed to open lock file"), strerror(errno));
state->control.cursor = 0;
return;
}
@@ -136,7 +136,7 @@ static void pv_crs_lock(pvstate_t state, int fd)
lock_fd = state->cursor.lock_fd;
}
} else {
pv_error(state, "%s: %s", _("lock attempt failed"), strerror(errno));
pv_error("%s: %s", _("lock attempt failed"), strerror(errno));
return;
}
}
@@ -397,7 +397,7 @@ void pv_crs_init(pvstate_t state)
*/
if (terminalfd < 0) {
pv_error(state, "%s: %s: %s", _("failed to open terminal"), ttyfile, strerror(errno));
pv_error("%s: %s: %s", _("failed to open terminal"), ttyfile, strerror(errno));
state->control.cursor = false;
return;
}
+42 -4
View File
@@ -49,17 +49,53 @@
#include <sys/ioctl.h>
#endif
/*
* The error prefix for messages (the program name); whether it has been
* set; and whether any output has been displayed yet, indicating whether
* any errors must be preceded by a newline.
*/
static char pv__error_prefix[64]; /* flawfinder: ignore */
static bool pv__error_prefix_set = false;
static bool pv__output_produced = false;
/*
* flawfinder rationale: zeroed before use, string copy is bounded to 1 less
* than size so it always has \0 termination. Not used unless initialised,
* by checking pv__error_prefix_set.
*/
/*
* Set the error message prefix.
*/
void pv_set_error_prefix( /*@unique@ */ const char *prefix)
{
if (NULL == prefix)
return;
memset(pv__error_prefix, 0, sizeof(pv__error_prefix));
strncpy(pv__error_prefix, prefix, sizeof(pv__error_prefix) - 1); /* flawfinder: ignore */
pv__error_prefix_set = true;
/*
* flawfinder rationale: strncpy's pointers are as valid as we can
* make them since the first is a static buffer and the second is
* caller-supplied. The caller must \0-terminate the string but in
* any case it is bounded to 1 less than the size of the
* destination. The destination is zeroed before use so the result
* is guaranteed to be \0-terminated.
*/
}
/*
* Output an error message. If we've displayed anything to the terminal
* already, then put a newline before our error so we don't write over what
* we've written.
*/
void pv_error(pvstate_t state, char *format, ...)
void pv_error(char *format, ...)
{
va_list ap;
if (state->display.output_produced)
if (pv__output_produced)
fprintf(stderr, "\n");
fprintf(stderr, "%s: ", state->status.program_name);
if (pv__error_prefix_set)
fprintf(stderr, "%s: ", pv__error_prefix);
va_start(ap, format);
(void) vfprintf(stderr, format, ap); /* flawfinder: ignore */
va_end(ap);
@@ -1005,7 +1041,7 @@ bool pv_format(pvstate_t state, pvcontrol_t control, readonly_pvtransferstate_t
new_buffer = malloc(new_size + 16);
if (NULL == new_buffer) {
pv_error(state, "%s: %s", _("buffer allocation failed"), strerror(errno));
pv_error("%s: %s", _("buffer allocation failed"), strerror(errno));
state->status.exit_status |= PV_ERROREXIT_MEMORY;
display->display_buffer = NULL;
return false;
@@ -1253,6 +1289,7 @@ void pv_display(pvstate_t state, bool final)
if (state->control.force || pv_in_foreground()) {
pv_crs_update(state, state->display.display_buffer);
state->display.output_produced = true;
pv__output_produced = true;
}
} else {
if (state->control.force || pv_in_foreground()) {
@@ -1260,6 +1297,7 @@ void pv_display(pvstate_t state, bool final)
state->display.display_string_bytes);
pv_tty_write(&(state->flags), "\r", 1);
state->display.output_produced = true;
pv__output_produced = true;
}
}
+8 -8
View File
@@ -144,7 +144,7 @@ static off_t pv_calc_total_bytes(pvstate_t state)
total = end_position;
}
if (lseek(state->control.output_fd, 0, SEEK_SET) != 0) {
pv_error(state, "%s: %s: %s",
pv_error("%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 |= PV_ERROREXIT_ACCESS;
@@ -228,7 +228,7 @@ static off_t pv_calc_total_lines(pvstate_t state)
* OK.
*/
if (numread < 0) {
pv_error(state, "%s: %s", state->files.filename[file_idx], strerror(errno));
pv_error("%s: %s", state->files.filename[file_idx], strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
break;
} else if (0 == numread) {
@@ -246,7 +246,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));
pv_error("%s: %s", state->files.filename[file_idx], strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
}
@@ -291,7 +291,7 @@ 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));
pv_error("%s: %s", _("failed to close file"), strerror(errno));
state->status.exit_status |= PV_ERROREXIT_TRANSITION;
return -1;
}
@@ -313,7 +313,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
* to open symlinks etc as that would be counterintuitive.
*/
if (fd < 0) {
pv_error(state, "%s: %s: %s",
pv_error("%s: %s: %s",
_("failed to read file"), state->files.filename[filenum], strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
return -1;
@@ -321,7 +321,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
}
if (0 != fstat(fd, &isb)) {
pv_error(state, "%s: %s: %s", _("failed to stat file"),
pv_error("%s: %s: %s", _("failed to stat file"),
NULL == state->files.filename ? "-" : state->files.filename[filenum], strerror(errno));
(void) close(fd);
state->status.exit_status |= PV_ERROREXIT_ACCESS;
@@ -329,7 +329,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
}
if (0 != fstat(state->control.output_fd, &osb)) {
pv_error(state, "%s: %s", _("failed to stat output file"), strerror(errno));
pv_error("%s: %s", _("failed to stat output file"), strerror(errno));
(void) close(fd);
state->status.exit_status |= PV_ERROREXIT_ACCESS;
return -1;
@@ -351,7 +351,7 @@ int pv_next_file(pvstate_t state, unsigned int filenum, int oldfd)
input_file_is_output = false;
if (input_file_is_output) {
pv_error(state, "%s: %s", _("input file is output file"),
pv_error("%s: %s", _("input file is output file"),
NULL == state->files.filename ? "-" : state->files.filename[filenum]);
(void) close(fd);
state->status.exit_status |= PV_ERROREXIT_OUROBOROS;
+3 -3
View File
@@ -781,7 +781,7 @@ int pv_watchpid_loop(pvstate_t state)
* it's not there at the start.
*/
if (kill(state->control.watch_pid, 0) != 0) {
pv_error(state, "%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
return PV_ERROREXIT_ACCESS;
}
@@ -832,7 +832,7 @@ 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));
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
if (NULL != info_array)
free(info_array);
@@ -885,7 +885,7 @@ int pv_watchpid_loop(pvstate_t state)
rc = pv_watchpid_scanfds(state, state->control.watch_pid, &array_length, &info_array, fd_to_idx);
if (rc != 0) {
if (first_pass) {
pv_error(state, "%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
pv_error("%s %u: %s", _("pid"), state->control.watch_pid, strerror(errno));
state->status.exit_status |= PV_ERROREXIT_ACCESS;
if (NULL != info_array)
free(info_array);
+10 -28
View File
@@ -36,8 +36,7 @@ static void pv_alloc_history(pvstate_t state)
* leak warnings, but in this case it's unavoidable, and
* mitigated by the fact we only translate each string once.
*/
fprintf(stderr, "%s: %s: %s\n", state->status.program_name,
_("history structure allocation failed"), strerror(errno));
pv_error("%s: %s", _("history structure allocation failed"), strerror(errno));
/*@+mustfreefresh@ */
return;
}
@@ -108,7 +107,7 @@ void pv_state_reset(pvstate_t state)
/*
* Create a new state structure, and return it, or 0 (NULL) on error.
*/
pvstate_t pv_state_alloc(const char *program_name)
pvstate_t pv_state_alloc(void)
{
pvstate_t state;
@@ -117,17 +116,6 @@ pvstate_t pv_state_alloc(const char *program_name)
return NULL;
memset(state, 0, sizeof(*state));
/* splint 3.1.2 thinks this is required for some reason. */
if (NULL != state->status.program_name) {
free(state->status.program_name);
}
state->status.program_name = pv_strdup(program_name);
if (NULL == state->status.program_name) {
free(state);
return NULL;
}
state->control.watch_pid = 0;
state->control.watch_fd = -1;
state->control.output_fd = -1;
@@ -172,9 +160,9 @@ void pv_state_free(pvstate_t state)
if (state->control.output_fd >= 0) {
if (STDOUT_FILENO != state->control.output_fd) {
if (close(state->control.output_fd) < 0) {
fprintf(stderr, "%s: %s: %s\n", state->status.program_name,
NULL == state->control.output_name ? "(null)" : state->control.output_name,
strerror(errno));
pv_error("%s: %s",
NULL == state->control.output_name ? "(null)" : state->control.output_name,
strerror(errno));
}
}
state->control.output_fd = -1;
@@ -185,10 +173,6 @@ void pv_state_free(pvstate_t state)
state->control.output_name = NULL;
}
if (NULL != state->status.program_name)
free(state->status.program_name);
state->status.program_name = NULL;
if (NULL != state->display.display_buffer)
free(state->display.display_buffer);
state->display.display_buffer = NULL;
@@ -549,9 +533,9 @@ void pv_state_output_set(pvstate_t state, int fd, const char *name)
*/
if (state->control.output_fd >= 0 && state->control.output_fd != STDOUT_FILENO) {
if (close(state->control.output_fd) < 0) {
fprintf(stderr, "%s: %s: %s\n", state->status.program_name,
NULL == state->control.output_name ? "(null)" : state->control.output_name,
strerror(errno));
pv_error("%s: %s",
NULL == state->control.output_name ? "(null)" : state->control.output_name,
strerror(errno));
}
}
if (NULL != state->control.output_name)
@@ -614,8 +598,7 @@ void pv_state_inputfiles(pvstate_t state, unsigned int input_file_count, const c
state->files.filename = calloc((size_t) (input_file_count + 1), sizeof(char *));
if (NULL == state->files.filename) {
/*@-mustfreefresh@ *//* see similar _() issue above */
fprintf(stderr, "%s: %s: %s\n", state->status.program_name, _("file list allocation failed"),
strerror(errno));
pv_error("%s: %s", _("file list allocation failed"), strerror(errno));
/*@+mustfreefresh@ */
return;
}
@@ -624,8 +607,7 @@ void pv_state_inputfiles(pvstate_t state, unsigned int input_file_count, const c
state->files.filename[file_idx] = pv_strdup(input_files[file_idx]);
if (NULL == state->files.filename[file_idx]) {
/*@-mustfreefresh@ *//* see similar _() issue above */
fprintf(stderr, "%s: %s: %s\n", state->status.program_name,
_("file list allocation failed"), strerror(errno));
pv_error("%s: %s", _("file list allocation failed"), strerror(errno));
/*@+mustfreefresh@ */
return;
}
+12 -14
View File
@@ -460,7 +460,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
* reached the end of this file.
*/
if (do_not_skip_errors) {
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("read failed"), strerror(errno));
pv_error("%s: %s: %s", pv_current_file_name(state), _("read failed"), strerror(errno));
*eof_in = true;
if (state->transfer.write_position >= state->transfer.read_position) {
*eof_out = true;
@@ -476,7 +476,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
if (!state->transfer.read_error_warning_shown) {
/*@-compdef@ */
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("warning: read errors detected"),
pv_error("%s: %s: %s", pv_current_file_name(state), _("warning: read errors detected"),
strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() call. */
@@ -492,7 +492,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
*/
if (0 > orig_offset) {
/*@-compdef@ */
pv_error(state, "%s: %s: %s", pv_current_file_name(state), _("file is not seekable"), strerror(errno));
pv_error("%s: %s: %s", pv_current_file_name(state), _("file is not seekable"), strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
*eof_in = true;
@@ -569,8 +569,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
*/
if (EINVAL != errno) {
/*@-compdef@ */
pv_error(state,
"%s: %s: %s", pv_current_file_name(state), _("failed to seek past error"),
pv_error("%s: %s: %s", pv_current_file_name(state), _("failed to seek past error"),
strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
@@ -588,7 +587,7 @@ static int pv__transfer_read(pvstate_t state, int fd, bool *eof_in, bool *eof_ou
state->transfer.read_position += amount_skipped;
if (state->control.skip_errors < 2) {
/*@-compdef@ */
pv_error(state, "%s: %s: %ld - %ld (%ld %s)",
pv_error("%s: %s: %ld - %ld (%ld %s)",
pv_current_file_name(state),
_("skipped past read error"), (long) orig_offset, (long) skip_offset,
(long) amount_skipped, _("B"));
@@ -631,7 +630,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
int write_errno;
if (NULL == state->transfer.transfer_buffer) {
pv_error(state, "%s", _("no transfer buffer allocated"));
pv_error("%s", _("no transfer buffer allocated"));
state->status.exit_status |= PV_ERROREXIT_MEMORY;
*eof_out = true;
state->transfer.written = -1;
@@ -673,7 +672,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
(long) (new_timer.it_value.tv_usec));
if (0 != setitimer(ITIMER_REAL, &new_timer, NULL)) {
pv_error(state, "%s: %s", _("failed to set interval timer"), strerror(errno));
pv_error("%s: %s", _("failed to set interval timer"), strerror(errno));
}
#else /* ! HAVE_SETITIMER */
@@ -699,7 +698,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
new_timer.it_value.tv_sec = 0;
new_timer.it_value.tv_usec = 0;
if (0 != setitimer(ITIMER_REAL, &new_timer, NULL)) {
pv_error(state, "%s: %s", _("failed to clear interval timer"), strerror(errno));
pv_error("%s: %s", _("failed to clear interval timer"), strerror(errno));
}
/*@+unrecog@ */
@@ -741,7 +740,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
state->transfer.line_positions =
calloc((size_t) (state->transfer.line_positions_capacity), sizeof(off_t));
if (NULL == state->transfer.line_positions) {
pv_error(state, "%s: %s", _("line position buffer allocation failed"),
pv_error("%s: %s", _("line position buffer allocation failed"),
strerror(errno));
}
/*@+mustfreeonly@ */
@@ -915,7 +914,7 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long
return 0;
}
pv_error(state, "%s: %s", _("write failed"), strerror(write_errno));
pv_error("%s: %s", _("write failed"), strerror(write_errno));
state->status.exit_status |= PV_ERROREXIT_TRANSFER;
*eof_out = true;
state->transfer.written = -1;
@@ -1054,7 +1053,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
state->transfer.transfer_buffer =
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));
pv_error("%s: %s", _("buffer allocation failed"), strerror(errno));
state->status.exit_status |= PV_ERROREXIT_MEMORY;
return -1;
}
@@ -1156,8 +1155,7 @@ ssize_t pv_transfer(pvstate_t state, int fd, bool *eof_in, bool *eof_out, off_t
* Any other error is a problem and we must report back.
*/
/*@-compdef@ */
pv_error(state, "%s: %s: %d: %s", pv_current_file_name(state), _("select call failed"), n,
strerror(errno));
pv_error("%s: %s: %d: %s", pv_current_file_name(state), _("select call failed"), n, strerror(errno));
/*@+compdef@ */
/* splint - see previous pv_current_file_name() calls. */
+13 -14
View File
@@ -96,7 +96,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (kill(info->watch_pid, 0) != 0) {
if (!automatic)
pv_error(state, "%s %u: %s", _("pid"), info->watch_pid, strerror(errno));
pv_error("%s %u: %s", _("pid"), info->watch_pid, strerror(errno));
return 1;
}
@@ -105,8 +105,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
PROC_PIDFDVNODEPATHINFO, &vnodeInfo,
PROC_PIDFDVNODEPATHINFO_SIZE);
if (size != PROC_PIDFDVNODEPATHINFO_SIZE) {
pv_error(state, "%s %u: %s %d: %s",
_("pid"), info->watch_pid, _("fd"), info->watch_fd, strerror(errno));
pv_error("%s %u: %s %d: %s", _("pid"), info->watch_pid, _("fd"), info->watch_fd, strerror(errno));
return 3;
}
@@ -116,7 +115,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (!(0 == stat(info->file_fdpath, &(info->sb_fd)))) {
if (!automatic)
pv_error(state, "%s %u: %s %d: %s: %s",
pv_error("%s %u: %s %d: %s: %s",
_("pid"),
info->watch_pid, _("fd"), info->watch_fd, info->file_fdpath, strerror(errno));
return 3;
@@ -124,7 +123,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (!filesize(info)) {
if (!automatic)
pv_error(state, "%s %u: %s %d: %s: %s",
pv_error("%s %u: %s %d: %s: %s",
_("pid"),
info->watch_pid,
_("fd"), info->watch_fd, info->file_fdpath, _("not a regular file or block device"));
@@ -162,7 +161,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (kill(info->watch_pid, 0) != 0) {
if (!automatic)
pv_error(state, "%s %u: %s", _("pid"), info->watch_pid, strerror(errno));
pv_error("%s %u: %s", _("pid"), info->watch_pid, strerror(errno));
return 1;
}
(void) pv_snprintf(info->file_fdinfo, PV_SIZEOF_FILE_FDINFO,
@@ -180,7 +179,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
* and then only if it's a block device - see filesize().
*/
if (!automatic)
pv_error(state, "%s %u: %s %d: %s",
pv_error("%s %u: %s %d: %s",
_("pid"), info->watch_pid, _("fd"), info->watch_fd, strerror(errno));
return 2;
}
@@ -188,7 +187,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (!((0 == stat(info->file_fd, &(info->sb_fd)))
&& (0 == lstat(info->file_fd, &(info->sb_fd_link))))) {
if (!automatic)
pv_error(state, "%s %u: %s %d: %s: %s",
pv_error("%s %u: %s %d: %s: %s",
_("pid"),
info->watch_pid, _("fd"), info->watch_fd, info->file_fdpath, strerror(errno));
return 3;
@@ -198,7 +197,7 @@ int pv_watchfd_info(pvstate_t state, pvwatchfd_t info, bool automatic)
if (!filesize(info)) {
if (!automatic)
pv_error(state, "%s %u: %s %d: %s: %s",
pv_error("%s %u: %s %d: %s: %s",
_("pid"),
info->watch_pid,
_("fd"), info->watch_fd, info->file_fdpath, _("not a regular file or block device"));
@@ -297,7 +296,7 @@ static int pidfds(pvstate_t state, unsigned int pid, struct proc_fdinfo **fds, i
{
int size_needed = proc_pidinfo(pid, PROC_PIDLISTFDS, 0, 0, 0);
if (size_needed == -1) {
pv_error(state, "%s: unable to list pid fds: %s", _("pid"), strerror(errno));
pv_error("%s: unable to list pid fds: %s", _("pid"), strerror(errno));
return -1;
}
@@ -305,7 +304,7 @@ static int pidfds(pvstate_t state, unsigned int pid, struct proc_fdinfo **fds, i
*fds = (struct proc_fdinfo *) malloc(size_needed);
if (*fds == NULL) {
pv_error(state, "%s: alloc failed: %s", _("pid"), strerror(errno));
pv_error("%s: alloc failed: %s", _("pid"), strerror(errno));
return -1;
}
memset(*fds, 0, size_needed);
@@ -382,7 +381,7 @@ int pv_watchpid_scanfds(pvstate_t state,
int fd_infos_count = 0;
if (pidfds(state, watch_pid, &fd_infos, &fd_infos_count) != 0) {
pv_error(state, "%s: pidfds failed", _("pid"));
pv_error("%s: pidfds failed", _("pid"));
return -1;
}
#else
@@ -403,7 +402,7 @@ int pv_watchpid_scanfds(pvstate_t state,
#ifdef __APPLE__
if (fd_infos_count < 1) {
pv_error(state, "%s: no fds found", _("pid"));
pv_error("%s: no fds found", _("pid"));
return -1;
}
for (int i = 0; i < fd_infos_count; i++) {
@@ -468,7 +467,7 @@ int pv_watchpid_scanfds(pvstate_t state,
/* Allocate new display state. */
/*@-mustfreeonly@ *//* splint - this is not a leak, this is a new entry. */
info_array[use_idx].state = pv_state_alloc(state->status.program_name);
info_array[use_idx].state = pv_state_alloc();
/*@+mustfreeonly@ */
if (NULL == info_array[use_idx].state)
return 2;