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 vfd1 = open(inf,O_WRONLY);
52 if (vfd0==-1 || vfd1 == -1) {
53 printf("Error opening vsys entry %s (%s)\n", argv[1],strerror(errno));
57 if (fcntl(vfd0, F_SETFL, O_RDONLY) == -1) {
58 printf("Error making pipe blocking: %m\n");
64 char do_input = 1, do_output = 1;
69 printf("vsys>");fflush(stdout);
75 ret = select(vfd0+1, &set, NULL, NULL, NULL);
76 if (FD_ISSET(0,&set)) {
79 ret=read(0,lineread,2048);
83 printf ("writing %s\n",lineread);
84 write(vfd1,lineread,ret);
86 if (FD_ISSET(vfd0,&set)) {
89 ret = read(vfd0,lineread,2048);
92 write(1,lineread,ret);
103 execve(argv[2],argv+2,envp);