1 /* gcc -Wall -O2 -g chpid.c -o chpid */
3 #define _XOPEN_SOURCE_EXTENDED
10 #include <sys/types.h>
12 #include <sys/syscall.h>
15 #include <sys/select.h>
16 #include <sys/resource.h>
17 #include <sys/mount.h>
25 int main(int argc, char **argv, char **envp)
28 printf("Usage: vsyssh <vsys entry> [cmd]\n");
36 inf=(char *)malloc(strlen(argv[1])+3);
37 outf=(char *)malloc(strlen(argv[1])+4);
43 vfd0 = open(outf,O_RDONLY|O_NONBLOCK);
44 printf("Out file: %d\n",vfd0);
45 vfd1 = open(inf,O_WRONLY);
46 printf("In file: %d\n",vfd1);
48 if (vfd0==-1 || vfd1 == -1) {
49 printf("Error opening vsys entry %s (%s)\n", argv[1],strerror(errno));
61 printf("vsys>");fflush(stdout);
64 ret = select(vfd0+1, &set, NULL, NULL, NULL);
65 if (FD_ISSET(0,&set)) {
68 ret=read(0,lineread,2048);
69 write(vfd1,lineread,ret);
71 } if (FD_ISSET(vfd0,&set)) {
74 ret=read(vfd0,lineread,2048);
75 write(1,lineread,ret);
87 execve(argv[3],argv+3,envp);