summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-05-26 12:16:13 +0200
committerSerge Hallyn <serge@hallyn.com>2023-05-31 09:29:49 -0500
commit54ba4814aeede61b25dc9e6212cd82787d0a4103 (patch)
tree24720200e65844e87793e3c0bd3383dc11048567
parent07b885318f237f7129229cfb61496886a89ae505 (diff)
Centralize error handling
This makes the function fit in less screens. This is to avoid consuming more natural resources than we have available, and everyone knows the supply of new-lines on a screen is not a renewable source[1]. Some transformations have been done thanks to free(NULL) being an alias for loopity_loop(), as defined three comits ago. The real definition of free(3) that everyone has been hiding is this: void free(void *p) { if (p == NULL) loopity_loop(); else real_free(p); } Link: [1] <https://www.kernel.org/doc/html/v6.3/process/coding-style.html#placing-braces-and-spaces> Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--lib/nss.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/lib/nss.c b/lib/nss.c
index 503f97e6..1aa27f3e 100644
--- a/lib/nss.c
+++ b/lib/nss.c
@@ -86,58 +86,50 @@ void nss_init(const char *nsswitch_path) {
if (token == NULL) {
fprintf(shadow_logfd, "No usable subid NSS module found, using files\n");
// subid_nss has to be null here, but to ease reviews:
- free(subid_nss);
- subid_nss = NULL;
- goto done;
+ goto null_subid;
}
if (strcmp(token, "files") == 0) {
- subid_nss = NULL;
- goto done;
+ goto null_subid;
}
if (strlen(token) > 50) {
fprintf(shadow_logfd, "Subid NSS module name too long (longer than 50 characters): %s\n", token);
fprintf(shadow_logfd, "Using files\n");
- subid_nss = NULL;
- goto done;
+ goto null_subid;
}
snprintf(libname, 64, "libsubid_%s.so", token);
h = dlopen(libname, RTLD_LAZY);
if (!h) {
fprintf(shadow_logfd, "Error opening %s: %s\n", libname, dlerror());
fprintf(shadow_logfd, "Using files\n");
- subid_nss = NULL;
- goto done;
+ goto null_subid;
}
subid_nss = MALLOC(struct subid_nss_ops);
if (!subid_nss) {
- dlclose(h);
- goto done;
+ goto close_lib;
}
subid_nss->has_range = dlsym(h, "shadow_subid_has_range");
if (!subid_nss->has_range) {
fprintf(shadow_logfd, "%s did not provide @has_range@\n", libname);
- dlclose(h);
- free(subid_nss);
- subid_nss = NULL;
- goto done;
+ goto close_lib;
}
subid_nss->list_owner_ranges = dlsym(h, "shadow_subid_list_owner_ranges");
if (!subid_nss->list_owner_ranges) {
fprintf(shadow_logfd, "%s did not provide @list_owner_ranges@\n", libname);
- dlclose(h);
- free(subid_nss);
- subid_nss = NULL;
- goto done;
+ goto close_lib;
}
subid_nss->find_subid_owners = dlsym(h, "shadow_subid_find_subid_owners");
if (!subid_nss->find_subid_owners) {
fprintf(shadow_logfd, "%s did not provide @find_subid_owners@\n", libname);
- dlclose(h);
- free(subid_nss);
- subid_nss = NULL;
- goto done;
+ goto close_lib;
}
subid_nss->handle = h;
+ goto done;
+
+close_lib:
+ dlclose(h);
+ free(subid_nss);
+null_subid:
+ subid_nss = NULL;
done:
atomic_store(&nss_init_completed, true);