* fhandler.h (fhandler_termios::tcinit): Make second argument non-optional.

* fhandler_console.cc (fhandler_console::open): Specify second argument to
tcinit.
* fhandler_termios.cc (fhandler_termios::tcinit): Rename second argument.  Set
pgid to 0 if this is a pty master.
(fhandler_termios::tcgetpgrp): Just return value of pgid.  It will be zero if
not initialized.
* fhandler_tty.cc (fhandler_tty_slave::open): Specify second argument to
tcinit.
(fhandler_tty_slave::ioctl): Implement TIOCGPRP/TIOCSPGRP.  Fix switch
indentation.
(fhandler_tty_master::ioctl): Implement TIOCGPRP/TIOCSPGRP.
* include/sys/termios.h (TIOCGPGRP): Define similarly to Linux.
* include/sys/termios.h (TIOCSPGRP): Ditto.
This commit is contained in:
Christopher Faylor 2010-10-23 18:07:08 +00:00
parent 2e859e0759
commit 4ce975efd3
6 changed files with 68 additions and 27 deletions

View File

@ -1,3 +1,21 @@
2010-10-23 Christopher Faylor <me+cygwin@cgf.cx>
* fhandler.h (fhandler_termios::tcinit): Make second argument
non-optional.
* fhandler_console.cc (fhandler_console::open): Specify second argument
to tcinit.
* fhandler_termios.cc (fhandler_termios::tcinit): Rename second
argument. Set pgid to 0 if this is a pty master.
(fhandler_termios::tcgetpgrp): Just return value of pgid. It will be
zero if not initialized.
* fhandler_tty.cc (fhandler_tty_slave::open): Specify second argument
to tcinit.
(fhandler_tty_slave::ioctl): Implement TIOCGPRP/TIOCSPGRP. Fix switch
indentation.
(fhandler_tty_master::ioctl): Implement TIOCGPRP/TIOCSPGRP.
* include/sys/termios.h (TIOCGPGRP): Define similarly to Linux.
(TIOCSPGRP): Ditto.
2010-10-18 Marco Atzeri <marco_atzeri@yahoo.it> 2010-10-18 Marco Atzeri <marco_atzeri@yahoo.it>
* winsup/cygwin/cygwin.din: Add llround and llroundf. * winsup/cygwin/cygwin.din: Add llround and llroundf.

View File

@ -885,7 +885,7 @@ class fhandler_termios: public fhandler_base
HANDLE& get_output_handle () { return output_handle; } HANDLE& get_output_handle () { return output_handle; }
line_edit_status line_edit (const char *rptr, int nread, termios&); line_edit_status line_edit (const char *rptr, int nread, termios&);
void set_output_handle (HANDLE h) { output_handle = h; } void set_output_handle (HANDLE h) { output_handle = h; }
void tcinit (tty_min *this_tc, bool force = false); void tcinit (tty_min *this_tc, bool force);
bool is_tty () const { return true; } bool is_tty () const { return true; }
int tcgetpgrp (); int tcgetpgrp ();
int tcsetpgrp (int pid); int tcsetpgrp (int pid);

View File

@ -695,7 +695,7 @@ fhandler_console::open (int flags, mode_t)
{ {
HANDLE h; HANDLE h;
tcinit (get_tty_stuff (flags)); tcinit (get_tty_stuff (flags), false);
set_io_handle (NULL); set_io_handle (NULL);
set_output_handle (NULL); set_output_handle (NULL);

View File

@ -23,13 +23,13 @@ details. */
/* Common functions shared by tty/console */ /* Common functions shared by tty/console */
void void
fhandler_termios::tcinit (tty_min *this_tc, bool force) fhandler_termios::tcinit (tty_min *this_tc, bool is_pty_master)
{ {
/* Initial termios values */ /* Initial termios values */
tc = this_tc; tc = this_tc;
if (force || !tc->initialized ()) if (is_pty_master || !tc->initialized ())
{ {
tc->ti.c_iflag = BRKINT | ICRNL | IXON; tc->ti.c_iflag = BRKINT | ICRNL | IXON;
tc->ti.c_oflag = OPOST | ONLCR; tc->ti.c_oflag = OPOST | ONLCR;
@ -55,7 +55,7 @@ fhandler_termios::tcinit (tty_min *this_tc, bool force)
tc->ti.c_cc[VWERASE] = CWERASE; tc->ti.c_cc[VWERASE] = CWERASE;
tc->ti.c_ispeed = tc->ti.c_ospeed = B38400; tc->ti.c_ispeed = tc->ti.c_ospeed = B38400;
tc->pgid = myself->pgid; tc->pgid = is_pty_master ? 0 : myself->pgid;
tc->initialized (true); tc->initialized (true);
} }
} }
@ -108,7 +108,7 @@ fhandler_termios::tcgetpgrp ()
int int
fhandler_pty_master::tcgetpgrp () fhandler_pty_master::tcgetpgrp ()
{ {
return myself->ctty != -1 && myself->ctty == tc->ntty ? tc->pgid : 0; return tc->pgid;
} }
void void

View File

@ -484,7 +484,7 @@ fhandler_tty_slave::open (int flags, mode_t)
goto out; goto out;
} }
tcinit (cygwin_shared->tty[get_unit ()]); tcinit (cygwin_shared->tty[get_unit ()], false);
cygwin_shared->tty.attach (get_unit ()); cygwin_shared->tty.attach (get_unit ());
@ -1065,6 +1065,21 @@ fhandler_tty_slave::ioctl (unsigned int cmd, void *arg)
set_nonblocking (*(int *) arg); set_nonblocking (*(int *) arg);
retval = 0; retval = 0;
goto out; goto out;
case TIOCGPGRP:
{
pid_t pid = this->tcgetpgrp ();
if (pid < 0)
retval = -1;
else
{
*((pid_t *) arg) = pid;
retval = 0;
}
}
goto out;
case TIOCSPGRP:
retval = this->tcsetpgrp ((pid_t) arg);
goto out;
default: default:
set_errno (EINVAL); set_errno (EINVAL);
return -1; return -1;
@ -1349,6 +1364,7 @@ fhandler_pty_master::open (int flags, mode_t)
// //
// FIXME: Do this better someday // FIXME: Do this better someday
fhandler_pty_master *arch = (fhandler_tty_master *) cmalloc_abort (HEAP_ARCHETYPES, sizeof (*this)); fhandler_pty_master *arch = (fhandler_tty_master *) cmalloc_abort (HEAP_ARCHETYPES, sizeof (*this));
small_printf ("tty%d myself->sid %d myself->pid %d this->tcgetpgrp %d\n", get_unit (), myself->sid, myself->pid, this->tcgetpgrp ());
*((fhandler_pty_master **) cygheap->fdtab.add_archetype ()) = arch; *((fhandler_pty_master **) cygheap->fdtab.add_archetype ()) = arch;
archetype = arch; archetype = arch;
*arch = *this; *arch = *this;
@ -1510,26 +1526,31 @@ fhandler_pty_master::ioctl (unsigned int cmd, void *arg)
{ {
switch (cmd) switch (cmd)
{ {
case TIOCPKT: case TIOCPKT:
pktmode = *(int *) arg; pktmode = *(int *) arg;
break; break;
case TIOCGWINSZ: case TIOCGWINSZ:
*(struct winsize *) arg = get_ttyp ()->winsize; *(struct winsize *) arg = get_ttyp ()->winsize;
break; break;
case TIOCSWINSZ: case TIOCSWINSZ:
if (get_ttyp ()->winsize.ws_row != ((struct winsize *) arg)->ws_row if (get_ttyp ()->winsize.ws_row != ((struct winsize *) arg)->ws_row
|| get_ttyp ()->winsize.ws_col != ((struct winsize *) arg)->ws_col) || get_ttyp ()->winsize.ws_col != ((struct winsize *) arg)->ws_col)
{ {
get_ttyp ()->winsize = *(struct winsize *) arg; get_ttyp ()->winsize = *(struct winsize *) arg;
killsys (-get_ttyp ()->getpgid (), SIGWINCH); killsys (-get_ttyp ()->getpgid (), SIGWINCH);
} }
break; break;
case FIONBIO: case TIOCGPGRP:
set_nonblocking (*(int *) arg); *((pid_t *) arg) = this->tcgetpgrp ();
break; break;
default: case TIOCSPGRP:
set_errno (EINVAL); return this->tcsetpgrp ((pid_t) arg);
return -1; case FIONBIO:
set_nonblocking (*(int *) arg);
break;
default:
set_errno (EINVAL);
return -1;
} }
return 0; return 0;
} }

View File

@ -348,5 +348,7 @@ struct winsize
#define TIOCGWINSZ (('T' << 8) | 1) #define TIOCGWINSZ (('T' << 8) | 1)
#define TIOCSWINSZ (('T' << 8) | 2) #define TIOCSWINSZ (('T' << 8) | 2)
#define TIOCLINUX (('T' << 8) | 3) #define TIOCLINUX (('T' << 8) | 3)
#define TIOCGPGRP (('T' << 8) | 0xf)
#define TIOCSPGRP (('T' << 8) | 0x10)
#endif /* _SYS_TERMIOS_H */ #endif /* _SYS_TERMIOS_H */