diff options
Diffstat (limited to 'snag/main.c')
| -rw-r--r-- | snag/main.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/snag/main.c b/snag/main.c index 10a5f86..c80ec65 100644 --- a/snag/main.c +++ b/snag/main.c @@ -5,7 +5,7 @@ #include <unistd.h> #define PKG_DB "../snaggies" -#define PKG_INFO_CMD "./snagpkginfo.sh" +#define PKG_INFO_CMD "./get_pkg_attrs.sh" typedef struct { char* id; @@ -40,6 +40,9 @@ void subcmd_install(char* pkgs[], size_t count) { } } +// loads and allocates package attributes for the info struct. does not do +// excessive validation, so this should be fine when loading package data in +// bulk. bool load_package_info(package_info_t* info, char* pkgid) { // construct package description directory path and ensure it exists @@ -63,13 +66,14 @@ bool load_package_info(package_info_t* info, char* pkgid) { return false; } - // run getpkginfo script that outputs package attributes + // run get_pkg_attrs script that outputs package attributes size_t cmd_len = strlen(PKG_INFO_CMD) + script_path_len + 3; char* cmd = malloc(cmd_len + 1); snprintf(cmd, cmd_len + 1, "%s '%s'", PKG_INFO_CMD, info->script_path); FILE* getinfo_fp = popen(cmd, "r"); + free(cmd); if (getinfo_fp == NULL) { - perror("failed to popen getpkginfo"); + perror("failed to popen get_pkg_attrs"); exit(1); // fatal error } @@ -98,9 +102,13 @@ bool load_package_info(package_info_t* info, char* pkgid) { } free(line); - // close the getpkginfo process - if (pclose(getinfo_fp) != 0) { - perror("failed to pclose getpkginfo"); + // close the get_pkg_attrs process + int close_err = pclose(getinfo_fp); + if (close_err == -1) { + perror("failed to pclose get_pkg_attrs"); + exit(1); // fatal error + } else if (close_err != 0) { + fprintf(stderr, "failed to execute get_pkg_attrs: %d\n", close_err); exit(1); // fatal error } |
