aboutsummaryrefslogtreecommitdiff
path: root/snag/src/build_db.c
diff options
context:
space:
mode:
authorJack Jamison <jackqjamison@gmail.com>2026-07-23 12:23:40 -0400
committerJack Jamison <jackqjamison@gmail.com>2026-07-23 12:23:40 -0400
commitfa4344e5dedff14af2bce55d29a272495dd6bbb5 (patch)
treeb90719263489365885a704bb4eab155c40c11d71 /snag/src/build_db.c
parente207f7382cf23dcf88700dead255a41c817a0863 (diff)
cache downloads and cleaning
Diffstat (limited to 'snag/src/build_db.c')
-rw-r--r--snag/src/build_db.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/snag/src/build_db.c b/snag/src/build_db.c
new file mode 100644
index 0000000..f2f4e01
--- /dev/null
+++ b/snag/src/build_db.c
@@ -0,0 +1,53 @@
+#include "build_db.h"
+#include "util.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+#define PKG_BUILD_CMD "./scripts/run_pkg_build.sh"
+
+void package_run_install(const package_info_t* info) {
+
+ // PIPE and FORK to run install script
+ int pipefds[2] = {0};
+ if (pipe(pipefds) < 0) die("failed to pipe: %s", strerror(errno));
+ pid_t pid = fork();
+ if (pid < 0) die("failed to fork: %s", strerror(errno));
+
+ if (pid == 0) {
+ // child proc
+ // connect my stdout and stderr to the pipe
+ close(pipefds[0]);
+ dup2(pipefds[1], STDOUT_FILENO);
+ dup2(pipefds[1], STDERR_FILENO);
+ close(pipefds[1]);
+ // exec into install script
+ char* argv[] = { PKG_BUILD_CMD, info->script_path, NULL };
+ char* envp[] = { NULL };
+ execve(PKG_BUILD_CMD, argv, envp);
+ // what are you still doing here?
+ die("CHILD - execve to %s failed: %s", PKG_BUILD_CMD, strerror(errno));
+ } else {
+ // parent proc, close write end of pipe
+ close(pipefds[1]);
+ }
+
+ // read from the pipe until EOF
+ char buf[4096];
+ ssize_t bytes_read = 0;
+ while ((bytes_read = read(pipefds[0], buf, sizeof(buf))) > 0) {
+ // print build out, can log and stuff in future
+ printf("%.*s", (int)bytes_read, buf);
+ }
+ 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) die("waitpid failed: %s", strerror(errno));
+ if (WEXITSTATUS(wstatus) != 0) die("the child failed to execute install script");
+}