1 /* tty.h: shared tty info for cygwin
3 This file is part of Cygwin.
5 This software is a copyrighted work licensed under the terms of the
6 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) (CTTY_IS_VALID ((p)->ctty) && !iscons_dev ((p)->ctty))
18 /* Input/Output/ioctl events */
20 #define INPUT_AVAILABLE_EVENT "cygtty.input.avail"
21 #define OUTPUT_MUTEX "cygtty.output.mutex"
22 #define INPUT_MUTEX "cygtty.input.mutex"
23 #define PIPE_SW_MUTEX "cygtty.pipe_sw.mutex"
24 #define TTY_SLAVE_ALIVE "cygtty.slave_alive"
25 #define TTY_SLAVE_READING "cygtty.slave_reading"
27 #include <sys/termios.h>
29 #ifndef MIN_CTRL_C_SLOP
30 #define MIN_CTRL_C_SLOP 50
38 pid_t sid
; /* Session ID of tty */
41 unsigned initialized
: 1; /* Set if tty is initialized */
46 bool output_stopped
; /* FIXME: Maybe do this with a mutex someday? */
48 ULONGLONG last_ctrl_c
; /* tick count of last ctrl-c */
52 IMPLEMENT_STATUS_FLAG (bool, initialized
)
55 struct winsize winsize
;
57 /* ioctl requests buffer */
61 struct termios termios
;
62 struct winsize winsize
;
66 /* XXX_retval variables holds master's completion codes. Error are stored as
71 void setntty (_major_t t
, _minor_t n
) {ntty
= (fh_devices
) FHDEV (t
, n
);}
72 dev_t
getntty () const {return ntty
;}
73 _minor_t
get_minor () const {return device::minor (ntty
);}
74 pid_t
getpgid () const {return pgid
;}
75 void setpgid (int pid
);
76 int getsid () const {return sid
;}
77 void setsid (pid_t tsid
) {sid
= tsid
;}
78 void kill_pgrp (int, pid_t target_pgid
= 0);
79 int is_orphaned_process_group (int);
80 const char *ttyname () __attribute (());
84 /* The name *nat* comes from 'native' which means non-cygwin
85 (native windows). They are used for non-cygwin process. */
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
);
94 pid_t master_pid
; /* PID of tty master process */
96 /* Transfer direction for fhandler_pty_slave::transfer_input() */
104 restore
, /* For restoring when exit from cygwin. */
105 cygwin
, /* For cygwin apps */
106 native
/* For native apps executed from cygwin. */
110 HANDLE _from_master_nat
;
112 HANDLE _to_master_nat
;
114 HANDLE _to_slave_nat
;
118 pid_t pcon_start_pid
;
119 bool switch_to_nat_pipe
;
120 DWORD nat_pipe_owner_pid
;
122 ULONGLONG fwd_last_time
;
124 HANDLE h_pcon_write_pipe
;
125 HANDLE h_pcon_condrv_reference
;
126 HANDLE h_pcon_conhost_process
;
129 bool pcon_cap_checked
;
131 bool need_invisible_console
;
132 pid_t invisible_console_pid
;
133 UINT previous_code_page
;
134 UINT previous_output_code_page
;
135 bool master_is_running_as_service
;
137 xfer_dir pty_input_state
;
140 bool stop_fwd_thread
;
143 HANDLE
from_master_nat () const { return _from_master_nat
; }
144 HANDLE
from_master () const { return _from_master
; }
145 HANDLE
to_master_nat () const { return _to_master_nat
; }
146 HANDLE
to_master () const { return _to_master
; }
147 HANDLE
to_slave_nat () const { return _to_slave_nat
; }
148 HANDLE
to_slave () const { return _to_slave
; }
149 void set_from_master_nat (HANDLE h
) { _from_master_nat
= h
; }
150 void set_from_master (HANDLE h
) { _from_master
= h
; }
151 void set_to_master_nat (HANDLE h
) { _to_master_nat
= h
; }
152 void set_to_master (HANDLE h
) { _to_master
= h
; }
153 void set_to_slave_nat (HANDLE h
) { _to_slave_nat
= h
; }
154 void set_to_slave (HANDLE h
) { _to_slave
= h
; }
157 bool was_opened
; /* True if opened at least once. */
158 int column
; /* Current Column */
161 HANDLE
open_inuse (ACCESS_MASK access
);
162 HANDLE
create_inuse (PSECURITY_ATTRIBUTES
);
164 HANDLE
open_mutex (const char *mutex
, ACCESS_MASK access
);
165 inline HANDLE
open_output_mutex (ACCESS_MASK access
)
166 { return open_mutex (OUTPUT_MUTEX
, access
); }
167 inline HANDLE
open_input_mutex (ACCESS_MASK access
)
168 { return open_mutex (INPUT_MUTEX
, access
); }
170 bool not_allocated (HANDLE
&, HANDLE
&);
171 void set_master_ctl_closed () {master_pid
= -1;}
172 static void create_master (int);
173 static void init_session ();
175 bool pty_input_state_eq (xfer_dir x
) { return pty_input_state
== x
; }
176 bool nat_fg (pid_t pgid
);
177 friend class fhandler_pty_common
;
178 friend class fhandler_pty_master
;
179 friend class fhandler_pty_slave
;
180 friend class tty_min
;
189 tty
* operator [](int n
) {return ttys
+ device::minor (n
);}
190 int allocate (HANDLE
& r
, HANDLE
& w
); /* allocate a pty */
193 tty_min
*get_cttyp ();
195 static void init_session ();
196 friend class lock_ttys
;
203 lock_ttys (DWORD
= INFINITE
);
204 static void release ();
205 void dont_release () {release_me
= false;}
213 extern "C" int ttyslot (void);