aboutsummaryrefslogtreecommitdiff
path: root/snag
diff options
context:
space:
mode:
authorRiley Beckett <rbeckettvt@gmail.com>2026-07-29 21:38:31 -0400
committerRiley Beckett <rbeckettvt@gmail.com>2026-07-29 21:38:31 -0400
commitf5e997c21034a6ac5bd11f6e9bbfea0c13d5c451 (patch)
tree6acaf06ca5da080c5d06b58df68fdf3d19688fb2 /snag
parentc404df1214d9989e79a78c0313b588468cead4e2 (diff)
install to fakeroot
Diffstat (limited to 'snag')
-rwxr-xr-xsnag/scripts/run_pkg_build.sh8
-rw-r--r--snag/src/build_db.c29
-rw-r--r--snag/src/build_db.h2
-rw-r--r--snag/src/main.c3
-rw-r--r--snag/src/source_db.c2
5 files changed, 41 insertions, 3 deletions
diff --git a/snag/scripts/run_pkg_build.sh b/snag/scripts/run_pkg_build.sh
index 3e4b867..5b98cfd 100755
--- a/snag/scripts/run_pkg_build.sh
+++ b/snag/scripts/run_pkg_build.sh
@@ -14,11 +14,19 @@ fi
api_send=$1
api_recv=$2
+getvar() {
+ eval "printf '\x03\x00\x00\x00$1' >&$api_send"
+ IFS= read -r data 0<&"$api_recv"
+ echo "$data"
+}
+
# should remove
eval "printf '\x02\x00\x00\x00' >&$api_send"
IFS= read -r data 0<&"$api_recv"
echo "data=$data"
+root=$(getvar root)
+
# load the description script
. $3
diff --git a/snag/src/build_db.c b/snag/src/build_db.c
index 7e22e09..7e045b0 100644
--- a/snag/src/build_db.c
+++ b/snag/src/build_db.c
@@ -4,6 +4,9 @@
#include "util.h"
#include "source_db.h"
+#define _XOPEN_SOURCE 500
+#include <ftw.h>
+
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
@@ -15,11 +18,13 @@
#include <sys/stat.h>
#include <errno.h>
+
#include "sandboxing.h"
#define API_MESSAGE_NONE 0
#define API_MESSAGE_FINISHED 1
#define API_MESSAGE_TEST 2
+#define API_MESSAGE_GET_VAR 3
bool set_child_sandbox(const package_build_t* build) {
struct landlock_ruleset_attr ruleset_attr = {
@@ -74,7 +79,7 @@ bool set_child_sandbox(const package_build_t* build) {
LANDLOCK_ACCESS_FS_IOCTL_DEV |
LANDLOCK_ACCESS_FS_RESOLVE_UNIX,
};
- if (!landlock_add_path_rule(landlock_fd, &ruleset_attr, build->source_directory, &path_beneath)) {
+ if (!landlock_add_path_rule(landlock_fd, &ruleset_attr, build->directory, &path_beneath)) {
return false;
}
path_beneath.allowed_access = LANDLOCK_ACCESS_FS_EXECUTE | LANDLOCK_ACCESS_FS_READ_FILE;
@@ -170,6 +175,9 @@ bool package_setup_build(const package_info_t* info, package_build_t* build) {
if (symlink(build->directory + cfg.build_db_len + 1, symlink_name) == -1) die("failed to create build symlink '%s': %s", symlink_name, strerror(errno));
free(symlink_name);
+ build->fakeroot = join_path(build->directory, "fakeroot");
+ if (mkdir(build->fakeroot, 0777) == -1) die("failed to create fakeroot directory: %s", strerror(errno));
+
// unpack package source (eventually this will be done by swenu api)
build->source_directory = join_path(build->directory, "source");
unpack_source(&info->attrs.source, build->source_directory);
@@ -260,6 +268,14 @@ void build_run(const package_build_t* build) {
printf("api test\n");
write(api_to_sh[1], "api test\n", strlen("api test\n"));
break;
+ case API_MESSAGE_GET_VAR:
+ bytes_read = read(api_from_sh[0], buf, sizeof(buf));
+ if (strncmp(buf, "root", sizeof("root") - 1) == 0) {
+ char* tmp = vastrcat(build->fakeroot, "\n");
+ write(api_to_sh[1], tmp, strlen(tmp));
+ free(tmp);
+ }
+ break;
case API_MESSAGE_NONE:
break;
}
@@ -280,3 +296,14 @@ void build_run(const package_build_t* build) {
if (waitpid(pid, &wstatus, 0) < 0) die("waitpid failed: %s", strerror(errno));
if (WEXITSTATUS(wstatus) != 0) die("the child failed to execute install script");
}
+
+int nftw_callback(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
+ char* path = strstr(fpath, "fakeroot") + strlen("fakeroot");
+ if (!path[0]) return 0;
+ print("%s\n", path);
+ return 0;
+}
+
+void list_fakeroot(const package_build_t* build) {
+ nftw(build->fakeroot, nftw_callback, 100, FTW_PHYS);
+}
diff --git a/snag/src/build_db.h b/snag/src/build_db.h
index dda9cfd..4b735a7 100644
--- a/snag/src/build_db.h
+++ b/snag/src/build_db.h
@@ -6,10 +6,12 @@
typedef struct {
const package_info_t* package;
char* directory;
+ char* fakeroot;
char* source_directory;
} package_build_t;
bool package_setup_build(const package_info_t* info, package_build_t* build);
void build_run(const package_build_t* info);
+void list_fakeroot(const package_build_t* info);
#endif
diff --git a/snag/src/main.c b/snag/src/main.c
index efe5c14..b0c0e4b 100644
--- a/snag/src/main.c
+++ b/snag/src/main.c
@@ -48,7 +48,7 @@ int cmd_install(char* cmd_name, ArgParser* parser) {
char* pkgid = ap_get_arg_at_index(parser, i);
package_info_t info;
if (load_package_info(pkgid, &info)) {
- print("Installing %s - %s\n", info.attrs.name, info.attrs.desc);
+ print("Installing %s %s - %s\n", info.attrs.name, info.attrs.version, info.attrs.desc);
// confirm that package source exists or is downloaded
if (!verify_source(&info.attrs.source) && !download_source(&info.attrs.source)) {
@@ -59,6 +59,7 @@ int cmd_install(char* cmd_name, ArgParser* parser) {
package_build_t build;
package_setup_build(&info, &build);
build_run(&build);
+ list_fakeroot(&build);
}
}
diff --git a/snag/src/source_db.c b/snag/src/source_db.c
index 75f2e61..64db008 100644
--- a/snag/src/source_db.c
+++ b/snag/src/source_db.c
@@ -75,7 +75,7 @@ bool download_source(source_info_t* source) {
hash_hex[SHA256_DIGEST_LENGTH * 2] = '\0';
// confirm that checksum matches
- assert(source->checksum != NULL);
+ assert(source->checksum != NULL);
if (strcmp(source->checksum, hash_hex) == 0) {
print("checksum verified for download: %s\n", hash_hex);
return true;