-
Notifications
You must be signed in to change notification settings - Fork 0
/
runtexexec4mkiv.c
147 lines (124 loc) · 3.87 KB
/
runtexexec4mkiv.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <stdlib.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/errno.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/wait.h>
int main(int argc, char *argv[]) {
#ifdef SCHNEE
const char *texexec="/opt/context/2004.6.30/bin/texexec";
#else
const char *texmfstart="/opt/context/current/bin/texmfstart";
#endif
int ret;
int fd,len;
char *cptr;
pid_t pid;
char dirname[1024];
char buf[1024];
char *progname;
struct rlimit limit;
int maxfile=10*1024*1024;
limit.rlim_cur=maxfile;
limit.rlim_max=maxfile;
if ( setpriority(PRIO_PROCESS, 0, 10) < 0) {
fprintf (stderr,"%s: setpriority error %s, exiting\n",progname,strerror(errno));
exit (-1);
}
if ( (ret = setrlimit(RLIMIT_FSIZE, &limit)) < 0) {
fprintf (stderr,"%s: setrlimit error %s, exiting\n",progname,strerror(errno));
exit(-1);
}
/* progname=argv[0]; */
#ifdef SCHNEE
ret = 0;
#else
ret = putenv("PATH=/opt/context/current/bin:/opt/texlive2007/bin/i386-linux:/opt/local/bin:/usr/bin:/bin");
/*
I (Mojca) replaced TEXMFCONTEXT because I had problems setting up the proper variable in the proper
texmf.cnf file. I also reshuffled things in PATH, since otherwise texexec from bin took precedence
over th latest texexec.
ret |= putenv("TEXMFCONTEXT=/opt/context/latest/texmf");
*/
// ret |= putenv("TEXMFCNF=/opt/context/current/texmf/web2c") ;
ret |= putenv("TEXMFCNF=/opt/texlive2007/texmf/web2c") ;
ret |= putenv("TEXMFMAIN=/opt/texlive2007/texmf") ;
ret |= putenv("TEXMFDIST=/opt/texlive2007/texmf-dist") ;
ret |= putenv("TEXMFMKIV=/opt/context/current/texmf") ;
ret |= putenv("TEXMFFONTS=/opt/local/texmf-fonts") ;
ret |= putenv("TEXMF='{$TEXMFMKIV,!!$TEXMFFONTS,!!$TEXMFDIST,!!$TEXMFMAIN}'");
ret |= putenv("TEXMFCACHE=/var/tmp/tex") ;
ret |= putenv("TEXFORMATS=/opt/context/current/texmf/web2c") ;
ret |= putenv("MPMEMS=/opt/context/current/texmf/web2c") ;
#endif
if (ret) {
fprintf (stderr,"%s: putenv error %s, exiting\n",progname,strerror(errno));
exit(-1);
}
if (argc != 2) {
fprintf(stderr,"argc=%d, usage: %s <id>\n",argc,progname);
exit (-1);
}
if (strlen(argv[1]) <3) {
fprintf (stderr,"%s: strange id, exiting\n",progname);
exit(-1);
}
cptr=strstr(argv[1],"/");
if (cptr) {
fprintf (stderr,"%s: string has / in it, exiting\n",progname);
exit(-1);
}
strcpy(dirname,"/tmp/texweb/");
strncat(dirname,argv[1],(sizeof(dirname) - strlen(dirname)));
/* strcat(dirname,"/output"); */
/* fprintf(stderr,"directory to use is: %s\n",argv[1]); */
setbuf(stdout, NULL);
ret=chdir(dirname);
if (ret) {
fprintf(stderr,"%s: chdir error: %s\n",progname, strerror(errno));
exit (-1);
}
if (! getcwd(buf,sizeof(buf)) ) {
fprintf(stderr,"%s: getcwd error: %s\n",progname, strerror(errno));
exit(-1);
}
/* fprintf(stderr,"cwd=%s\n",buf); */
if ( (fd=open("output",O_WRONLY|O_CREAT, 0666)) < 0) {
fprintf(stderr,"%s: open error: %s\n",progname, strerror(errno));
exit (-1);
}
if ( (pid = fork()) < 0) {
fprintf(stderr,"%s: fork error: %s\n",progname, strerror(errno));
exit (-1);
} else if (pid==0) {
/* child */
dup2(fd,STDOUT_FILENO);
ret=execl ("/usr/bin/ruby", "ruby", texmfstart, "texexec", "--lua", "texweb.tex",NULL);
if (ret) {
fprintf(stderr,"%s: execl error: %s\n",progname, strerror(errno));
exit (-1);
}
}
if (wait(&ret) <0) {
perror("wait");
exit (-1);
}
close(fd);
if ( (fd=open("result",O_WRONLY|O_CREAT, 0666)) < 0) {
fprintf(stderr,"%s: open error: %s\n",progname, strerror(errno));
exit (-1);
}
sprintf(buf,"%d\n",WEXITSTATUS(ret));
len=write(fd,buf,sizeof(buf));
if (len==-1) {
perror("write");
exit(-1);
}
close (fd);
return WEXITSTATUS(ret);
}