Skip to content

Commit 0f41e73

Browse files
committed
krun/nitro: Redirect enclave VM output to stdout
Nitro enclaves print their output logs via vsock. As such, libkrun-nitro spawns a listener thread to retrieve enclave application output from vsock and forward it to a file. Redirect all krun-nitro application output to stdout to allowing viewing of logs from container applications launched within nitro enclaves. Signed-off-by: Tyler Fanelli <tfanelli@redhat.com>
1 parent bf28834 commit 0f41e73

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcrun/handlers/krun.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ libkrun_exec (void *cookie, libcrun_container_t *container, const char *pathname
311311
int32_t (*krun_set_root) (uint32_t ctx_id, const char *root_path);
312312
int32_t (*krun_set_root_disk) (uint32_t ctx_id, const char *disk_path);
313313
int32_t (*krun_set_tee_config_file) (uint32_t ctx_id, const char *file_path);
314+
int32_t (*krun_set_console_output) (uint32_t ctx_id, const char *c_filepath);
314315
struct krun_config *kconf = (struct krun_config *) cookie;
315316
void *handle;
316317
uint32_t num_vcpus, ram_mib;
@@ -370,6 +371,19 @@ libkrun_exec (void *cookie, libcrun_container_t *container, const char *pathname
370371
error (EXIT_FAILURE, -ret, "could not set krun root");
371372
}
372373

374+
if (kconf->nitro)
375+
{
376+
// need krun_set_exec and krun_set_console_output.
377+
krun_set_console_output = dlsym (handle, "krun_set_console_output");
378+
if (krun_set_console_output == NULL)
379+
error (EXIT_FAILURE, 0, "could not find symbol in `libkrun.so`");
380+
381+
// Redirect all enclave output (read from vsock) to stdout.
382+
ret = krun_set_console_output (ctx_id, "/dev/stdout");
383+
if (UNLIKELY (ret < 0))
384+
error (EXIT_FAILURE, -ret, "could not redirect enclave output to stdout");
385+
}
386+
373387
ret = libkrun_configure_vm (ctx_id, handle, &configured, &config_tree, &err);
374388
if (UNLIKELY (ret))
375389
{

0 commit comments

Comments
 (0)