blob: d3106cb4d98794bb2aff6ab6f4700419580f9c1e [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* Logging of zebra
2 * Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#include <zebra.h>
23
24#include "log.h"
25#include "memory.h"
26#include "command.h"
ajs7d149b82004-11-28 23:00:01 +000027#ifndef SUNOS_5
28#include <sys/un.h>
29#endif
paul718e3742002-12-13 20:15:29 +000030
31struct zlog *zlog_default = NULL;
32
33const char *zlog_proto_names[] =
34{
35 "NONE",
36 "DEFAULT",
37 "ZEBRA",
38 "RIP",
39 "BGP",
40 "OSPF",
41 "RIPNG",
42 "OSPF6",
jardin9e867fe2003-12-23 08:56:18 +000043 "ISIS",
paul718e3742002-12-13 20:15:29 +000044 "MASC",
45 NULL,
46};
47
48const char *zlog_priority[] =
49{
50 "emergencies",
51 "alerts",
52 "critical",
53 "errors",
54 "warnings",
55 "notifications",
56 "informational",
57 "debugging",
58 NULL,
59};
60
61
62
63/* For time string format. */
64#define TIME_BUF 27
65
66/* Utility routine for current time printing. */
67static void
68time_print (FILE *fp)
69{
70 int ret;
71 char buf [TIME_BUF];
72 time_t clock;
73 struct tm *tm;
74
75 time (&clock);
76 tm = localtime (&clock);
77
78 ret = strftime (buf, TIME_BUF, "%Y/%m/%d %H:%M:%S", tm);
79 if (ret == 0) {
80 zlog_warn ("strftime error");
81 }
82
83 fprintf (fp, "%s ", buf);
84}
85
86/* va_list version of zlog. */
ajsd246bd92004-11-23 17:35:08 +000087static void
88vzlog (struct zlog *zl, int priority, const char *format, va_list args)
paul718e3742002-12-13 20:15:29 +000089{
90 /* If zlog is not specified, use default one. */
91 if (zl == NULL)
92 zl = zlog_default;
93
94 /* When zlog_default is also NULL, use stderr for logging. */
95 if (zl == NULL)
96 {
97 time_print (stderr);
98 fprintf (stderr, "%s: ", "unknown");
ajsd246bd92004-11-23 17:35:08 +000099 vfprintf (stderr, format, args);
paul718e3742002-12-13 20:15:29 +0000100 fprintf (stderr, "\n");
101 fflush (stderr);
102
103 /* In this case we return at here. */
104 return;
105 }
106
107 /* only log this information if it has not been masked out */
108 if ( priority > zl->maskpri )
109 return ;
110
111 /* Syslog output */
112 if (zl->flags & ZLOG_SYSLOG)
ajsd246bd92004-11-23 17:35:08 +0000113 {
114 va_list ac;
115 va_copy(ac, args);
116 vsyslog (priority|zlog_default->facility, format, ac);
117 va_end(ac);
118 }
paul718e3742002-12-13 20:15:29 +0000119
120 /* File output. */
121 if (zl->flags & ZLOG_FILE)
122 {
ajsd246bd92004-11-23 17:35:08 +0000123 va_list ac;
paul718e3742002-12-13 20:15:29 +0000124 time_print (zl->fp);
hassob04c6992004-10-04 19:10:31 +0000125 if (zl->record_priority)
126 fprintf (zl->fp, "%s: ", zlog_priority[priority]);
paul718e3742002-12-13 20:15:29 +0000127 fprintf (zl->fp, "%s: ", zlog_proto_names[zl->protocol]);
ajsd246bd92004-11-23 17:35:08 +0000128 va_copy(ac, args);
129 vfprintf (zl->fp, format, ac);
130 va_end(ac);
paul718e3742002-12-13 20:15:29 +0000131 fprintf (zl->fp, "\n");
132 fflush (zl->fp);
133 }
134
135 /* stdout output. */
136 if (zl->flags & ZLOG_STDOUT)
137 {
ajsd246bd92004-11-23 17:35:08 +0000138 va_list ac;
paul718e3742002-12-13 20:15:29 +0000139 time_print (stdout);
hassob04c6992004-10-04 19:10:31 +0000140 if (zl->record_priority)
141 fprintf (stdout, "%s: ", zlog_priority[priority]);
paul718e3742002-12-13 20:15:29 +0000142 fprintf (stdout, "%s: ", zlog_proto_names[zl->protocol]);
ajsd246bd92004-11-23 17:35:08 +0000143 va_copy(ac, args);
144 vfprintf (stdout, format, ac);
145 va_end(ac);
paul718e3742002-12-13 20:15:29 +0000146 fprintf (stdout, "\n");
147 fflush (stdout);
148 }
149
150 /* stderr output. */
151 if (zl->flags & ZLOG_STDERR)
152 {
ajsd246bd92004-11-23 17:35:08 +0000153 va_list ac;
paul718e3742002-12-13 20:15:29 +0000154 time_print (stderr);
hassob04c6992004-10-04 19:10:31 +0000155 if (zl->record_priority)
156 fprintf (stderr, "%s: ", zlog_priority[priority]);
paul718e3742002-12-13 20:15:29 +0000157 fprintf (stderr, "%s: ", zlog_proto_names[zl->protocol]);
ajsd246bd92004-11-23 17:35:08 +0000158 va_copy(ac, args);
159 vfprintf (stderr, format, ac);
160 va_end(ac);
paul718e3742002-12-13 20:15:29 +0000161 fprintf (stderr, "\n");
162 fflush (stderr);
163 }
164
165 /* Terminal monitor. */
ajsd246bd92004-11-23 17:35:08 +0000166 vty_log (zlog_proto_names[zl->protocol], format, args);
paul718e3742002-12-13 20:15:29 +0000167}
168
ajs59a06a92004-11-23 18:19:14 +0000169static char *
170str_append(char *dst, int len, const char *src)
171{
172 while ((len-- > 0) && *src)
173 *dst++ = *src++;
174 return dst;
175}
176
177static char *
178num_append(char *s, int len, u_long x)
179{
180 char buf[30];
ajs7d149b82004-11-28 23:00:01 +0000181 char *t;
ajs59a06a92004-11-23 18:19:14 +0000182
ajs7d149b82004-11-28 23:00:01 +0000183 if (!x)
184 return str_append(s,len,"0");
185 *(t = &buf[sizeof(buf)-1]) = '\0';
ajs59a06a92004-11-23 18:19:14 +0000186 while (x && (t > buf))
187 {
188 *--t = '0'+(x % 10);
189 x /= 10;
190 }
191 return str_append(s,len,t);
192}
193
ajs7d149b82004-11-28 23:00:01 +0000194static char *
195hex_append(char *s, int len, u_long x)
196{
197 char buf[30];
198 char *t;
199
200 if (!x)
201 return str_append(s,len,"0");
202 *(t = &buf[sizeof(buf)-1]) = '\0';
203 while (x && (t > buf))
204 {
205 u_int cc = (x % 16);
206 *--t = ((cc < 10) ? ('0'+cc) : ('a'+cc-10));
207 x /= 16;
208 }
209 return str_append(s,len,t);
210}
211
212static int syslog_fd = -1;
213
214/* Needs to be enhanced to support Solaris. */
215static int
216syslog_connect(void)
217{
218#ifdef SUNOS_5
219 return -1;
220#else
221 int fd;
222 char *s;
223 struct sockaddr_un addr;
224
225 if ((fd = socket(AF_UNIX,SOCK_DGRAM,0)) < 0)
226 return -1;
227 addr.sun_family = AF_UNIX;
228#ifdef _PATH_LOG
229#define SYSLOG_SOCKET_PATH _PATH_LOG
230#else
231#define SYSLOG_SOCKET_PATH "/dev/log"
232#endif
233 s = str_append(addr.sun_path,sizeof(addr.sun_path),SYSLOG_SOCKET_PATH);
234#undef SYSLOG_SOCKET_PATH
235 *s = '\0';
236 if (connect(fd,(struct sockaddr *)&addr,sizeof(addr)) < 0)
237 {
238 close(fd);
239 return -1;
240 }
241 return fd;
242#endif
243}
244
245static void
246syslog_sigsafe(int priority, const char *msg, size_t msglen)
247{
248 char buf[sizeof("<1234567890>ripngd[1234567890]: ")+msglen+50];
249 char *s;
250
251 if ((syslog_fd < 0) && ((syslog_fd = syslog_connect()) < 0))
252 return;
253
254#define LOC s,buf+sizeof(buf)-s
255 s = buf;
256 s = str_append(LOC,"<");
257 s = num_append(LOC,priority);
258 s = str_append(LOC,">");
259 /* forget about the timestamp, too difficult in a signal handler */
260 s = str_append(LOC,zlog_default->ident);
261 if (zlog_default->syslog_options & LOG_PID)
262 {
263 s = str_append(LOC,"[");
264 s = num_append(LOC,getpid());
265 s = str_append(LOC,"]");
266 }
267 s = str_append(LOC,": ");
268 s = str_append(LOC,msg);
269 write(syslog_fd,buf,s-buf);
270#undef LOC
271}
272
273/* Note: the goal here is to use only async-signal-safe functions. */
ajs59a06a92004-11-23 18:19:14 +0000274void
275zlog_signal(int signo, const char *action)
276{
277 time_t now;
278 char buf[sizeof("DEFAULT: Received signal S at T; aborting...")+60];
279 char *s = buf;
ajs7d149b82004-11-28 23:00:01 +0000280 char *msgstart = buf;
ajs59a06a92004-11-23 18:19:14 +0000281#define LOC s,buf+sizeof(buf)-s
282
283 time(&now);
284 if (zlog_default)
285 {
286 s = str_append(LOC,zlog_proto_names[zlog_default->protocol]);
287 *s++ = ':';
288 *s++ = ' ';
ajs7d149b82004-11-28 23:00:01 +0000289 msgstart = s;
ajs59a06a92004-11-23 18:19:14 +0000290 }
291 s = str_append(LOC,"Received signal ");
292 s = num_append(LOC,signo);
293 s = str_append(LOC," at ");
294 s = num_append(LOC,now);
295 s = str_append(LOC,"; ");
296 s = str_append(LOC,action);
ajs7d149b82004-11-28 23:00:01 +0000297 if (s < buf+sizeof(buf))
298 *s++ = '\n';
ajs59a06a92004-11-23 18:19:14 +0000299
300#define DUMP(FP) write(fileno(FP),buf,s-buf);
301 if (!zlog_default)
302 DUMP(stderr)
303 else
304 {
305 if ((zlog_default->flags & ZLOG_FILE) && zlog_default->fp)
306 DUMP(zlog_default->fp)
307 if (zlog_default->flags & ZLOG_STDOUT)
308 DUMP(stdout)
309 if (zlog_default->flags & ZLOG_STDERR)
310 DUMP(stderr)
ajs7d149b82004-11-28 23:00:01 +0000311 if (zlog_default->flags & ZLOG_SYSLOG)
312 {
313 *--s = '\0';
314 syslog_sigsafe(LOG_ERR|zlog_default->facility,msgstart,s-msgstart);
315 }
ajs59a06a92004-11-23 18:19:14 +0000316 }
317#undef DUMP
318
ajs48d6c692004-11-26 20:52:59 +0000319 zlog_backtrace_sigsafe(LOG_ERR);
ajs063ee522004-11-26 18:11:14 +0000320#undef LOC
321}
ajs59a06a92004-11-23 18:19:14 +0000322
ajs063ee522004-11-26 18:11:14 +0000323/* Log a backtrace using only async-signal-safe functions.
324 Needs to be enhanced to support syslog logging. */
325void
ajs48d6c692004-11-26 20:52:59 +0000326zlog_backtrace_sigsafe(int priority)
ajs063ee522004-11-26 18:11:14 +0000327{
328#ifdef HAVE_GLIBC_BACKTRACE
329 void *array[20];
330 int size;
331 char buf[100];
332 char *s;
333#define LOC s,buf+sizeof(buf)-s
334
335 /* only log this information if it has not been masked out */
336 if (zlog_default && (priority > zlog_default->maskpri))
337 return;
338
339 if (((size = backtrace(array,sizeof(array)/sizeof(array[0]))) <= 0) ||
340 ((size_t)size > sizeof(array)/sizeof(array[0])))
341 return;
342 s = buf;
343 s = str_append(LOC,"Backtrace for ");
344 s = num_append(LOC,size);
345 s = str_append(LOC," stack frames:\n");
ajs59a06a92004-11-23 18:19:14 +0000346
347#define DUMP(FP) { \
348 write(fileno(FP),buf,s-buf); \
349 backtrace_symbols_fd(array, size, fileno(FP)); \
350}
351
352 if (!zlog_default)
353 DUMP(stderr)
354 else
355 {
356 if ((zlog_default->flags & ZLOG_FILE) && zlog_default->fp)
ajs063ee522004-11-26 18:11:14 +0000357 DUMP(zlog_default->fp)
ajs59a06a92004-11-23 18:19:14 +0000358 if (zlog_default->flags & ZLOG_STDOUT)
ajs063ee522004-11-26 18:11:14 +0000359 DUMP(stdout)
ajs59a06a92004-11-23 18:19:14 +0000360 if (zlog_default->flags & ZLOG_STDERR)
ajs063ee522004-11-26 18:11:14 +0000361 DUMP(stderr)
ajs7d149b82004-11-28 23:00:01 +0000362 if (zlog_default->flags & ZLOG_SYSLOG)
363 {
364 int i;
365 *--s = '\0';
366 syslog_sigsafe(priority|zlog_default->facility,buf,s-buf);
367 /* Just print the function addresses. */
368 for (i = 0; i < size; i++)
369 {
370 s = buf;
371 s = str_append(LOC,"[bt ");
372 s = num_append(LOC,i);
373 s = str_append(LOC,"] 0x");
374 s = hex_append(LOC,(u_long)(array[i]));
375 *s = '\0';
376 syslog_sigsafe(priority|zlog_default->facility,buf,s-buf);
377 }
378 }
ajs59a06a92004-11-23 18:19:14 +0000379 }
380#undef DUMP
ajs59a06a92004-11-23 18:19:14 +0000381#undef LOC
ajs063ee522004-11-26 18:11:14 +0000382#endif /* HAVE_GLIBC_BACKTRACE */
383}
384
385void
386zlog_backtrace(int priority)
387{
388#ifndef HAVE_GLIBC_BACKTRACE
389 zlog(NULL, priority, "No backtrace available on this platform.");
390#else
391 void *array[20];
392 int size, i;
393 char **strings;
394
395 if (((size = backtrace(array,sizeof(array)/sizeof(array[0]))) <= 0) ||
396 ((size_t)size > sizeof(array)/sizeof(array[0])))
397 {
398 zlog_err("Cannot get backtrace, returned invalid # of frames %d "
399 "(valid range is between 1 and %u)",
400 size, sizeof(array)/sizeof(array[0]));
401 return;
402 }
403 zlog(NULL, priority, "Backtrace for %d stack frames:", size);
404 if (!(strings = backtrace_symbols(array, size)))
405 {
406 zlog_err("Cannot get backtrace symbols (out of memory?)");
407 for (i = 0; i < size; i++)
408 zlog(NULL, priority, "[bt %d] %p",i,array[i]);
409 }
410 else
411 {
412 for (i = 0; i < size; i++)
413 zlog(NULL, priority, "[bt %d] %s",i,strings[i]);
414 free(strings);
415 }
416#endif /* HAVE_GLIBC_BACKTRACE */
ajs59a06a92004-11-23 18:19:14 +0000417}
418
paul718e3742002-12-13 20:15:29 +0000419void
420zlog (struct zlog *zl, int priority, const char *format, ...)
421{
ajsd246bd92004-11-23 17:35:08 +0000422 va_list args;
paul718e3742002-12-13 20:15:29 +0000423
ajsd246bd92004-11-23 17:35:08 +0000424 va_start(args, format);
paul718e3742002-12-13 20:15:29 +0000425 vzlog (zl, priority, format, args);
ajsd246bd92004-11-23 17:35:08 +0000426 va_end (args);
paul718e3742002-12-13 20:15:29 +0000427}
428
ajsd246bd92004-11-23 17:35:08 +0000429#define ZLOG_FUNC(FUNCNAME,PRIORITY) \
430void \
431FUNCNAME(const char *format, ...) \
432{ \
433 va_list args; \
434 va_start(args, format); \
435 vzlog (NULL, PRIORITY, format, args); \
436 va_end(args); \
paul718e3742002-12-13 20:15:29 +0000437}
438
ajsd246bd92004-11-23 17:35:08 +0000439ZLOG_FUNC(zlog_err, LOG_ERR)
paul718e3742002-12-13 20:15:29 +0000440
ajsd246bd92004-11-23 17:35:08 +0000441ZLOG_FUNC(zlog_warn, LOG_WARNING)
paul718e3742002-12-13 20:15:29 +0000442
ajsd246bd92004-11-23 17:35:08 +0000443ZLOG_FUNC(zlog_info, LOG_INFO)
paul718e3742002-12-13 20:15:29 +0000444
ajsd246bd92004-11-23 17:35:08 +0000445ZLOG_FUNC(zlog_notice, LOG_NOTICE)
446
447ZLOG_FUNC(zlog_debug, LOG_DEBUG)
448
449#undef ZLOG_FUNC
450
451#define PLOG_FUNC(FUNCNAME,PRIORITY) \
452void \
453FUNCNAME(struct zlog *zl, const char *format, ...) \
454{ \
455 va_list args; \
456 va_start(args, format); \
457 vzlog (zl, PRIORITY, format, args); \
458 va_end(args); \
paul718e3742002-12-13 20:15:29 +0000459}
460
ajsd246bd92004-11-23 17:35:08 +0000461PLOG_FUNC(plog_err, LOG_ERR)
paul718e3742002-12-13 20:15:29 +0000462
ajsd246bd92004-11-23 17:35:08 +0000463PLOG_FUNC(plog_warn, LOG_WARNING)
paul718e3742002-12-13 20:15:29 +0000464
ajsd246bd92004-11-23 17:35:08 +0000465PLOG_FUNC(plog_info, LOG_INFO)
paul718e3742002-12-13 20:15:29 +0000466
ajsd246bd92004-11-23 17:35:08 +0000467PLOG_FUNC(plog_notice, LOG_NOTICE)
paul718e3742002-12-13 20:15:29 +0000468
ajsd246bd92004-11-23 17:35:08 +0000469PLOG_FUNC(plog_debug, LOG_DEBUG)
paul718e3742002-12-13 20:15:29 +0000470
ajsd246bd92004-11-23 17:35:08 +0000471#undef PLOG_FUNC
paul718e3742002-12-13 20:15:29 +0000472
ajscee3df12004-11-24 17:14:49 +0000473void
474_zlog_assert_failed (const char *assertion, const char *file,
475 unsigned int line, const char *function)
476{
477 zlog_err("Assertion `%s' failed in file %s, line %u, function %s",
478 assertion,file,line,(function ? function : "?"));
ajs063ee522004-11-26 18:11:14 +0000479 zlog_backtrace(LOG_ERR);
ajscee3df12004-11-24 17:14:49 +0000480 abort();
481}
482
paul718e3742002-12-13 20:15:29 +0000483
484/* Open log stream */
485struct zlog *
486openzlog (const char *progname, int flags, zlog_proto_t protocol,
487 int syslog_flags, int syslog_facility)
488{
489 struct zlog *zl;
490
491 zl = XMALLOC(MTYPE_ZLOG, sizeof (struct zlog));
492 memset (zl, 0, sizeof (struct zlog));
493
494 zl->ident = progname;
495 zl->flags = flags;
496 zl->protocol = protocol;
497 zl->facility = syslog_facility;
498 zl->maskpri = LOG_DEBUG;
499 zl->record_priority = 0;
ajs7d149b82004-11-28 23:00:01 +0000500 zl->syslog_options = syslog_flags;
paul718e3742002-12-13 20:15:29 +0000501
502 openlog (progname, syslog_flags, zl->facility);
503
504 return zl;
505}
506
507void
508closezlog (struct zlog *zl)
509{
510 closelog();
511 fclose (zl->fp);
512
513 XFREE (MTYPE_ZLOG, zl);
514}
515
516/* Called from command.c. */
517void
518zlog_set_flag (struct zlog *zl, int flags)
519{
520 if (zl == NULL)
521 zl = zlog_default;
522
523 zl->flags |= flags;
524}
525
526void
527zlog_reset_flag (struct zlog *zl, int flags)
528{
529 if (zl == NULL)
530 zl = zlog_default;
531
532 zl->flags &= ~flags;
533}
534
535int
ajsd246bd92004-11-23 17:35:08 +0000536zlog_set_file (struct zlog *zl, const char *filename)
paul718e3742002-12-13 20:15:29 +0000537{
538 FILE *fp;
gdtaa593d52003-12-22 20:15:53 +0000539 mode_t oldumask;
paul718e3742002-12-13 20:15:29 +0000540
541 /* There is opend file. */
542 zlog_reset_file (zl);
543
544 /* Set default zl. */
545 if (zl == NULL)
546 zl = zlog_default;
547
548 /* Open file. */
gdtaa593d52003-12-22 20:15:53 +0000549 oldumask = umask (0777 & ~LOGFILE_MASK);
paul718e3742002-12-13 20:15:29 +0000550 fp = fopen (filename, "a");
551 if (fp == NULL)
gdtaa593d52003-12-22 20:15:53 +0000552 {
553 umask(oldumask);
554 return 0;
555 }
556 umask(oldumask);
paul718e3742002-12-13 20:15:29 +0000557
558 /* Set flags. */
559 zl->filename = strdup (filename);
560 zl->flags |= ZLOG_FILE;
561 zl->fp = fp;
562
563 return 1;
564}
565
566/* Reset opend file. */
567int
568zlog_reset_file (struct zlog *zl)
569{
570 if (zl == NULL)
571 zl = zlog_default;
572
573 zl->flags &= ~ZLOG_FILE;
574
575 if (zl->fp)
576 fclose (zl->fp);
577 zl->fp = NULL;
578
579 if (zl->filename)
580 free (zl->filename);
581 zl->filename = NULL;
582
583 return 1;
584}
585
586/* Reopen log file. */
587int
588zlog_rotate (struct zlog *zl)
589{
590 FILE *fp;
591
592 if (zl == NULL)
593 zl = zlog_default;
594
595 if (zl->fp)
596 fclose (zl->fp);
597 zl->fp = NULL;
598
599 if (zl->filename)
600 {
gdtaa593d52003-12-22 20:15:53 +0000601 mode_t oldumask;
602
603 oldumask = umask (0777 & ~LOGFILE_MASK);
paul718e3742002-12-13 20:15:29 +0000604 fp = fopen (zl->filename, "a");
605 if (fp == NULL)
gdtaa593d52003-12-22 20:15:53 +0000606 {
607 umask(oldumask);
608 return -1;
609 }
610 umask(oldumask);
paul718e3742002-12-13 20:15:29 +0000611 zl->fp = fp;
612 }
613
614 return 1;
615}
616
paul718e3742002-12-13 20:15:29 +0000617/* Message lookup function. */
hasso8c328f12004-10-05 21:01:23 +0000618const char *
paul718e3742002-12-13 20:15:29 +0000619lookup (struct message *mes, int key)
620{
621 struct message *pnt;
622
623 for (pnt = mes; pnt->key != 0; pnt++)
624 if (pnt->key == key)
625 return pnt->str;
626
627 return "";
628}
629
630/* Very old hacky version of message lookup function. Still partly
hassob04c6992004-10-04 19:10:31 +0000631 used in bgpd and ospfd. FIXME Seems that it's not used any more. */
hasso8c328f12004-10-05 21:01:23 +0000632const char *
paul718e3742002-12-13 20:15:29 +0000633mes_lookup (struct message *meslist, int max, int index)
634{
635 if (index < 0 || index >= max)
636 {
637 zlog_err ("message index out of bound: %d", max);
638 return NULL;
639 }
640 return meslist[index].str;
641}
ajsca359762004-11-19 23:40:16 +0000642
643/* Wrapper around strerror to handle case where it returns NULL. */
644const char *
645safe_strerror(int errnum)
646{
647 const char *s = strerror(errnum);
648 return (s != NULL) ? s : "Unknown error";
649}