diff options
| author | Riley Beckett <rbeckettvt@gmail.com> | 2026-07-21 22:14:36 -0400 |
|---|---|---|
| committer | Riley Beckett <rbeckettvt@gmail.com> | 2026-07-21 22:14:36 -0400 |
| commit | 2d1c5db52be9cde9e013a724c149d7a84fe057ba (patch) | |
| tree | b613b945ce27e467132c689bd065871652db03f0 /snag/pkg_db.c | |
| parent | feef592b397f6ec6b8b848d93b0cea9b9800f955 (diff) | |
add gen.sh and some better logging
Diffstat (limited to 'snag/pkg_db.c')
| -rw-r--r-- | snag/pkg_db.c | 30 |
1 files changed, 15 insertions, 15 deletions
diff --git a/snag/pkg_db.c b/snag/pkg_db.c index 3ed36cf..2bfa686 100644 --- a/snag/pkg_db.c +++ b/snag/pkg_db.c @@ -12,7 +12,7 @@ #define PKG_INST_CMD "./run_pkg_install.sh" // note: fixed location of package database for now -const char pkg_db[] = "../packages"; +const char pkg_db[] = "../packages"; const size_t pkg_db_len = sizeof(pkg_db) - 1; bool load_package_info(char* pkgid, package_info_t* info) { @@ -30,7 +30,7 @@ bool load_package_info(char* pkgid, package_info_t* info) { memcpy(pkg_dir + pkg_db_len + 1, pkgid, pkgid_len); pkg_dir[pkg_dir_len] = '\0'; if (access(pkg_dir, F_OK) != 0) { - eprintf("Package '%s' not found\n", pkgid); + log("Package '%s' not found\n", pkgid); free(pkg_dir); return false; } @@ -48,7 +48,7 @@ bool load_package_info(char* pkgid, package_info_t* info) { info->script_path[script_path_len] = '\0'; free(pkg_dir); if (access(info->script_path, F_OK) != 0) { - eprintf("Package '%s' broken, doesn't have description script\n", pkgid); + log("Package '%s' broken, doesn't have description script\n", pkgid); free(info->script_path); return false; } @@ -56,9 +56,9 @@ bool load_package_info(char* pkgid, package_info_t* info) { // PIPE and FORK to run pkg attrs script int pipefds[2] = {0}; - if (pipe(pipefds) < 0) error_out("failed to pipe: %s", strerror(errno)); + if (pipe(pipefds) < 0) die("failed to pipe: %s", strerror(errno)); pid_t pid = fork(); - if (pid < 0) error_out("failed to fork: %s", strerror(errno)); + if (pid < 0) die("failed to fork: %s", strerror(errno)); if (pid == 0) { // child proc @@ -71,7 +71,7 @@ bool load_package_info(char* pkgid, package_info_t* info) { char* envp[] = { NULL }; execve(PKG_INFO_CMD, argv, envp); // what are you still doing here? - error_out("execve failed"); + die("execve failed"); } else { // parent proc, close write end of pipe close(pipefds[1]); @@ -79,12 +79,12 @@ bool load_package_info(char* pkgid, package_info_t* info) { // wait for child to finish int wstatus; - if (waitpid(pid, &wstatus, 0) < 0) error_out("waitpid failed: %s", strerror(errno)); - if (WEXITSTATUS(wstatus) != 0) error_out("failed to execute get pkg attr script"); + if (waitpid(pid, &wstatus, 0) < 0) die("waitpid failed: %s", strerror(errno)); + if (WEXITSTATUS(wstatus) != 0) die("failed to execute get pkg attr script"); // read all bytes from pipe into attr buffer ssize_t bytes_read = read(pipefds[0], info->attrs.buffer, sizeof(info->attrs.buffer)); - if (bytes_read < 0) error_out("failed to read from pipe: %s", strerror(errno)); + if (bytes_read < 0) die("failed to read from pipe: %s", strerror(errno)); close(pipefds[0]); // read attributes from attr buffer @@ -118,9 +118,9 @@ void run_package_install(const package_info_t* info) { // PIPE and FORK to run install script int pipefds[2] = {0}; - if (pipe(pipefds) < 0) error_out("failed to pipe: %s", strerror(errno)); + if (pipe(pipefds) < 0) die("failed to pipe: %s", strerror(errno)); pid_t pid = fork(); - if (pid < 0) error_out("failed to fork: %s", strerror(errno)); + if (pid < 0) die("failed to fork: %s", strerror(errno)); if (pid == 0) { // child proc @@ -134,7 +134,7 @@ void run_package_install(const package_info_t* info) { char* envp[] = { NULL }; execve(PKG_INST_CMD, argv, envp); // what are you still doing here? - error_out("execve failed"); + die("execve failed"); } else { // parent proc, close write end of pipe close(pipefds[1]); @@ -147,11 +147,11 @@ void run_package_install(const package_info_t* info) { // print build out, can log and stuff in future printf("%.*s", (int)bytes_read, buf); } - if (bytes_read < 0) error_out("failed to read from pipe: %s", strerror(errno)); + if (bytes_read < 0) die("failed to read from pipe: %s", strerror(errno)); close(pipefds[0]); // reap the child to finish int wstatus; - if (waitpid(pid, &wstatus, 0) < 0) error_out("waitpid failed: %s", strerror(errno)); - if (WEXITSTATUS(wstatus) != 0) error_out("failed to execute install script"); + if (waitpid(pid, &wstatus, 0) < 0) die("waitpid failed: %s", strerror(errno)); + if (WEXITSTATUS(wstatus) != 0) die("failed to execute install script"); } |
