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.29 by ayin, Thu Jun 28 17:41:01 2007 UTC vs.
Revision 1.36 by sf-exg, Fri Jan 8 11:48:53 2010 UTC

23 * You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software 24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 *---------------------------------------------------------------------*/ 26 *---------------------------------------------------------------------*/
27 27
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 <cstring> 33#include <cstring>
34#include <csignal> 34#include <csignal>
35 35
36#include <sys/types.h> 36#include <sys/types.h>
37#include <sys/stat.h>
37#include <unistd.h> 38#include <unistd.h>
38#include <fcntl.h> 39#include <fcntl.h>
39 40
40#ifdef HAVE_SYS_IOCTL_H 41#ifdef HAVE_SYS_IOCTL_H
41# include <sys/ioctl.h> 42# include <sys/ioctl.h>
42#endif 43#endif
43#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H) 44#if defined(HAVE_DEV_PTMX) && defined(HAVE_SYS_STROPTS_H)
44# include <sys/stropts.h> /* for I_PUSH */ 45# include <sys/stropts.h> /* for I_PUSH */
45#endif 46#endif
46#ifdef HAVE_ISASTREAM 47#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
47# include <stropts.h> 48# include <stropts.h>
48#endif 49#endif
49#if defined(HAVE_PTY_H) 50#if defined(HAVE_PTY_H)
50# include <pty.h> 51# include <pty.h>
51#elif defined(HAVE_LIBUTIL_H) 52#elif defined(HAVE_LIBUTIL_H)
86 87
87 if (pfd >= 0) 88 if (pfd >= 0)
88 { 89 {
89 if (grantpt (pfd) == 0 /* change slave permissions */ 90 if (grantpt (pfd) == 0 /* change slave permissions */
90 && unlockpt (pfd) == 0) 91 && unlockpt (pfd) == 0)
92 {
91 { /* slave now unlocked */ 93 /* slave now unlocked */
92 *ttydev = strdup (ptsname (pfd)); /* get slave's name */ 94 *ttydev = strdup (ptsname (pfd)); /* get slave's name */
93 return pfd; 95 return pfd;
94 } 96 }
95 97
96 close (pfd); 98 close (pfd);
122 124
123 static int 125 static int
124 get_pty (int *fd_tty, char **ttydev) 126 get_pty (int *fd_tty, char **ttydev)
125 { 127 {
126 int pfd; 128 int pfd;
129 char *slave;
127 130
128 *ttydev = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0); 131 slave = _getpty (&pfd, O_RDWR | O_NONBLOCK | O_NOCTTY, 0622, 0);
129 132
130 if (*ttydev != NULL) 133 if (slave != NULL)
134 {
135 *ttydev = strdup (slave);
131 return pfd; 136 return pfd;
137 }
132 138
133 return -1; 139 return -1;
134 } 140 }
135 141
136#elif defined(HAVE_DEV_PTC) 142#elif defined(HAVE_DEV_PTC)
242 * documentation is really unclear about whether it is any close () on 248 * documentation is really unclear about whether it is any close () on
243 * the master side or the last close () - i.e. a proper STREAMS dismantling 249 * the master side or the last close () - i.e. a proper STREAMS dismantling
244 * close () - on the master side which causes a hang up to be sent 250 * close () - on the master side which causes a hang up to be sent
245 * through - Geoff Wing 251 * through - Geoff Wing
246 */ 252 */
247# ifdef HAVE_ISASTREAM 253#if defined(HAVE_ISASTREAM) && defined(HAVE_STROPTS_H)
248 if (isastream (fd_tty) == 1) 254 if (isastream (fd_tty) == 1)
249# endif 255# endif
250 { 256 {
251 ioctl (fd_tty, I_PUSH, "ptem"); 257 ioctl (fd_tty, I_PUSH, "ptem");
252 ioctl (fd_tty, I_PUSH, "ldterm"); 258 ioctl (fd_tty, I_PUSH, "ldterm");
322 { 328 {
323#ifdef TTY_GID_SUPPORT 329#ifdef TTY_GID_SUPPORT
324 struct group *gr = getgrnam ("tty"); 330 struct group *gr = getgrnam ("tty");
325 331
326 if (gr) 332 if (gr)
333 {
327 { /* change group ownership of tty to "tty" */ 334 /* change group ownership of tty to "tty" */
328 mode = S_IRUSR | S_IWUSR | S_IWGRP; 335 mode = S_IRUSR | S_IWUSR | S_IWGRP;
329 gid = gr->gr_gid; 336 gid = gr->gr_gid;
330 } 337 }
331 else 338 else
332#endif /* TTY_GID_SUPPORT */ 339#endif /* TTY_GID_SUPPORT */
333 { 340 {
334 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH; 341 mode = S_IRUSR | S_IWUSR | S_IWGRP | S_IWOTH;
335 gid = 0; 342 gid = 0;
336 } 343 }
337 } 344 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines