2 * Copyright (C) 2009 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <apr_general.h>
30 #include <apr_errno.h>
32 #include "hostinfod.h"
37 openlog ("hostinfo", 0, LOG_DAEMON);
41 print (int level, const char *msg)
45 case LOG_WARNING: errwarn = "warning"; break;
46 case LOG_ERR: errwarn = "error"; break;
47 default: errwarn = "info";
50 if (messages_to_stderr)
51 fprintf (stderr, "hostinfo: %s: %s\n", errwarn, msg);
52 syslog (LOG_DAEMON|level, "%s: %s", errwarn, msg);
56 debug (const char *fs, ...)
63 int err = vasprintf (&msg, fs, args);
68 print (LOG_INFO, msg);
74 message (const char *fs, ...)
80 int err = vasprintf (&msg, fs, args);
85 print (LOG_INFO, msg);
90 error (const char *fs, ...)
96 int err = vasprintf (&msg, fs, args);
101 print (LOG_ERR, msg);
106 warning (const char *fs, ...)
112 int err = vasprintf (&msg, fs, args);
117 print (LOG_WARNING, msg);
122 perrorf (const char *fs, ...)
129 int err = vasprintf (&msg, fs, args);
136 strerror_r (errnum, buf, sizeof buf);
140 buf = strerror_r (errnum, _buf, sizeof _buf);
143 msg = realloc (msg, strlen (msg) + 2 + strlen (buf) + 1);
147 print (LOG_ERR, msg);
152 pwarningf (const char *fs, ...)
159 int err = vasprintf (&msg, fs, args);
166 strerror_r (errnum, buf, sizeof buf);
170 buf = strerror_r (errnum, _buf, sizeof _buf);
173 msg = realloc (msg, strlen (msg) + 2 + strlen (buf) + 1);
177 print (LOG_WARNING, msg);
182 paprerror (apr_status_t r, const char *fs, ...)
189 int err = vasprintf (&msg, fs, args);
194 apr_strerror (r, buf, sizeof buf);
196 msg = realloc (msg, strlen (msg) + 2 + strlen (buf) + 1);
200 print (LOG_ERR, msg);