1 /* gcc -Wall -O2 -g vsyssh.c -o vsyssh */
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>
20 #include <sys/types.h>
27 void pipe_handler (int sig) {
33 int main(int argc, char **argv, char **envp) {
35 if ( (argc<2) || (strcmp(argv[1],"--help")==0) ) {
36 printf("Usage: vsyssh <vsys entry> [cmd]\n");
43 printf ("%s requires root privileges, please run under sudo\n",argv[0]);
50 char inf[FILELEN], outf[FILELEN];
53 signal(SIGPIPE,pipe_handler);
55 sprintf(inf,"/vsys/%s.in",argv[1]);
56 sprintf(outf,"/vsys/%s.out",argv[1]);
57 vfd0 = open(outf,O_RDONLY|O_NONBLOCK);
59 printf("Error opening vsys channel %s (%m)\n",outf);
62 vfd1 = open(inf,O_WRONLY);
64 printf("Error opening vsys channel %s (%m)\n",inf);
68 if (fcntl(vfd0, F_SETFL, O_RDONLY) == -1) {
69 printf("Error making pipe blocking: %m\n");
73 if (fatal) { exit(1);}
76 /* interactive mode */
78 char do_input = 1, do_output = 1;
82 printf("vsys>");fflush(stdout);
88 ret = select(vfd0+1, &set, NULL, NULL, NULL);
89 if (FD_ISSET(0,&set)) {
92 ret=read(0,lineread,2048);
93 /*printf ("read=%d\n",ret);*/
97 printf ("writing %s\n",lineread);
98 write(vfd1,lineread,ret);
100 if (FD_ISSET(vfd0,&set)) {
103 ret = read(vfd0,lineread,2048);
106 write(1,lineread,ret);
117 execve(argv[2],argv+2,envp);