[cowdancer] 02/02: qemubuilder.c: Use qemu monitor, with sane tty settings
James Clarke
jrtc27-guest at moszumanska.debian.org
Mon May 2 23:43:43 UTC 2016
This is an automated email from the git hooks/post-receive script.
jrtc27-guest pushed a commit to branch master
in repository cowdancer.
commit 8109e6b47e5257391dca31a61bcd7b235389782f
Author: James Clarke <jrtc27 at jrtc27.com>
Date: Mon May 2 20:15:03 2016 +0100
qemubuilder.c: Use qemu monitor, with sane tty settings
---
qemubuilder.c | 46 ++++++++++++++++++++++++++++++++++++----------
1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/qemubuilder.c b/qemubuilder.c
index abad6c0..8bc65c6 100755
--- a/qemubuilder.c
+++ b/qemubuilder.c
@@ -198,16 +198,21 @@ static FILE* create_script(const char* mountpoint, const char* relative_path)
return ret;
}
-/* minimally fix terminal I/O */
-static void fix_terminal(void)
+static struct termios saved_termios;
+
+static void save_termios(void)
{
- struct termios t;
+ if (isatty(1))
+ {
+ tcgetattr(1, &saved_termios);
+ }
+}
+static void restore_termios(void)
+{
if (isatty(1))
{
- tcgetattr(1, &t);
- t.c_lflag |= ECHO;
- tcsetattr(1, TCSANOW, &t);
+ tcsetattr(1, TCSANOW, &saved_termios);
}
}
@@ -444,6 +449,8 @@ static int fork_qemu(const char* hda, const char* hdb, const struct pbuilderconf
return -1;
}
+ save_termios();
+
fflush(NULL);
if ((child=fork()))
{
@@ -524,6 +531,16 @@ static int fork_qemu(const char* hda, const char* hdb, const struct pbuilderconf
const int MAX_ARGS = 40;
char *argv[MAX_ARGS];
int i;
+ int is_tty = isatty(1);
+ const char *term;
+ if (is_tty)
+ {
+ term = getenv("TERM");
+ if (!term)
+ term = ""; /* Use whatever getty defaults to */
+ }
+ else
+ term = "dumb";
if (qemu == NULL || machine == NULL) {
fprintf(stderr, "Your architecture %s does not seem to be supported\n", pc->arch);
@@ -560,9 +577,10 @@ static int fork_qemu(const char* hda, const char* hdb, const struct pbuilderconf
/* panic < 0 means reboot immediately on panic; this will actually
halt as -no-reboot is given to qemu */
asprintf(&append_command,
- "root=/dev/%sa quiet init=/sbin/getty console=%s panic=-1 -- -n -l /pbuilder-run -",
+ "root=/dev/%sa quiet init=/usr/bin/setsid console=%s panic=-1 -- -c -w /sbin/getty -n -l /pbuilder-run -8 -L - %s",
qemu_arch_diskdevice(pc),
- qemu_arch_tty(pc->arch));
+ qemu_arch_tty(pc->arch),
+ term);
dup2(sp[1],1);
dup2(sp[1],2);
@@ -594,7 +612,14 @@ static int fork_qemu(const char* hda, const char* hdb, const struct pbuilderconf
argv[argc++]="-append";
argv[argc++]=append_command;
argv[argc++]="-serial";
- argv[argc++]="stdio";
+ if (is_tty)
+ {
+ argv[argc++]="mon:stdio";
+ }
+ else
+ {
+ argv[argc++]="stdio";
+ }
argv[argc++]="-net";
argv[argc++]="user";
if (!strcmp(machine, "virt")) {
@@ -632,7 +657,7 @@ static int fork_qemu(const char* hda, const char* hdb, const struct pbuilderconf
return -1;
}
- fix_terminal();
+ restore_termios();
return exit_code;
}
@@ -674,6 +699,7 @@ static void write_first_stage(FILE *f, const struct pbuilderconfig* pc)
"echo ' -> qemu-pbuilder first-stage' \n"
"export PBUILDER_INIT_VERSION="XSTR(PBUILDER_INIT_VERSION)"\n"
"export PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'\n"
+ "stty sane\n"
"[ -d /proc/1 ] || mount -n /proc /proc -t proc\n"
"ln -s /dev/shm /run/shm\n"
"mkdir /run/lock\n"
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pbuilder/cowdancer.git
More information about the Pbuilder-maint
mailing list