diff options
| author | Nicholas Rodrigues Lordello <[email protected]> | 2026-09-04 22:26:09 +0200 |
|---|---|---|
| committer | Nicholas Rodrigues Lordello <[email protected]> | 2026-09-04 22:26:09 +0200 |
| commit | 8165883a153e4bc2d50fa3710e47b76d9f79bb15 (patch) | |
| tree | 459dfc254dea60427159d24f48af4899b1d9fa53 /src/proc.c | |
| parent | 8c8d3ed3d7a478789a8fe3edf15ca4ce4c6a8b66 (diff) | |
Started Implementing Container Creation
We setup a single-use SSH key and can generate an SSH
configuration. Additionally, we support user SSH settings in
`~/.config/dbx/$NAME.ssh_config`.
This still doesn't quite work (there are some left-over TODOs).
In particular:
1. We need to get the generated SSH public key to the authorized
keys list on the devbox
2. We need to SCP and run the optional post-installation script
Diffstat (limited to 'src/proc.c')
| -rw-r--r-- | src/proc.c | 43 |
1 files changed, 28 insertions, 15 deletions
@@ -75,7 +75,7 @@ bool dbx_proc_find(const char *name, char file[PATH_MAX]) { return found; } -int dbx_proc_run(char *const command[]) { +int dbx_proc_run(const char *const command[], enum dbx_proc_output out) { assert(command != NULL && command[0] != NULL); int result; @@ -91,23 +91,32 @@ int dbx_proc_run(char *const command[]) { dbx_perror("posix_spawn_file_actions_addclose(stdin)", result); goto cleanup; } - result = posix_spawn_file_actions_addopen(&file_actions, STDOUT_FILENO, - _PATH_DEVNULL, O_WRONLY, 0); - if (result != 0) { - dbx_perror("posix_spawn_file_actions_addopen(stdout)", result); - goto cleanup; + + if ((out & DBXP_STDOUT) == 0) { + result = posix_spawn_file_actions_addopen(&file_actions, STDOUT_FILENO, + _PATH_DEVNULL, O_WRONLY, 0); + if (result != 0) { + dbx_perror("posix_spawn_file_actions_addopen(stdout)", result); + goto cleanup; + } } - result = posix_spawn_file_actions_addopen(&file_actions, STDERR_FILENO, - _PATH_DEVNULL, O_WRONLY, 0); - if (result != 0) { - dbx_perror("posix_spawn_file_actions_addopen(stderr)", result); - goto cleanup; + + if ((out & DBXP_STDERR) == 0) { + result = posix_spawn_file_actions_addopen(&file_actions, STDERR_FILENO, + _PATH_DEVNULL, O_WRONLY, 0); + if (result != 0) { + dbx_perror("posix_spawn_file_actions_addopen(stderr)", result); + goto cleanup; + } } + // POSIX guarantees that the pointer is not modified, so the cast is safe. + char *const *argv = (char *const *)command; + pid_t pid; - result = posix_spawn(&pid, command[0], &file_actions, NULL, command, environ); + result = posix_spawnp(&pid, command[0], &file_actions, NULL, argv, environ); if (result != 0) { - dbx_perror("posix_spawn", result); + dbx_perror("posix_spawnp", result); goto cleanup; } @@ -133,9 +142,13 @@ cleanup: return exit_code; } -bool dbx_proc_exec(char *const command[]) { +bool dbx_proc_exec(const char *const command[]) { assert(command != NULL && command[0] != NULL); - execv(command[0], command); + + // POSIX guarantees that the pointer is not modified, so the cast is safe. + char *const *argv = (char *const *)command; + + execvp(command[0], argv); // execvp only ever returns if there was an error. dbx_perror("execv", errno); |
