info_msg.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Utility routines.
  4. *
  5. * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  8. */
  9. #include "libbb.h"
  10. #include <syslog.h>
  11. void FAST_FUNC bb_info_msg(const char *s, ...)
  12. {
  13. #ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE
  14. va_list p;
  15. /* va_copy is used because it is not portable
  16. * to use va_list p twice */
  17. va_list p2;
  18. va_start(p, s);
  19. va_copy(p2, p);
  20. if (logmode & LOGMODE_STDIO) {
  21. vprintf(s, p);
  22. fputs(msg_eol, stdout);
  23. }
  24. if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG))
  25. vsyslog(LOG_INFO, s, p2);
  26. va_end(p2);
  27. va_end(p);
  28. #else
  29. int used;
  30. char *msg;
  31. va_list p;
  32. if (logmode == 0)
  33. return;
  34. va_start(p, s);
  35. used = vasprintf(&msg, s, p);
  36. va_end(p);
  37. if (used < 0)
  38. return;
  39. if (ENABLE_FEATURE_SYSLOG && (logmode & LOGMODE_SYSLOG))
  40. syslog(LOG_INFO, "%s", msg);
  41. if (logmode & LOGMODE_STDIO) {
  42. fflush_all();
  43. /* used = strlen(msg); - must be true already */
  44. msg[used++] = '\n';
  45. full_write(STDOUT_FILENO, msg, used);
  46. }
  47. free(msg);
  48. #endif
  49. }