Reformatted with "indent" to a line length of 120.
This commit is contained in:
+2
-4
@@ -33,8 +33,7 @@ void debugging_output_destination(const char *filename)
|
||||
* Output debugging information to the file specified earlier by a call to
|
||||
* debugging_output_destination(), if any.
|
||||
*/
|
||||
void debugging_output(const char *function, const char *file, int line,
|
||||
const char *format, ...)
|
||||
void debugging_output(const char *function, const char *file, int line, const char *format, ...)
|
||||
{
|
||||
static bool tried_open = false;
|
||||
static FILE *debugfptr = NULL;
|
||||
@@ -72,8 +71,7 @@ void debugging_output(const char *function, const char *file, int line,
|
||||
}
|
||||
tbuf[sizeof(tbuf) - 1] = '\0'; /* enforce termination */
|
||||
|
||||
(void) 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);
|
||||
(void) vfprintf(debugfptr, format, ap); /* flawfinder: ignore */
|
||||
|
||||
+15
-33
@@ -72,8 +72,7 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
state = pv_state_alloc(opts->program_name);
|
||||
if (NULL == state) {
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
|
||||
_("state allocation failed"), strerror(errno));
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name, _("state allocation failed"), strerror(errno));
|
||||
opts_free(opts);
|
||||
debug("%s: %d", "exiting with status", 64);
|
||||
return 64;
|
||||
@@ -86,16 +85,14 @@ int main(int argc, char **argv)
|
||||
FILE *pidfptr;
|
||||
pidfptr = fopen(opts->pidfile, "w");
|
||||
if (NULL == pidfptr) {
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
|
||||
opts->pidfile, strerror(errno));
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno));
|
||||
pv_state_free(state);
|
||||
opts_free(opts);
|
||||
return 1;
|
||||
}
|
||||
fprintf(pidfptr, "%d\n", getpid());
|
||||
if (0 != fclose(pidfptr)) {
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
|
||||
opts->pidfile, strerror(errno));
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,8 +107,7 @@ int main(int argc, char **argv)
|
||||
/*
|
||||
* Put our list of files into the PV internal state.
|
||||
*/
|
||||
pv_state_inputfiles(state, opts->argc,
|
||||
(const char **) (opts->argv));
|
||||
pv_state_inputfiles(state, opts->argc, (const char **) (opts->argv));
|
||||
|
||||
if (0 == opts->watch_pid) {
|
||||
/*
|
||||
@@ -120,8 +116,7 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
if ((0 == opts->size) && (false == opts->linemode)) {
|
||||
opts->size = pv_calc_total_size(state);
|
||||
debug("%s: %llu", "no size given - calculated",
|
||||
opts->size);
|
||||
debug("%s: %llu", "no size given - calculated", opts->size);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -154,13 +149,11 @@ int main(int argc, char **argv)
|
||||
pv_screensize(&width, &height);
|
||||
if (0 == opts->width) {
|
||||
opts->width = width;
|
||||
debug("%s: %u", "auto-detected terminal width",
|
||||
width);
|
||||
debug("%s: %u", "auto-detected terminal width", width);
|
||||
}
|
||||
if (0 == opts->height) {
|
||||
opts->height = height;
|
||||
debug("%s: %u", "auto-detected terminal height",
|
||||
height);
|
||||
debug("%s: %u", "auto-detected terminal height", height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,8 +208,7 @@ int main(int argc, char **argv)
|
||||
|
||||
pv_state_set_format(state, opts->progress, opts->timer, opts->eta,
|
||||
opts->fineta, opts->rate, opts->average_rate,
|
||||
opts->bytes, opts->bufpercent,
|
||||
opts->lastwritten, opts->name);
|
||||
opts->bytes, opts->bufpercent, opts->lastwritten, opts->name);
|
||||
|
||||
#ifdef MAKE_STDOUT_NONBLOCKING
|
||||
/*
|
||||
@@ -225,8 +217,7 @@ int main(int argc, char **argv)
|
||||
* Note that this can cause problems with (broken) applications
|
||||
* such as dd.
|
||||
*/
|
||||
fcntl(STDOUT_FILENO, F_SETFL,
|
||||
O_NONBLOCK | fcntl(STDOUT_FILENO, F_GETFL));
|
||||
fcntl(STDOUT_FILENO, F_SETFL, O_NONBLOCK | fcntl(STDOUT_FILENO, F_GETFL));
|
||||
#endif /* MAKE_STDOUT_NONBLOCKING */
|
||||
|
||||
/*
|
||||
@@ -249,8 +240,7 @@ int main(int argc, char **argv)
|
||||
t_saved = true;
|
||||
} else {
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name,
|
||||
_("failed to read terminal attributes"),
|
||||
strerror(errno));
|
||||
_("failed to read terminal attributes"), strerror(errno));
|
||||
}
|
||||
}
|
||||
t_save = t;
|
||||
@@ -266,15 +256,12 @@ int main(int argc, char **argv)
|
||||
pv_sig_init(state);
|
||||
retcode = pv_watchfd_loop(state);
|
||||
if (t_needs_reset && pv_in_foreground()) {
|
||||
(void) tcsetattr(STDERR_FILENO, TCSANOW,
|
||||
&t_save);
|
||||
(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));
|
||||
opts->program_name, opts->pidfile, strerror(errno));
|
||||
}
|
||||
}
|
||||
pv_sig_fini(state);
|
||||
@@ -282,15 +269,12 @@ int main(int argc, char **argv)
|
||||
pv_sig_init(state);
|
||||
retcode = pv_watchpid_loop(state);
|
||||
if (t_needs_reset && pv_in_foreground()) {
|
||||
(void) tcsetattr(STDERR_FILENO, TCSANOW,
|
||||
&t_save);
|
||||
(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));
|
||||
opts->program_name, opts->pidfile, strerror(errno));
|
||||
}
|
||||
}
|
||||
pv_sig_fini(state);
|
||||
@@ -305,9 +289,7 @@ int main(int argc, char **argv)
|
||||
}
|
||||
if (opts->pidfile != NULL) {
|
||||
if (0 != remove(opts->pidfile)) {
|
||||
fprintf(stderr, "%s: %s: %s\n",
|
||||
opts->program_name, opts->pidfile,
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: %s: %s\n", opts->program_name, opts->pidfile, strerror(errno));
|
||||
}
|
||||
}
|
||||
pv_sig_fini(state);
|
||||
|
||||
+19
-47
@@ -95,8 +95,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
};
|
||||
int option_index = 0;
|
||||
#endif /* HAVE_GETOPT_LONG */
|
||||
char *short_options =
|
||||
"hVpteIrab8TA:fnqcWD:s:l0i:w:H:N:F:L:B:CESYKR:P:d:m:"
|
||||
char *short_options = "hVpteIrab8TA:fnqcWD:s:l0i:w:H:N:F:L:B:CESYKR:P:d:m:"
|
||||
#ifdef ENABLE_DEBUGGING
|
||||
"!:"
|
||||
#endif
|
||||
@@ -109,9 +108,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
|
||||
opts = calloc(1, sizeof(*opts));
|
||||
if (!opts) {
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0],
|
||||
_("option structure allocation failed"),
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: %s: %s\n", argv[0], _("option structure allocation failed"), strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -124,8 +121,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
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));
|
||||
_("option structure argv allocation failed"), strerror(errno));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
@@ -140,9 +136,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
|
||||
do {
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
c = getopt_long(argc, argv,
|
||||
short_options, long_options,
|
||||
&option_index);
|
||||
c = getopt_long(argc, argv, short_options, long_options, &option_index);
|
||||
#else
|
||||
c = getopt(argc, argv, short_options);
|
||||
#endif
|
||||
@@ -165,22 +159,16 @@ opts_t opts_parse(int argc, char **argv)
|
||||
case 'B':
|
||||
case 'R':
|
||||
case 'm':
|
||||
if (pv_getnum_check(optarg, PV_NUMTYPE_INTEGER) !=
|
||||
0) {
|
||||
fprintf(stderr, "%s: -%c: %s\n",
|
||||
opts->program_name, c,
|
||||
_("integer argument expected"));
|
||||
if (pv_getnum_check(optarg, PV_NUMTYPE_INTEGER) != 0) {
|
||||
fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("integer argument expected"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
break;
|
||||
case 'i':
|
||||
case 'D':
|
||||
if (pv_getnum_check(optarg, PV_NUMTYPE_DOUBLE) !=
|
||||
0) {
|
||||
fprintf(stderr, "%s: -%c: %s\n",
|
||||
opts->program_name, c,
|
||||
_("numeric argument expected"));
|
||||
if (pv_getnum_check(optarg, PV_NUMTYPE_DOUBLE) != 0) {
|
||||
fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("numeric argument expected"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
@@ -189,16 +177,12 @@ opts_t opts_parse(int argc, char **argv)
|
||||
if (sscanf(optarg, "%u:%d", &check_pid, &check_fd)
|
||||
< 1) {
|
||||
fprintf(stderr, "%s: -%c: %s\n",
|
||||
opts->program_name, c,
|
||||
_
|
||||
("process ID or pid:fd pair expected"));
|
||||
opts->program_name, c, _("process ID or pid:fd pair expected"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
if (check_pid < 1) {
|
||||
fprintf(stderr, "%s: -%c: %s\n",
|
||||
opts->program_name, c,
|
||||
_("invalid process ID"));
|
||||
fprintf(stderr, "%s: -%c: %s\n", opts->program_name, c, _("invalid process ID"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
@@ -297,9 +281,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
} else {
|
||||
fprintf(stderr, "%s: %s %s: %s\n",
|
||||
opts->program_name,
|
||||
_("failed to stat file"),
|
||||
size_file,
|
||||
strerror(errno));
|
||||
_("failed to stat file"), size_file, strerror(errno));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
@@ -361,8 +343,7 @@ opts_t opts_parse(int argc, char **argv)
|
||||
opts->watch_pid = 0;
|
||||
opts->watch_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", &(opts->watch_pid), &(opts->watch_fd));
|
||||
break;
|
||||
case 'm':
|
||||
opts->average_rate_window = pv_getnum_ui(optarg);
|
||||
@@ -374,13 +355,9 @@ opts_t opts_parse(int argc, char **argv)
|
||||
#endif /* ENABLE_DEBUGGING */
|
||||
default:
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
fprintf(stderr,
|
||||
_("Try `%s --help' for more information."),
|
||||
opts->program_name);
|
||||
fprintf(stderr, _("Try `%s --help' for more information."), opts->program_name);
|
||||
#else
|
||||
fprintf(stderr,
|
||||
_("Try `%s -h' for more information."),
|
||||
opts->program_name);
|
||||
fprintf(stderr, _("Try `%s -h' for more information."), opts->program_name);
|
||||
#endif
|
||||
fprintf(stderr, "\n");
|
||||
opts_free(opts);
|
||||
@@ -394,40 +371,35 @@ opts_t opts_parse(int argc, char **argv)
|
||||
|| (opts->skip_errors > 0) || (opts->buffer_size > 0)
|
||||
|| (opts->rate_limit > 0)) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
_
|
||||
("cannot use line mode or transfer modifier options when watching file descriptors"));
|
||||
_("cannot use line mode or transfer modifier options when watching file descriptors"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (opts->cursor) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
_
|
||||
("cannot use cursor positioning when watching file descriptors"));
|
||||
_("cannot use cursor positioning when watching file descriptors"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (0 != opts->remote) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
_
|
||||
("cannot use remote control when watching file descriptors"));
|
||||
_("cannot use remote control when watching file descriptors"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (optind < argc) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
_
|
||||
("cannot transfer files when watching file descriptors"));
|
||||
_("cannot transfer files when watching file descriptors"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
#ifndef __APPLE__
|
||||
if (0 != access("/proc/self/fdinfo", X_OK)) {
|
||||
fprintf(stderr, "%s: -d: %s\n", opts->program_name,
|
||||
_
|
||||
("not available on systems without /proc/self/fdinfo"));
|
||||
_("not available on systems without /proc/self/fdinfo"));
|
||||
opts_free(opts);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
+9
-21
@@ -103,8 +103,7 @@ int pv_remote_set(opts_t opts)
|
||||
* Check that the remote process exists.
|
||||
*/
|
||||
if (kill((pid_t) (opts->remote), 0) != 0) {
|
||||
fprintf(stderr, "%s: %u: %s\n", opts->program_name,
|
||||
opts->remote, strerror(errno));
|
||||
fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -148,29 +147,25 @@ int pv_remote_set(opts_t opts)
|
||||
strncpy(msgbuf.name, opts->name, sizeof(msgbuf.name) - 1);
|
||||
}
|
||||
if (opts->format != NULL) {
|
||||
strncpy(msgbuf.format, opts->format,
|
||||
sizeof(msgbuf.format) - 1);
|
||||
strncpy(msgbuf.format, opts->format, sizeof(msgbuf.format) - 1);
|
||||
}
|
||||
|
||||
msgid = remote__msgget();
|
||||
if (msgid < 0) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
memset(&qbuf, 0, sizeof(qbuf));
|
||||
if (msgctl(msgid, IPC_STAT, &qbuf) < 0) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
initial_qnum = qbuf.msg_qnum;
|
||||
|
||||
if (msgsnd(msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), 0) != 0) {
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name,
|
||||
strerror(errno));
|
||||
fprintf(stderr, "%s: %s\n", opts->program_name, strerror(errno));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -206,9 +201,7 @@ int pv_remote_set(opts_t opts)
|
||||
*/
|
||||
memset(&qbuf, 0, sizeof(qbuf));
|
||||
if (msgctl(msgid, IPC_STAT, &qbuf) >= 0) {
|
||||
(void) msgrcv(msgid, &msgbuf,
|
||||
sizeof(msgbuf) - sizeof(long),
|
||||
(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.
|
||||
@@ -219,8 +212,7 @@ int pv_remote_set(opts_t opts)
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote,
|
||||
_("message not received"));
|
||||
fprintf(stderr, "%s: %u: %s\n", opts->program_name, opts->remote, _("message not received"));
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -242,9 +234,7 @@ void pv_remote_check(pvstate_t state)
|
||||
|
||||
memset(&msgbuf, 0, sizeof(msgbuf));
|
||||
|
||||
got =
|
||||
msgrcv(remote__msgid, &msgbuf, sizeof(msgbuf) - sizeof(long),
|
||||
getpid(), IPC_NOWAIT);
|
||||
got = msgrcv(remote__msgid, &msgbuf, sizeof(msgbuf) - sizeof(long), getpid(), IPC_NOWAIT);
|
||||
if (got < 0) {
|
||||
/*
|
||||
* If our queue had been deleted, re-create it.
|
||||
@@ -265,9 +255,7 @@ void pv_remote_check(pvstate_t state)
|
||||
msgbuf.eta, msgbuf.fineta, msgbuf.rate,
|
||||
msgbuf.average_rate,
|
||||
msgbuf.bytes, msgbuf.bufpercent,
|
||||
msgbuf.lastwritten,
|
||||
'\0' ==
|
||||
msgbuf.name[0] ? NULL : strdup(msgbuf.name));
|
||||
msgbuf.lastwritten, '\0' == msgbuf.name[0] ? NULL : strdup(msgbuf.name));
|
||||
|
||||
if (msgbuf.rate_limit > 0)
|
||||
pv_state_rate_limit_set(state, msgbuf.rate_limit);
|
||||
|
||||
Reference in New Issue
Block a user