blob: 56ca2efd4d0039c5a3c05e67f001add824ff9bb9 [file] [log] [blame]
Denis Vlasenko3da6aa82006-09-07 05:09:22 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Utility routines.
4 *
5 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02007 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Denis Vlasenko3da6aa82006-09-07 05:09:22 +00008 */
9
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000010#include "libbb.h"
Nguyễn Thái Ngọc Duy125d0152010-04-09 14:34:28 +020011#if ENABLE_FEATURE_SYSLOG
12# include <syslog.h>
13#endif
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000014
Denis Vlasenkodefc1ea2008-06-27 02:52:20 +000015void FAST_FUNC bb_info_msg(const char *s, ...)
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000016{
Denis Vlasenko517413f2008-12-10 11:16:47 +000017#ifdef THIS_ONE_DOESNT_DO_SINGLE_WRITE
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000018 va_list p;
Denis Vlasenkodbe6e662007-08-14 16:43:01 +000019 /* va_copy is used because it is not portable
20 * to use va_list p twice */
21 va_list p2;
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000022
23 va_start(p, s);
Denis Vlasenkodbe6e662007-08-14 16:43:01 +000024 va_copy(p2, p);
25 if (logmode & LOGMODE_STDIO) {
26 vprintf(s, p);
27 fputs(msg_eol, stdout);
28 }
Nguyễn Thái Ngọc Duy125d0152010-04-09 14:34:28 +020029# if ENABLE_FEATURE_SYSLOG
30 if (logmode & LOGMODE_SYSLOG)
Denis Vlasenkodbe6e662007-08-14 16:43:01 +000031 vsyslog(LOG_INFO, s, p2);
Nguyễn Thái Ngọc Duy125d0152010-04-09 14:34:28 +020032# endif
Denis Vlasenkodbe6e662007-08-14 16:43:01 +000033 va_end(p2);
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000034 va_end(p);
Denis Vlasenko517413f2008-12-10 11:16:47 +000035#else
36 int used;
37 char *msg;
38 va_list p;
39
40 if (logmode == 0)
41 return;
42
43 va_start(p, s);
44 used = vasprintf(&msg, s, p);
Denys Vlasenko78fcec42009-12-13 17:42:49 +010045 va_end(p);
Denis Vlasenko517413f2008-12-10 11:16:47 +000046 if (used < 0)
47 return;
48
Nguyễn Thái Ngọc Duy125d0152010-04-09 14:34:28 +020049# if ENABLE_FEATURE_SYSLOG
50 if (logmode & LOGMODE_SYSLOG)
Denis Vlasenko517413f2008-12-10 11:16:47 +000051 syslog(LOG_INFO, "%s", msg);
Nguyễn Thái Ngọc Duy125d0152010-04-09 14:34:28 +020052# endif
Denis Vlasenko517413f2008-12-10 11:16:47 +000053 if (logmode & LOGMODE_STDIO) {
Denys Vlasenko8131eea2009-11-02 14:19:51 +010054 fflush_all();
Denis Vlasenko517413f2008-12-10 11:16:47 +000055 /* used = strlen(msg); - must be true already */
56 msg[used++] = '\n';
57 full_write(STDOUT_FILENO, msg, used);
58 }
59
60 free(msg);
Denis Vlasenko517413f2008-12-10 11:16:47 +000061#endif
Denis Vlasenko3da6aa82006-09-07 05:09:22 +000062}