Annotation of embedaddon/tmux/pty.c, revision 1.1.1.1

1.1       misho       1: /* $OpenBSD$ */
                      2: 
                      3: /*
                      4:  * Copyright (c) 2017 Nicholas Marriott <nicholas.marriott@gmail.com>
                      5:  *
                      6:  * Permission to use, copy, modify, and distribute this software for any
                      7:  * purpose with or without fee is hereby granted, provided that the above
                      8:  * copyright notice and this permission notice appear in all copies.
                      9:  *
                     10:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     11:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     12:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     13:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     14:  * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
                     15:  * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
                     16:  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     17:  */
                     18: 
                     19: #include <sys/types.h>
                     20: #include <sys/ioctl.h>
                     21: #include <sys/time.h>
                     22: #ifdef __OpenBSD__
                     23: #include <sys/tty.h>
                     24: #endif
                     25: 
                     26: #include <fcntl.h>
                     27: #include <string.h>
                     28: #include <termios.h>
                     29: #include <unistd.h>
                     30: 
                     31: #include "compat.h"
                     32: 
                     33: int    pty_open(int *);
                     34: pid_t  pty_fork(int, int *, char *, size_t, struct winsize *);
                     35: 
                     36: #ifdef __OpenBSD__
                     37: int
                     38: pty_open(int *fd)
                     39: {
                     40:        *fd = open(PATH_PTMDEV, O_RDWR|O_CLOEXEC);
                     41:        if (*fd < 0)
                     42:            return (-1);
                     43:        return (0);
                     44: }
                     45: #else
                     46: int
                     47: pty_open(__unused int *fd)
                     48: {
                     49:        *fd = -1;
                     50:        return (0);
                     51: }
                     52: #endif
                     53: 
                     54: #ifdef __OpenBSD__
                     55: pid_t
                     56: pty_fork(int ptmfd, int *fd, char *name, size_t namelen, struct winsize *ws)
                     57: {
                     58:        struct ptmget   ptm;
                     59:        pid_t           pid;
                     60: 
                     61:        if (ioctl(ptmfd, PTMGET, &ptm) == -1)
                     62:                return (-1);
                     63: 
                     64:        strlcpy(name, ptm.sn, namelen);
                     65:        ioctl(ptm.sfd, TIOCSWINSZ, ws);
                     66: 
                     67:        switch (pid = fork()) {
                     68:        case -1:
                     69:                close(ptm.cfd);
                     70:                close(ptm.sfd);
                     71:                return (-1);
                     72:        case 0:
                     73:                close(ptm.cfd);
                     74:                login_tty(ptm.sfd);
                     75:                return (0);
                     76:        }
                     77:        *fd = ptm.cfd;
                     78:        close(ptm.sfd);
                     79:        return (pid);
                     80: }
                     81: #else
                     82: pid_t
                     83: pty_fork(__unused int ptmfd, int *fd, char *name, __unused size_t namelen,
                     84:     struct winsize *ws)
                     85: {
                     86:        return (forkpty(fd, name, NULL, ws));
                     87: }
                     88: #endif

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>