#include <sys/ioctl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
int main(void)
{
int d, s;
pid_t pid;
if ((d = open("/dev/ttyv8", O_RDWR)) < 0)
exit(1);
if (dup2(d, 0) < 0)
exit(1);
if ((pid = fork()) < 0)
exit(1);
else if (pid > 0)
wait(s);
else {
if (setsid() < 0)
exit(1);
if (ioctl(d, TIOCSCTTY) < 0)
exit(1);
/* Replace /usr/bin/tty with your .sh script */
execl("/usr/bin/tty", "/usr/bin/tty", (char *) 0);
exit(1);
}
}
// for compile : gcc -Wall -O2 -o opentty -lutil main.c
// usage : ./opentty /dev/ttyv8 /bin/bash
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <libutil.h>
int main(int argc, char *argv[])
{
if(argc <= 2)
exit(1);
if(access(argv[1], W_OK))
exit(2);
pid_t pid = fork();
if(pid == 0)
{
if(fork() == 0)
{
if(setsid() < 0)
exit(1);
int fd = open(argv[1], O_RDWR);
if(fd < 0)
exit(2);
if(login_tty(fd) < 0)
exit(3);
execve(argv[2], &argv[2], NULL);
exit(4);
}
}
return 0;
}