diff options
-rw-r--r-- | lib9p/tests/test_server/main.c | 13 | ||||
-rw-r--r-- | lib9p/tests/testclient-sess.c | 17 | ||||
-rw-r--r-- | libhw_cr/host_alarmclock.c | 15 | ||||
-rw-r--r-- | libhw_cr/host_net.c | 20 | ||||
-rw-r--r-- | libhw_cr/host_util.c | 7 |
5 files changed, 43 insertions, 29 deletions
diff --git a/lib9p/tests/test_server/main.c b/lib9p/tests/test_server/main.c index 052d180..6c7dc1c 100644 --- a/lib9p/tests/test_server/main.c +++ b/lib9p/tests/test_server/main.c @@ -5,10 +5,13 @@ */ #include <errno.h> -#include <error.h> #include <stdio.h> #include <stdlib.h> /* for atoi() */ +#define error __error +#include <error.h> +#undef error + #include <lib9p/srv.h> #include <libcr/coroutine.h> #include <libhw/generic/alarmclock.h> @@ -117,12 +120,12 @@ static COROUTINE init_cr(void *) { for (int i = 0; i < _CONFIG_9P_MAX_CONNS; i++) { char name[] = {'r', 'e', 'a', 'd', '-', hexdig[i], '\0'}; if (!coroutine_add(name, read_cr, &i)) - error(1, 0, "coroutine_add(read_cr, &i)"); + __error(1, 0, "coroutine_add(read_cr, &i)"); } for (int i = 0; i < _CONFIG_9P_MAX_REQS; i++) { char name[] = {'w', 'r', 'i', 't', 'e', '-', hexdig[i], '\0'}; if (!coroutine_add(name, write_cr, NULL)) - error(1, 0, "coroutine_add(write_cr, NULL)"); + __error(1, 0, "coroutine_add(write_cr, NULL)"); } cr_exit(); @@ -153,12 +156,12 @@ static void tstlog_msg(struct lib9p_srv_ctx *ctx, enum lib9p_msg_type typ, void int main(int argc, char *argv[]) { if (argc != 3) - error(2, 0, "usage: %s PORT_NUMBER LOGFILE", argv[0]); + __error(2, 0, "usage: %s PORT_NUMBER LOGFILE", argv[0]); globals.port = atoi(argv[1]); globals.logstream = fopen(argv[2], "w"); if (!globals.logstream) - error(2, errno, "fopen"); + __error(2, errno, "fopen"); globals.srv.msglog = tstlog_msg; struct hostclock clock_monotonic = { diff --git a/lib9p/tests/testclient-sess.c b/lib9p/tests/testclient-sess.c index 276f932..d466eea 100644 --- a/lib9p/tests/testclient-sess.c +++ b/lib9p/tests/testclient-sess.c @@ -6,13 +6,16 @@ #include <arpa/inet.h> /* for htons(), inet_addr() */ #include <errno.h> -#include <error.h> #include <netinet/in.h> /* for struct sockaddr{,_in} */ #include <stdlib.h> /* for atoi() */ #include <sys/socket.h> /* for socket(), connect() */ #include <sys/uio.h> /* for writev() */ #include <unistd.h> /* for read() */ +#define error __error +#include <error.h> +#undef error + #include <lib9p/core.h> #include <libmisc/assert.h> #include <libmisc/endian.h> @@ -28,7 +31,7 @@ static void _send9p(int fd, struct lib9p_ctx *ctx, enum lib9p_msg_type typ, void exp += buf.iov[i].iov_len; ssize_t act = writev(fd, buf.iov, buf.iov_cnt); if (act < 0) - error(1, errno, "writev"); + __error(1, errno, "writev"); assert((size_t)act == exp); } @@ -41,7 +44,7 @@ static void _recv9p(int fd) { while (done < goal) { ssize_t n = read(fd, &buf[done], goal-done); if (n < 0) - error(1, errno, "read"); + __error(1, errno, "read"); done += n; } goal = uint32le_decode(buf); @@ -49,7 +52,7 @@ static void _recv9p(int fd) { while (done < goal) { ssize_t n = read(fd, &buf[done], goal-done); if (n < 0) - error(1, errno, "read"); + __error(1, errno, "read"); done += n; } } @@ -58,7 +61,7 @@ static void _recv9p(int fd) { int main(int argc, char *argv[]) { if (argc != 2) - error(2, 0, "Usage: %s SERVER_PORT", argv[0]); + __error(2, 0, "Usage: %s SERVER_PORT", argv[0]); uint16_t server_port = atoi(argv[1]); union { @@ -71,9 +74,9 @@ int main(int argc, char *argv[]) { int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) - error(1, errno, "socket"); + __error(1, errno, "socket"); if (connect(fd, &server_addr.gen, sizeof(server_addr)) < 0) - error(1, errno, "connect"); + __error(1, errno, "connect"); struct lib9p_ctx ctx = { .max_msg_size = 16*1024, diff --git a/libhw_cr/host_alarmclock.c b/libhw_cr/host_alarmclock.c index ac2093c..325f7e0 100644 --- a/libhw_cr/host_alarmclock.c +++ b/libhw_cr/host_alarmclock.c @@ -5,9 +5,12 @@ */ #include <errno.h> -#include <error.h> #include <signal.h> +#define error __error +#include <error.h> +#undef error + #include <libcr/coroutine.h> #include <libmisc/assert.h> @@ -27,7 +30,7 @@ static uint64_t hostclock_get_time_ns(struct hostclock *alarmclock) { struct timespec ts; if (clock_gettime(alarmclock->clock_id, &ts) != 0) - error(1, errno, "clock_gettime(%d)", (int)alarmclock->clock_id); + __error(1, errno, "clock_gettime(%d)", (int)alarmclock->clock_id); return ns_from_host_ns_time(ts); } @@ -52,7 +55,7 @@ static void hostclock_handle_sig_alarm(int LM_UNUSED(sig), siginfo_t *info, void .it_interval = {}, }; if (timer_settime(alarmclock->timer_id, TIMER_ABSTIME, &alarmspec, NULL) != 0) - error(1, errno, "timer_settime"); + __error(1, errno, "timer_settime"); } } @@ -93,9 +96,9 @@ static bool hostclock_add_trigger(struct hostclock *alarmclock, .sa_sigaction = hostclock_handle_sig_alarm, }; if (sigaction(how_to_notify.sigev_signo, &action, NULL) != 0) - error(1, errno, "sigaction"); + __error(1, errno, "sigaction"); if (timer_create(alarmclock->clock_id, &how_to_notify, &alarmclock->timer_id) != 0) - error(1, errno, "timer_create(%d)", (int)alarmclock->clock_id); + __error(1, errno, "timer_create(%d)", (int)alarmclock->clock_id); alarmclock->initialized = true; } if (alarmclock->queue == trigger) { @@ -104,7 +107,7 @@ static bool hostclock_add_trigger(struct hostclock *alarmclock, .it_interval = {}, }; if (timer_settime(alarmclock->timer_id, TIMER_ABSTIME, &alarmspec, NULL) != 0) - error(1, errno, "timer_settime"); + __error(1, errno, "timer_settime"); } cr_restore_interrupts(saved); diff --git a/libhw_cr/host_net.c b/libhw_cr/host_net.c index c8d4472..6093792 100644 --- a/libhw_cr/host_net.c +++ b/libhw_cr/host_net.c @@ -7,7 +7,9 @@ #define _GNU_SOURCE /* for pthread_sigqueue(3gnu) */ /* misc */ #include <errno.h> /* for errno, EAGAIN, EINVAL */ +#define error __error #include <error.h> /* for error(3gnu) */ +#undef error #include <stdlib.h> /* for abs(), shutdown(), SHUT_RD, SHUT_WR, SHUT_RDWR */ #include <unistd.h> /* for read(), write() */ /* net */ @@ -63,7 +65,7 @@ static void hostnet_init(void) { action.sa_flags = SA_SIGINFO; action.sa_sigaction = hostnet_handle_sig_io; if (sigaction(hostnet_sig_io, &action, NULL) < 0) - error(1, errno, "sigaction"); + __error(1, errno, "sigaction"); } #define WAKE_COROUTINE(args) do { \ @@ -136,15 +138,15 @@ void hostnet_tcp_listener_init(struct hostnet_tcp_listener *self, uint16_t port) addr.in.sin_port = htons(port); listenerfd = socket(AF_INET, SOCK_STREAM, 0); if (listenerfd < 0) - error(1, errno, "socket"); + __error(1, errno, "socket"); if (setsockopt(listenerfd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)) < 0) - error(1, errno, "setsockopt(fd=%d, SO_REUSEADDR=1)", listenerfd); + __error(1, errno, "setsockopt(fd=%d, SO_REUSEADDR=1)", listenerfd); if (setsockopt(listenerfd, SOL_SOCKET, SO_REUSEPORT, &(int){1}, sizeof(int)) < 0) - error(1, errno, "setsockopt(fd=%d, SO_REUSEPORT=1)", listenerfd); + __error(1, errno, "setsockopt(fd=%d, SO_REUSEPORT=1)", listenerfd); if (bind(listenerfd, &addr.gen, sizeof addr) < 0) - error(1, errno, "bind(fd=%d)", listenerfd); + __error(1, errno, "bind(fd=%d)", listenerfd); if (listen(listenerfd, 0) < 0) - error(1, errno, "listen(fd=%d)", listenerfd); + __error(1, errno, "listen(fd=%d)", listenerfd); self->fd = listenerfd; } @@ -375,11 +377,11 @@ void hostnet_udp_conn_init(struct hostnet_udp_conn *self, uint16_t port) { addr.in.sin_port = htons(port); fd = socket(AF_INET, SOCK_DGRAM, 0); if (fd < 0) - error(1, errno, "socket"); + __error(1, errno, "socket"); if (setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &(int){1}, sizeof(int)) < 0) - error(1, errno, "setsockopt(fd=%d, SO_BROADCAST=1)", fd); + __error(1, errno, "setsockopt(fd=%d, SO_BROADCAST=1)", fd); if (bind(fd, &addr.gen, sizeof addr) < 0) - error(1, errno, "bind"); + __error(1, errno, "bind"); self->fd = fd; self->read_deadline_ns = 0; diff --git a/libhw_cr/host_util.c b/libhw_cr/host_util.c index 8cacd57..d0f01d7 100644 --- a/libhw_cr/host_util.c +++ b/libhw_cr/host_util.c @@ -4,9 +4,12 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ -#include <error.h> /* for error(3gnu) */ #include <signal.h> /* for SIGRTMIN, SIGRTMAX */ +#define error __error +#include <error.h> +#undef error + #include <libhw/generic/alarmclock.h> /* for {X}S_PER_S */ #include "host_util.h" @@ -18,7 +21,7 @@ int host_sigrt_alloc(void) { next = SIGRTMIN; int ret = next++; if (ret > SIGRTMAX) - error(1, 0, "SIGRTMAX exceeded"); + __error(1, 0, "SIGRTMAX exceeded"); return ret; } |