ssize_t n;
n = read(randfd, p, sz);
- if (n < 0) die(1, "error reading `/dev/urandom': %s", strerror(errno));
- else if (n < sz) die(1, "unexpected short read from `/dev/urandom'");
+ if (n < 0) fatal("error reading `/dev/urandom': %s", strerror(errno));
+ else if (n < sz) fatal("unexpected short read from `/dev/urandom'");
}
/*----- Address-type operations -------------------------------------------*/
/* Open a netlink socket for interrogating the kernel. */
if ((fd = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE)) < 0)
- die(1, "failed to create netlink socket: %s", strerror(errno));
+ fatal("failed to create netlink socket: %s", strerror(errno));
/* We want to read the routing table. There doesn't seem to be a good way
* to do this without just crawling through the whole thing.
rtgen->rtgen_family = af;
if (write(fd, nlmsg, nlmsg->nlmsg_len) < 0)
- die(1, "failed to send RTM_GETROUTE request: %s", strerror(errno));
+ fatal("failed to send RTM_GETROUTE request: %s", strerror(errno));
/* Now we try to parse the answer. */
for (;;) {
/* Not finished yet, so read another chunk of answer. */
if ((n = read(fd, buf, sizeof(buf))) < 0)
- die(1, "failed to read RTM_GETROUTE response: %s", strerror(errno));
+ fatal("failed to read RTM_GETROUTE response: %s", strerror(errno));
/* Start at the beginning of the response. */
nlmsg = (struct nlmsghdr *)buf;
va_end(ap);
}
+/* Format and report MSG as a fatal error, and exit. */
+void fatal(const char *msg, ...)
+{
+ va_list ap;
+
+ va_start(ap, msg);
+ vlogmsg(0, LOG_CRIT, msg, &ap);
+ va_end(ap);
+ exit(1);
+}
+
/* Fix up a socket FD so that it won't bite us. Returns zero on success, or
* nonzero on error.
*/
extern void PRINTF_LIKE(3, 4)
logmsg(const struct query */*q*/, int /*prio*/, const char */*msg*/, ...);
+/* Format and report MSG as a fatal error, and exit. */
+extern void PRINTF_LIKE(1, 2) fatal(const char */*msg*/, ...);
+
/*----- System-specific connection identification code --------------------*/
/* Find out who is responsible for the connection described in the query Q.