aboutsummaryrefslogtreecommitdiff
path: root/snag/main.c
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-07-20 15:56:56 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-07-20 15:56:56 -0400
commit86af4e8487f27dd69863b1380fe17e841605214f (patch)
treea6e23f1286ef0c01d2577cb03460fc76caa8d8f8 /snag/main.c
parent0ad03c0647b94683c26045bbc143b0d6450d914f (diff)
improvements and fixes
Diffstat (limited to 'snag/main.c')
-rw-r--r--snag/main.c20
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
}