tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Enhance ptyfs to handle multiple instances.



Small test.

#include <util.h>
#include <stdio.h>
#include <termios.h>
#include <err.h>
#include <stdlib.h>

#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>

#include <errno.h>
#include <fcntl.h>
#include <grp.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>


main (){
    int amaster, aslave, master;
    char name[100] = "/dev/ptm";
    struct termios termp;
    struct winsize winp;
    printf("Pty device is : %s \n", name);
//    if ( openpty(&amaster, &aslave, name, &termp, &winp) == -1 )
        if ((master = open(name, O_RDWR)) != -1) {
                struct ptmget pt;
//              if (ioctl(master, TIOCPTSNAME, &pt) != -1) {
                if (ioctl(master, TIOCPTMGET, &pt) != -1) {
                        //(void)close(master);
                        master = pt.cfd;
                        aslave = pt.sfd;
                        (void)strcpy(name, pt.sn);
                        goto gotit;
                }
                err(EXIT_FAILURE, "Can't ioctl() TIOCPTSNAME");
        }
        err(EXIT_FAILURE, "Can't open /dev/ptmx");
gotit:
    printf("Name is : %s \n", name);
    open(name, O_RDWR);
    sleep(60);
}


Home | Main Index | Thread Index | Old Index