chiark / gitweb /
Add libutil as disabled package
authorFredrik Fornwall <fredrik@fornwall.net>
Sat, 12 Sep 2015 21:36:00 +0000 (17:36 -0400)
committerFredrik Fornwall <fredrik@fornwall.net>
Sat, 12 Sep 2015 21:36:00 +0000 (17:36 -0400)
disabled-packages/libutil/build.sh [new file with mode: 0644]
disabled-packages/libutil/pty.c [new file with mode: 0644]
disabled-packages/libutil/pty.h [new file with mode: 0644]

diff --git a/disabled-packages/libutil/build.sh b/disabled-packages/libutil/build.sh
new file mode 100644 (file)
index 0000000..5640a57
--- /dev/null
@@ -0,0 +1,11 @@
+TERMUX_PKG_HOMEPAGE=https://refspecs.linuxbase.org/LSB_2.1.0/LSB-generic/LSB-generic/libutil.html
+TERMUX_PKG_DESCRIPTION="Library with terminal functions"
+TERMUX_PKG_VERSION=0.1
+TERMUX_PKG_BUILD_IN_SRC=yes
+
+termux_step_make_install () {
+       CFLAGS+=" -std=c11"
+       $CC $CFLAGS -c -fPIC $TERMUX_PKG_BUILDER_DIR/pty.c -o pty.o
+       $CC -shared -fPIC $LDFLAGS -o $TERMUX_PREFIX/lib/libutil.so pty.o
+       cp $TERMUX_PKG_BUILDER_DIR/pty.h $TERMUX_PREFIX/include/
+}
diff --git a/disabled-packages/libutil/pty.c b/disabled-packages/libutil/pty.c
new file mode 100644 (file)
index 0000000..a2b8958
--- /dev/null
@@ -0,0 +1,68 @@
+#include <fcntl.h>
+#include <sys/ioctl.h>
+#include <sys/param.h>
+#include <sys/types.h>
+#include <stdlib.h>
+#include <termios.h>
+#include <unistd.h>
+
+
+int openpty(int* amaster, int* aslave, char* name, struct termios* termp, struct winsize* winp)
+{
+       char buf[512];
+
+       int master = open("/dev/ptmx", O_RDWR);
+       if (master == -1) return -1;
+       if (grantpt(master) || unlockpt(master) || ptsname_r(master, buf, sizeof buf)) goto fail;
+
+       int slave = open(buf, O_RDWR | O_NOCTTY);
+       if (slave == -1) goto fail;
+
+       /* XXX Should we ignore errors here?  */
+       if (termp) tcsetattr(slave, TCSAFLUSH, termp);
+       if (winp) ioctl(slave, TIOCSWINSZ, winp);
+
+       *amaster = master;
+       *aslave = slave;
+       if (name != NULL) strcpy(name, buf);
+       return 0;
+
+fail:
+       close(master);
+       return -1;
+}
+
+
+int login_tty(int fd)
+{
+       setsid();
+       if (ioctl(fd, TIOCSCTTY, NULL) == -1) return -1;
+       dup2(fd, 0);
+       dup2(fd, 1);
+       dup2(fd, 2);
+       if (fd > 2) close(fd);
+       return 0;
+}
+
+
+int forkpty(int* amaster, char* name, struct termios* termp, struct winsize* winp)
+{
+       int master, slave;
+       if (openpty(&master, &slave, name, termp, winp) == -1) {
+               return -1;
+       }
+
+       int pid;
+       switch (pid = fork()) {
+               case -1:
+                       return -1;
+               case 0:
+                       close(master);
+                       if (login_tty(slave)) _exit(1);
+                       return 0;
+               default:
+                       *amaster = master;
+                       close (slave);
+                       return pid;
+       }
+}
diff --git a/disabled-packages/libutil/pty.h b/disabled-packages/libutil/pty.h
new file mode 100644 (file)
index 0000000..899e17d
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef _PTY_H
+#define _PTY_H
+
+#include <termios.h>
+
+int openpty(int* amaster, int* aslave, char* name, struct termios* termp, struct winsize* winp);
+
+int login_tty(int fd);
+
+int forkpty(int* amaster, char* name, struct termios* termp, struct winsize* winp);
+
+#endif