ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libptytty/src/ptytty.C
(Generate patch)

Comparing libptytty/src/ptytty.C (file contents):
Revision 1.41 by sf-exg, Fri Nov 11 15:11:18 2011 UTC vs.
Revision 1.46 by sf-exg, Tue Dec 20 21:03:21 2011 UTC

28#include "config.h" 28#include "config.h"
29 29
30#include "ptytty.h" 30#include "ptytty.h"
31 31
32#include <cstdlib> 32#include <cstdlib>
33#include <cstdio>
33#include <cstring> 34#include <cstring>
34#include <csignal>
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/stat.h> 37#include <sys/stat.h>
38#include <unistd.h> 38#include <unistd.h>
39#include <fcntl.h> 39#include <fcntl.h>
55# include <util.h> 55# include <util.h>
56#endif 56#endif
57#ifdef TTY_GID_SUPPORT 57#ifdef TTY_GID_SUPPORT
58#include <grp.h> 58#include <grp.h>
59#endif 59#endif
60
61#include <cstdio>
62 60
63///////////////////////////////////////////////////////////////////////////// 61/////////////////////////////////////////////////////////////////////////////
64 62
65/* ------------------------------------------------------------------------- * 63/* ------------------------------------------------------------------------- *
66 * GET PSEUDO TELETYPE - MASTER AND SLAVE * 64 * GET PSEUDO TELETYPE - MASTER AND SLAVE *
76 get_pty (int *fd_tty, char **ttydev) 74 get_pty (int *fd_tty, char **ttydev)
77 { 75 {
78 int pfd; 76 int pfd;
79 77
80# if defined(HAVE_GETPT) 78# if defined(HAVE_GETPT)
81 pfd = getpt(); 79 pfd = getpt ();
82# elif defined(HAVE_POSIX_OPENPT) 80# elif defined(HAVE_POSIX_OPENPT)
83 pfd = posix_openpt (O_RDWR | O_NOCTTY); 81 pfd = posix_openpt (O_RDWR | O_NOCTTY);
84# else 82# else
85# ifdef _AIX 83# ifdef _AIX
86 pfd = open ("/dev/ptc", O_RDWR | O_NOCTTY, 0); 84 pfd = open ("/dev/ptc", O_RDWR | O_NOCTTY, 0);
130 get_pty (int *fd_tty, char **ttydev) 128 get_pty (int *fd_tty, char **ttydev)
131 { 129 {
132 int pfd; 130 int pfd;
133 char *slave; 131 char *slave;
134 132
135 slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); 133 slave = _getpty (&pfd, O_RDWR | O_NOCTTY, 0622, 0);
136 134
137 if (slave != NULL) 135 if (slave != NULL)
138 { 136 {
139 *ttydev = strdup (slave); 137 *ttydev = strdup (slave);
140 return pfd; 138 return pfd;
156 const char *majors = "pqrstuvwxyzabcde"; 154 const char *majors = "pqrstuvwxyzabcde";
157 const char *minors = "0123456789abcdef"; 155 const char *minors = "0123456789abcdef";
158 156
159 for (i = 0; i < 256; i++) 157 for (i = 0; i < 256; i++)
160 { 158 {
161 snprintf(pty_name, 32, "/dev/pty%c%c", majors[i / 16], minors[i % 16]); 159 snprintf (pty_name, 32, "/dev/pty%c%c", majors[i / 16], minors[i % 16]);
162 snprintf(tty_name, 32, "/dev/tty%c%c", majors[i / 16], minors[i % 16]); 160 snprintf (tty_name, 32, "/dev/tty%c%c", majors[i / 16], minors[i % 16]);
163 161
164 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1) 162 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
165 { 163 {
166 snprintf(pty_name, 32, "/dev/ptyp%d", i); 164 snprintf (pty_name, 32, "/dev/ptyp%d", i);
167 snprintf(tty_name, 32, "/dev/ttyp%d", i); 165 snprintf (tty_name, 32, "/dev/ttyp%d", i);
168 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1) 166 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
169 continue; 167 continue;
170 } 168 }
171 169
172 if (access (tty_name, R_OK | W_OK) == 0) 170 if (access (tty_name, R_OK | W_OK) == 0)
328ptytty_unix::get () 326ptytty_unix::get ()
329{ 327{
330 /* get master (pty) */ 328 /* get master (pty) */
331 if ((pty = get_pty (&tty, &name)) < 0) 329 if ((pty = get_pty (&tty, &name)) < 0)
332 return false; 330 return false;
333
334 fcntl (pty, F_SETFL, O_NONBLOCK);
335 331
336 /* get slave (tty) */ 332 /* get slave (tty) */
337 if (tty < 0) 333 if (tty < 0)
338 { 334 {
339#ifndef NO_SETOWNER_TTYDEV 335#ifndef NO_SETOWNER_TTYDEV
376 ioctl (tty, I_PUSH, "ldterm"); 372 ioctl (tty, I_PUSH, "ldterm");
377 ioctl (tty, I_PUSH, "ttcompat"); 373 ioctl (tty, I_PUSH, "ttcompat");
378 } 374 }
379#endif 375#endif
380 376
377#if UTMP_SUPPORT
378# if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
379 int fd_stdin = dup (STDIN_FILENO);
380 dup2 (tty, STDIN_FILENO);
381
382 utmp_pos = ttyslot ();
383
384 dup2 (fd_stdin, STDIN_FILENO);
385 close (fd_stdin);
386# endif
387#endif
388
381 return true; 389 return true;
382} 390}
383 391

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines