add login_tty function
authorFelix Janda <felix.janda@posteo.de>
Sun, 21 Dec 2014 01:13:27 +0000 (20:13 -0500)
committerRich Felker <dalias@aerifal.cx>
Sun, 21 Dec 2014 01:13:27 +0000 (20:13 -0500)
include/utmp.h
src/misc/login_tty.c [new file with mode: 0644]

index e9ba23e2de059f832e1bf8297dfe4987b3b82aca..24e2da7bf9964407fe1afb283033289843f818bd 100644 (file)
@@ -35,6 +35,8 @@ void         setutent(void);
 
 void updwtmp(const char *, const struct utmp *);
 
+int login_tty(int);
+
 #define _PATH_UTMP "/dev/null/utmp"
 #define _PATH_WTMP "/dev/null/wtmp"
 
diff --git a/src/misc/login_tty.c b/src/misc/login_tty.c
new file mode 100644 (file)
index 0000000..f0be0a0
--- /dev/null
@@ -0,0 +1,14 @@
+#include <utmp.h>
+#include <sys/ioctl.h>
+#include <unistd.h>
+
+int login_tty(int fd)
+{
+       setsid();
+       if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1;
+       dup2(fd, 0);
+       dup2(fd, 1);
+       dup2(fd, 2);
+       if (fd>2) close(fd);
+       return 0;
+}