-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpty.c
executable file
·63 lines (58 loc) · 1.29 KB
/
pty.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
** pty.c for in /home/locque_d//rendu/proj/my_script
**
** Made by damien locque
** Login <[email protected]>
**
** Started on Thu Feb 24 19:25:24 2011 damien locque
** Last update Sun Feb 27 14:25:16 2011 damien locque
*/
#include <stdlib.h>
#include <unistd.h>
#include <pty.h>
#include <stdio.h>
#include <utmp.h>
#include <sys/time.h>
#include <sys/wait.h>
#include <sys/types.h>
#include "my_script.h"
void father_pty(t_fd *fd, pid_t pid)
{
int rc;
fd_set set;
int status;
char buffer[BUFF_SIZE];
xclose(fd->fds);
FD_ZERO(&set);
while (waitpid(pid, &status, WNOHANG) != pid)
{
FD_SET(0, &set);
FD_SET(fd->fdm, &set);
xselect((fd->fdm + 1), &set, NULL, NULL, NULL);
if ((FD_ISSET(0, &set)
&& (rc = read(0, buffer, BUFF_SIZE)) > 0))
xwrite(fd->fdm, buffer, rc);
if (FD_ISSET(fd->fdm, &set) &&
((rc = read(fd->fdm, buffer, BUFF_SIZE)) > 0))
{
xwrite(1, buffer, rc);
xwrite(fd->filefd, buffer, rc);
}
}
}
int child_pty(t_fd *fd)
{
int ret;
close(fd->fdm);
my_login_tty(fd->fds);
if (getenv("SHELL"))
ret = execl(getenv("SHELL"), getenv("SHELL"), NULL);
else
ret = execl("/bin/tcsh", "tcsh", NULL);
if (ret == -1)
{
fprintf(stderr, "exec fail\n");
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}