1 /* gcc -Wall -O2 -g chpid.c -o chpid */
3 #define _XOPEN_SOURCE_EXTENDED
11 #include <sys/types.h>
13 #include <sys/syscall.h>
16 #include <sys/select.h>
17 #include <sys/resource.h>
18 #include <sys/mount.h>
26 void pipe_handler (int sig) {
30 int main(int argc, char **argv, char **envp)
33 printf("Usage: vsyssh <vsys entry> [cmd]\n");
41 signal(SIGPIPE,pipe_handler);
42 inf=(char *)malloc(strlen(argv[1])+3);
43 outf=(char *)malloc(strlen(argv[1])+4);
49 vfd0 = open(outf,O_RDONLY|O_NONBLOCK);
50 printf("Out file: %d\n",vfd0);
51 vfd1 = open(inf,O_WRONLY);
52 printf("In file: %d\n",vfd1);
54 if (vfd0==-1 || vfd1 == -1) {
55 printf("Error opening vsys entry %s (%s)\n", argv[1],strerror(errno));
68 printf("vsys>");fflush(stdout);
71 ret = select(vfd0+1, &set, NULL, NULL, NULL);
72 if (FD_ISSET(0,&set)) {
75 ret=read(0,lineread,2048);
77 printf ("writing %s\n",lineread);
78 write(vfd1,lineread,ret);
80 } if (FD_ISSET(vfd0,&set)) {
83 ret=read(vfd0,lineread,2048);
84 write(1,lineread,ret);
96 execve(argv[3],argv+3,envp);