summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0x221E2026-05-10 22:53:59 +0200
committer0x221E2026-05-10 22:53:59 +0200
commitb4cd16236d97c0074a927159bb7df8620273f263 (patch)
tree7d825dc482f38b13d0cc0d652759fa7d7ea3ba69
parent0bdf49ae045071a99674b4ac426c2c852f744443 (diff)
cookbook: add process return code checking for cookbook recipes
cookbook_recipe_run() now returns the return code of fork() to manage success state.
-rw-r--r--include/cookbook.h5
-rw-r--r--src/cookbook.c47
-rw-r--r--src/pkgman.c28
3 files changed, 47 insertions, 33 deletions
diff --git a/include/cookbook.h b/include/cookbook.h
index 86f66aa..05a8f63 100644
--- a/include/cookbook.h
+++ b/include/cookbook.h
@@ -2,7 +2,10 @@
#define COOKBOOK_H
typedef struct url url;
+typedef struct string_view string_view;
-int cookbook_run(struct url *script_loc, char *script);
+int cookbook_recipe_run(struct url *script_loc,
+ char *script,
+ struct string_view *out);
#endif
diff --git a/src/cookbook.c b/src/cookbook.c
index db2c81a..19227c0 100644
--- a/src/cookbook.c
+++ b/src/cookbook.c
@@ -6,12 +6,15 @@
#include <sys/wait.h>
#include <stdlib.h>
+#include <lib/sv.h>
#include <lib/url.h>
#include <err.h>
-int cookbook_run(struct url *script_loc, char *script)
+int cookbook_recipe_run(struct url *script_loc,
+ char *script,
+ struct string_view *out)
{
- printf("Launching build script...\n");
+ printf("Launching cookbook recipe...\n");
int pipefd[2];
@@ -31,40 +34,24 @@ int cookbook_run(struct url *script_loc, char *script)
chdir(script_loc->buffer);
url_append(script_loc, "build.sh");
- if(execve(script_loc->buffer,
- (char*[]){ script_loc->buffer, script,NULL},
- (char*[]){
- "PWD=/tmp/pkgman/nvim-extract",
- "PATH=/bin:/usr/bin",
- NULL }) == -1) {
- fprintf(stderr, "An error was encountered!\n");
- }
+ if(execve(
+ script_loc->buffer,
+ (char*[]){ script_loc->buffer, script, NULL},
+ (char*[]){"PATH=/bin:/usr/bin", NULL }) == -1)
+ fprintf(stderr, "An error was encountered!\n");
break;
default: {
- size_t size = 0;
- size_t cap = 40;
- char *mem = malloc(40);
- char buf[1024];
- memset(buf, 0, 1024);
-
+ char buf[2];
+ buf[1] = '\0';
close(pipefd[1]);
- while (read(pipefd[0], buf, 1) > 0) {
- if (size >= cap) {
- cap *= 2;
- mem = realloc(mem, cap);
- printf("Realloced!");
- }
-
- memcpy(mem + size, buf, 1);
- size++;
- }
- printf("Build script stdouts: %.*s\n", size, mem);
-
- free(mem);
+ while (read(pipefd[0], buf, 1) > 0)
+ sv_concat_cstr(out, buf);
+
int ret;
waitpid(ps, &ret, 0);
- printf("Build script exited with code %d\n", ret);
+ printf("Cookbook process exited with code %d\n", ret);
+ return ret;
}
}
}
diff --git a/src/pkgman.c b/src/pkgman.c
index b5edc69..d22d15c 100644
--- a/src/pkgman.c
+++ b/src/pkgman.c
@@ -100,6 +100,8 @@ int pkgman_download(const char *url, const char *dst)
int pkgman_install_pkg(const char *pkg)
{
+ int ret = -ERR;
+
struct url path = {0};
url_init(&path, "/tmp/pkgman");
url_append_path(&path, pkg);
@@ -113,9 +115,31 @@ int pkgman_install_pkg(const char *pkg)
pkg_extract(path.buffer, &dst_path);
- cookbook_run(&dst_path, "artifacts");
- cookbook_run(&dst_path, "install");
+ struct string_view recipe_out = {0};
+ sv_init(&recipe_out, "");
+ if (int cret = cookbook_recipe_run(&dst_path, "test", &recipe_out)
+ != 0) {
+ printf("Artifacts recipe failed with error code: %d", cret);
+ ret = -ERR;
+ goto cleanup;
+ }
+
+ printf("Not displaying artifacts...\n");
+
+ sv_free(&recipe_out);
+ sv_init(&recipe_out, "");
+
+ if (int cret = cookbook_recipe_run(&dst_path, "install", &recipe_out)
+ != 0) {
+ printf("Install recipe failed with error code: %d", cret);
+ ret = -ERR;
+ goto cleanup;
+ }
+ printf("Build script response: %s\n", recipe_out.buf);
+
+ cleanup:
+ sv_free(&recipe_out);
url_free(&dst_path);
url_free(&path);
return SUCCESS;