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.47 by sf-exg, Wed Dec 21 11:07:22 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>
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 60
61#include <cstdio> 61#ifndef O_NOCTTY
62# define O_NOCTTY 0
63#endif
62 64
63///////////////////////////////////////////////////////////////////////////// 65/////////////////////////////////////////////////////////////////////////////
64 66
65/* ------------------------------------------------------------------------- * 67/* ------------------------------------------------------------------------- *
66 * GET PSEUDO TELETYPE - MASTER AND SLAVE * 68 * GET PSEUDO TELETYPE - MASTER AND SLAVE *
76 get_pty (int *fd_tty, char **ttydev) 78 get_pty (int *fd_tty, char **ttydev)
77 { 79 {
78 int pfd; 80 int pfd;
79 81
80# if defined(HAVE_GETPT) 82# if defined(HAVE_GETPT)
81 pfd = getpt(); 83 pfd = getpt ();
82# elif defined(HAVE_POSIX_OPENPT) 84# elif defined(HAVE_POSIX_OPENPT)
83 pfd = posix_openpt (O_RDWR | O_NOCTTY); 85 pfd = posix_openpt (O_RDWR | O_NOCTTY);
84# else 86# else
85# ifdef _AIX 87# ifdef _AIX
86 pfd = open ("/dev/ptc", O_RDWR | O_NOCTTY, 0); 88 pfd = open ("/dev/ptc", O_RDWR | O_NOCTTY, 0);
130 get_pty (int *fd_tty, char **ttydev) 132 get_pty (int *fd_tty, char **ttydev)
131 { 133 {
132 int pfd; 134 int pfd;
133 char *slave; 135 char *slave;
134 136
135 slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); 137 slave = _getpty (&pfd, O_RDWR | O_NOCTTY, 0622, 0);
136 138
137 if (slave != NULL) 139 if (slave != NULL)
138 { 140 {
139 *ttydev = strdup (slave); 141 *ttydev = strdup (slave);
140 return pfd; 142 return pfd;
156 const char *majors = "pqrstuvwxyzabcde"; 158 const char *majors = "pqrstuvwxyzabcde";
157 const char *minors = "0123456789abcdef"; 159 const char *minors = "0123456789abcdef";
158 160
159 for (i = 0; i < 256; i++) 161 for (i = 0; i < 256; i++)
160 { 162 {
161 snprintf(pty_name, 32, "/dev/pty%c%c", majors[i / 16], minors[i % 16]); 163 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]); 164 snprintf (tty_name, 32, "/dev/tty%c%c", majors[i / 16], minors[i % 16]);
163 165
164 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1) 166 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
165 { 167 {
166 snprintf(pty_name, 32, "/dev/ptyp%d", i); 168 snprintf (pty_name, 32, "/dev/ptyp%d", i);
167 snprintf(tty_name, 32, "/dev/ttyp%d", i); 169 snprintf (tty_name, 32, "/dev/ttyp%d", i);
168 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1) 170 if ((pfd = open (pty_name, O_RDWR | O_NOCTTY, 0)) == -1)
169 continue; 171 continue;
170 } 172 }
171 173
172 if (access (tty_name, R_OK | W_OK) == 0) 174 if (access (tty_name, R_OK | W_OK) == 0)
328ptytty_unix::get () 330ptytty_unix::get ()
329{ 331{
330 /* get master (pty) */ 332 /* get master (pty) */
331 if ((pty = get_pty (&tty, &name)) < 0) 333 if ((pty = get_pty (&tty, &name)) < 0)
332 return false; 334 return false;
333
334 fcntl (pty, F_SETFL, O_NONBLOCK);
335 335
336 /* get slave (tty) */ 336 /* get slave (tty) */
337 if (tty < 0) 337 if (tty < 0)
338 { 338 {
339#ifndef NO_SETOWNER_TTYDEV 339#ifndef NO_SETOWNER_TTYDEV
376 ioctl (tty, I_PUSH, "ldterm"); 376 ioctl (tty, I_PUSH, "ldterm");
377 ioctl (tty, I_PUSH, "ttcompat"); 377 ioctl (tty, I_PUSH, "ttcompat");
378 } 378 }
379#endif 379#endif
380 380
381#if UTMP_SUPPORT
382# if defined(HAVE_STRUCT_UTMP) && !defined(HAVE_UTMP_PID)
383 int fd_stdin = dup (STDIN_FILENO);
384 dup2 (tty, STDIN_FILENO);
385
386 utmp_pos = ttyslot ();
387
388 dup2 (fd_stdin, STDIN_FILENO);
389 close (fd_stdin);
390# endif
391#endif
392
381 return true; 393 return true;
382} 394}
383 395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines