1 /* tty.h: shared tty info for cygwin
3 Copyright 2000, 2001, 2002, 2003, 2004, 2006, 2009, 2010, 2011 Red Hat, Inc.
5 This file is part of Cygwin.
7 This software is a copyrighted work licensed under the terms of the
8 Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 #define INP_BUFFER_SIZE 256
14 #define OUT_BUFFER_SIZE 256
16 #define real_tty_attached(p) ((p)->ctty >= 0 && !iscons_dev ((p)->ctty))
18 /* Input/Output/ioctl events */
20 #define OUTPUT_DONE_EVENT "cygtty.output.done"
21 #define IOCTL_REQUEST_EVENT "cygtty.ioctl.request"
22 #define IOCTL_DONE_EVENT "cygtty.ioctl.done"
23 #define RESTART_OUTPUT_EVENT "cygtty.output.restart"
24 #define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
25 #define OUTPUT_MUTEX "cygtty.output.mutex"
26 #define INPUT_MUTEX "cygtty.input.mutex"
27 #define TTY_SLAVE_ALIVE "cygtty.slave_alive"
28 #define TTY_MASTER_ALIVE "cygtty.master_alive"
30 #include <sys/termios.h>
32 #ifndef MIN_CTRL_C_SLOP
33 #define MIN_CTRL_C_SLOP 50
39 pid_t sid; /* Session ID of tty */
42 unsigned initialized : 1; /* Set if tty is initialized */
43 unsigned rstcons : 1; /* Set if console needs to be set to "non-cooked" */
50 DWORD last_ctrl_c; /* tick count of last ctrl-c */
51 HWND hwnd; /* Console window handle tty belongs to */
53 IMPLEMENT_STATUS_FLAG (bool, initialized)
54 IMPLEMENT_STATUS_FLAG (bool, rstcons)
57 struct winsize winsize;
59 /* ioctl requests buffer */
63 struct termios termios;
64 struct winsize winsize;
68 /* XXX_retval variables holds master's completion codes. Error are stored as
74 void setntty (_major_t t, int n) {ntty = (fh_devices) FHDEV (t, n);}
75 int getntty () const {return ntty;}
76 int get_unit () const {return device::minor (ntty);}
77 pid_t getpgid () const {return pgid;}
78 void setpgid (int pid) {pgid = pid;}
79 int getsid () const {return sid;}
80 void setsid (pid_t tsid) {sid = tsid;}
81 void kill_pgrp (int sig);
82 HWND gethwnd () const {return hwnd;}
83 void sethwnd (HWND wnd) {hwnd = wnd;}
84 const char *ttyname () __attribute ((regparm (1)));
87 class fhandler_pty_master;
89 class tty: public tty_min
91 HANDLE get_event (const char *fmt, PSECURITY_ATTRIBUTES sa,
92 BOOL manual_reset = FALSE);
93 __attribute__ ((regparm (3)));
95 pid_t master_pid; /* PID of tty master process */
97 HANDLE from_master, to_master;
100 bool was_opened; /* True if opened at least once. */
103 HANDLE open_inuse (ACCESS_MASK access);
104 HANDLE create_inuse (PSECURITY_ATTRIBUTES);
106 HANDLE open_mutex (const char *mutex, ACCESS_MASK access);
107 inline HANDLE open_output_mutex (ACCESS_MASK access)
108 { return open_mutex (OUTPUT_MUTEX, access); }
109 inline HANDLE open_input_mutex (ACCESS_MASK access)
110 { return open_mutex (INPUT_MUTEX, access); }
112 void set_master_closed () {master_pid = -1;}
113 static void __stdcall create_master (int);
114 static void __stdcall init_session ();
115 friend class fhandler_pty_master;
124 tty * operator [](int n) {return ttys + device::minor (n);}
125 int allocate (bool); /* true if allocate a tty, pty otherwise */
129 tty_min *get_cttyp ();
130 int __stdcall attach (int n) __attribute__ ((regparm (2)));
131 static void __stdcall init_session ();
132 friend class lock_ttys;
139 lock_ttys (DWORD = INFINITE);
140 static void release ();
141 void dont_release () {release_me = false;}
149 extern "C" int ttyslot (void);