Lines 24-29
Link Here
|
24 |
#include <string.h> |
24 |
#include <string.h> |
25 |
#include <signal.h> |
25 |
#include <signal.h> |
26 |
#include <sys/types.h> |
26 |
#include <sys/types.h> |
|
|
27 |
#ifdef AUTO_HOTSYNC |
28 |
#include <sys/socket.h> |
29 |
#endif |
27 |
#include <time.h> |
30 |
#include <time.h> |
28 |
#include <ctype.h> |
31 |
#include <ctype.h> |
29 |
#ifndef sunos4 |
32 |
#ifndef sunos4 |
Lines 258-263
Link Here
|
258 |
timeouts++; |
261 |
timeouts++; |
259 |
} |
262 |
} |
260 |
|
263 |
|
|
|
264 |
#ifdef AUTO_HOTSYNC |
265 |
#define BUF_SIZE 8192 |
266 |
#define STDOUT 0 |
267 |
static int child_exited = 0; |
268 |
int mg_dump; |
269 |
|
270 |
static void sig_child(int signal) |
271 |
{ |
272 |
child_exited = 1; |
273 |
} |
274 |
|
275 |
int read_to_ring(int fromh, char *buf, char **tail_ptr, char *head) |
276 |
{ |
277 |
char *tail = *tail_ptr; |
278 |
int ret = 1; |
279 |
|
280 |
if ((tail + 1 - buf) % BUF_SIZE == (head - buf) % BUF_SIZE) { |
281 |
/* buffer full */ |
282 |
ret = 0; |
283 |
} |
284 |
else { |
285 |
if ( tail < head ) { |
286 |
ret = read(fromh, tail, head - tail - 1); |
287 |
} |
288 |
else { |
289 |
if ( head == buf ) { |
290 |
ret = read(fromh, tail, buf + BUF_SIZE - tail - 1); |
291 |
} |
292 |
else { |
293 |
ret = read(fromh, tail, buf + BUF_SIZE - tail); |
294 |
if ( ret == buf + BUF_SIZE - tail ) { |
295 |
/* read more */ |
296 |
struct timeval tv; |
297 |
fd_set fds; |
298 |
int got; |
299 |
|
300 |
FD_ZERO(&fds); |
301 |
FD_SET(fromh, &fds); |
302 |
tv.tv_sec = 0; |
303 |
tv.tv_usec = 0; |
304 |
got = select(fromh + 1, &fds, NULL, NULL, &tv); |
305 |
if ( got < 0 ) { |
306 |
lprintf(L_FATAL, "read_to_ring: select error %d, %s", |
307 |
errno, strerror(errno)); |
308 |
exit(errno); |
309 |
} |
310 |
else if (got > 0) { |
311 |
got = read(fromh, buf, head - buf - 1); |
312 |
if ( got < 0 ) { |
313 |
ret = got; |
314 |
} |
315 |
else { |
316 |
FD_ZERO(&fds); |
317 |
FD_SET(fromh, &fds); |
318 |
tv.tv_sec = 0; |
319 |
tv.tv_usec = 0; |
320 |
if ( got == head - buf -1 && |
321 |
select(fromh + 1, &fds, NULL, NULL, |
322 |
&tv) > 0) { |
323 |
|
324 |
lprintf(L_WARN, "read_to_ring: " |
325 |
"buffer full reise BUF_SIZE " |
326 |
"& recompile mgetty"); |
327 |
} |
328 |
ret += got; |
329 |
} |
330 |
} |
331 |
} |
332 |
} |
333 |
} |
334 |
if (ret < 0 ) { |
335 |
ret = -errno; |
336 |
} |
337 |
else { |
338 |
tail = buf + (tail - buf + ret) % BUF_SIZE; |
339 |
} |
340 |
} |
341 |
|
342 |
*tail_ptr = tail; |
343 |
|
344 |
return ret; |
345 |
} |
346 |
|
347 |
int write_from_ring(int tofh, char *buf, char *tail, char **head_ptr) |
348 |
{ |
349 |
char *head = *head_ptr; |
350 |
int ret = 1; |
351 |
|
352 |
if ( head == tail ) { |
353 |
/* buffer empty */ |
354 |
ret = 0; |
355 |
} |
356 |
else { |
357 |
if ( tail > head ) { |
358 |
ret = write(tofh, head, tail - head); |
359 |
} |
360 |
else { |
361 |
ret = write(tofh, head, buf + BUF_SIZE - head); |
362 |
if ( ret == buf + BUF_SIZE - head ) { |
363 |
/* write more? */ |
364 |
struct timeval tv; |
365 |
fd_set fds; |
366 |
int got; |
367 |
|
368 |
FD_ZERO(&fds); |
369 |
FD_SET(tofh, &fds); |
370 |
tv.tv_sec = 0; |
371 |
tv.tv_usec = 0; |
372 |
got = select(tofh + 1, NULL, &fds, NULL, &tv); |
373 |
if ( got < 0 ) { |
374 |
lprintf(L_FATAL, "write_from_ring: select error %d, %s", |
375 |
errno, strerror(errno)); |
376 |
exit(errno); |
377 |
} |
378 |
else if ( got > 0 ) { |
379 |
got = write(tofh, buf, tail - head); |
380 |
if ( got < 0 ) { |
381 |
ret = got; |
382 |
} |
383 |
else { |
384 |
ret += got; |
385 |
} |
386 |
} |
387 |
} |
388 |
} |
389 |
if ( ret < 0 ) { |
390 |
ret = -errno; |
391 |
} |
392 |
else { |
393 |
head = buf + (head + ret - buf) % BUF_SIZE; |
394 |
} |
395 |
} |
396 |
|
397 |
*head_ptr = head; |
398 |
return ret; |
399 |
} |
400 |
#endif |
401 |
|
261 |
/* getlogname() |
402 |
/* getlogname() |
262 |
* |
403 |
* |
263 |
* read the login name into "char buf[]", maximum length "maxsize". |
404 |
* read the login name into "char buf[]", maximum length "maxsize". |
Lines 282-287
Link Here
|
282 |
static int ppp_level = 0, ppp_escaped = 0; |
423 |
static int ppp_level = 0, ppp_escaped = 0; |
283 |
char ppp_ch; |
424 |
char ppp_ch; |
284 |
#endif |
425 |
#endif |
|
|
426 |
#ifdef AUTO_HOTSYNC |
427 |
int pipefd[2]; |
428 |
int pid; |
429 |
int sel; |
430 |
struct timeval tv; |
431 |
fd_set fds, pipefds; |
432 |
char pipebuf[BUF_SIZE] = {HOTSYNC}; |
433 |
char devbuf[BUF_SIZE]; |
434 |
char *pipe_tail = pipebuf + 1; |
435 |
char *pipe_head = pipebuf; |
436 |
char *dev_tail = devbuf; |
437 |
char *dev_head = devbuf; |
438 |
int devr = 0, devw = 0, piper = 0, pipew = 0; |
439 |
#endif |
285 |
|
440 |
|
286 |
/* read character by character! */ |
441 |
/* read character by character! */ |
287 |
tio_save = *tio; |
442 |
tio_save = *tio; |
Lines 315-321
Link Here
|
315 |
newlogin_noemsi: |
470 |
newlogin_noemsi: |
316 |
#endif |
471 |
#endif |
317 |
|
472 |
|
318 |
printf( "\r\n%s", final_prompt ); |
473 |
if (*final_prompt) |
|
|
474 |
printf( "%s", final_prompt ); |
319 |
|
475 |
|
320 |
if ( ferror( stdin ) ) |
476 |
if ( ferror( stdin ) ) |
321 |
{ |
477 |
{ |
Lines 427-432
Link Here
|
427 |
ppp_escaped = 0; |
583 |
ppp_escaped = 0; |
428 |
} |
584 |
} |
429 |
#endif |
585 |
#endif |
|
|
586 |
#ifdef AUTO_HOTSYNC |
587 |
if (ch == (char) HOTSYNC) { |
588 |
strcpy(buf, "/HotSync/"); |
589 |
i = 9; /* Length of magic word /HotSync/ */ |
590 |
ch = '\n'; |
591 |
|
592 |
if (socketpair(PF_UNIX, SOCK_STREAM, 0, pipefd) < 0 ) { |
593 |
lprintf(L_FATAL, "getlogname: pipe error %d, %s", |
594 |
errno, strerror(errno)); |
595 |
return -1; |
596 |
} |
597 |
|
598 |
signal(SIGCHLD, sig_child); |
599 |
|
600 |
pid = fork(); |
601 |
|
602 |
if ( pid < 0 ) { |
603 |
lprintf( L_FATAL, "getlogname: unable to fork %d, %s", |
604 |
errno, strerror(errno)); |
605 |
return -1; |
606 |
} |
607 |
else if (pid > 0) { |
608 |
/* parent */ |
609 |
do { |
610 |
tv.tv_usec = 0; |
611 |
tv.tv_sec = 10; |
612 |
FD_ZERO(&fds); |
613 |
FD_ZERO(&pipefds); |
614 |
|
615 |
FD_SET(pipefd[1], &pipefds); |
616 |
FD_SET(STDOUT, &pipefds); |
617 |
|
618 |
FD_SET(STDIN, &fds); |
619 |
FD_SET(pipefd[1], &fds); |
620 |
sel = select(pipefd[1] + 1, &fds, &pipefds, NULL, &tv); |
621 |
if ( sel > 0 ) { |
622 |
|
623 |
/* Checking read descriptors in fds */ |
624 |
if ( FD_ISSET(STDIN, &fds) ) { |
625 |
sel = read_to_ring(STDIN, pipebuf, &pipe_tail, pipe_head); |
626 |
devr += sel; |
627 |
if ( sel == 0 ) { |
628 |
lprintf(L_WARN, "getlogname: no space in pipebuf"); |
629 |
} |
630 |
else if ( sel < 0 ) { |
631 |
lprintf(L_FATAL, |
632 |
"getlogname: stdin read error %d, %s", |
633 |
-sel, strerror(-sel)); |
634 |
exit(-sel); |
635 |
} |
636 |
} |
637 |
if ( FD_ISSET(pipefd[1], &fds) ) { |
638 |
sel = read_to_ring(pipefd[1], devbuf, &dev_tail, dev_head); |
639 |
piper += sel; |
640 |
if ( sel == 0 ) { |
641 |
lprintf(L_WARN, "getlogname: no space in devbuf"); |
642 |
} |
643 |
else if ( sel < 0 ) { |
644 |
lprintf(L_FATAL, |
645 |
"getlogname: pipe read error %d, %s", |
646 |
-sel, strerror(-sel)); |
647 |
exit(-sel); |
648 |
} |
649 |
} |
650 |
|
651 |
/* Checking write descriptors in pipefds */ |
652 |
if ( FD_ISSET(pipefd[1], &pipefds) ) { |
653 |
sel = write_from_ring(pipefd[1], pipebuf, pipe_tail, &pipe_head); |
654 |
pipew += sel; |
655 |
if ( sel == 0 ) { |
656 |
lprintf(L_NOISE, "getlogname: pipe buffer empty"); |
657 |
} |
658 |
else if ( sel < 0 ) { |
659 |
lprintf(L_FATAL, |
660 |
"getlogname: pipe write error %d, %s", |
661 |
-sel, strerror(-sel)); |
662 |
exit(-sel); |
663 |
} |
664 |
} |
665 |
if ( FD_ISSET(STDOUT, &pipefds) ) { |
666 |
sel = write_from_ring(STDOUT, devbuf, dev_tail, &dev_head); |
667 |
devw += sel; |
668 |
if ( sel == 0 ) { |
669 |
lprintf(L_NOISE, "getlogname: stdout buffer empty"); |
670 |
} |
671 |
else if ( sel < 0 ) { |
672 |
lprintf(L_FATAL, |
673 |
"getlogname: stdout write error %d, %s", |
674 |
-sel, strerror(-sel)); |
675 |
exit(-sel); |
676 |
} |
677 |
} |
678 |
} |
679 |
else if ( sel < 0 ) { |
680 |
lprintf(L_FATAL, "getlogname: select error %d, %s", |
681 |
errno, strerror(errno)); |
682 |
exit(errno); |
683 |
} |
684 |
else { |
685 |
lprintf(L_WARN, "getlogname: select timeout"); |
686 |
} |
687 |
} while ( !child_exited ); |
688 |
|
689 |
lprintf(L_AUDIT, "getlogname: child exited, device r/w: %d/%d, pipe r/w: %d/%d", |
690 |
devr, devw, piper, pipew); |
691 |
|
692 |
exit(0); |
693 |
} |
694 |
|
695 |
/* child (pid == 0) */ |
696 |
dup2(pipefd[0], STDIN); |
697 |
return 0; |
698 |
} |
699 |
#endif |
430 |
|
700 |
|
431 |
#ifdef JANUS |
701 |
#ifdef JANUS |
432 |
/* ignore ^X as first character, some JANUS programs send it first |
702 |
/* ignore ^X as first character, some JANUS programs send it first |