summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--discover/pb-discover.c12
-rw-r--r--lib/log/log.c6
-rw-r--r--ui/ncurses/generic-main.c11
-rw-r--r--ui/ncurses/ps3-main.c11
-rw-r--r--ui/twin/main-generic.c11
-rw-r--r--ui/twin/main-ps3.c11
6 files changed, 39 insertions, 23 deletions
diff --git a/discover/pb-discover.c b/discover/pb-discover.c
index fa1c28e..aac50df 100644
--- a/discover/pb-discover.c
+++ b/discover/pb-discover.c
@@ -7,6 +7,7 @@
#include <getopt.h>
#include <stdlib.h>
#include <signal.h>
+#include <string.h>
#include <waiter/waiter.h>
#include <log/log.h>
@@ -103,7 +104,6 @@ int main(int argc, char *argv[])
struct opts opts;
struct udev *udev;
struct user_event *uev;
- FILE *log;
if (opts_parse(&opts, argc, argv)) {
print_usage();
@@ -120,9 +120,13 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
diff --git a/lib/log/log.c b/lib/log/log.c
index 697af6c..ecbd714 100644
--- a/lib/log/log.c
+++ b/lib/log/log.c
@@ -11,7 +11,7 @@ void pb_log(const char *fmt, ...)
va_list ap;
FILE *stream;
- stream = logf ? logf : stdout;
+ stream = logf ? logf : stderr;
va_start(ap, fmt);
vfprintf(stream, fmt, ap);
@@ -23,13 +23,13 @@ void pb_log(const char *fmt, ...)
void pb_log_set_stream(FILE *stream)
{
- fflush(logf ? logf : stdout);
+ fflush(logf ? logf : stderr);
logf = stream;
}
FILE * pb_log_get_stream(void)
{
- return logf;
+ return logf ? logf : stderr;
}
void pb_log_always_flush(int state)
diff --git a/ui/ncurses/generic-main.c b/ui/ncurses/generic-main.c
index 6b8f5ba..4d154ee 100644
--- a/ui/ncurses/generic-main.c
+++ b/ui/ncurses/generic-main.c
@@ -234,7 +234,6 @@ int main(int argc, char *argv[])
static struct opts opts;
int result;
int cui_result;
- FILE *log;
result = opts_parse(&opts, argc, argv);
@@ -253,9 +252,13 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
diff --git a/ui/ncurses/ps3-main.c b/ui/ncurses/ps3-main.c
index 890e47b..69913ed 100644
--- a/ui/ncurses/ps3-main.c
+++ b/ui/ncurses/ps3-main.c
@@ -597,7 +597,6 @@ int main(int argc, char *argv[])
int result;
int cui_result;
unsigned int mode;
- FILE *log;
result = opts_parse(&opts, argc, argv);
@@ -616,9 +615,13 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
diff --git a/ui/twin/main-generic.c b/ui/twin/main-generic.c
index ce6a573..7cf510a 100644
--- a/ui/twin/main-generic.c
+++ b/ui/twin/main-generic.c
@@ -285,7 +285,6 @@ int main(int argc, char *argv[])
static struct pbt_opts opts;
int result;
int ui_result;
- FILE *log;
struct pbt_client *client;
result = pbt_opts_parse(&opts, argc, argv);
@@ -305,9 +304,13 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
diff --git a/ui/twin/main-ps3.c b/ui/twin/main-ps3.c
index 66ba561..138cd28 100644
--- a/ui/twin/main-ps3.c
+++ b/ui/twin/main-ps3.c
@@ -372,7 +372,6 @@ int main(int argc, char *argv[])
int result;
int ui_result = -1;
unsigned int mode;
- FILE *log;
result = pbt_opts_parse(&opts, argc, argv);
@@ -391,9 +390,13 @@ int main(int argc, char *argv[])
return EXIT_SUCCESS;
}
- log = fopen(opts.log_file, "a");
- assert(log);
- pb_log_set_stream(log);
+ if (strcmp(opts.log_file, "-")) {
+ FILE *log = fopen(opts.log_file, "a");
+
+ assert(log);
+ pb_log_set_stream(log);
+ } else
+ pb_log_set_stream(stderr);
#if defined(DEBUG)
pb_log_always_flush(1);
OpenPOWER on IntegriCloud