diff options
| author | Riley Beckett <rbeckettvt@gmail.com> | 2026-07-29 21:38:31 -0400 |
|---|---|---|
| committer | Riley Beckett <rbeckettvt@gmail.com> | 2026-07-29 21:38:31 -0400 |
| commit | f5e997c21034a6ac5bd11f6e9bbfea0c13d5c451 (patch) | |
| tree | 6acaf06ca5da080c5d06b58df68fdf3d19688fb2 /snag/src/build_db.c | |
| parent | c404df1214d9989e79a78c0313b588468cead4e2 (diff) | |
install to fakeroot
Diffstat (limited to 'snag/src/build_db.c')
| -rw-r--r-- | snag/src/build_db.c | 29 |
1 files changed, 28 insertions, 1 deletions
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); +} |
