[Pkg-kbd-devel] A bug in the openvt program from the kbd-1.15.2 package (some add-ons)

Alexander Kozhushkin alex at grave.users.botik.ru
Sat Apr 16 07:34:11 UTC 2011


There is yet another reason for the parent openvt process to
close the terminal device file given by the file descriptor
fd0 before forking the child. That was proposed in my previous
letter "A bug in the openvt program from the kbd-1.15.2 package".

Whenever I run the original openvt program from the shell as
follows

bash# openvt -ws

the parent openvt fails to deallocate the terminal used by the
child after the child terminates.

I've got the following message from the parent process on its exit:

bash# openvt -ws
openvt: could not deallocate console 5
bash#

(Here the child process was using the `/dev/tty5')

Such a warning message appears because the parent openvt process
tries to deallocate (at line #320) the virtual terminal which was
used by its child while still keeping the respective device file
open (see the partial listing below). The parent process clearly
fails to do that,  and so prints out  the warning message to the
stderr.

Note that the program with the changes suggested  in my previous
letter always successfully deallocates the terminal in that case.


......................................
039  int
040  main(int argc, char *argv[])
041  {
        ......................................
155     /* Can we open the vt we want? */
156     if ((fd0 = open(vtname, O_RDWR)) == -1) {
157        int errsv = errno;
158        if (!optc) {
                   ......................................
163               for (i=vtno+1; i<16; i++) {
164                   if((vtstat.v_state & (1<<i)) == 0) {
165                       sprintf(vtname, VTNAME, i);
166                       if ((fd0 = open(vtname, O_RDWR)) >= 0) {
167                           vtno = i;
168                           goto got_vtno;
169                       }
170                   }
171               }
172               sprintf(vtname, VTNAME, vtno);
173        }
174        fprintf(stderr, _("openvt: Unable to open %s: %s\n"),
175               vtname, strerror(errsv));
176        return(5);
177     }
178  got_vtno:
        ......................................

308     if ( do_wait ) {
309        wait(NULL);
310        if (show) { /* Switch back... */
311          if (ioctl(consfd, VT_ACTIVATE, vtstat.v_active)) {
                 ......................................
314          }
315          /* wait to be really sure we have switched */
316          if (ioctl(consfd, VT_WAITACTIVE, vtstat.v_active)) {
                 ......................................
319          }
320          if (ioctl(consfd, VT_DISALLOCATE, vtno)) {
321            fprintf(stderr, _("openvt: could not deallocate console 
%d\n"),
322                vtno);
323            return(8);
324          }
325        }
326     }
327
328     return 0;
329  }




More information about the Pkg-kbd-devel mailing list