From e37c78afc7fcee6d8edaa506b99d9081249adb7d Mon Sep 17 00:00:00 2001 From: Robert White Date: Fri, 8 Apr 2011 00:35:01 +0400 Subject: [PATCH] openvt: Fix -w option The openvt command, when using option -w needs to close the file descriptor attached to the allocated vt or it will always return an error because the vt is "still in use" by openvt. Signed-off-by: Robert White Signed-off-by: Alexey Gladkov --- src/openvt.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/openvt.c b/src/openvt.c index cf68dab..2de0504 100644 --- a/src/openvt.c +++ b/src/openvt.c @@ -298,7 +298,14 @@ main(int argc, char *argv[]) } if (do_wait) { + int retval = 0; /* actual value returned form process */ + wait(NULL); + waitpid(pid, &retval, 0); + + /* we need to clean up our file descriptors if we want dallocation to work later */ + close(fd0); + if (show) { /* Switch back... */ if (ioctl(consfd, VT_ACTIVATE, vtstat.v_active)) { perror("VT_ACTIVATE"); @@ -314,6 +321,13 @@ main(int argc, char *argv[]) return (8); } } + + /* if all our stuff went right, we want to return the exit code of the command we ran + super vital for scripting loops etc */ + return(retval); + + } else { + close(fd0); } return 0; -- 2.7.4