From: John Hodge Date: Tue, 30 Jul 2013 03:01:50 +0000 (+0800) Subject: Usermode/libposix - PTY Support (stubbed) X-Git-Tag: rel0.15~304 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=f3c8ff41bf688d23419c958a36de30847b694bc7;p=tpg%2Facess2.git Usermode/libposix - PTY Support (stubbed) --- diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile index ce28c7e4..ca566cdc 100644 --- a/Usermode/Libraries/libposix.so_src/Makefile +++ b/Usermode/Libraries/libposix.so_src/Makefile @@ -11,7 +11,7 @@ LDFLAGS += -soname libposix.so -Map map.txt -lc OBJ = main.o unistd.o dirent.o stat.o utmpx.o termios.o OBJ += pwd.o syslog.o sys_time.o sys_ioctl.o sys_resource.o OBJ += fcntl.o clocks.o sys_wait.o unistd_crypt.o -OBJ += grp.o +OBJ += grp.o pty.o DEPFILES := $(OBJ:%.o=%.d) BIN = libposix.so diff --git a/Usermode/Libraries/libposix.so_src/include_exp/pty.h b/Usermode/Libraries/libposix.so_src/include_exp/pty.h new file mode 100644 index 00000000..03b3d56e --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/include_exp/pty.h @@ -0,0 +1,22 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * pty.h + * - PTY Management + * + * BSD Conforming (Non-POSIX) + */ +#ifndef _LIBPOSIX__PTY_H_ +#define _LIBPOSIX__PTY_H_ + +#include +#include + +extern int openpty(int *amaster, int *aslave, char *name, const struct termios *termp, const struct winsize *winp); +extern pid_t forkpty(int *amaster, char *name, const struct termios *termp, const struct winsize *winp); +// - utmp.h? +extern int login_tty(int fd); + +#endif + diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h index b0b83749..f24011ae 100644 --- a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h +++ b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h @@ -83,6 +83,9 @@ extern int usleep(useconds_t usec); // - crypt.c extern char *crypt(const char *key, const char *salt); +// - pty.c +extern char *ttyname(int fd); +extern int ttyname_r(int fd, char *buf, size_t buflen); // signal.h / sys/types.h extern int kill(pid_t pid, int sig); diff --git a/Usermode/Libraries/libposix.so_src/pty.c b/Usermode/Libraries/libposix.so_src/pty.c new file mode 100644 index 00000000..f8c21683 --- /dev/null +++ b/Usermode/Libraries/libposix.so_src/pty.c @@ -0,0 +1,50 @@ +/* + * Acess2 POSIX Emulation Layer + * - By John Hodge + * + * pty.c + * - PTY Management + * + * BSD Conforming (Non-POSIX) + */ +#include +#include +#include +#include +#include +#include + +// === CODE === +int openpty(int *amaster, int *aslave, char *name, const struct termios *termp, const struct winsize *winp) +{ + errno = ENOTIMPL; + return -1; +} + +pid_t forkpty(int *amaster, char *name, const struct termios *termp, const struct winsize *winp) +{ + int child; + + int ret = openpty(amaster, &child, name, termp, winp); + if(ret) return -1; + + pid_t rv = fork(); + if(rv) return rv; + + login_tty(child); + + // In child + dup2(child, 0); + dup2(child, 1); + dup2(child, 2); + close(child); + + return 0; +} + +// - utmp.h? +int login_tty(int fd) +{ + // nop! + return 0; +} diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c index 545ef164..211948f8 100644 --- a/Usermode/Libraries/libposix.so_src/unistd.c +++ b/Usermode/Libraries/libposix.so_src/unistd.c @@ -252,3 +252,23 @@ char *getpass(const char *prompt) return passbuf; } +char *ttyname(int fd) +{ + static char ttyname_buf[32]; + errno = ttyname_r(fd, ttyname_buf, sizeof(ttyname_buf)); + if(errno) return NULL; + + return ttyname_buf; +} +int ttyname_r(int fd, char *buf, size_t buflen) +{ + int type = _SysIOCtl(fd, DRV_IOCTL_TYPE, NULL); + if( type == -1 ) + return errno; + if( type != DRV_TYPE_TERMINAL ) + return ENOTTY; + + _SysIOCtl(fd, PTY_IOCTL_GETID, NULL); + + return ENOTIMPL; +}