This repository has been archived on 2025-02-27. You can view files and clone it, but cannot push or open issues or pull requests.
portland-os/src/user/knob/task.c
Benji Dial 053c6f0d9f removing stub for special handling of 'sd' prefix in file paths from knob
passing a path with an 'sd' prefix will now act like any other path on the first drive, instead of closing the calling program.
eventually, i will add a system of mounting drives directly into a file hierarchy (like in unix), and have all of the system calls just pass a path, no drive number
2021-03-02 20:43:19 -05:00

35 lines
No EOL
881 B
C

#include <pland/syscall.h>
#include <knob/file.h>
#include <knob/heap.h>
#include <knob/block.h>
#include <stdbool.h>
#include <knob/format.h>
_task_handle_t run_command(const char *path, _task_handle_t stdio_task) {
for (const char *ptr = path; *ptr; ++ptr)
if (*ptr == ' ') {
char *new_path = get_block(ptr - path + 1);
blockcpy(new_path, path, ptr - path);
new_path[ptr - path] = '\0';
_task_handle_t handle = _start_task(0, new_path, ptr + 1, stdio_task);
free_block(new_path);
return handle;
}
return _start_task(0, path, "", stdio_task);
}
bool try_run_command_blocking(const char *path, _task_handle_t stdio_task) {
_task_handle_t handle = run_command(path, stdio_task);
if (!handle) {
return false;
}
do {
_wait_for_task(handle);
_yield_task();
} while (_is_task_running(handle));
return true;
}