1 /* tty.h: shared tty info for cygwin
3 Copyright 2000, 2001, 2002, 2003, 2004, 2006 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 && (p)->ctty != TTY_CONSOLE)
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
38 pid_t sid; /* Session ID of tty */
41 unsigned initialized : 1; /* Set if tty is initialized */
42 unsigned rstcons : 1; /* Set if console needs to be set to "non-cooked" */
49 DWORD last_ctrl_c; /* tick count of last ctrl-c */
50 HWND hwnd; /* Console window handle tty belongs to */
52 IMPLEMENT_STATUS_FLAG (bool, initialized)
53 IMPLEMENT_STATUS_FLAG (bool, rstcons)
56 struct winsize winsize;
58 /* ioctl requests buffer */
62 struct termios termios;
63 struct winsize winsize;
67 /* XXX_retval variables holds master's completion codes. Error are stored as
73 void setntty (int n) {ntty = n;}
74 pid_t getpgid () {return pgid;}
75 void setpgid (int pid) {pgid = pid;}
76 int getsid () {return sid;}
77 void setsid (pid_t tsid) {sid = tsid;}
78 void kill_pgrp (int sig);
79 HWND gethwnd () {return hwnd;}
80 void sethwnd (HWND wnd) {hwnd = wnd;}
83 class fhandler_pty_master;
85 class tty: public tty_min
87 HANDLE get_event (const char *fmt, BOOL manual_reset = FALSE)
88 __attribute__ ((regparm (3)));
90 pid_t master_pid; /* PID of tty master process */
92 HANDLE from_master, to_master;
95 bool was_opened; /* True if opened at least once. */
98 HANDLE create_inuse (const char *);
99 bool alive (const char *fmt);
101 bool master_alive ();
102 HANDLE open_mutex (const char *mutex);
103 HANDLE open_output_mutex ();
104 HANDLE open_input_mutex ();
109 HANDLE h = open_output_mutex ();
115 return slave_alive ();
117 void set_master_closed () {master_pid = -1;}
118 static void __stdcall create_master (int);
119 static void __stdcall init_session ();
120 friend class fhandler_pty_master;
129 tty * operator [](int n) {return ttys + n;}
130 int allocate (bool); /* true if allocate a tty, pty otherwise */
134 tty_min *get_tty (int n);
135 int __stdcall attach (int);
136 static void __stdcall init_session ();
137 friend class lock_ttys;
144 lock_ttys (DWORD = INFINITE);
145 static void release ();
146 void dont_release () {release_me = false;}
154 extern "C" int ttyslot (void);