signals: require and always use sigaction()
[tftp-hpa.git] / tftpd / misc.c
blob9070f96fc7e677bea72cb617ee470965b6d18f89
1 /* ----------------------------------------------------------------------- *
3 * Copyright 2001-2007 H. Peter Anvin - All Rights Reserved
5 * This program is free software available under the same license
6 * as the "OpenBSD" operating system, distributed at
7 * http://www.openbsd.org/.
9 * ----------------------------------------------------------------------- */
12 * misc.c
14 * Minor help routines.
17 #include "config.h" /* Must be included first! */
18 #include <syslog.h>
19 #include "tftpd.h"
22 * Set the signal handler and flags, and error out on failure.
24 void set_signal(int signum, sighandler_t handler, int flags)
26 if (tftp_signal(signum, handler, flags)) {
27 syslog(LOG_ERR, "sigaction: %m");
28 exit(EX_OSERR);
33 * malloc() that syslogs an error message and bails if it fails.
35 void *tfmalloc(size_t size)
37 void *p = malloc(size);
39 if (!p) {
40 syslog(LOG_ERR, "malloc: %m");
41 exit(EX_OSERR);
44 return p;
48 * strdup() that does the equivalent
50 char *tfstrdup(const char *str)
52 char *p = strdup(str);
54 if (!p) {
55 syslog(LOG_ERR, "strdup: %m");
56 exit(EX_OSERR);
59 return p;