hush: move msh/lash config into hush.c, no code changes
[oweals/busybox.git] / libbb / info_msg.c
index b0ce64338e7def89c9bde905ed3743567016259a..81164faa0a5854f2af1b79525e2e9316427621ba 100644 (file)
@@ -7,11 +7,14 @@
  * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  */
 
-#include <syslog.h>
 #include "libbb.h"
+#if ENABLE_FEATURE_SYSLOG
+# include <syslog.h>
+#endif
 
-void bb_info_msg(const char *s, ...)
+void FAST_FUNC bb_info_msg(const char *s, ...)
 {
+#ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE
        va_list p;
        /* va_copy is used because it is not portable
         * to use va_list p twice */
@@ -23,8 +26,37 @@ void bb_info_msg(const char *s, ...)
                vprintf(s, p);
                fputs(msg_eol, stdout);
        }
-       if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG))
+# if ENABLE_FEATURE_SYSLOG
+       if (logmode & LOGMODE_SYSLOG)
                vsyslog(LOG_INFO, s, p2);
+# endif
        va_end(p2);
        va_end(p);
+#else
+       int used;
+       char *msg;
+       va_list p;
+
+       if (logmode == 0)
+               return;
+
+       va_start(p, s);
+       used = vasprintf(&msg, s, p);
+       va_end(p);
+       if (used < 0)
+               return;
+
+# if ENABLE_FEATURE_SYSLOG
+       if (logmode & LOGMODE_SYSLOG)
+               syslog(LOG_INFO, "%s", msg);
+# endif
+       if (logmode & LOGMODE_STDIO) {
+               fflush_all();
+               /* used = strlen(msg); - must be true already */
+               msg[used++] = '\n';
+               full_write(STDOUT_FILENO, msg, used);
+       }
+
+       free(msg);
+#endif
 }