/*
- * console.c: A dumb serial console client
+ * virsh-console.c: A dumb serial console client
*
- * Copyright (C) 2007-2008, 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2007-2008, 2010-2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
- * Daniel Berrange <berrange@redhat.com>
+ * Authors:
+ * Daniel Berrange <berrange@redhat.com>
*/
#include <config.h>
# include <c-ctype.h>
# include "internal.h"
-# include "console.h"
+# include "virsh-console.h"
# include "virlog.h"
# include "virfile.h"
# include "viralloc.h"
char *data;
};
+
typedef struct virConsole virConsole;
typedef virConsole *virConsolePtr;
struct virConsole {
char escapeChar;
};
+
static int got_signal = 0;
-static void do_signal(int sig ATTRIBUTE_UNUSED) {
+static void
+virConsoleHandleSignal(int sig ATTRIBUTE_UNUSED)
+{
got_signal = 1;
}
+
# ifndef HAVE_CFMAKERAW
static void
cfmakeraw(struct termios *attr)
}
# endif /* !HAVE_CFMAKERAW */
+
static void
virConsoleShutdown(virConsolePtr con)
{
virCondSignal(&con->cond);
}
+
+static void
+virConsoleFree(virConsolePtr con)
+{
+ if (!con)
+ return;
+
+ if (con->st)
+ virStreamFree(con->st);
+ virMutexDestroy(&con->lock);
+ virCondDestroy(&con->cond);
+ VIR_FREE(con);
+}
+
+
static void
virConsoleEventOnStream(virStreamPtr st,
int events, void *opaque)
avail = con->terminalToStream.length - con->terminalToStream.offset;
if (avail > 1024) {
- if (VIR_REALLOC_N(con->terminalToStream.data,
- con->terminalToStream.offset + 1024) < 0)
- {}
+ ignore_value(VIR_REALLOC_N(con->terminalToStream.data,
+ con->terminalToStream.offset + 1024));
con->terminalToStream.length = con->terminalToStream.offset + 1024;
}
}
}
}
+
static void
virConsoleEventOnStdin(int watch ATTRIBUTE_UNUSED,
int fd ATTRIBUTE_UNUSED,
}
}
+
static void
virConsoleEventOnStdout(int watch ATTRIBUTE_UNUSED,
int fd,
avail = con->streamToTerminal.length - con->streamToTerminal.offset;
if (avail > 1024) {
- if (VIR_REALLOC_N(con->streamToTerminal.data,
- con->streamToTerminal.offset + 1024) < 0)
- {}
+ ignore_value(VIR_REALLOC_N(con->streamToTerminal.data,
+ con->streamToTerminal.offset + 1024));
con->streamToTerminal.length = con->streamToTerminal.offset + 1024;
}
}
return *s;
}
+
int
vshMakeStdinRaw(struct termios *ttyattr, bool report_errors)
{
return 0;
}
-int vshRunConsole(virDomainPtr dom,
- const char *dev_name,
- const char *escape_seq,
- unsigned int flags)
+
+int
+vshRunConsole(virDomainPtr dom,
+ const char *dev_name,
+ const char *escape_seq,
+ unsigned int flags)
{
int ret = -1;
struct termios ttyattr;
the original terminal settings on STDIN before the
process exits - people don't like being left with a
messed up terminal ! */
- old_sigquit = signal(SIGQUIT, do_signal);
- old_sigterm = signal(SIGTERM, do_signal);
- old_sigint = signal(SIGINT, do_signal);
- old_sighup = signal(SIGHUP, do_signal);
- old_sigpipe = signal(SIGPIPE, do_signal);
+ old_sigquit = signal(SIGQUIT, virConsoleHandleSignal);
+ old_sigterm = signal(SIGTERM, virConsoleHandleSignal);
+ old_sigint = signal(SIGINT, virConsoleHandleSignal);
+ old_sighup = signal(SIGHUP, virConsoleHandleSignal);
+ old_sigpipe = signal(SIGPIPE, virConsoleHandleSignal);
got_signal = 0;
if (VIR_ALLOC(con) < 0)
ret = 0;
- cleanup:
-
- if (con) {
- if (con->st)
- virStreamFree(con->st);
- virMutexDestroy(&con->lock);
- virCondDestroy(&con->cond);
- VIR_FREE(con);
- }
+cleanup:
+ virConsoleFree(con);
/* Restore original signal handlers */
signal(SIGPIPE, old_sigpipe);
/*
- * console.c: A dumb serial console client
+ * virsh-console.h: A dumb serial console client
*
- * Copyright (C) 2007, 2010, 2012 Red Hat, Inc.
+ * Copyright (C) 2007, 2010, 2012-2013 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License along with this library. If not, see
* <http://www.gnu.org/licenses/>.
*
- * Daniel Berrange <berrange@redhat.com>
+ * Authors:
+ * Daniel Berrange <berrange@redhat.com>
*/
#ifndef __VIR_CONSOLE_H__