Blob


1 #include "9term.h"
3 int
4 getchildwd(int pid, char *wdir, int bufn)
5 {
6 char path[256];
7 char cwd[256];
9 if(getcwd(cwd, sizeof cwd) < 0)
10 return -1;
11 snprint(path, sizeof path, "/proc/%d/cwd", pid);
12 if(chdir(path) < 0)
13 return -1;
14 if(getcwd(wdir, bufn) < 0)
15 return -1;
16 chdir(cwd);
17 return 0;
18 }
20 int
21 getpts(int fd[], char *slave)
22 {
23 fd[1] = open("/dev/ptmx", ORDWR);
24 if ((grantpt(fd[1]) < 0) || (unlockpt(fd[1]) < 0))
25 return -1;
26 fchmod(fd[1], 0622);
27 strcpy(slave, ptsname(fd[1]));
28 fd[0] = open(slave, OREAD);
29 return 0;
30 }