58#define BUFFER_MAX 0x1000
80 if (
strcmp(argv[i],
"--") == 0)
88 args->
box = argv[i + 1];
89 args->
argv = &argv[i + 1];
90 args->
argc = argc - (i + 1);
102 const char* key = argv[
i];
105 if (
strcmp(key,
"stdin") == 0)
114 else if (
strcmp(key,
"stdout") == 0)
123 else if (
strcmp(key,
"stderr") == 0)
132 else if (
strcmp(key,
"group") == 0)
141 else if (
strcmp(key,
"namespace") == 0)
143 args->namespace =
claim(value);
144 if (args->namespace ==
ERR)
175 if (argv ==
NULL || argc == 0)
194 {
"BOX",
F(
"/box/%s/", args.
box)},
209 snprintf(ctx->
result,
sizeof(ctx->
result),
"error due to manifest of '%s' missing 'priority' entry", args.
box);
235 snprintf(ctx->
result,
sizeof(ctx->
result),
"error due to manifest of '%s' having invalid 'profile' entry",
267 ctl =
open(
F(
"/proc/%llu/ctl", pid));
277 if (
swrite(ctl,
F(
"setns %llu", args.namespace)) ==
ERR)
286 if (
swrite(ctl,
"mount /:Lrwx tmpfs") ==
ERR)
298 char* value =
namespace->entries[
i].value;
300 if (
swrite(ctl,
F(
"touch %s:rwcp && bind %s %s", key, key, value)) ==
ERR)
338 fd_t wait =
open(
F(
"/proc/%llu/wait", pid));
384 for (
int i = 0;
i < 3;
i++)
397 close(args.namespace);
410 char*
id =
sreadfile(
"/net/local/seqpacket");
417 if (
swritefile(
F(
"/net/local/%s/ctl",
id),
"bind boxspawn && listen") ==
ERR)
423 printf(
"boxd: listening for connections...\n");
426 fd_t client =
open(
F(
"/net/local/%s/accept",
id));
#define errno
Error number variable.
const char ** argsplit_buf(void *buf, uint64_t size, const char *str, uint64_t maxLen, uint64_t *count)
Standardized argument parsing function using a provided buffer.
#define ARRAY_SIZE(x)
Get the number of elements in a static array.
#define KEY_128BIT
The size of a buffer needed to hold a 128-bit key.
fd_t open(const char *path)
System call for opening files.
uint64_t close(fd_t fd)
System call for closing files.
#define F(format,...)
Allocates a formatted string on the stack.
size_t read(fd_t fd, void *buffer, size_t count)
System call for reading from files.
size_t swrite(fd_t fd, const char *string)
Wrapper for writing a null-terminated string to a file.
size_t swritefile(const char *path, const char *string)
Wrapper for writing a null-terminated string directly to a file using a path.
fd_t claim(const char *key)
System call for claiming a shared file descriptor.
#define STDOUT_FILENO
Standard output file descriptor.
char * sreadfile(const char *path)
Wrapper for reading an entire file directly into a null-terminated string.
#define STDERR_FILENO
Standard error file descriptor.
uint64_t share(char *key, uint64_t size, fd_t fd, clock_t timeout)
System call for sharing a file descriptor with another process.
#define STDIN_FILENO
Standard input file descriptor.
spawn_flags_t
Spawn behaviour flags.
pid_t spawn(const char **argv, spawn_flags_t flags)
System call for spawning new processes.
uint64_t kill(pid_t pid)
Helper for sending the "kill" command to a process.
@ SPAWN_EMPTY_GROUP
Don't inherit the parent's process group, instead create a new group.
@ SPAWN_EMPTY_NS
Create a new empty namespace, the new namespace will not contain any mountpoints or even a root.
@ SPAWN_EMPTY_ENV
Don't inherit the parent's environment variables.
@ SPAWN_EMPTY_CWD
Don't inherit the parent's current working directory, starts at root (/).
#define NULL
Pointer error value.
#define FD_NONE
No file descriptor constant.
#define ERR
Integer error value.
__UINT64_TYPE__ fd_t
A file descriptor.
__UINT64_TYPE__ pid_t
Process Identifier.
uint64_t manifest_parse(manifest_t *manifest, const char *path)
char * manifest_get_value(section_t *section, const char *key)
void manifest_substitute(manifest_t *manifest, substitution_t *substitutions, uint64_t amount)
uint64_t manifest_get_integer(section_t *section, const char *key)
static uint64_t box_args_parse(box_args_t *args, uint64_t argc, const char **argv, box_spawn_t *ctx)
static void box_spawn(box_spawn_t *ctx)
static const path_flag_t flags[]
_PUBLIC int printf(const char *_RESTRICT format,...)
_PUBLIC int snprintf(char *_RESTRICT s, size_t n, const char *_RESTRICT format,...)
_PUBLIC _NORETURN void abort(void)
_PUBLIC void free(void *ptr)
_PUBLIC char * strerror(int errnum)
_PUBLIC int strcmp(const char *s1, const char *s2)
_PUBLIC char * strchr(const char *s, int c)
char key[MANIFEST_STRING_MAX]
char value[MANIFEST_STRING_MAX]
section_entry_t entries[MANIFEST_SECTION_MAX]