Make sure we don't user std{err,in,out} if they don't exist.
authorSylvain Munaut <tnt@246tNt.com>
Fri, 17 Sep 2010 12:38:17 +0000 (14:38 +0200)
committerSylvain Munaut <tnt@246tNt.com>
Fri, 17 Sep 2010 12:38:17 +0000 (14:38 +0200)
This is required for target build in libosmocore

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
src/logging.c
src/process.c

index 5be4e58..b3b5cb6 100644 (file)
@@ -294,14 +294,11 @@ void log_set_category_filter(struct log_target *target, int category,
        target->categories[category].loglevel = level;
 }
 
-/* since C89/C99 says stderr is a macro, we can safely do this! */
-#ifdef stderr
 static void _file_output(struct log_target *target, const char *log)
 {
        fprintf(target->tgt_file.out, "%s", log);
        fflush(target->tgt_file.out);
 }
-#endif
 
 struct log_target *log_target_create(void)
 {
@@ -374,8 +371,12 @@ void log_target_destroy(struct log_target *target)
        log_del_target(target);
 
        if (target->output == &_file_output) {
+/* since C89/C99 says stderr is a macro, we can safely do this! */
+#ifdef stderr
                /* don't close stderr */
-               if (target->tgt_file.out != stderr) {
+               if (target->tgt_file.out != stderr)
+#endif
+               {
                        fclose(target->tgt_file.out);
                        target->tgt_file.out = NULL;
                }
index ab4b37e..180efa5 100644 (file)
@@ -63,9 +63,12 @@ int osmo_daemonize(void)
                return rc;
 
        /* Redirect stdio to /dev/null */
+/* since C89/C99 says stderr is a macro, we can safely do this! */
+#ifdef stderr
        freopen("/dev/null", "r", stdin);
        freopen("/dev/null", "w", stdout);
        freopen("/dev/null", "w", stderr);
+#endif
 
        return 0;
 }