If gvir_sandbox_console_attach is called with NULL as the stdin parameter it results in a segfault in the console-rpc module from libvirt-sandbox. Calling with NULL is of course useful when running something noninteractive and you don't want it to grab the stdin or pass any fd whatsoever.
commit f94f23314ab654c13bd1e25bd9094f1687fd681a Author: Radu Caragea <sinaelgl@xxxxxxxxx> Date: Tue Jun 12 21:31:09 2012 +0300 Fix crash on null stdin When we don't want to run something interactive and we use NULL as the stdin the app should still work. Signed-off-by: Radu Caragea <sinaelgl@xxxxxxxxx> diff --git a/libvirt-sandbox/libvirt-sandbox-console-rpc.c b/libvirt-sandbox/libvirt-sandbox-console-rpc.c index af78314..c63b0e9 100644 --- a/libvirt-sandbox/libvirt-sandbox-console-rpc.c +++ b/libvirt-sandbox/libvirt-sandbox-console-rpc.c @@ -402,9 +402,14 @@ static gboolean gvir_sandbox_console_rpc_start_term(GVirSandboxConsoleRpc *conso GError **error) { GVirSandboxConsoleRpcPrivate *priv = console->priv; - int fd = g_unix_input_stream_get_fd(localStdin); + int fd; struct termios ios; + if (!localStdin) + return TRUE; + + fd = g_unix_input_stream_get_fd(localStdin); + if (!isatty(fd)) return TRUE; @@ -443,7 +448,12 @@ static gboolean gvir_sandbox_console_rpc_stop_term(GVirSandboxConsoleRpc *consol GError **error) { GVirSandboxConsoleRpcPrivate *priv = console->priv; - int fd = g_unix_input_stream_get_fd(localStdin); + int fd; + + if (!localStdin) + return TRUE; + + fd = g_unix_input_stream_get_fd(localStdin); if (!isatty(fd)) return TRUE; @@ -483,7 +493,7 @@ static void do_console_rpc_update_events(GVirSandboxConsoleRpc *console) /* If nothing is waiting to be sent to guest, we can read * some more of stdin */ if (!priv->tx && !priv->localEOF) { - if (priv->localStdinSource == NULL) { + if (priv->localStdinSource == NULL && priv->localStdin) { priv->localStdinSource = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM(priv->localStdin), NULL); g_source_set_callback(priv->localStdinSource, @@ -926,7 +936,9 @@ static gboolean gvir_sandbox_console_rpc_attach(GVirSandboxConsole *console, localStdin, error)) return FALSE; - priv->localStdin = g_object_ref(localStdin); + if (localStdin) + priv->localStdin = g_object_ref(localStdin); + priv->localStdout = g_object_ref(localStdout); priv->localStderr = g_object_ref(localStderr); @@ -983,7 +995,8 @@ static gboolean gvir_sandbox_console_rpc_detach(GVirSandboxConsole *console, priv->localStdinSource = priv->localStdoutSource = priv->localStderrSource = NULL; priv->consoleWatch = 0; - g_object_unref(priv->localStdin); + if (priv->localStdin) + g_object_unref(priv->localStdin); g_object_unref(priv->localStdout); g_object_unref(priv->localStderr); priv->localStdin = NULL;
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list