From: yasuoka Date: Mon, 1 Jul 2024 05:20:01 +0000 (+0000) Subject: Exit with an error code when error or module die. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=593962704d3cce1629dae6e0defb6078788d7f17;p=openbsd Exit with an error code when error or module die. CVS ---------------------------------------------------------------------- --- diff --git a/usr.sbin/radiusd/radiusd.c b/usr.sbin/radiusd/radiusd.c index c40b0754481..79d274191ea 100644 --- a/usr.sbin/radiusd/radiusd.c +++ b/usr.sbin/radiusd/radiusd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd.c,v 1.41 2024/07/01 05:18:16 yasuoka Exp $ */ +/* $OpenBSD: radiusd.c,v 1.42 2024/07/01 05:20:01 yasuoka Exp $ */ /* * Copyright (c) 2013, 2023 Internet Initiative Japan Inc. @@ -193,10 +193,16 @@ main(int argc, char *argv[]) if (event_loop(0) < 0) radiusd_stop(radiusd); + if (radiusd->error != 0) + log_warnx("exiting on error"); + radiusd_free(radiusd); event_base_free(NULL); - exit(EXIT_SUCCESS); + if (radiusd->error != 0) + exit(EXIT_FAILURE); + else + exit(EXIT_SUCCESS); } static int @@ -263,6 +269,7 @@ radiusd_start(struct radiusd *radiusd) return (0); on_error: + radiusd->error++; radiusd_stop(radiusd); return (-1); @@ -703,7 +710,7 @@ radiusd_on_sigchld(int fd, short evmask, void *ctx) struct radiusd *radiusd = ctx; struct radiusd_module *module; pid_t pid; - int status; + int status, ndeath = 0; log_debug("Received SIGCHLD"); while ((pid = wait3(&status, WNOHANG, NULL)) != 0) { @@ -719,6 +726,7 @@ radiusd_on_sigchld(int fd, short evmask, void *ctx) log_warnx("module `%s'(pid=%d) exited " "by signal %d", module->name, (int)pid, WTERMSIG(status)); + ndeath++; break; } } @@ -733,6 +741,10 @@ radiusd_on_sigchld(int fd, short evmask, void *ctx) WTERMSIG(status)); } } + if (ndeath > 0) { + radiusd->error++; + event_loopbreak(); + } } static const char * diff --git a/usr.sbin/radiusd/radiusd_local.h b/usr.sbin/radiusd/radiusd_local.h index c3d1c805b58..24e4f74074f 100644 --- a/usr.sbin/radiusd/radiusd_local.h +++ b/usr.sbin/radiusd/radiusd_local.h @@ -1,4 +1,4 @@ -/* $OpenBSD: radiusd_local.h,v 1.9 2024/07/01 03:32:09 yasuoka Exp $ */ +/* $OpenBSD: radiusd_local.h,v 1.10 2024/07/01 05:20:01 yasuoka Exp $ */ /* * Copyright (c) 2013 Internet Initiative Japan Inc. @@ -106,6 +106,7 @@ struct radiusd { TAILQ_HEAD(,radiusd_authentication) authen; TAILQ_HEAD(,radiusd_client) client; TAILQ_HEAD(,radius_query) query; + int error; }; struct radius_query {