Skip to content

Commit

Permalink
openvt: handle -ws correctly. By James Simmons <jsimmons AT infradead…
Browse files Browse the repository at this point in the history
….org>

function                                             old     new   delta
openvt_main                                          343     429     +86
  • Loading branch information
Denis Vlasenko committed Apr 19, 2008
1 parent 50d068c commit 1b2d0b2
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions console-tools/openvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ int openvt_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
{
char vtname[sizeof(VC_FORMAT) + sizeof(int)*3];
struct vt_stat vtstat;
char *str_c;
int vtno;
int flags;
Expand Down Expand Up @@ -137,6 +138,7 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)
close(0);
/*setsid(); - BAD IDEA: after we exit, child is SIGHUPed... */
xopen(vtname, O_RDWR);
xioctl(0, VT_GETSTATE, &vtstat);

if (flags & OPT_s) {
xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)vtno);
Expand All @@ -163,9 +165,16 @@ int openvt_main(int argc ATTRIBUTE_UNUSED, char **argv)

vfork_child(argv);
if (flags & OPT_w) {
wait(NULL);
// TODO: -ws handling should be here
/* We have only one child, wait for it */
safe_waitpid(-1, NULL, 0); /* loops on EINTR */
if (flags & OPT_s) {
xioctl(0, VT_ACTIVATE, (void*)(ptrdiff_t)(vtstat.v_active));
xioctl(0, VT_WAITACTIVE, (void*)(ptrdiff_t)(vtstat.v_active));
// Compat: even with -c N (try to) disallocate:
// # /usr/app/kbd-1.12/bin/openvt -f -c 9 -ws sleep 5
// openvt: could not deallocate console 9
xioctl(0, VT_DISALLOCATE, (void*)(ptrdiff_t)vtno);
}
}

return EXIT_SUCCESS;
}

0 comments on commit 1b2d0b2

Please sign in to comment.