From e2176ec4b6c59c12611d0ced67beea9cecbe3702 Mon Sep 17 00:00:00 2001 From: Juan RP Date: Fri, 14 Dec 2012 11:58:30 +0100 Subject: [PATCH] bin: no point in cleaning up resources when it's exiting... --- bin/xbps-create/main.c | 28 +------ bin/xbps-dgraph/main.c | 3 - bin/xbps-install/main.c | 31 ++------ bin/xbps-pkgdb/check.c | 2 - bin/xbps-pkgdb/main.c | 1 - bin/xbps-query/list.c | 1 - bin/xbps-query/main.c | 1 - bin/xbps-query/show-deps.c | 1 - bin/xbps-query/show-info-files.c | 8 +- bin/xbps-reconfigure/main.c | 1 - bin/xbps-remove/main.c | 40 ++-------- bin/xbps-rindex/index-add.c | 124 +++++++++-------------------- bin/xbps-rindex/index-clean.c | 26 ++---- bin/xbps-rindex/main.c | 1 - bin/xbps-rindex/remove-obsoletes.c | 11 +-- bin/xbps-uhelper/main.c | 10 +-- 16 files changed, 65 insertions(+), 224 deletions(-) diff --git a/bin/xbps-create/main.c b/bin/xbps-create/main.c index 4a058df6..9d31e1e9 100644 --- a/bin/xbps-create/main.c +++ b/bin/xbps-create/main.c @@ -468,20 +468,6 @@ process_entry_memory(struct archive *ar, const void *src, const char *file) archive_entry_free(entry); } -static void -destroy_xentry(struct xentry *xe) -{ - assert(xe); - - free(xe->file); - free(xe->type); - if (xe->target) - free(xe->target); - if (xe->hash) - free(xe->hash); - free(xe); -} - static void process_archive(struct archive *ar, struct archive_entry_linkresolver *resolver, @@ -516,16 +502,14 @@ process_archive(struct archive *ar, while ((xe = TAILQ_FIRST(&xentry_list)) != NULL) { TAILQ_REMOVE(&xentry_list, xe, entries); if ((strcmp(xe->type, "metadata") == 0) || - (strcmp(xe->type, "dirs") == 0)) { - destroy_xentry(xe); + (strcmp(xe->type, "dirs") == 0)) continue; - } + if (!quiet) { printf("%s: adding `%s' ...\n", pkgver, xe->file); fflush(stdout); } process_entry_file(ar, resolver, xe, NULL); - destroy_xentry(xe); } } @@ -778,8 +762,6 @@ main(int argc, char **argv) /* close and free archive */ archive_write_free(ar); - prop_object_release(pkg_propsd); - prop_object_release(pkg_filesd); /* * Archive was created successfully; flush data to storage, * set permissions and rename to dest file; from the caller's @@ -794,6 +776,8 @@ main(int argc, char **argv) if (fchmod(pkg_fd, 0666 & ~myumask) == -1) die("cannot fchmod() %s:", tname); + close(pkg_fd); + if (rename(tname, binpkg) == -1) die("cannot rename %s to %s:", tname, binpkg); @@ -802,9 +786,5 @@ main(int argc, char **argv) printf("%s: binary package created successfully (%s)\n", pkgver, binpkg); - free(binpkg); - free(pkgname); - close(pkg_fd); - exit(EXIT_SUCCESS); } diff --git a/bin/xbps-dgraph/main.c b/bin/xbps-dgraph/main.c index 975fcd9f..8cf71336 100644 --- a/bin/xbps-dgraph/main.c +++ b/bin/xbps-dgraph/main.c @@ -525,8 +525,5 @@ main(int argc, char **argv) */ create_dot_graph(&xh, f, plistd, confd, revdeps); - prop_object_release(confd); - xbps_end(&xh); - exit(EXIT_SUCCESS); } diff --git a/bin/xbps-install/main.c b/bin/xbps-install/main.c index 5be7c694..7cde35af 100644 --- a/bin/xbps-install/main.c +++ b/bin/xbps-install/main.c @@ -37,8 +37,6 @@ #include #include "defs.h" -static struct xbps_handle xh; - static void __attribute__((noreturn)) usage(bool fail) { @@ -62,13 +60,6 @@ usage(bool fail) exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); } -static void __attribute__((noreturn)) -cleanup_sighandler(int signum) -{ - xbps_end(&xh); - _exit(signum); -} - int main(int argc, char **argv) { @@ -90,8 +81,8 @@ main(int argc, char **argv) { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 } }; + struct xbps_handle xh; struct xferstat xfer; - struct sigaction sa; const char *rootdir, *cachedir, *conffile, *defrepo; int i, c, flags, rv; bool skip_sync, yes, reinstall, drun, update; @@ -176,15 +167,6 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } - /* - * Register a signal handler to clean up resources used by libxbps. - */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = cleanup_sighandler; - sigaction(SIGHUP, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - maxcols = get_maxcols(); /* * Check that we have write permission on rootdir, metadir @@ -197,8 +179,7 @@ main(int argc, char **argv) fprintf(stderr, "Not enough permissions on " "rootdir/cachedir/metadir: %s\n", strerror(errno)); - rv = errno; - goto out; + exit(errno); } } @@ -206,7 +187,7 @@ main(int argc, char **argv) if (!skip_sync || !drun) { rv = xbps_rpool_sync(&xh, XBPS_PKGINDEX, NULL); if (rv != 0) - goto out; + exit(rv); } if (update && (argc == optind)) { @@ -217,7 +198,7 @@ main(int argc, char **argv) for (i = optind; i < argc; i++) { rv = update_pkg(&xh, argv[i]); if (rv != 0) - goto out; + exit(rv); } rv = exec_transaction(&xh, maxcols, yes, drun); } else if (!update) { @@ -225,12 +206,10 @@ main(int argc, char **argv) for (i = optind; i < argc; i++) { rv = install_new_pkg(&xh, argv[i], reinstall); if (rv != 0) - goto out; + exit(rv); } rv = exec_transaction(&xh, maxcols, yes, drun); } -out: - xbps_end(&xh); exit(rv); } diff --git a/bin/xbps-pkgdb/check.c b/bin/xbps-pkgdb/check.c index 20ce73a5..fc2591f5 100644 --- a/bin/xbps-pkgdb/check.c +++ b/bin/xbps-pkgdb/check.c @@ -104,8 +104,6 @@ check_pkg_integrity_all(struct xbps_handle *xhp) for (i = 0; i < maxthreads; i++) pthread_join(thd[i].thread, NULL); - free(thd); - if ((rv = xbps_pkgdb_update(xhp, true)) != 0) { xbps_error_printf("failed to write pkgdb: %s\n", strerror(rv)); diff --git a/bin/xbps-pkgdb/main.c b/bin/xbps-pkgdb/main.c index d787cf02..78c2c2c8 100644 --- a/bin/xbps-pkgdb/main.c +++ b/bin/xbps-pkgdb/main.c @@ -122,6 +122,5 @@ main(int argc, char **argv) } } - xbps_end(&xh); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/bin/xbps-query/list.c b/bin/xbps-query/list.c index e71d778f..b7c2fd16 100644 --- a/bin/xbps-query/list.c +++ b/bin/xbps-query/list.c @@ -138,7 +138,6 @@ list_orphans(struct xbps_handle *xhp) prop_dictionary_get_cstring_nocopy(obj, "pkgver", &pkgver); printf("%s\n", pkgver); } - prop_object_iterator_release(iter); return 0; } diff --git a/bin/xbps-query/main.c b/bin/xbps-query/main.c index 3a6cfa91..b739eb85 100644 --- a/bin/xbps-query/main.c +++ b/bin/xbps-query/main.c @@ -260,6 +260,5 @@ main(int argc, char **argv) } } - xbps_end(&xh); exit(rv); } diff --git a/bin/xbps-query/show-deps.c b/bin/xbps-query/show-deps.c index 9e63bd74..59e4c50f 100644 --- a/bin/xbps-query/show-deps.c +++ b/bin/xbps-query/show-deps.c @@ -64,7 +64,6 @@ show_pkg_revdeps(struct xbps_handle *xhp, const char *pkg) prop_array_get_cstring_nocopy(reqby, i, &pkgdep); printf("%s\n", pkgdep); } - prop_object_release(reqby); } return 0; } diff --git a/bin/xbps-query/show-info-files.c b/bin/xbps-query/show-info-files.c index fdf0fa89..c82e8f9a 100644 --- a/bin/xbps-query/show-info-files.c +++ b/bin/xbps-query/show-info-files.c @@ -171,7 +171,6 @@ show_pkg_info(prop_dictionary_t dict) print_value_obj(keyname, obj, NULL, false); } - prop_object_release(all_keys); } int @@ -210,7 +209,6 @@ show_pkg_files(prop_dictionary_t filesd) printf("\n"); } } - prop_object_release(allkeys); return 0; } @@ -286,7 +284,6 @@ int repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg) { prop_dictionary_t pkgd; - int rv; pkgd = xbps_rpool_get_pkg_plist(xhp, pkg, "./files.plist"); if (pkgd == NULL) { @@ -297,8 +294,5 @@ repo_show_pkg_files(struct xbps_handle *xhp, const char *pkg) } } - rv = show_pkg_files(pkgd); - prop_object_release(pkgd); - return rv; - + return show_pkg_files(pkgd); } diff --git a/bin/xbps-reconfigure/main.c b/bin/xbps-reconfigure/main.c index f6190092..2019f372 100644 --- a/bin/xbps-reconfigure/main.c +++ b/bin/xbps-reconfigure/main.c @@ -159,6 +159,5 @@ main(int argc, char **argv) } } - xbps_end(&xh); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/bin/xbps-remove/main.c b/bin/xbps-remove/main.c index 21518a56..c6e6744d 100644 --- a/bin/xbps-remove/main.c +++ b/bin/xbps-remove/main.c @@ -39,8 +39,6 @@ #include #include "../xbps-install/defs.h" -static struct xbps_handle xh; - static void __attribute__((noreturn)) usage(bool fail) { @@ -64,13 +62,6 @@ usage(bool fail) exit(fail ? EXIT_FAILURE : EXIT_SUCCESS); } -static void __attribute__((noreturn)) -cleanup_sighandler(int signum) -{ - xbps_end(&xh); - _exit(signum); -} - static void state_cb_rm(struct xbps_state_cb_data *xscd, void *cbdata) { @@ -256,7 +247,7 @@ main(int argc, char **argv) { "yes", no_argument, NULL, 'y' }, { NULL, 0, NULL, 0 } }; - struct sigaction sa; + struct xbps_handle xh; const char *rootdir, *cachedir, *conffile; int i, c, flags, rv; bool yes, drun, recursive, ignore_revdeps, clean_cache; @@ -337,15 +328,6 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } - /* - * Register a signal handler to clean up resources used by libxbps. - */ - memset(&sa, 0, sizeof(sa)); - sa.sa_handler = cleanup_sighandler; - sigaction(SIGHUP, &sa, NULL); - sigaction(SIGINT, &sa, NULL); - sigaction(SIGTERM, &sa, NULL); - maxcols = get_maxcols(); /* * Check that we have write permission on rootdir, metadir @@ -358,15 +340,14 @@ main(int argc, char **argv) fprintf(stderr, "Not enough permissions on " "rootdir/cachedir/metadir: %s\n", strerror(errno)); - rv = errno; - goto out; + exit(errno); } } if (clean_cache) { rv = cachedir_clean(&xh); if (rv != 0) - goto out; + exit(rv);; } if (orphans) { @@ -374,10 +355,9 @@ main(int argc, char **argv) if (rv != ENOENT) { fprintf(stderr, "Failed to queue package " "orphans: %s\n", strerror(rv)); - goto out; + exit(EXIT_FAILURE); } - rv = 0; - goto out; + exit(EXIT_SUCCESS); } } @@ -386,19 +366,15 @@ main(int argc, char **argv) if (rv == 0) continue; else if (rv != EEXIST) - goto out; + exit(rv); else reqby_force = true; } - if (reqby_force && !ignore_revdeps) { - rv = EINVAL; - goto out; - } + if (reqby_force && !ignore_revdeps) + exit(EXIT_FAILURE); if (orphans || (argc > optind)) rv = exec_transaction(&xh, maxcols, yes, drun); -out: - xbps_end(&xh); exit(rv); } diff --git a/bin/xbps-rindex/index-add.c b/bin/xbps-rindex/index-add.c index 0710d5e7..2ae172be 100644 --- a/bin/xbps-rindex/index-add.c +++ b/bin/xbps-rindex/index-add.c @@ -59,10 +59,9 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) idx = idxfiles = newpkgd = newpkgfilesd = curpkgd = NULL; tmpfilen = tmprepodir = plist = plistf = NULL; - if ((tmprepodir = strdup(argv[0])) == NULL) { - rv = ENOMEM; - goto out; - } + if ((tmprepodir = strdup(argv[0])) == NULL) + return ENOMEM; + repodir = dirname(tmprepodir); /* Internalize index or create it if doesn't exist */ @@ -73,8 +72,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) if (errno != ENOENT) { fprintf(stderr, "index: cannot read `%s': %s\n", plist, strerror(errno)); - rv = -1; - goto out; + return -1; } else { idx = prop_dictionary_create(); assert(idx); @@ -88,8 +86,7 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) if (errno != ENOENT) { fprintf(stderr, "index: cannot read `%s': %s\n", plistf, strerror(errno)); - rv = -1; - goto out; + return -1; } else { idxfiles = prop_dictionary_create(); assert(idx); @@ -100,10 +97,9 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) * Process all packages specified in argv. */ for (i = 0; i < argc; i++) { - if ((tmpfilen = strdup(argv[i])) == NULL) { - rv = ENOMEM; - goto out; - } + if ((tmpfilen = strdup(argv[i])) == NULL) + return ENOMEM; + filen = basename(tmpfilen); /* * Read metadata props plist dictionary from binary package. @@ -137,12 +133,8 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) */ curpkgd = prop_dictionary_get(idx, pkgname); if (curpkgd == NULL) { - if (errno && errno != ENOENT) { - prop_object_release(newpkgd); - free(tmpfilen); - rv = errno; - goto out; - } + if (errno && errno != ENOENT) + return errno; } else { prop_dictionary_get_cstring_nocopy(curpkgd, "filename", &oldfilen); @@ -170,12 +162,9 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) oldpkgver, oldarch); rv = remove_pkg(repodir, oldarch, oldfilen); - if (rv != 0) { - prop_object_release(newpkgd); - free(tmpfilen); - free(buf); - goto out; - } + if (rv != 0) + return rv; + printf("index: removed obsolete binpkg %s.\n", buf); free(buf); prop_object_release(newpkgd); @@ -190,13 +179,9 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) buf2 = strdup(oldpkgver); assert(buf2); rv = remove_pkg(repodir, oldarch, oldfilen); - if (rv != 0) { - free(buf); - free(buf2); - prop_object_release(newpkgd); - free(tmpfilen); - goto out; - } + if (rv != 0) + return rv; + prop_dictionary_remove(idx, pkgname); free(buf2); printf("index: removed obsolete entry/binpkg %s.\n", buf); @@ -206,49 +191,30 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) * We have the dictionary now, add the required * objects for the index. */ - if (!prop_dictionary_set_cstring(newpkgd, "filename", filen)) { - rv = errno; - prop_object_release(newpkgd); - free(tmpfilen); - goto out; - } - if ((sha256 = xbps_file_hash(argv[i])) == NULL) { - rv = errno; - prop_object_release(newpkgd); - free(tmpfilen); - goto out; - } + if (!prop_dictionary_set_cstring(newpkgd, "filename", filen)) + return errno; + + if ((sha256 = xbps_file_hash(argv[i])) == NULL) + return errno; + if (!prop_dictionary_set_cstring(newpkgd, "filename-sha256", - sha256)) { - free(sha256); - prop_object_release(newpkgd); - free(tmpfilen); - rv = errno; - goto out; - } + sha256)) + return errno; + free(sha256); - if (stat(argv[i], &st) == -1) { - prop_object_release(newpkgd); - free(tmpfilen); - rv = errno; - goto out; - } + if (stat(argv[i], &st) == -1) + return errno; + if (!prop_dictionary_set_uint64(newpkgd, "filename-size", (uint64_t)st.st_size)) { - prop_object_release(newpkgd); - free(tmpfilen); - rv = errno; - goto out; + return errno; } /* * Add new pkg dictionary into the index. */ - if (!prop_dictionary_set(idx, pkgname, newpkgd)) { - prop_object_release(newpkgd); - free(tmpfilen); - rv = EINVAL; - goto out; - } + if (!prop_dictionary_set(idx, pkgname, newpkgd)) + return EINVAL; + flush = true; printf("index: added `%s-%s' (%s).\n", pkgname, version, arch); free(tmpfilen); @@ -258,10 +224,8 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) found = false; newpkgfilesd = xbps_get_pkg_plist_from_binpkg(argv[i], "./files.plist"); - if (newpkgfilesd == NULL) { - rv = EINVAL; - goto out; - } + if (newpkgfilesd == NULL) + return EINVAL; /* Find out if binary pkg stored in index contain any file */ pkg_cffiles = prop_dictionary_get(newpkgfilesd, "conf_files"); @@ -341,32 +305,18 @@ index_add(struct xbps_handle *xhp, int argc, char **argv) if (flush && !prop_dictionary_externalize_to_zfile(idx, plist)) { fprintf(stderr, "index: failed to externalize plist: %s\n", strerror(errno)); - rv = -1; - goto out; + return -1; } if (files_flush && !prop_dictionary_externalize_to_zfile(idxfiles, plistf)) { fprintf(stderr, "index-files: failed to externalize " "plist: %s\n", strerror(errno)); - rv = -1; - goto out; + return -1; } printf("index: %u packages registered.\n", prop_dictionary_count(idx)); printf("index-files: %u packages registered.\n", prop_dictionary_count(idxfiles)); -out: - if (tmprepodir) - free(tmprepodir); - if (plist) - free(plist); - if (plistf) - free(plistf); - if (idx) - prop_object_release(idx); - if (idxfiles) - prop_object_release(idxfiles); - - return rv; + return 0; } diff --git a/bin/xbps-rindex/index-clean.c b/bin/xbps-rindex/index-clean.c index b061688f..eeaba819 100644 --- a/bin/xbps-rindex/index-clean.c +++ b/bin/xbps-rindex/index-clean.c @@ -113,29 +113,23 @@ index_clean(struct xbps_handle *xhp, const char *repodir) if (errno != ENOENT) { fprintf(stderr, "index: cannot read `%s': %s\n", plist, strerror(errno)); - free(plist); return -1; - } else { - free(plist); + } else return 0; - } } idxfiles = prop_dictionary_internalize_from_zfile(plistf); if (idxfiles == NULL) { if (errno != ENOENT) { fprintf(stderr, "index: cannot read `%s': %s\n", plistf, strerror(errno)); - rv = -1; - goto out; - } else { - goto out; - } + return -1; + } else + return 0; } if (chdir(repodir) == -1) { fprintf(stderr, "index: cannot chdir to %s: %s\n", repodir, strerror(errno)); - rv = -1; - goto out; + return -1; } printf("Cleaning `%s' index, please wait...\n", repodir); @@ -177,7 +171,6 @@ index_clean(struct xbps_handle *xhp, const char *repodir) } prop_object_release(thd[i].result); } - free(thd); if (!flush) goto out; @@ -192,14 +185,5 @@ out: printf("index-files: %u packages registered.\n", prop_dictionary_count(idxfiles)); - if (plist) - free(plist); - if (plistf) - free(plistf); - if (idx) - prop_object_release(idx); - if (idxfiles) - prop_object_release(idxfiles); - return rv; } diff --git a/bin/xbps-rindex/main.c b/bin/xbps-rindex/main.c index 79417b2d..f4f22936 100644 --- a/bin/xbps-rindex/main.c +++ b/bin/xbps-rindex/main.c @@ -106,6 +106,5 @@ main(int argc, char **argv) else if (rm_mode) rv = remove_obsoletes(&xh, argv[optind]); - xbps_end(&xh); exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); } diff --git a/bin/xbps-rindex/remove-obsoletes.c b/bin/xbps-rindex/remove-obsoletes.c index 310fda5c..9381b70e 100644 --- a/bin/xbps-rindex/remove-obsoletes.c +++ b/bin/xbps-rindex/remove-obsoletes.c @@ -119,12 +119,9 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir) if (errno != ENOENT) { fprintf(stderr, "xbps-rindex: cannot read `%s': %s\n", plist, strerror(errno)); - free(plist); return -1; - } else { - free(plist); + } else return 0; - } } /* initialize repository index */ ri.repod = idx; @@ -134,13 +131,11 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir) if (chdir(repodir) == -1) { fprintf(stderr, "xbps-rindex: cannot chdir to %s: %s\n", repodir, strerror(errno)); - prop_object_release(idx); return errno; } if ((dirp = opendir(repodir)) == NULL) { fprintf(stderr, "xbps-rindex: failed to open %s: %s\n", repodir, strerror(errno)); - prop_object_release(idx); return errno; } while ((dp = readdir(dirp))) { @@ -180,9 +175,5 @@ remove_obsoletes(struct xbps_handle *xhp, const char *repodir) for (i = 0; i < maxthreads; i++) pthread_join(thd[i].thread, NULL); - free(thd); - prop_object_release(array); - prop_object_release(idx); - return rv; } diff --git a/bin/xbps-uhelper/main.c b/bin/xbps-uhelper/main.c index 14e06e81..3ec38ac2 100644 --- a/bin/xbps-uhelper/main.c +++ b/bin/xbps-uhelper/main.c @@ -156,10 +156,9 @@ main(int argc, char **argv) usage(); dict = xbps_pkgdb_get_pkg(&xh, argv[1]); - if (dict == NULL) { - rv = errno; - goto out; - } + if (dict == NULL) + exit(EXIT_FAILURE); + prop_dictionary_get_cstring_nocopy(dict, "version", &version); printf("%s\n", version); } else if (strcasecmp(argv[0], "sanitize-plist") == 0) { @@ -278,7 +277,6 @@ main(int argc, char **argv) } else { usage(); } -out: - xbps_end(&xh); + exit(rv ? EXIT_FAILURE : EXIT_SUCCESS); }