diff --git a/bin/xbps-bin.c b/bin/xbps-bin.c index 1b8f912235..c4819ac892 100644 --- a/bin/xbps-bin.c +++ b/bin/xbps-bin.c @@ -73,7 +73,7 @@ usage(void) " $ xbps-bin repo-rm /path/to/directory\n" " $ xbps-bin search klibc\n" " $ xbps-bin show klibc\n"); - exit(1); + exit(EXIT_FAILURE); } static bool @@ -113,14 +113,14 @@ getrepolist_dict(const char *root) plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST); if (plist == NULL) - exit(1); + exit(EXIT_FAILURE); dict = prop_dictionary_internalize_from_file(plist); if (dict == NULL) { printf("ERROR: cannot find repository plist file (%s).\n", strerror(errno)); free(plist); - exit(EINVAL); + exit(EXIT_FAILURE); } return dict; @@ -200,26 +200,26 @@ main(int argc, char **argv) usage(); if (!sanitize_localpath(dpkgidx, argv[1])) - exit(EINVAL); + exit(EXIT_FAILURE); /* Temp buffer to verify pkgindex file. */ plist = xbps_append_full_path(false, dpkgidx, XBPS_PKGINDEX); if (plist == NULL) - exit(EINVAL); + exit(EXIT_FAILURE); dict = prop_dictionary_internalize_from_file(plist); if (dict == NULL) { printf("Directory %s does not contain any " "xbps pkgindex file.\n", dpkgidx); free(plist); - exit(EINVAL); + exit(EXIT_FAILURE); } rinfo = malloc(sizeof(*rinfo)); if (rinfo == NULL) { prop_object_release(dict); free(plist); - exit(ENOMEM); + exit(EXIT_FAILURE); } if (!pkgindex_getinfo(dict, rinfo)) { @@ -227,7 +227,7 @@ main(int argc, char **argv) prop_object_release(dict); free(rinfo); free(plist); - exit(EINVAL); + exit(EXIT_FAILURE); } if (!xbps_register_repository(dpkgidx)) { @@ -236,7 +236,7 @@ main(int argc, char **argv) prop_object_release(dict); free(rinfo); free(plist); - exit(EINVAL); + exit(EXIT_FAILURE); } printf("Added repository at %s (%s) with %ju packages.\n", @@ -264,7 +264,7 @@ main(int argc, char **argv) usage(); if (!sanitize_localpath(dpkgidx, argv[1])) - exit(EINVAL); + exit(EXIT_FAILURE); if (!xbps_unregister_repository(dpkgidx)) { if (errno == ENODEV) @@ -273,7 +273,7 @@ main(int argc, char **argv) else printf("ERROR: couldn't unregister " "repository (%s)\n", strerror(errno)); - exit(EINVAL); + exit(EXIT_FAILURE); } } else if (strcasecmp(argv[0], "search") == 0) { @@ -299,7 +299,7 @@ main(int argc, char **argv) free(plist); printf("ERROR: unable to locate package '%s'.\n", argv[1]); - exit(EINVAL); + exit(EXIT_FAILURE); } prop_object_release(dict); free(plist); @@ -311,20 +311,20 @@ main(int argc, char **argv) plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB); if (plist == NULL) - exit(EINVAL); + exit(EXIT_FAILURE); dict = prop_dictionary_internalize_from_file(plist); if (dict == NULL) { printf("No packages currently registered.\n"); free(plist); - exit(0); + exit(EXIT_SUCCESS); } if (!xbps_callback_array_iter_in_dict(dict, "packages", xbps_list_pkgs_in_dict, NULL)) { prop_object_release(dict); free(plist); - exit(EINVAL); + exit(EXIT_FAILURE); } prop_object_release(dict); free(plist); @@ -334,6 +334,12 @@ main(int argc, char **argv) if (argc != 2) usage(); + if (geteuid() != 0) { + printf("ERROR: root permissions are needed to install " + "binary packages."); + exit(EXIT_FAILURE); + } + /* Install into root directory by default. */ rv = xbps_install_binary_pkg(argv[1], root); if (rv) { @@ -344,5 +350,5 @@ main(int argc, char **argv) usage(); } - exit(0); + exit(EXIT_SUCCESS); } diff --git a/bin/xbps-digest.c b/bin/xbps-digest.c index b0476dc19d..d7e8481dc9 100644 --- a/bin/xbps-digest.c +++ b/bin/xbps-digest.c @@ -41,7 +41,7 @@ static void usage(void) { fprintf(stderr, "usage: xbps-digest ...\n"); - exit(1); + exit(EXIT_FAILURE); } int @@ -59,14 +59,14 @@ main(int argc, char **argv) if ((fd = open(argv[i], O_RDONLY)) == -1) { printf("xbps-digest: cannot open %s (%s)\n", argv[i], strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } digest = malloc(SHA256_DIGEST_LENGTH * 2 + 1); if (digest == NULL) { printf("xbps-digest: malloc failed (%s)\n", strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } SHA256_Init(&ctx); @@ -78,5 +78,5 @@ main(int argc, char **argv) close(fd); } - exit(0); + exit(EXIT_SUCCESS); } diff --git a/bin/xbps-pkgdb.c b/bin/xbps-pkgdb.c index af5ced19ac..15ebc461c5 100644 --- a/bin/xbps-pkgdb.c +++ b/bin/xbps-pkgdb.c @@ -41,7 +41,7 @@ write_plist_file(prop_dictionary_t dict, const char *file) prop_object_release(dict); printf("=> ERROR: couldn't write to %s (%s)", file, strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } } @@ -82,7 +82,7 @@ main(int argc, char **argv) /* To specify the root directory */ root = strdup(optarg); if (root == NULL) - exit(ENOMEM); + exit(EXIT_FAILURE); xbps_set_rootdir(root); break; case '?': @@ -101,7 +101,7 @@ main(int argc, char **argv) if (dbfile == NULL) { printf("=> ERROR: couldn't find regpkdb file (%s)\n", strerror(errno)); - exit(EINVAL); + exit(EXIT_FAILURE); } in_chroot_env = getenv("in_chroot"); @@ -139,7 +139,7 @@ main(int argc, char **argv) printf("=> ERROR: couldn't unregister %s " "from database (%s)\n", argv[1], strerror(errno)); - exit(EINVAL); + exit(EXIT_FAILURE); } printf("%s=> %s-%s unregistered successfully.\n", @@ -152,15 +152,15 @@ main(int argc, char **argv) dbdict = prop_dictionary_internalize_from_file(dbfile); if (dbdict == NULL) - exit(1); + exit(EXIT_FAILURE); pkgdict = xbps_find_pkg_in_dict(dbdict, argv[1]); if (pkgdict == NULL) - exit(1); + exit(EXIT_FAILURE); if (!prop_dictionary_get_cstring_nocopy(pkgdict, "version", &version)) - exit(1); + exit(EXIT_FAILURE); printf("%s\n", version); @@ -173,7 +173,7 @@ main(int argc, char **argv) if (dbdict == NULL) { printf("=> ERROR: couldn't sanitize %s plist file " "(%s)\n", argv[1], strerror(errno)); - exit(1); + exit(EXIT_FAILURE); } write_plist_file(dbdict, argv[1]); @@ -181,5 +181,5 @@ main(int argc, char **argv) usage(); } - exit(0); + exit(EXIT_SUCCESS); }