Added all changes made between v1.6.6 and June 2020

This commit is contained in:
Andrew Wood
2021-09-04 21:00:00 +01:00
parent 9dd06d8acb
commit 7d68a574ca
33 changed files with 2067 additions and 1825 deletions
+16 -12
View File
@@ -23,7 +23,7 @@
void debugging_output(const char *function, const char *file, int line,
const char *format, ...)
{
static int tried_open = 0;
static bool tried_open = false;
static FILE *debugfptr = NULL;
char *debugfile;
va_list ap;
@@ -31,30 +31,31 @@ void debugging_output(const char *function, const char *file, int line,
struct tm *tm;
char tbuf[128];
if (0 == tried_open) {
if (false == tried_open) {
debugfile = getenv("DEBUG");
if (NULL != debugfile)
debugfptr = fopen(debugfile, "a");
tried_open = 1;
tried_open = true;
}
if (NULL == debugfptr)
return;
time(&t);
(void) time(&t);
tm = localtime(&t);
tbuf[0] = 0;
strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", tm);
tbuf[0] = '\0';
if (0 == strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", tm))
tbuf[0] = '\0';
fprintf(debugfptr, "[%s] (%d) %s (%s:%d): ", tbuf, getpid(),
function, file, line);
(void) fprintf(debugfptr, "[%s] (%d) %s (%s:%d): ", tbuf, getpid(),
function, file, line);
va_start(ap, format);
vfprintf(debugfptr, format, ap);
(void) vfprintf(debugfptr, format, ap);
va_end(ap);
fprintf(debugfptr, "\n");
fflush(debugfptr);
(void) fprintf(debugfptr, "\n");
(void) fflush(debugfptr);
}
#else /* ! ENABLE_DEBUGGING */
@@ -62,7 +63,10 @@ void debugging_output(const char *function, const char *file, int line,
/*
* Stub debugging output function.
*/
void debugging_output(const char *function, const char *file, int line,
void debugging_output( __attribute__ ((unused))
const char *function, __attribute__ ((unused))
const char *file, __attribute__ ((unused))
int line, __attribute__ ((unused))
const char *format, ...)
{
}
+16 -10
View File
@@ -103,7 +103,7 @@ void display_help(void)
N_("show version information and exit")},
{0, 0, 0, 0}
};
int i, col1max = 0, tw = 77;
unsigned int i, col1max = 0, tw = 77;
char *optbuf;
printf(_("Usage: %s [OPTION] [FILE]..."), PROGRAM_NAME);
@@ -113,13 +113,14 @@ void display_help(void)
"with monitoring."));
for (i = 0; optlist[i].optshort; i++) {
int width = 0;
unsigned int width = 0;
char *param;
width = 2 + strlen(optlist[i].optshort);
width = 2 + (unsigned int) strlen(optlist[i].optshort);
#ifdef HAVE_GETOPT_LONG
if (optlist[i].optlong)
width += 2 + strlen(optlist[i].optlong);
width +=
2 + (unsigned int) strlen(optlist[i].optlong);
#endif
param = optlist[i].param;
if (param)
@@ -133,10 +134,10 @@ void display_help(void)
col1max++;
optbuf = malloc(col1max + 16);
optbuf = malloc((size_t) (col1max + 16));
if (NULL == optbuf) {
fprintf(stderr, "%s: %s\n", PROGRAM_NAME, strerror(errno));
exit(1);
exit(EXIT_FAILURE);
}
for (i = 0; optlist[i].optshort; i++) {
@@ -145,7 +146,7 @@ void display_help(void)
char *start;
char *end;
if (0 == optlist[i].optshort[0]) {
if ('\0' == optlist[i].optshort[0]) {
printf("\n");
continue;
}
@@ -157,7 +158,12 @@ void display_help(void)
if (description)
description = _(description);
#ifdef HAVE_SNPRINTF
(void) snprintf(optbuf, (size_t) (col1max + 15),
"%s%s%s%s%s", optlist[i].optshort,
#else
sprintf(optbuf, "%s%s%s%s%s", optlist[i].optshort,
#endif
#ifdef HAVE_GETOPT_LONG
optlist[i].optlong ? ", " : "",
optlist[i].optlong ? optlist[i].optlong : "",
@@ -166,7 +172,7 @@ void display_help(void)
#endif
param ? " " : "", param ? param : "");
printf(" %-*s ", col1max - 2, optbuf);
printf(" %-*s ", (int) (col1max - 2), optbuf);
if (NULL == description) {
printf("\n");
@@ -175,7 +181,7 @@ void display_help(void)
start = description;
while (strlen(start) > tw - col1max) {
while ((unsigned int) strlen(start) > tw - col1max) {
end = start + tw - col1max;
while ((end > start) && (end[0] != ' '))
end--;
@@ -185,7 +191,7 @@ void display_help(void)
end++;
}
printf("%.*s\n%*s ", (int) (end - start), start,
col1max, "");
(int) col1max, "");
if (end == start)
end++;
start = end;
+70 -21
View File
@@ -35,12 +35,13 @@ int main(int argc, char **argv)
struct termios t, t_save;
opts_t opts;
pvstate_t state;
bool t_saved, t_needs_reset;
int retcode = 0;
#ifdef ENABLE_NLS
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
(void) setlocale(LC_ALL, "");
(void) bindtextdomain(PACKAGE, LOCALEDIR);
(void) textdomain(PACKAGE);
#endif
opts = opts_parse(argc, argv);
@@ -90,7 +91,10 @@ int main(int argc, char **argv)
return 1;
}
fprintf(pidfptr, "%d\n", getpid());
fclose(pidfptr);
if (0 != fclose(pidfptr)) {
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
opts->pidfile, strerror(errno));
}
}
/*
@@ -112,7 +116,7 @@ int main(int argc, char **argv)
* If no size was given, and we're not in line mode, try to
* calculate the total size.
*/
if ((0 == opts->size) && (0 == opts->linemode)) {
if ((0 == opts->size) && (false == opts->linemode)) {
opts->size = pv_calc_total_size(state);
debug("%s: %llu", "no size given - calculated",
opts->size);
@@ -122,7 +126,7 @@ int main(int argc, char **argv)
* If the size is unknown, we cannot have an ETA.
*/
if (opts->size < 1) {
opts->eta = 0;
opts->eta = false;
debug("%s", "size unknown - ETA disabled");
}
}
@@ -132,9 +136,9 @@ int main(int argc, char **argv)
* outputting numerically, we will have nothing to display at all.
*/
if ((0 == isatty(STDERR_FILENO))
&& (0 == opts->force)
&& (0 == opts->numeric)) {
opts->no_op = 1;
&& (false == opts->force)
&& (false == opts->numeric)) {
opts->no_op = true;
debug("%s", "nothing to display - setting no_op");
}
@@ -219,6 +223,13 @@ int main(int argc, char **argv)
O_NONBLOCK | fcntl(STDOUT_FILENO, F_GETFL));
#endif /* MAKE_STDOUT_NONBLOCKING */
/*
* Keep track of whether we've saved the terminal attributes and
* whether we need to reset them at the end.
*/
t_saved = false;
t_needs_reset = false;
/*
* Set terminal option TOSTOP so we get signal SIGTTOU if we try to
* write to the terminal while backgrounded.
@@ -226,25 +237,56 @@ int main(int argc, char **argv)
* Also, save the current terminal attributes for later restoration.
*/
memset(&t, 0, sizeof(t));
tcgetattr(STDERR_FILENO, &t);
if (0 != isatty(STDERR_FILENO)) {
if (0 == tcgetattr(STDERR_FILENO, &t)) {
debug("%s", "saved terminal attributes");
t_saved = true;
} else {
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
_("failed to read terminal attributes"),
strerror(errno));
}
}
t_save = t;
t.c_lflag |= TOSTOP;
tcsetattr(STDERR_FILENO, TCSANOW, &t);
if (t_saved && pv_in_foreground()) {
t.c_lflag |= TOSTOP;
(void) tcsetattr(STDERR_FILENO, TCSANOW, &t);
t_needs_reset = true;
debug("%s", "set terminal TOSTOP attribute");
}
if (0 != opts->watch_pid) {
if (0 <= opts->watch_fd) {
pv_sig_init(state);
retcode = pv_watchfd_loop(state);
tcsetattr(STDERR_FILENO, TCSANOW, &t_save);
if (opts->pidfile != NULL)
remove(opts->pidfile);
if (t_needs_reset && pv_in_foreground()) {
(void) tcsetattr(STDERR_FILENO, TCSANOW,
&t_save);
}
if (opts->pidfile != NULL) {
if (0 != remove(opts->pidfile)) {
fprintf(stderr, "%s: %s: %s\n",
opts->program_name,
opts->pidfile,
strerror(errno));
}
}
pv_sig_fini(state);
} else {
pv_sig_init(state);
retcode = pv_watchpid_loop(state);
tcsetattr(STDERR_FILENO, TCSANOW, &t_save);
if (opts->pidfile != NULL)
remove(opts->pidfile);
if (t_needs_reset && pv_in_foreground()) {
(void) tcsetattr(STDERR_FILENO, TCSANOW,
&t_save);
}
if (opts->pidfile != NULL) {
if (0 != remove(opts->pidfile)) {
fprintf(stderr, "%s: %s: %s\n",
opts->program_name,
opts->pidfile,
strerror(errno));
}
}
pv_sig_fini(state);
}
} else {
@@ -252,9 +294,16 @@ int main(int argc, char **argv)
pv_remote_init();
retcode = pv_main_loop(state);
pv_remote_fini();
tcsetattr(STDERR_FILENO, TCSANOW, &t_save);
if (opts->pidfile != NULL)
remove(opts->pidfile);
if (t_needs_reset && pv_in_foreground()) {
(void) tcsetattr(STDERR_FILENO, TCSANOW, &t_save);
}
if (opts->pidfile != NULL) {
if (0 != remove(opts->pidfile)) {
fprintf(stderr, "%s: %s: %s\n",
opts->program_name, opts->pidfile,
strerror(errno));
}
}
pv_sig_fini(state);
}
+106 -118
View File
@@ -27,7 +27,7 @@ void opts_free(opts_t opts)
{
if (!opts)
return;
if (opts->argv)
if (NULL != opts->argv)
free(opts->argv);
free(opts);
}
@@ -47,40 +47,40 @@ opts_t opts_parse(int argc, char **argv)
{
#ifdef HAVE_GETOPT_LONG
struct option long_options[] = {
{"help", 0, 0, 'h'},
{"version", 0, 0, 'V'},
{"progress", 0, 0, 'p'},
{"timer", 0, 0, 't'},
{"eta", 0, 0, 'e'},
{"fineta", 0, 0, 'I'},
{"rate", 0, 0, 'r'},
{"average-rate", 0, 0, 'a'},
{"bytes", 0, 0, 'b'},
{"buffer-percent", 0, 0, 'T'},
{"last-written", 1, 0, 'A'},
{"force", 0, 0, 'f'},
{"numeric", 0, 0, 'n'},
{"quiet", 0, 0, 'q'},
{"cursor", 0, 0, 'c'},
{"wait", 0, 0, 'W'},
{"delay-start", 1, 0, 'D'},
{"size", 1, 0, 's'},
{"line-mode", 0, 0, 'l'},
{"null", 0, 0, '0'},
{"interval", 1, 0, 'i'},
{"width", 1, 0, 'w'},
{"height", 1, 0, 'H'},
{"name", 1, 0, 'N'},
{"format", 1, 0, 'F'},
{"rate-limit", 1, 0, 'L'},
{"buffer-size", 1, 0, 'B'},
{"no-splice", 0, 0, 'C'},
{"skip-errors", 0, 0, 'E'},
{"stop-at-size", 0, 0, 'S'},
{"remote", 1, 0, 'R'},
{"pidfile", 1, 0, 'P'},
{"watchfd", 1, 0, 'd'},
{0, 0, 0, 0}
{"help", 0, NULL, (int) 'h'},
{"version", 0, NULL, (int) 'V'},
{"progress", 0, NULL, (int) 'p'},
{"timer", 0, NULL, (int) 't'},
{"eta", 0, NULL, (int) 'e'},
{"fineta", 0, NULL, (int) 'I'},
{"rate", 0, NULL, (int) 'r'},
{"average-rate", 0, NULL, (int) 'a'},
{"bytes", 0, NULL, (int) 'b'},
{"buffer-percent", 0, NULL, (int) 'T'},
{"last-written", 1, NULL, (int) 'A'},
{"force", 0, NULL, (int) 'f'},
{"numeric", 0, NULL, (int) 'n'},
{"quiet", 0, NULL, (int) 'q'},
{"cursor", 0, NULL, (int) 'c'},
{"wait", 0, NULL, (int) 'W'},
{"delay-start", 1, NULL, (int) 'D'},
{"size", 1, NULL, (int) 's'},
{"line-mode", 0, NULL, (int) 'l'},
{"null", 0, NULL, (int) '0'},
{"interval", 1, NULL, (int) 'i'},
{"width", 1, NULL, (int) 'w'},
{"height", 1, NULL, (int) 'H'},
{"name", 1, NULL, (int) 'N'},
{"format", 1, NULL, (int) 'F'},
{"rate-limit", 1, NULL, (int) 'L'},
{"buffer-size", 1, NULL, (int) 'B'},
{"no-splice", 0, NULL, (int) 'C'},
{"skip-errors", 0, NULL, (int) 'E'},
{"stop-at-size", 0, NULL, (int) 'S'},
{"remote", 1, NULL, (int) 'R'},
{"pidfile", 1, NULL, (int) 'P'},
{"watchfd", 1, NULL, (int) 'd'},
{NULL, 0, NULL, 0}
};
int option_index = 0;
#endif
@@ -94,28 +94,25 @@ opts_t opts_parse(int argc, char **argv)
opts = calloc(1, sizeof(*opts));
if (!opts) {
fprintf(stderr,
_("%s: option structure allocation failed (%s)"),
argv[0], strerror(errno));
fprintf(stderr, "\n");
return 0;
fprintf(stderr, "%s: %s: %s\n", argv[0],
_("option structure allocation failed"),
strerror(errno));
return NULL;
}
opts->program_name = argv[0];
ptr = strrchr(opts->program_name, '/');
if (NULL != ptr)
opts->program_name = &(ptr[1]);
opts->program_name = 1 + ptr;
opts->argc = 0;
opts->argv = calloc(argc + 1, sizeof(char *));
if (!opts->argv) {
fprintf(stderr,
_
("%s: option structure argv allocation failed (%s)"),
opts->program_name, strerror(errno));
fprintf(stderr, "\n");
opts->argv = calloc((size_t) (argc + 1), sizeof(char *));
if (NULL == opts->argv) {
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
_("option structure argv allocation failed"),
strerror(errno));
opts_free(opts);
return 0;
return NULL;
}
numopts = 0;
@@ -153,7 +150,7 @@ opts_t opts_parse(int argc, char **argv)
opts->program_name, c,
_("integer argument expected"));
opts_free(opts);
return 0;
return NULL;
}
break;
case 'i':
@@ -164,7 +161,7 @@ opts_t opts_parse(int argc, char **argv)
opts->program_name, c,
_("numeric argument expected"));
opts_free(opts);
return 0;
return NULL;
}
break;
case 'd':
@@ -175,14 +172,14 @@ opts_t opts_parse(int argc, char **argv)
_
("process ID or pid:fd pair expected"));
opts_free(opts);
return 0;
return NULL;
}
if (check_pid < 1) {
fprintf(stderr, "%s: -%c: %s\n",
opts->program_name, c,
_("invalid process ID"));
opts_free(opts);
return 0;
return NULL;
}
break;
default:
@@ -195,109 +192,110 @@ opts_t opts_parse(int argc, char **argv)
switch (c) {
case 'h':
display_help();
opts->do_nothing = 1;
return opts;
break;
opts->do_nothing = true;
return opts; /* early return */
case 'V':
display_version();
opts->do_nothing = 1;
return opts;
break;
opts->do_nothing = true;
return opts; /* early return */
case 'p':
opts->progress = 1;
opts->progress = true;
numopts++;
break;
case 't':
opts->timer = 1;
opts->timer = true;
numopts++;
break;
case 'I':
opts->fineta = 1;
opts->fineta = true;
numopts++;
break;
case 'e':
opts->eta = 1;
opts->eta = true;
numopts++;
break;
case 'r':
opts->rate = 1;
opts->rate = true;
numopts++;
break;
case 'a':
opts->average_rate = 1;
opts->average_rate = true;
numopts++;
break;
case 'b':
opts->bytes = 1;
opts->bytes = true;
numopts++;
break;
case 'T':
opts->bufpercent = 1;
opts->bufpercent = true;
numopts++;
opts->no_splice = true;
break;
case 'A':
opts->lastwritten = pv_getnum_i(optarg);
opts->lastwritten = pv_getnum_ui(optarg);
numopts++;
opts->no_splice = true;
break;
case 'f':
opts->force = 1;
opts->force = true;
break;
case 'n':
opts->numeric = 1;
opts->numeric = true;
numopts++;
break;
case 'q':
opts->no_op = 1;
opts->no_op = true;
numopts++;
break;
case 'c':
opts->cursor = 1;
opts->cursor = true;
break;
case 'W':
opts->wait = 1;
opts->wait = true;
break;
case 'D':
opts->delay_start = pv_getnum_d(optarg);
break;
case 's':
opts->size = pv_getnum_ll(optarg);
opts->size = pv_getnum_ull(optarg);
break;
case 'l':
opts->linemode = 1;
opts->linemode = true;
break;
case '0':
opts->null = 1;
opts->linemode = 1;
opts->null = true;
opts->linemode = true;
break;
case 'i':
opts->interval = pv_getnum_d(optarg);
break;
case 'w':
opts->width = pv_getnum_i(optarg);
opts->width = pv_getnum_ui(optarg);
break;
case 'H':
opts->height = pv_getnum_i(optarg);
opts->height = pv_getnum_ui(optarg);
break;
case 'N':
opts->name = optarg;
break;
case 'L':
opts->rate_limit = pv_getnum_ll(optarg);
opts->rate_limit = pv_getnum_ull(optarg);
break;
case 'B':
opts->buffer_size = pv_getnum_ll(optarg);
opts->buffer_size = pv_getnum_ull(optarg);
opts->no_splice = true;
break;
case 'C':
opts->no_splice = 1;
opts->no_splice = true;
break;
case 'E':
opts->skip_errors++;
break;
case 'S':
opts->stop_at_size = 1;
opts->stop_at_size = true;
break;
case 'R':
opts->remote = pv_getnum_i(optarg);
opts->remote = pv_getnum_ui(optarg);
break;
case 'P':
opts->pidfile = optarg;
@@ -308,8 +306,9 @@ opts_t opts_parse(int argc, char **argv)
case 'd':
opts->watch_pid = 0;
opts->watch_fd = -1;
sscanf(optarg, "%u:%d", &(opts->watch_pid),
&(opts->watch_fd));
/* No syntax check here, already done earlier */
(void) sscanf(optarg, "%u:%d", &(opts->watch_pid),
&(opts->watch_fd));
break;
default:
#ifdef HAVE_GETOPT_LONG
@@ -323,8 +322,7 @@ opts_t opts_parse(int argc, char **argv)
#endif
fprintf(stderr, "\n");
opts_free(opts);
return 0;
break;
return NULL; /* early return */
}
} while (c != -1);
@@ -333,53 +331,43 @@ opts_t opts_parse(int argc, char **argv)
if (opts->linemode || opts->null || opts->stop_at_size
|| (opts->skip_errors > 0) || (opts->buffer_size > 0)
|| (opts->rate_limit > 0)) {
fprintf(stderr,
fprintf(stderr, "%s: %s\n", opts->program_name,
_
("%s: cannot use line mode or transfer modifier options when watching file descriptors"),
opts->program_name);
fprintf(stderr, "\n");
("cannot use line mode or transfer modifier options when watching file descriptors"));
opts_free(opts);
return 0;
return NULL;
}
if (opts->cursor) {
fprintf(stderr,
fprintf(stderr, "%s: %s\n", opts->program_name,
_
("%s: cannot use cursor positioning when watching file descriptors"),
opts->program_name);
fprintf(stderr, "\n");
("cannot use cursor positioning when watching file descriptors"));
opts_free(opts);
return 0;
return NULL;
}
if (0 != opts->remote) {
fprintf(stderr,
fprintf(stderr, "%s: %s\n", opts->program_name,
_
("%s: cannot use remote control when watching file descriptors"),
opts->program_name);
fprintf(stderr, "\n");
("cannot use remote control when watching file descriptors"));
opts_free(opts);
return 0;
return NULL;
}
if (optind < argc) {
fprintf(stderr,
fprintf(stderr, "%s: %s\n", opts->program_name,
_
("%s: cannot transfer files when watching file descriptors"),
opts->program_name);
fprintf(stderr, "\n");
("cannot transfer files when watching file descriptors"));
opts_free(opts);
return 0;
return NULL;
}
if (0 != access("/proc/self/fdinfo", X_OK)) {
fprintf(stderr,
fprintf(stderr, "%s: -d: %s\n", opts->program_name,
_
("%s: -d: not available on systems without /proc/self/fdinfo"),
opts->program_name);
fprintf(stderr, "\n");
("not available on systems without /proc/self/fdinfo"));
opts_free(opts);
return 0;
return NULL;
}
}
@@ -387,11 +375,11 @@ opts_t opts_parse(int argc, char **argv)
* Default options: -pterb
*/
if (0 == numopts) {
opts->progress = 1;
opts->timer = 1;
opts->eta = 1;
opts->rate = 1;
opts->bytes = 1;
opts->progress = true;
opts->timer = true;
opts->eta = true;
opts->rate = true;
opts->bytes = true;
}
/*
+33 -29
View File
@@ -25,14 +25,14 @@
#ifdef HAVE_IPC
struct remote_msg {
long mtype;
unsigned char progress; /* progress bar flag */
unsigned char timer; /* timer flag */
unsigned char eta; /* ETA flag */
unsigned char fineta; /* absolute ETA flag */
unsigned char rate; /* rate counter flag */
unsigned char average_rate; /* average rate counter flag */
unsigned char bytes; /* bytes transferred flag */
unsigned char bufpercent; /* transfer buffer percentage flag */
bool progress; /* progress bar flag */
bool timer; /* timer flag */
bool eta; /* ETA flag */
bool fineta; /* absolute ETA flag */
bool rate; /* rate counter flag */
bool average_rate; /* average rate counter flag */
bool bytes; /* bytes transferred flag */
bool bufpercent; /* transfer buffer percentage flag */
unsigned int lastwritten; /* last-written bytes count */
unsigned long long rate_limit; /* rate limit, in bytes per second */
unsigned long long buffer_size; /* buffer size, in bytes (0=default) */
@@ -59,14 +59,12 @@ static int remote__msgid = -1;
*/
static key_t remote__genkey(void)
{
int uid;
uid_t uid;
key_t key;
uid = geteuid();
if (uid < 0)
uid = 0;
key = ftok("/tmp", 'P') | uid;
key = ftok("/tmp", (int) 'P') | uid;
return key;
}
@@ -79,7 +77,7 @@ static key_t remote__genkey(void)
static int remote__msgget(void)
{
/* Catch SIGSYS in case msgget() raises it, so we get ENOSYS */
signal(SIGSYS, SIG_IGN);
(void) signal(SIGSYS, SIG_IGN);
return msgget(remote__genkey(), IPC_CREAT | 0600);
}
@@ -97,13 +95,13 @@ int pv_remote_set(opts_t opts)
struct msqid_ds qbuf;
long timeout;
int msgid;
long initial_qnum;
unsigned long initial_qnum;
/*
* Check that the remote process exists.
*/
if (kill(opts->remote, 0) != 0) {
fprintf(stderr, "%s: %d: %s\n", opts->program_name,
if (kill((pid_t) (opts->remote), 0) != 0) {
fprintf(stderr, "%s: %u: %s\n", opts->program_name,
opts->remote, strerror(errno));
return 1;
}
@@ -111,15 +109,15 @@ int pv_remote_set(opts_t opts)
/*
* Make sure parameters are within sensible bounds.
*/
if (opts->width < 0)
if (opts->width < 1)
opts->width = 80;
if (opts->height < 0)
if (opts->height < 1)
opts->height = 25;
if (opts->width > 999999)
opts->width = 999999;
if (opts->height > 999999)
opts->height = 999999;
if ((opts->interval != 0) && (opts->interval < 0.1))
if ((opts->interval > 0) && (opts->interval < 0.1))
opts->interval = 0.1;
if (opts->interval > 600)
opts->interval = 600;
@@ -128,7 +126,7 @@ int pv_remote_set(opts_t opts)
* Copy parameters into message buffer.
*/
memset(&msgbuf, 0, sizeof(msgbuf));
msgbuf.mtype = opts->remote;
msgbuf.mtype = (long) (opts->remote);
msgbuf.progress = opts->progress;
msgbuf.timer = opts->timer;
msgbuf.eta = opts->eta;
@@ -159,6 +157,7 @@ int pv_remote_set(opts_t opts)
return 1;
}
memset(&qbuf, 0, sizeof(qbuf));
if (msgctl(msgid, IPC_STAT, &qbuf) < 0) {
fprintf(stderr, "%s: %s\n", opts->program_name,
strerror(errno));
@@ -178,14 +177,16 @@ int pv_remote_set(opts_t opts)
while (timeout > 10000) {
struct timeval tv;
memset(&tv, 0, sizeof(tv));
tv.tv_sec = 0;
tv.tv_usec = 10000;
select(0, NULL, NULL, NULL, &tv);
(void) select(0, NULL, NULL, NULL, &tv);
timeout -= 10000;
/*
* If we can't stat the queue, it must have been deleted.
*/
memset(&qbuf, 0, sizeof(qbuf));
if (msgctl(msgid, IPC_STAT, &qbuf) < 0)
break;
@@ -201,20 +202,22 @@ int pv_remote_set(opts_t opts)
/*
* Message not received - delete it.
*/
memset(&qbuf, 0, sizeof(qbuf));
if (msgctl(msgid, IPC_STAT, &qbuf) >= 0) {
msgrcv(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long),
opts->remote, IPC_NOWAIT);
(void) msgrcv(msgid, &msgbuf,
sizeof(msgbuf) - sizeof(long),
(long) (opts->remote), IPC_NOWAIT);
/*
* If this leaves nothing on the queue, remove the
* queue, in case we created one for no reason.
*/
if (msgctl(msgid, IPC_STAT, &qbuf) >= 0) {
if (qbuf.msg_qnum < 1)
msgctl(msgid, IPC_RMID, &qbuf);
(void) msgctl(msgid, IPC_RMID, &qbuf);
}
}
fprintf(stderr, "%s: %d: %s\n", opts->program_name, opts->remote,
fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote,
_("message not received"));
return 1;
}
@@ -230,7 +233,7 @@ int pv_remote_set(opts_t opts)
void pv_remote_check(pvstate_t state)
{
struct remote_msg msgbuf;
int got;
ssize_t got;
if (remote__msgid < 0)
return;
@@ -261,7 +264,7 @@ void pv_remote_check(pvstate_t state)
msgbuf.average_rate,
msgbuf.bytes, msgbuf.bufpercent,
msgbuf.lastwritten,
0 ==
'\0' ==
msgbuf.name[0] ? NULL : strdup(msgbuf.name));
if (msgbuf.rate_limit > 0)
@@ -277,7 +280,7 @@ void pv_remote_check(pvstate_t state)
pv_state_width_set(state, msgbuf.width);
if (msgbuf.height > 0)
pv_state_height_set(state, msgbuf.height);
if (msgbuf.format[0] != 0)
if (msgbuf.format[0] != '\0')
pv_state_format_string_set(state, strdup(msgbuf.format));
}
@@ -298,7 +301,8 @@ void pv_remote_fini(void)
{
if (remote__msgid >= 0) {
struct msqid_ds qbuf;
msgctl(remote__msgid, IPC_RMID, &qbuf);
memset(&qbuf, 0, sizeof(qbuf));
(void) msgctl(remote__msgid, IPC_RMID, &qbuf);
}
}