Date: Wed, 12 Feb 2025 19:34:28 GMT From: John Baldwin <jhb@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 450a84c292ae - main - ctld: Some bool-related cleanups Message-ID: <202502121934.51CJYSdK059727@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=450a84c292ae5c4195d38bc7f7204d0e1e455f20 commit 450a84c292ae5c4195d38bc7f7204d0e1e455f20 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-02-12 19:25:52 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-02-12 19:25:52 +0000 ctld: Some bool-related cleanups - Convert a few variables from int to bool - Return bool instead of inverted 0/1 from configuration parsing functions and the auth check functions - Invert the existing dont_daemonize bool into a daemonize boolx Reviewed by: asomers Sponsored by: Chelsio Communications Differential Revision: https://reviews.freebsd.org/D48928 --- usr.sbin/ctld/ctld.c | 131 ++++++++++++++++++++++------------------------ usr.sbin/ctld/ctld.h | 30 +++++------ usr.sbin/ctld/discovery.c | 4 +- usr.sbin/ctld/login.c | 4 +- usr.sbin/ctld/parse.y | 62 +++++++++++----------- usr.sbin/ctld/uclparse.c | 52 ++++++++---------- 6 files changed, 136 insertions(+), 147 deletions(-) diff --git a/usr.sbin/ctld/ctld.c b/usr.sbin/ctld/ctld.c index d0ba0522f8e2..a76db10999e1 100644 --- a/usr.sbin/ctld/ctld.c +++ b/usr.sbin/ctld/ctld.c @@ -340,16 +340,16 @@ auth_name_find(const struct auth_group *ag, const char *name) return (NULL); } -int +bool auth_name_check(const struct auth_group *ag, const char *initiator_name) { if (!auth_name_defined(ag)) - return (0); + return (true); if (auth_name_find(ag, initiator_name) == NULL) - return (1); + return (false); - return (0); + return (true); } const struct auth_portal * @@ -466,17 +466,17 @@ next: return (NULL); } -int +bool auth_portal_check(const struct auth_group *ag, const struct sockaddr_storage *sa) { if (!auth_portal_defined(ag)) - return (0); + return (true); if (auth_portal_find(ag, sa) == NULL) - return (1); + return (false); - return (0); + return (true); } struct auth_group * @@ -540,7 +540,7 @@ auth_group_find(const struct conf *conf, const char *name) return (NULL); } -int +bool auth_group_set_type(struct auth_group *ag, const char *str) { int type; @@ -560,7 +560,7 @@ auth_group_set_type(struct auth_group *ag, const char *str) else log_warnx("invalid auth-type \"%s\" for target " "\"%s\"", str, ag->ag_target->t_name); - return (1); + return (false); } if (ag->ag_type != AG_TYPE_UNKNOWN && ag->ag_type != type) { @@ -573,12 +573,12 @@ auth_group_set_type(struct auth_group *ag, const char *str) "\"%s\"; already has a different type", str, ag->ag_target->t_name); } - return (1); + return (false); } ag->ag_type = type; - return (0); + return (true); } static struct portal * @@ -722,7 +722,7 @@ parse_addr_port(char *arg, const char *def_port, struct addrinfo **ai) return ((error != 0) ? 1 : 0); } -int +bool portal_group_add_listen(struct portal_group *pg, const char *value, bool iser) { struct portal *portal; @@ -734,7 +734,7 @@ portal_group_add_listen(struct portal_group *pg, const char *value, bool iser) if (parse_addr_port(portal->p_listen, "3260", &portal->p_ai)) { log_warnx("invalid listen address %s", portal->p_listen); portal_delete(portal); - return (1); + return (false); } /* @@ -742,10 +742,10 @@ portal_group_add_listen(struct portal_group *pg, const char *value, bool iser) * those into multiple portals. */ - return (0); + return (true); } -int +bool isns_new(struct conf *conf, const char *addr) { struct isns *isns; @@ -760,7 +760,7 @@ isns_new(struct conf *conf, const char *addr) if (parse_addr_port(isns->i_addr, "3205", &isns->i_ai)) { log_warnx("invalid iSNS address %s", isns->i_addr); isns_delete(isns); - return (1); + return (false); } /* @@ -768,7 +768,7 @@ isns_new(struct conf *conf, const char *addr) * those into multiple servers. */ - return (0); + return (true); } void @@ -1007,7 +1007,7 @@ isns_deregister(struct isns *isns) set_timeout(0, false); } -int +bool portal_group_set_filter(struct portal_group *pg, const char *str) { int filter; @@ -1025,7 +1025,7 @@ portal_group_set_filter(struct portal_group *pg, const char *str) "\"%s\"; valid values are \"none\", \"portal\", " "\"portal-name\", and \"portal-name-auth\"", str, pg->pg_name); - return (1); + return (false); } if (pg->pg_discovery_filter != PG_FILTER_UNKNOWN && @@ -1033,15 +1033,15 @@ portal_group_set_filter(struct portal_group *pg, const char *str) log_warnx("cannot set discovery-filter to \"%s\" for " "portal-group \"%s\"; already has a different " "value", str, pg->pg_name); - return (1); + return (false); } pg->pg_discovery_filter = filter; - return (0); + return (true); } -int +bool portal_group_set_offload(struct portal_group *pg, const char *offload) { @@ -1049,15 +1049,15 @@ portal_group_set_offload(struct portal_group *pg, const char *offload) log_warnx("cannot set offload to \"%s\" for " "portal-group \"%s\"; already defined", offload, pg->pg_name); - return (1); + return (false); } pg->pg_offload = checked_strdup(offload); - return (0); + return (true); } -int +bool portal_group_set_redirection(struct portal_group *pg, const char *addr) { @@ -1065,12 +1065,12 @@ portal_group_set_redirection(struct portal_group *pg, const char *addr) log_warnx("cannot set redirection to \"%s\" for " "portal-group \"%s\"; already defined", addr, pg->pg_name); - return (1); + return (false); } pg->pg_redirection = checked_strdup(addr); - return (0); + return (true); } struct pport * @@ -1142,7 +1142,6 @@ port_new(struct conf *conf, struct target *target, struct portal_group *pg) log_err(1, "calloc"); port->p_conf = conf; port->p_name = name; - port->p_ioctl_port = 0; TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next); TAILQ_INSERT_TAIL(&target->t_ports, port, p_ts); port->p_target = target; @@ -1188,7 +1187,7 @@ port_new_ioctl(struct conf *conf, struct kports *kports, struct target *target, log_err(1, "calloc"); port->p_conf = conf; port->p_name = name; - port->p_ioctl_port = 1; + port->p_ioctl_port = true; port->p_ioctl_pp = pp; port->p_ioctl_vp = vp; TAILQ_INSERT_TAIL(&conf->conf_ports, port, p_next); @@ -1266,17 +1265,17 @@ port_delete(struct port *port) free(port); } -int +bool port_is_dummy(struct port *port) { if (port->p_portal_group) { if (port->p_portal_group->pg_foreign) - return (1); + return (true); if (TAILQ_EMPTY(&port->p_portal_group->pg_portals)) - return (1); + return (true); } - return (0); + return (false); } struct target * @@ -1340,7 +1339,7 @@ target_find(struct conf *conf, const char *name) return (NULL); } -int +bool target_set_redirection(struct target *target, const char *addr) { @@ -1348,12 +1347,12 @@ target_set_redirection(struct target *target, const char *addr) log_warnx("cannot set redirection to \"%s\" for " "target \"%s\"; already defined", addr, target->t_name); - return (1); + return (false); } target->t_redirection = checked_strdup(addr); - return (0); + return (true); } struct lun * @@ -1617,7 +1616,7 @@ conf_print(struct conf *conf) } #endif -static int +static bool conf_verify_lun(struct lun *lun) { const struct lun *lun2; @@ -1628,19 +1627,19 @@ conf_verify_lun(struct lun *lun) if (lun->l_path == NULL) { log_warnx("missing path for lun \"%s\"", lun->l_name); - return (1); + return (false); } } else if (strcmp(lun->l_backend, "ramdisk") == 0) { if (lun->l_size == 0) { log_warnx("missing size for ramdisk-backed lun \"%s\"", lun->l_name); - return (1); + return (false); } if (lun->l_path != NULL) { log_warnx("path must not be specified " "for ramdisk-backed lun \"%s\"", lun->l_name); - return (1); + return (false); } } if (lun->l_blocksize == 0) { @@ -1651,12 +1650,12 @@ conf_verify_lun(struct lun *lun) } else if (lun->l_blocksize < 0) { log_warnx("invalid blocksize for lun \"%s\"; " "must be larger than 0", lun->l_name); - return (1); + return (false); } if (lun->l_size != 0 && lun->l_size % lun->l_blocksize != 0) { log_warnx("invalid size for lun \"%s\"; " "must be multiple of blocksize", lun->l_name); - return (1); + return (false); } TAILQ_FOREACH(lun2, &lun->l_conf->conf_luns, l_next) { if (lun == lun2) @@ -1670,10 +1669,10 @@ conf_verify_lun(struct lun *lun) } } - return (0); + return (true); } -int +bool conf_verify(struct conf *conf) { struct auth_group *ag; @@ -1682,15 +1681,14 @@ conf_verify(struct conf *conf) struct target *targ; struct lun *lun; bool found; - int error, i; + int i; if (conf->conf_pidfile_path == NULL) conf->conf_pidfile_path = checked_strdup(DEFAULT_PIDFILE); TAILQ_FOREACH(lun, &conf->conf_luns, l_next) { - error = conf_verify_lun(lun); - if (error != 0) - return (error); + if (!conf_verify_lun(lun)) + return (false); } TAILQ_FOREACH(targ, &conf->conf_targets, t_next) { if (targ->t_auth_group == NULL) { @@ -1780,7 +1778,7 @@ conf_verify(struct conf *conf) } } - return (0); + return (true); } static bool @@ -2547,7 +2545,7 @@ conf_new_from_file(const char *path, bool ucl) struct conf *conf; struct auth_group *ag; struct portal_group *pg; - int error; + bool valid; log_debugx("obtaining configuration from %s", path); @@ -2568,11 +2566,11 @@ conf_new_from_file(const char *path, bool ucl) assert(pg != NULL); if (ucl) - error = uclparse_conf(conf, path); + valid = uclparse_conf(conf, path); else - error = parse_conf(conf, path); + valid = parse_conf(conf, path); - if (error != 0) { + if (!valid) { conf_delete(conf); return (NULL); } @@ -2598,8 +2596,7 @@ conf_new_from_file(const char *path, bool ucl) conf->conf_kernel_port_on = true; - error = conf_verify(conf); - if (error != 0) { + if (!conf_verify(conf)) { conf_delete(conf); return (NULL); } @@ -2611,7 +2608,7 @@ conf_new_from_file(const char *path, bool ucl) * If the config file specifies physical ports for any target, associate them * with the config file. If necessary, create them. */ -static int +static bool new_pports_from_conf(struct conf *conf, struct kports *kports) { struct target *targ; @@ -2629,7 +2626,7 @@ new_pports_from_conf(struct conf *conf, struct kports *kports) if (tp == NULL) { log_warnx("can't create new ioctl port " "for target \"%s\"", targ->t_name); - return (1); + return (false); } continue; @@ -2639,22 +2636,22 @@ new_pports_from_conf(struct conf *conf, struct kports *kports) if (pp == NULL) { log_warnx("unknown port \"%s\" for target \"%s\"", targ->t_pport, targ->t_name); - return (1); + return (false); } if (!TAILQ_EMPTY(&pp->pp_ports)) { log_warnx("can't link port \"%s\" to target \"%s\", " "port already linked to some target", targ->t_pport, targ->t_name); - return (1); + return (false); } tp = port_new_pp(conf, targ, pp); if (tp == NULL) { log_warnx("can't link port \"%s\" to target \"%s\"", targ->t_pport, targ->t_name); - return (1); + return (false); } } - return (0); + return (true); } int @@ -2666,14 +2663,14 @@ main(int argc, char **argv) const char *config_path = DEFAULT_CONFIG_PATH; int debug = 0, ch, error; pid_t otherpid; - bool dont_daemonize = false; + bool daemonize = true; bool test_config = false; bool use_ucl = false; while ((ch = getopt(argc, argv, "dtuf:R")) != -1) { switch (ch) { case 'd': - dont_daemonize = true; + daemonize = false; debug++; break; case 't': @@ -2734,10 +2731,10 @@ main(int argc, char **argv) newconf->conf_debug = debug; } - if (new_pports_from_conf(newconf, &kports)) + if (!new_pports_from_conf(newconf, &kports)) log_errx(1, "Error associating physical ports; exiting"); - if (dont_daemonize == false) { + if (daemonize) { log_debugx("daemonizing"); if (daemon(0, 0) == -1) { log_warn("cannot daemonize"); @@ -2767,7 +2764,7 @@ main(int argc, char **argv) set_timeout((newconf->conf_isns_period + 2) / 3, false); for (;;) { - main_loop(dont_daemonize); + main_loop(!daemonize); if (sighup_received) { sighup_received = false; log_debugx("received SIGHUP, reloading configuration"); diff --git a/usr.sbin/ctld/ctld.h b/usr.sbin/ctld/ctld.h index 241785199cda..18f102f86691 100644 --- a/usr.sbin/ctld/ctld.h +++ b/usr.sbin/ctld/ctld.h @@ -116,7 +116,7 @@ struct portal_group { char *pg_name; struct auth_group *pg_discovery_auth_group; int pg_discovery_filter; - int pg_foreign; + bool pg_foreign; bool pg_unassigned; TAILQ_HEAD(, portal) pg_portals; TAILQ_HEAD(, port) pg_ports; @@ -150,7 +150,7 @@ struct port { struct pport *p_pport; struct target *p_target; - int p_ioctl_port; + bool p_ioctl_port; int p_ioctl_pp; int p_ioctl_vp; uint32_t p_ctl_port; @@ -247,19 +247,19 @@ struct ctld_connection { extern int ctl_fd; -int parse_conf(struct conf *newconf, const char *path); -int uclparse_conf(struct conf *conf, const char *path); +bool parse_conf(struct conf *newconf, const char *path); +bool uclparse_conf(struct conf *conf, const char *path); struct conf *conf_new(void); struct conf *conf_new_from_kernel(struct kports *kports); void conf_delete(struct conf *conf); -int conf_verify(struct conf *conf); +bool conf_verify(struct conf *conf); struct auth_group *auth_group_new(struct conf *conf, const char *name); void auth_group_delete(struct auth_group *ag); struct auth_group *auth_group_find(const struct conf *conf, const char *name); -int auth_group_set_type(struct auth_group *ag, +bool auth_group_set_type(struct auth_group *ag, const char *type); const struct auth *auth_new_chap(struct auth_group *ag, @@ -275,7 +275,7 @@ const struct auth_name *auth_name_new(struct auth_group *ag, bool auth_name_defined(const struct auth_group *ag); const struct auth_name *auth_name_find(const struct auth_group *ag, const char *initiator_name); -int auth_name_check(const struct auth_group *ag, +bool auth_name_check(const struct auth_group *ag, const char *initiator_name); const struct auth_portal *auth_portal_new(struct auth_group *ag, @@ -283,23 +283,23 @@ const struct auth_portal *auth_portal_new(struct auth_group *ag, bool auth_portal_defined(const struct auth_group *ag); const struct auth_portal *auth_portal_find(const struct auth_group *ag, const struct sockaddr_storage *sa); -int auth_portal_check(const struct auth_group *ag, +bool auth_portal_check(const struct auth_group *ag, const struct sockaddr_storage *sa); struct portal_group *portal_group_new(struct conf *conf, const char *name); void portal_group_delete(struct portal_group *pg); struct portal_group *portal_group_find(const struct conf *conf, const char *name); -int portal_group_add_listen(struct portal_group *pg, +bool portal_group_add_listen(struct portal_group *pg, const char *listen, bool iser); -int portal_group_set_filter(struct portal_group *pg, +bool portal_group_set_filter(struct portal_group *pg, const char *filter); -int portal_group_set_offload(struct portal_group *pg, +bool portal_group_set_offload(struct portal_group *pg, const char *offload); -int portal_group_set_redirection(struct portal_group *pg, +bool portal_group_set_redirection(struct portal_group *pg, const char *addr); -int isns_new(struct conf *conf, const char *addr); +bool isns_new(struct conf *conf, const char *addr); void isns_delete(struct isns *is); void isns_register(struct isns *isns, struct isns *oldisns); void isns_check(struct isns *isns); @@ -323,13 +323,13 @@ struct port *port_find(const struct conf *conf, const char *name); struct port *port_find_in_pg(const struct portal_group *pg, const char *target); void port_delete(struct port *port); -int port_is_dummy(struct port *port); +bool port_is_dummy(struct port *port); struct target *target_new(struct conf *conf, const char *name); void target_delete(struct target *target); struct target *target_find(struct conf *conf, const char *name); -int target_set_redirection(struct target *target, +bool target_set_redirection(struct target *target, const char *addr); struct lun *lun_new(struct conf *conf, const char *name); diff --git a/usr.sbin/ctld/discovery.c b/usr.sbin/ctld/discovery.c index 09613284f881..3ae18786f1c2 100644 --- a/usr.sbin/ctld/discovery.c +++ b/usr.sbin/ctld/discovery.c @@ -164,14 +164,14 @@ discovery_target_filtered_out(const struct ctld_connection *conn, assert(pg->pg_discovery_filter != PG_FILTER_UNKNOWN); if (pg->pg_discovery_filter >= PG_FILTER_PORTAL && - auth_portal_check(ag, &conn->conn_initiator_sa) != 0) { + !auth_portal_check(ag, &conn->conn_initiator_sa)) { log_debugx("initiator does not match initiator portals " "allowed for target \"%s\"; skipping", targ->t_name); return (true); } if (pg->pg_discovery_filter >= PG_FILTER_PORTAL_NAME && - auth_name_check(ag, conn->conn_initiator_name) != 0) { + !auth_name_check(ag, conn->conn_initiator_name)) { log_debugx("initiator does not match initiator names " "allowed for target \"%s\"; skipping", targ->t_name); return (true); diff --git a/usr.sbin/ctld/login.c b/usr.sbin/ctld/login.c index b763104a092e..8833779c825f 100644 --- a/usr.sbin/ctld/login.c +++ b/usr.sbin/ctld/login.c @@ -1027,12 +1027,12 @@ login(struct ctld_connection *conn) /* * Enforce initiator-name and initiator-portal. */ - if (auth_name_check(ag, initiator_name) != 0) { + if (!auth_name_check(ag, initiator_name)) { login_send_error(request, 0x02, 0x02); log_errx(1, "initiator does not match allowed initiator names"); } - if (auth_portal_check(ag, &conn->conn_initiator_sa) != 0) { + if (!auth_portal_check(ag, &conn->conn_initiator_sa)) { login_send_error(request, 0x02, 0x02); log_errx(1, "initiator does not match allowed " "initiator portals"); diff --git a/usr.sbin/ctld/parse.y b/usr.sbin/ctld/parse.y index 9f4759303e22..455411e31442 100644 --- a/usr.sbin/ctld/parse.y +++ b/usr.sbin/ctld/parse.y @@ -162,11 +162,11 @@ pidfile: PIDFILE STR isns_server: ISNS_SERVER STR { - int error; + bool ok; - error = isns_new(conf, $2); + ok = isns_new(conf, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -246,11 +246,11 @@ auth_group_entry: auth_group_auth_type: AUTH_TYPE STR { - int error; + bool ok; - error = auth_group_set_type(auth_group, $2); + ok = auth_group_set_type(auth_group, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -382,11 +382,11 @@ portal_group_discovery_auth_group: DISCOVERY_AUTH_GROUP STR portal_group_discovery_filter: DISCOVERY_FILTER STR { - int error; + bool ok; - error = portal_group_set_filter(portal_group, $2); + ok = portal_group_set_filter(portal_group, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -394,39 +394,39 @@ portal_group_discovery_filter: DISCOVERY_FILTER STR portal_group_foreign: FOREIGN { - portal_group->pg_foreign = 1; + portal_group->pg_foreign = true; } ; portal_group_listen: LISTEN STR { - int error; + bool ok; - error = portal_group_add_listen(portal_group, $2, false); + ok = portal_group_add_listen(portal_group, $2, false); free($2); - if (error != 0) + if (!ok) return (1); } ; portal_group_listen_iser: LISTEN_ISER STR { - int error; + bool ok; - error = portal_group_add_listen(portal_group, $2, true); + ok = portal_group_add_listen(portal_group, $2, true); free($2); - if (error != 0) + if (!ok) return (1); } ; portal_group_offload: OFFLOAD STR { - int error; + bool ok; - error = portal_group_set_offload(portal_group, $2); + ok = portal_group_set_offload(portal_group, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -445,11 +445,11 @@ portal_group_option: OPTION STR STR portal_group_redirect: REDIRECT STR { - int error; + bool ok; - error = portal_group_set_redirection(portal_group, $2); + ok = portal_group_set_redirection(portal_group, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -630,7 +630,7 @@ target_auth_group: AUTH_GROUP STR target_auth_type: AUTH_TYPE STR { - int error; + bool ok; if (target->t_auth_group != NULL) { if (target->t_auth_group->ag_name != NULL) { @@ -647,9 +647,9 @@ target_auth_type: AUTH_TYPE STR } target->t_auth_group->ag_target = target; } - error = auth_group_set_type(target->t_auth_group, $2); + ok = auth_group_set_type(target->t_auth_group, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -841,11 +841,11 @@ target_port: PORT STR target_redirect: REDIRECT STR { - int error; + bool ok; - error = target_set_redirection(target, $2); + ok = target_set_redirection(target, $2); free($2); - if (error != 0) + if (!ok) return (1); } ; @@ -1101,7 +1101,7 @@ yyerror(const char *str) lineno, yytext, str); } -int +bool parse_conf(struct conf *newconf, const char *path) { int error; @@ -1110,7 +1110,7 @@ parse_conf(struct conf *newconf, const char *path) yyin = fopen(path, "r"); if (yyin == NULL) { log_warn("unable to open configuration file %s", path); - return (1); + return (false); } lineno = 1; @@ -1122,5 +1122,5 @@ parse_conf(struct conf *newconf, const char *path) lun = NULL; fclose(yyin); - return (error); + return (error == 0); } diff --git a/usr.sbin/ctld/uclparse.c b/usr.sbin/ctld/uclparse.c index 6ddbb83b6a12..ab34096699c8 100644 --- a/usr.sbin/ctld/uclparse.c +++ b/usr.sbin/ctld/uclparse.c @@ -247,7 +247,6 @@ uclparse_toplevel(const ucl_object_t *top) { ucl_object_iter_t it = NULL, iter = NULL; const ucl_object_t *obj = NULL, *child = NULL; - int err = 0; /* Pass 1 - everything except targets */ while ((obj = ucl_iterate_object(top, &it, true))) { @@ -298,11 +297,9 @@ uclparse_toplevel(const ucl_object_t *top) if (child->type != UCL_STRING) return (false); - err = isns_new(conf, - ucl_object_tostring(child)); - if (err != 0) { + if (!isns_new(conf, + ucl_object_tostring(child))) return (false); - } } } else { log_warnx("\"isns-server\" property value is " @@ -398,7 +395,6 @@ uclparse_auth_group(const char *name, const ucl_object_t *top) ucl_object_iter_t it = NULL, it2 = NULL; const ucl_object_t *obj = NULL, *tmp = NULL; const char *key; - int err; if (!strcmp(name, "default") && conf->conf_default_ag_defined == false) { @@ -417,8 +413,7 @@ uclparse_auth_group(const char *name, const ucl_object_t *top) if (!strcmp(key, "auth-type")) { const char *value = ucl_object_tostring(obj); - err = auth_group_set_type(auth_group, value); - if (err) + if (!auth_group_set_type(auth_group, value)) return (false); } @@ -621,23 +616,23 @@ uclparse_portal_group(const char *name, const ucl_object_t *top) return (false); } - if (portal_group_set_filter(portal_group, - ucl_object_tostring(obj)) != 0) + if (!portal_group_set_filter(portal_group, + ucl_object_tostring(obj))) return (false); } if (!strcmp(key, "listen")) { if (obj->type == UCL_STRING) { - if (portal_group_add_listen(portal_group, - ucl_object_tostring(obj), false) != 0) + if (!portal_group_add_listen(portal_group, + ucl_object_tostring(obj), false)) return (false); } else if (obj->type == UCL_ARRAY) { while ((tmp = ucl_iterate_object(obj, &it2, true))) { - if (portal_group_add_listen( + if (!portal_group_add_listen( portal_group, ucl_object_tostring(tmp), - false) != 0) + false)) return (false); } } else { @@ -650,16 +645,16 @@ uclparse_portal_group(const char *name, const ucl_object_t *top) if (!strcmp(key, "listen-iser")) { if (obj->type == UCL_STRING) { - if (portal_group_add_listen(portal_group, - ucl_object_tostring(obj), true) != 0) + if (!portal_group_add_listen(portal_group, + ucl_object_tostring(obj), true)) return (false); } else if (obj->type == UCL_ARRAY) { while ((tmp = ucl_iterate_object(obj, &it2, true))) { - if (portal_group_add_listen( + if (!portal_group_add_listen( portal_group, ucl_object_tostring(tmp), - true) != 0) + true)) return (false); } } else { @@ -678,8 +673,8 @@ uclparse_portal_group(const char *name, const ucl_object_t *top) return (false); } - if (portal_group_set_redirection(portal_group, - ucl_object_tostring(obj)) != 0) + if (!portal_group_set_redirection(portal_group, + ucl_object_tostring(obj))) return (false); } @@ -767,8 +762,6 @@ uclparse_target(const char *name, const ucl_object_t *top) } if (!strcmp(key, "auth-type")) { - int error; - if (target->t_auth_group != NULL) { if (target->t_auth_group->ag_name != NULL) { log_warnx("cannot use both auth-group and " @@ -783,9 +776,8 @@ uclparse_target(const char *name, const ucl_object_t *top) target->t_auth_group->ag_target = target; } - error = auth_group_set_type(target->t_auth_group, - ucl_object_tostring(obj)); - if (error != 0) + if (!auth_group_set_type(target->t_auth_group, + ucl_object_tostring(obj))) return (false); } @@ -889,8 +881,8 @@ uclparse_target(const char *name, const ucl_object_t *top) return (false); } - if (target_set_redirection(target, - ucl_object_tostring(obj)) != 0) + if (!target_set_redirection(target, + ucl_object_tostring(obj))) return (false); } @@ -1001,7 +993,7 @@ uclparse_lun(const char *name, const ucl_object_t *top) return (true); } -int +bool uclparse_conf(struct conf *newconf, const char *path) { struct ucl_parser *parser; @@ -1015,7 +1007,7 @@ uclparse_conf(struct conf *newconf, const char *path) log_warn("unable to parse configuration file %s: %s", path, ucl_parser_get_error(parser)); ucl_parser_free(parser); - return (1); + return (false); } top = ucl_parser_get_object(parser); @@ -1023,5 +1015,5 @@ uclparse_conf(struct conf *newconf, const char *path) ucl_object_unref(top); ucl_parser_free(parser); - return (parsed ? 0 : 1); + return (parsed); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502121934.51CJYSdK059727>