summaryrefslogtreecommitdiff
path: root/src/user/knob
diff options
context:
space:
mode:
Diffstat (limited to 'src/user/knob')
-rw-r--r--src/user/knob/format.c19
-rw-r--r--src/user/knob/ipc.c12
-rw-r--r--src/user/knob/task.c16
3 files changed, 34 insertions, 13 deletions
diff --git a/src/user/knob/format.c b/src/user/knob/format.c
index 54d50ef..c5d2447 100644
--- a/src/user/knob/format.c
+++ b/src/user/knob/format.c
@@ -81,6 +81,8 @@ static const char *get_format(const char *from, struct format_spec *format_out)
return from + 1;
}
+//char debug[] = "-- format_v: fmt = \" \"...";
+
//allocates new memory
char *format_v(const char *fmt, va_list args) {
buf = get_block(FORMAT_BUF_INIT_SIZE);
@@ -90,6 +92,11 @@ char *format_v(const char *fmt, va_list args) {
buf_i = buf;
while (*fmt) {
+ //debug[20] = *fmt;
+ //debug[21] = fmt[1];
+ //debug[22] = fmt[2];
+ //_system_log(debug);
+
if (*fmt != '%') {
ensure(1);
*(buf_i++) = *(fmt++);
@@ -133,11 +140,15 @@ char *format_v(const char *fmt, va_list args) {
case UNSIGNED_DECIMAL:
k = va_arg(args, uint32_t);
if (!form.len) {
- uint32_t n = 10;
- ++form.len;
- while (k >= n) {
+ if (k >= 1000000000)
+ form.len = 10;
+ else {
+ uint32_t n = 10;
++form.len;
- n *= 10;
+ while (k >= n) {
+ ++form.len;
+ n *= 10;
+ }
}
}
ensure(form.len);
diff --git a/src/user/knob/ipc.c b/src/user/knob/ipc.c
index dbf1a22..5ca4bb4 100644
--- a/src/user/knob/ipc.c
+++ b/src/user/knob/ipc.c
@@ -2,10 +2,12 @@
//blocking, returns early if other process is dead.
//return value is number of bytes written.
-uint32_t try_send_ipc(_task_handle_t to, void *buffer, uint32_t size) {
+uint32_t try_send_ipc(_task_handle_t to, const void *buffer, uint32_t size) {
const uint32_t size_backup = size;
while (size) {
+ //syslogf("_ipc_send(0x%2h, 0x%h, %u)", to, buffer, size);
uint32_t res = _ipc_send(to, size, buffer);
+ //syslogf("=> %u", res);
if (!res) {
_wait_ipc_read(to);
_yield_task();
@@ -17,16 +19,19 @@ uint32_t try_send_ipc(_task_handle_t to, void *buffer, uint32_t size) {
buffer += res;
}
}
+ return size_backup;
}
//blocking, returns early if other process is dead.
//return value is number of bytes read.
-uint32_t read_ipc(_task_handle_t from, void *buffer, uint32_t size) {
+uint32_t try_read_ipc(_task_handle_t from, void *buffer, uint32_t size) {
const uint32_t size_backup = size;
while (size) {
+ //syslogf("_ipc_read(0x%2h, 0x%h, %u)", from, buffer, size);
uint32_t res = _ipc_read(from, size, buffer);
+ //syslogf("=> %u", res);
if (!res) {
- _wait_ipc_send(from);
+ _wait_ipc_sent(from);
_yield_task();
}
else if (res == -1)
@@ -36,6 +41,7 @@ uint32_t read_ipc(_task_handle_t from, void *buffer, uint32_t size) {
buffer += res;
}
}
+ return size_backup;
}
void flush_ipc(_task_handle_t from) {
diff --git a/src/user/knob/task.c b/src/user/knob/task.c
index 3bf3e85..9a49386 100644
--- a/src/user/knob/task.c
+++ b/src/user/knob/task.c
@@ -1,9 +1,12 @@
-#include <stdbool.h>
#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) {
uint8_t dn;
path = remove_prefix(path, &dn);
@@ -14,9 +17,9 @@ _task_handle_t run_command(const char *path, _task_handle_t stdio_task) {
blockcpy(new_path, path, ptr - path);
new_path[ptr - path] = '\0';
- bool succeded = _start_task(dn, new_path, ptr + 1, stdio_task);
+ _task_handle_t handle = _start_task(dn, new_path, ptr + 1, stdio_task);
free_block(new_path);
- return succeded;
+ return handle;
}
return _start_task(dn, path, "", stdio_task);
@@ -24,11 +27,12 @@ _task_handle_t run_command(const char *path, _task_handle_t 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)
+ if (!handle) {
return false;
- while (_is_task_running(handle)) {
+ }
+ do {
_wait_for_task(handle);
_yield_task();
- }
+ } while (_is_task_running(handle));
return true;
} \ No newline at end of file