diff --git a/src/include/options.h b/src/include/options.h index 65f244f..7e5e632 100644 --- a/src/include/options.h +++ b/src/include/options.h @@ -56,7 +56,7 @@ struct opts_s { /* structure describing run-time options */ bool discard_input; /* set to write nothing to stdout */ double interval; /* interval between updates */ double delay_start; /* delay before first display */ - unsigned int watch_pid; /* process to watch fds of */ + pid_t watch_pid; /* process to watch fds of */ int watch_fd; /* fd to watch */ unsigned int average_rate_window; /* time window in seconds for average rate calculations */ unsigned int width; /* screen width */ diff --git a/src/include/pv-internal.h b/src/include/pv-internal.h index 3aece37..32e8b33 100644 --- a/src/include/pv-internal.h +++ b/src/include/pv-internal.h @@ -114,7 +114,7 @@ struct pvstate_s { off_t size; /* total size of data */ double interval; /* interval between updates */ double delay_start; /* delay before first display */ - unsigned int watch_pid; /* process to watch fds of */ + pid_t watch_pid; /* process to watch fds of */ int watch_fd; /* fd to watch */ unsigned int width; /* screen width */ unsigned int height; /* screen height */ @@ -264,7 +264,7 @@ struct pvstate_s { struct pvwatchfd_s { - unsigned int watch_pid; /* PID to watch */ + pid_t watch_pid; /* PID to watch */ int watch_fd; /* fd to watch, -1 = not displayed */ #ifdef __APPLE__ #else @@ -309,7 +309,7 @@ int pv_remote_set(pvstate_t); int pv_watchfd_info(pvstate_t, pvwatchfd_t, int); int pv_watchfd_changed(pvwatchfd_t); -long long pv_watchfd_position(pvwatchfd_t); +off_t pv_watchfd_position(pvwatchfd_t); int pv_watchpid_scanfds(pvstate_t, pvstate_t, unsigned int, int *, pvwatchfd_t *, pvstate_t *, int *); void pv_watchpid_setname(pvstate_t, pvwatchfd_t); diff --git a/src/include/pv.h b/src/include/pv.h index 0e651b5..24e3de1 100644 --- a/src/include/pv.h +++ b/src/include/pv.h @@ -171,7 +171,7 @@ extern void pv_state_width_set(pvstate_t, unsigned int, bool); extern void pv_state_height_set(pvstate_t, unsigned int, bool); extern void pv_state_name_set(pvstate_t, /*@null@*/ const char *); extern void pv_state_format_string_set(pvstate_t, /*@null@*/ const char *); -extern void pv_state_watch_pid_set(pvstate_t, unsigned int); +extern void pv_state_watch_pid_set(pvstate_t, pid_t); extern void pv_state_watch_fd_set(pvstate_t, int); extern void pv_state_average_rate_window_set(pvstate_t, unsigned int); diff --git a/src/main/options.c b/src/main/options.c index 2a3c8be..4a72eb5 100644 --- a/src/main/options.c +++ b/src/main/options.c @@ -157,8 +157,8 @@ opts_t opts_parse(unsigned int argc, char **argv) #endif ; int c, numopts; - unsigned int check_pid; - int check_fd; + unsigned int check_pid, parse_pid; + int check_fd, parse_fd; opts_t opts; char *leafptr; @@ -465,10 +465,12 @@ opts_t opts_parse(unsigned int argc, char **argv) } break; case 'd': - opts->watch_pid = 0; - opts->watch_fd = -1; + parse_pid = 0; + parse_fd = -1; /* No syntax check here, already done earlier */ - (void) sscanf(optarg, "%u:%d", &(opts->watch_pid), &(opts->watch_fd)); + (void) sscanf(optarg, "%u:%d", &parse_pid, &parse_fd); + opts->watch_pid = (pid_t) parse_pid; + opts->watch_fd = parse_fd; break; case 'm': opts->average_rate_window = pv_getnum_count(optarg); diff --git a/src/pv/loop.c b/src/pv/loop.c index 4c3eb73..7ded148 100644 --- a/src/pv/loop.c +++ b/src/pv/loop.c @@ -34,7 +34,8 @@ int pv_main_loop(pvstate_t state) { long lineswritten; - off_t written, total_written, transferred_since_last, cansend; + off_t total_written, transferred_since_last, cansend; + ssize_t written; long double target; bool eof_in, eof_out, final_update; struct timespec start_time, next_update, next_ratecheck, cur_time; @@ -197,6 +198,7 @@ int pv_main_loop(pvstate_t state) written = pv_transfer(state, fd, &eof_in, &eof_out, cansend, &lineswritten); } + /* End on write error. */ if (written < 0) { if (state->cursor) pv_crs_fini(state); @@ -363,12 +365,11 @@ int pv_main_loop(pvstate_t state) int pv_watchfd_loop(pvstate_t state) { struct pvwatchfd_s info; - long long position_now, total_written, transferred_since_last; + off_t position_now, total_written, transferred_since_last; struct timespec next_update, cur_time; struct timespec init_time, next_remotecheck, transfer_elapsed; long double elapsed_seconds; - int ended; - int first_check; + bool ended, first_check; int rc; memset(&info, 0, sizeof(info)); @@ -407,10 +408,10 @@ int pv_watchfd_loop(pvstate_t state) pv_elapsedtime_copy(&next_update, &cur_time); pv_elapsedtime_add_nsec(&next_update, (long long) (1000000000.0 * state->interval)); - ended = 0; + ended = false; total_written = 0; transferred_since_last = 0; - first_check = 1; + first_check = true; while (!ended) { /* @@ -427,13 +428,13 @@ int pv_watchfd_loop(pvstate_t state) position_now = pv_watchfd_position(&info); if (position_now < 0) { - ended = 1; + ended = true; } else { transferred_since_last += position_now - total_written; total_written = position_now; if (first_check) { state->initial_offset = position_now; - first_check = 0; + first_check = false; } } @@ -441,7 +442,6 @@ int pv_watchfd_loop(pvstate_t state) /* Ended - force a display update. */ if (ended) { - ended = 1; pv_elapsedtime_copy(&next_update, &cur_time); } diff --git a/src/pv/number.c b/src/pv/number.c index e62f9be..f1664b9 100644 --- a/src/pv/number.c +++ b/src/pv/number.c @@ -114,7 +114,7 @@ off_t pv_getnum_size(const char *str) if (shiftby > 30) shiftby = 30; - /*@-shiftimplementation@*/ + /*@-shiftimplementation@ */ /* * splint note: ignore the fact that the types we are * shifting are signed, because we know they are definitely @@ -122,7 +122,7 @@ off_t pv_getnum_size(const char *str) */ integral_part = (off_t) (integral_part << shiftby); fractional_part = (off_t) (fractional_part << shiftby); - /*@+shiftimplementation@*/ + /*@+shiftimplementation@ */ shift -= shiftby; } diff --git a/src/pv/state.c b/src/pv/state.c index 29ae4c7..88969f1 100644 --- a/src/pv/state.c +++ b/src/pv/state.c @@ -332,7 +332,7 @@ void pv_state_format_string_set(pvstate_t state, /*@null@ */ const char *val) state->format_string = pv_strdup(val); } -void pv_state_watch_pid_set(pvstate_t state, unsigned int val) +void pv_state_watch_pid_set(pvstate_t state, pid_t val) { state->watch_pid = val; } diff --git a/src/pv/transfer.c b/src/pv/transfer.c index 32019cd..1bafe60 100644 --- a/src/pv/transfer.c +++ b/src/pv/transfer.c @@ -777,7 +777,9 @@ static int pv__transfer_write(pvstate_t state, bool *eof_in, bool *eof_out, long * * Returns NULL on complete allocation failure. */ - /*@null@*//*@only@ */ static char *pv__allocate_aligned_buffer(int fd, size_t target_size) +/*@null@*/ +/*@only@*/ +static char *pv__allocate_aligned_buffer(int fd, size_t target_size) { char *newptr; diff --git a/src/pv/watchpid.c b/src/pv/watchpid.c index 40fbd62..45bc7ae 100644 --- a/src/pv/watchpid.c +++ b/src/pv/watchpid.c @@ -211,9 +211,10 @@ int pv_watchfd_changed(pvwatchfd_t info) * Return the current file position of the given file descriptor, or -1 if * the fd has closed or has changed in some way. */ -long long pv_watchfd_position(pvwatchfd_t info) +off_t pv_watchfd_position(pvwatchfd_t info) { - long long position; + off_t position; + unsigned long long pos_long; #ifdef __APPLE__ struct vnode_fdinfowithpath vnodeInfo = { }; int32_t proc_fd = (int32_t) info->watch_fd; @@ -225,7 +226,7 @@ long long pv_watchfd_position(pvwatchfd_t info) return -1; } - position = (long long) vnodeInfo.pfi.fi_offset; + position = (off_t) vnodeInfo.pfi.fi_offset; #else FILE *fptr; @@ -235,9 +236,10 @@ long long pv_watchfd_position(pvwatchfd_t info) fptr = fopen(info->file_fdinfo, "r"); if (NULL == fptr) return -1; + pos_long = -1; position = -1; - if (1 != fscanf(fptr, "pos: %llu", &position)) - position = -1; + if (1 == fscanf(fptr, "pos: %llu", &pos_long)) + position = (off_t) pos_long; fclose(fptr); #endif @@ -317,7 +319,7 @@ int pv_watchpid_scanfds(pvstate_t state, pvstate_t pristine, while ((d = readdir(dptr)) != NULL) { #endif int fd, check_idx, use_idx, rc; - long long position_now; + off_t position_now; fd = -1; #ifdef __APPLE__