Cleaned up the repository, getting rid of binary files.
[vsys.git] / vsyssh / vsyssh.c
1 /* gcc -Wall -O2 -g chpid.c -o chpid */
2 #define _XOPEN_SOURCE
3 #define _XOPEN_SOURCE_EXTENDED
4 #define _SVID_SOURCE
5 #define _GNU_SOURCE
6 #include <stdio.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <stdlib.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <sys/syscall.h>
13 #include <sys/wait.h>
14 #include <sys/time.h>
15 #include <sys/resource.h>
16 #include <sys/mount.h>
17 #include <sys/vfs.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <sched.h>
21 #include <stdarg.h>
22 #include <dirent.h>
23
24 int main(int argc, char **argv, char **envp)
25 {
26         if (argc<3) {
27                 printf("Usage: vsyssh <vsys entry> <cmd>\n");
28                 exit(1);
29         }
30         else {
31                 int vfd0,vfd1;
32                 char *inf,*outf;
33                 inf=(char *)malloc(strlen(argv[1])+3);
34                 outf=(char *)malloc(strlen(argv[2])+4);
35                 strcpy(inf,argv[1]);
36                 strcpy(inf,argv[2]);
37                 strcat(inf,".in");
38                 strcat(outf,".out");
39
40                 vfd1 = open(inf,O_WRONLY);
41                 vfd0 = open(outf,O_RDONLY);
42
43                 if (vfd0==-1 || vfd1 == -1) {
44                         printf("Error opening vsys entry %s\n", argv[1]);
45                         exit(1);
46                 }
47
48                 close(0);
49                 close(1);
50
51                 dup2(vfd0,0);
52                 dup2(vfd1,1);
53
54                 execve(argv[3],argv+3,envp);
55        }
56
57        return;
58
59 }