From: John Crispin Date: Sat, 28 Mar 2015 17:12:21 +0000 (+0100) Subject: properly handle return codes X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=73a7133b6e42edc218da5b8011c580ed48c7731a;p=oweals%2Fodhcpd.git properly handle return codes Signed-off-by: John Crispin --- diff --git a/src/config.c b/src/config.c index 5fbb921..9dbe7f0 100644 --- a/src/config.c +++ b/src/config.c @@ -683,9 +683,10 @@ void odhcpd_reload(void) static void handle_signal(int signal) { char b[1] = {0}; - if (signal == SIGHUP) - write(reload_pipe[1], b, sizeof(b)); - else + + if (signal == SIGHUP) { + if (write(reload_pipe[1], b, sizeof(b)) < 0) {} + } else uloop_end(); } @@ -694,7 +695,7 @@ static void handle_signal(int signal) static void reload_cb(struct uloop_fd *u, _unused unsigned int events) { char b[512]; - read(u->fd, b, sizeof(b)); + if (read(u->fd, b, sizeof(b) < 0)) {} odhcpd_reload(); } @@ -702,7 +703,7 @@ static struct uloop_fd reload_fd = { .cb = reload_cb }; void odhcpd_run(void) { - pipe2(reload_pipe, O_NONBLOCK | O_CLOEXEC); + if (pipe2(reload_pipe, O_NONBLOCK | O_CLOEXEC) < 0) {} reload_fd.fd = reload_pipe[0]; uloop_fd_add(&reload_fd, ULOOP_READ); diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 7db4cee..74e3441 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -219,7 +219,7 @@ void dhcpv6_write_statefile(void) return; lockf(fd, F_LOCK, 0); - ftruncate(fd, 0); + if (ftruncate(fd, 0) < 0) {} FILE *fp = fdopen(fd, "w"); if (!fp) { diff --git a/src/ndp.c b/src/ndp.c index 45bb9db..5e8b5ac 100644 --- a/src/ndp.c +++ b/src/ndp.c @@ -132,7 +132,7 @@ int setup_ndp_interface(struct interface *iface, bool enable) iface->ndp_event.uloop.fd = -1; if (!enable || iface->ndp != RELAYD_RELAY) - write(procfd, "0\n", 2); + if (write(procfd, "0\n", 2) < 0) {} dump_neigh = true; } @@ -152,7 +152,7 @@ int setup_ndp_interface(struct interface *iface, bool enable) } if (enable && iface->ndp == RELAYD_RELAY) { - write(procfd, "1\n", 2); + if (write(procfd, "1\n", 2) < 0) {} close(procfd); int sock = socket(AF_PACKET, SOCK_DGRAM | SOCK_CLOEXEC, htons(ETH_P_IPV6)); diff --git a/src/odhcpd.c b/src/odhcpd.c index 76dee9e..52bca13 100644 --- a/src/odhcpd.c +++ b/src/odhcpd.c @@ -415,9 +415,9 @@ void odhcpd_process(struct odhcpd_event *event) odhcpd_receive_packets(&event->uloop, 0); } -void odhcpd_urandom(void *data, size_t len) +int odhcpd_urandom(void *data, size_t len) { - read(urandom_fd, data, len); + return read(urandom_fd, data, len); } diff --git a/src/odhcpd.h b/src/odhcpd.h index 1ada4aa..21dc99f 100644 --- a/src/odhcpd.h +++ b/src/odhcpd.h @@ -190,7 +190,7 @@ int odhcpd_get_interface_mtu(const char *ifname); int odhcpd_get_mac(const struct interface *iface, uint8_t mac[6]); struct interface* odhcpd_get_interface_by_index(int ifindex); struct interface* odhcpd_get_master_interface(void); -void odhcpd_urandom(void *data, size_t len); +int odhcpd_urandom(void *data, size_t len); void odhcpd_setup_route(const struct in6_addr *addr, int prefixlen, const struct interface *iface, const struct in6_addr *gw, bool add);