14 |
|
#include "paths.h" |
15 |
|
#include <signal.h> |
16 |
|
#include <sys/types.h> |
17 |
+ |
#ifdef INCL_SEL_H |
18 |
+ |
#include <sys/select.h> |
19 |
+ |
#endif |
20 |
|
#include <sys/stat.h> |
21 |
|
/* select call compatibility stuff */ |
22 |
|
#ifndef FD_SETSIZE |
143 |
|
n = strlen(buf); |
144 |
|
if (write(persistfd, buf, n) < n) |
145 |
|
error(SYSTEM, "error writing persist file"); |
146 |
+ |
lseek(persistfd, 0L, 0); |
147 |
|
/* wait TIMELIM for someone to signal us */ |
148 |
|
got_io = 0; |
149 |
|
signal(SIGIO, sig_io); |
152 |
|
pflock(0); /* unlock persist file for attach */ |
153 |
|
while (!got_io) |
154 |
|
pause(); /* wait for attach */ |
151 |
– |
pflock(1); /* grab persist file right back! */ |
155 |
|
alarm(0); /* turn off alarm */ |
156 |
|
signal(SIGALRM, oldalrm); |
157 |
|
signal(SIGIO, SIG_DFL); |
158 |
< |
if (lseek(persistfd, 0L, 0) < 0 || ftruncate(persistfd, 0L) < 0) |
156 |
< |
error(SYSTEM, "seek/truncate error on persist file"); |
158 |
> |
pflock(1); /* grab persist file back */ |
159 |
|
/* someone wants us; reopen stdin and stdout */ |
160 |
|
if (freopen(inpname, "r", stdin) == NULL) |
161 |
|
goto openerr; |
188 |
|
int fdin, fdout, fderr = -1; |
189 |
|
fd_set readfds, writefds, excepfds; |
190 |
|
/* load persist file */ |
191 |
+ |
n = 40; |
192 |
|
while ((nr = read(persistfd, buf, sizeof(buf)-1)) == 0) { |
193 |
+ |
if (!n--) |
194 |
+ |
error(USER, "unattended persist file?"); |
195 |
|
pflock(0); |
196 |
|
sleep(15); /* wait until ready */ |
197 |
|
pflock(1); |
198 |
|
} |
194 |
– |
pfdetach(); /* close persist file */ |
199 |
|
if (nr < 0) |
200 |
|
error(SYSTEM, "error reading persist file"); |
201 |
< |
buf[nr] = '\0'; |
201 |
> |
ftruncate(persistfd, 0L); /* truncate persist file */ |
202 |
> |
pfdetach(); /* close & release persist file */ |
203 |
> |
buf[nr] = '\0'; /* parse what we got */ |
204 |
|
if ((cp = index(buf, ' ')) == NULL) |
205 |
|
goto formerr; |
206 |
|
*cp++ = '\0'; |
268 |
|
goto readerr; |
269 |
|
if (nr == 0) { |
270 |
|
close(fderr); |
271 |
< |
close(2); |
271 |
> |
/* close(2); don't close stderr! */ |
272 |
|
fderr = -1; |
273 |
|
} else |
274 |
|
do { /* write it all */ |