ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/libptytty/src/libptytty.h
Revision: 1.17
Committed: Sat Jun 26 14:31:15 2021 UTC (5 years, 3 months ago) by sf-exg
Content type: text/plain
Branch: MAIN
Changes since 1.16: +26 -0 lines
Log Message:
Remove PTYTTY_{WARN,FATAL} and throw on failure

File Contents

# User Rev Content
1 root 1.10 #ifndef LIBPTYTTY_H_ /* public libptytty header file */
2     #define LIBPTYTTY_H_
3 root 1.1
4 root 1.10 #ifdef __cplusplus
5 root 1.8
6 root 1.12 // C++ API
7 root 1.8
8 sf-exg 1.17 #include <exception>
9     #include <string.h>
10    
11     class ptytty_error : public std::exception
12     {
13     private:
14     char *msg;
15    
16     public:
17     ptytty_error (const char *what_arg)
18     {
19     msg = strdup (what_arg);
20     }
21    
22     ~ptytty_error ()
23     {
24     free (msg);
25     }
26    
27     const char *
28     what () const noexcept override
29     {
30     return msg;
31     }
32     };
33    
34 sf-exg 1.16 struct ptytty
35     {
36 root 1.14 int pty; // pty file descriptor; connected to terminal emulator
37 root 1.10 int tty; // tty file descriptor; connected to child
38 root 1.1
39 root 1.10 virtual ~ptytty ()
40     {
41     }
42 root 1.1
43 root 1.10 virtual bool get () = 0;
44     virtual void login (int cmd_pid, bool login_shell, const char *hostname) = 0;
45 root 1.1
46 root 1.10 void close_tty ();
47     bool make_controlling_tty ();
48     void set_utf8_mode (bool on);
49 root 1.1
50 root 1.13 static void sanitise_stdfd ();
51 root 1.10 static void init ();
52     static ptytty *create (); // create a new pty object
53 root 1.6
54 root 1.10 static void drop_privileges ();
55     static void use_helper ();
56 root 1.4
57 root 1.10 static bool send_fd (int socket, int fd);
58     static int recv_fd (int socket);
59 root 1.4
60 root 1.10 protected:
61 root 1.4
62 root 1.10 ptytty ()
63     : pty(-1), tty(-1)
64     {
65     }
66     };
67 root 1.1
68 root 1.10 #else
69 root 1.8
70 root 1.12 // C API
71 root 1.8
72 root 1.10 typedef void *PTYTTY;
73 root 1.8
74 root 1.10 int ptytty_pty (PTYTTY ptytty);
75     int ptytty_tty (PTYTTY ptytty);
76     void ptytty_delete (PTYTTY ptytty);
77     int ptytty_get (PTYTTY ptytty);
78 root 1.11 void ptytty_login (PTYTTY ptytty, int cmd_pid, int login_shell, const char *hostname);
79 root 1.8
80 root 1.10 void ptytty_close_tty (PTYTTY ptytty);
81     int ptytty_make_controlling_tty (PTYTTY ptytty);
82     void ptytty_set_utf8_mode (PTYTTY ptytty, int on);
83 root 1.8
84 root 1.13 void ptytty_sanitise_stdfd ();
85 root 1.10 void ptytty_init ();
86     PTYTTY ptytty_create ();
87 root 1.8
88 root 1.10 void ptytty_drop_privileges ();
89     void ptytty_use_helper ();
90 root 1.1
91 root 1.10 #endif
92 root 1.9
93 root 1.10 #endif
94 root 1.9