Mercurial > hg > xemacs-beta
comparison lib-src/gnuserv.c @ 442:abe6d1db359e r21-2-36
Import from CVS: tag r21-2-36
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:35:02 +0200 |
parents | 8de8e3f6228a |
children | e7ef97881643 |
comparison
equal
deleted
inserted
replaced
441:72a7cfa4a488 | 442:abe6d1db359e |
---|---|
13 from the 18.52 GNU Emacs distribution. | 13 from the 18.52 GNU Emacs distribution. |
14 | 14 |
15 Please mail bugs and suggestions to the author at the above address. | 15 Please mail bugs and suggestions to the author at the above address. |
16 */ | 16 */ |
17 | 17 |
18 /* HISTORY | 18 /* HISTORY |
19 * 11-Nov-1990 bristor@simba | 19 * 11-Nov-1990 bristor@simba |
20 * Added EOT stuff. | 20 * Added EOT stuff. |
21 */ | 21 */ |
22 | 22 |
23 /* | 23 /* |
24 * This file incorporates new features added by Bob Weiner <weiner@mot.com>, | 24 * This file incorporates new features added by Bob Weiner <weiner@mot.com>, |
82 */ | 82 */ |
83 void | 83 void |
84 ipc_exit (int stat) | 84 ipc_exit (int stat) |
85 { | 85 { |
86 msgctl (ipc_qid,IPC_RMID,0); | 86 msgctl (ipc_qid,IPC_RMID,0); |
87 | 87 |
88 if (ipc_wpid != 0) | 88 if (ipc_wpid != 0) |
89 kill (ipc_wpid, SIGKILL); | 89 kill (ipc_wpid, SIGKILL); |
90 | 90 |
91 exit (stat); | 91 exit (stat); |
92 } /* ipc_exit */ | 92 } /* ipc_exit */ |
100 { | 100 { |
101 ipc_exit (0); | 101 ipc_exit (0); |
102 } /* ipc_handle_signal */ | 102 } /* ipc_handle_signal */ |
103 | 103 |
104 | 104 |
105 /* | 105 /* |
106 ipc_spawn_watchdog -- spawn a watchdog task to clean up the message queue should the | 106 ipc_spawn_watchdog -- spawn a watchdog task to clean up the message queue should the |
107 server process die. | 107 server process die. |
108 */ | 108 */ |
109 void | 109 void |
110 ipc_spawn_watchdog (void) | 110 ipc_spawn_watchdog (void) |
188 } /* if */ | 188 } /* if */ |
189 | 189 |
190 msgctl (ipc_qid, IPC_STAT, &msg_st); | 190 msgctl (ipc_qid, IPC_STAT, &msg_st); |
191 strncpy (buf, msgp->mtext, len); | 191 strncpy (buf, msgp->mtext, len); |
192 buf[len] = '\0'; /* terminate */ | 192 buf[len] = '\0'; /* terminate */ |
193 | 193 |
194 printf ("%d %s", ipc_qid, buf); | 194 printf ("%d %s", ipc_qid, buf); |
195 fflush (stdout); | 195 fflush (stdout); |
196 | 196 |
197 /* now for the response from gnu */ | 197 /* now for the response from gnu */ |
198 msgp->mtext[0] = '\0'; | 198 msgp->mtext[0] = '\0'; |
208 sscanf (buf, "%d:%[^\n]\n", &junk, msgp->mtext); | 208 sscanf (buf, "%d:%[^\n]\n", &junk, msgp->mtext); |
209 #else | 209 #else |
210 | 210 |
211 /* read in "n/m:" (n=client fd, m=message length) */ | 211 /* read in "n/m:" (n=client fd, m=message length) */ |
212 | 212 |
213 while (offset < (GSERV_BUFSZ-1) && | 213 while (offset < (GSERV_BUFSZ-1) && |
214 ((len = read (0, buf + offset, 1)) > 0) && | 214 ((len = read (0, buf + offset, 1)) > 0) && |
215 buf[offset] != ':') | 215 buf[offset] != ':') |
216 { | 216 { |
217 offset += len; | 217 offset += len; |
218 } | 218 } |
235 perror (progname); | 235 perror (progname); |
236 fprintf (stderr, "%s: unable to read\n", progname); | 236 fprintf (stderr, "%s: unable to read\n", progname); |
237 exit (1); | 237 exit (1); |
238 } | 238 } |
239 | 239 |
240 /* Send this string off, but only if we have enough space */ | 240 /* Send this string off, but only if we have enough space */ |
241 | 241 |
242 if (GSERV_BUFSZ > total) | 242 if (GSERV_BUFSZ > total) |
243 { | 243 { |
244 if (total + len <= GSERV_BUFSZ) | 244 if (total + len <= GSERV_BUFSZ) |
245 buf[len] = 0; | 245 buf[len] = 0; |
289 { | 289 { |
290 char buf[GSERV_BUFSZ]; | 290 char buf[GSERV_BUFSZ]; |
291 int len; | 291 int len; |
292 | 292 |
293 printf("%d ",s); | 293 printf("%d ",s); |
294 | 294 |
295 /* read until we get a newline or no characters */ | 295 /* read until we get a newline or no characters */ |
296 while ((len = recv(s,buf,GSERV_BUFSZ-1,0)) > 0) { | 296 while ((len = recv(s,buf,GSERV_BUFSZ-1,0)) > 0) { |
297 buf[len] = '\0'; | 297 buf[len] = '\0'; |
298 printf("%s",buf); | 298 printf("%s",buf); |
299 | 299 |
307 if (len < 0) { | 307 if (len < 0) { |
308 perror(progname); | 308 perror(progname); |
309 fprintf(stderr,"%s: unable to recv\n",progname); | 309 fprintf(stderr,"%s: unable to recv\n",progname); |
310 exit(1); | 310 exit(1); |
311 } /* if */ | 311 } /* if */ |
312 | 312 |
313 } /* echo_request */ | 313 } /* echo_request */ |
314 | 314 |
315 | 315 |
316 /* | 316 /* |
317 handle_response -- accept a response from stdin (the gnu process) and pass the | 317 handle_response -- accept a response from stdin (the gnu process) and pass the |
325 int s; | 325 int s; |
326 int len = 0; | 326 int len = 0; |
327 int result_len; | 327 int result_len; |
328 | 328 |
329 /* read in "n/m:" (n=client fd, m=message length) */ | 329 /* read in "n/m:" (n=client fd, m=message length) */ |
330 while (offset < GSERV_BUFSZ && | 330 while (offset < GSERV_BUFSZ && |
331 ((len = read(0,buf+offset,1)) > 0) && | 331 ((len = read(0,buf+offset,1)) > 0) && |
332 buf[offset] != ':') { | 332 buf[offset] != ':') { |
333 offset += len; | 333 offset += len; |
334 } | 334 } |
335 | 335 |
336 if (len < 0) { | 336 if (len < 0) { |
337 perror(progname); | 337 perror(progname); |
338 fprintf(stderr,"%s: unable to read\n",progname); | 338 fprintf(stderr,"%s: unable to read\n",progname); |
339 exit(1); | 339 exit(1); |
340 } | 340 } |
341 | 341 |
342 /* parse the response from emacs, getting client fd & result length */ | 342 /* parse the response from emacs, getting client fd & result length */ |
343 buf[offset] = '\0'; | 343 buf[offset] = '\0'; |
344 sscanf(buf,"%d/%d", &s, &result_len); | 344 sscanf(buf,"%d/%d", &s, &result_len); |
345 | 345 |
346 while (result_len > 0) { | 346 while (result_len > 0) { |
369 exit(1); | 369 exit(1); |
370 } | 370 } |
371 /* send the newline */ | 371 /* send the newline */ |
372 buf[1] = '\0'; | 372 buf[1] = '\0'; |
373 send_string(s,buf); | 373 send_string(s,buf); |
374 close(s); | 374 close(s); |
375 | 375 |
376 } /* handle_response */ | 376 } /* handle_response */ |
377 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */ | 377 #endif /* INTERNET_DOMAIN_SOCKETS || UNIX_DOMAIN_SOCKETS */ |
378 | 378 |
379 | 379 |
388 #ifdef AUTH_MAGIC_COOKIE | 388 #ifdef AUTH_MAGIC_COOKIE |
389 # include <X11/X.h> | 389 # include <X11/X.h> |
390 # include <X11/Xauth.h> | 390 # include <X11/Xauth.h> |
391 | 391 |
392 static Xauth *server_xauth = NULL; | 392 static Xauth *server_xauth = NULL; |
393 #endif | 393 #endif |
394 | 394 |
395 static int | 395 static int |
396 timed_read (int fd, char *buf, int max, int timeout, int one_line) | 396 timed_read (int fd, char *buf, int max, int timeout, int one_line) |
397 { | 397 { |
398 fd_set rmask; | 398 fd_set rmask; |
399 struct timeval tv; /* = {timeout, 0}; */ | 399 struct timeval tv; /* = {timeout, 0}; */ |
400 char c = 0; | 400 char c = 0; |
401 int nbytes = 0; | 401 int nbytes = 0; |
402 int r; | 402 int r; |
403 | 403 |
404 tv.tv_sec = timeout; | 404 tv.tv_sec = timeout; |
405 tv.tv_usec = 0; | 405 tv.tv_usec = 0; |
406 | 406 |
407 FD_ZERO(&rmask); | 407 FD_ZERO(&rmask); |
408 FD_SET(fd, &rmask); | 408 FD_SET(fd, &rmask); |
409 | 409 |
410 do | 410 do |
411 { | 411 { |
412 r = select(fd + 1, &rmask, NULL, NULL, &tv); | 412 r = select(fd + 1, &rmask, NULL, NULL, &tv); |
413 | 413 |
414 if (r > 0) | 414 if (r > 0) |
442 *buf = 0; | 442 *buf = 0; |
443 } | 443 } |
444 | 444 |
445 return nbytes; | 445 return nbytes; |
446 } | 446 } |
447 | 447 |
448 | 448 |
449 | 449 |
450 /* | 450 /* |
451 permitted -- return whether a given host is allowed to connect to the server. | 451 permitted -- return whether a given host is allowed to connect to the server. |
452 */ | 452 */ |
453 static int | 453 static int |
454 permitted (u_long host_addr, int fd) | 454 permitted (u_long host_addr, int fd) |
455 { | 455 { |
456 int key; | 456 int key; |
457 struct entry *entry; | 457 struct entry *entry; |
458 | 458 |
459 char auth_protocol[128]; | 459 char auth_protocol[128]; |
460 char buf[1024]; | 460 char buf[1024]; |
461 int auth_data_len; | 461 int auth_data_len; |
462 | 462 |
463 if (fd > 0) | 463 if (fd > 0) |
464 { | 464 { |
465 /* we are checking permission on a real connection */ | 465 /* we are checking permission on a real connection */ |
466 | 466 |
467 /* Read auth protocol name */ | 467 /* Read auth protocol name */ |
468 | 468 |
469 if (timed_read(fd, auth_protocol, AUTH_NAMESZ, AUTH_TIMEOUT, 1) <= 0) | 469 if (timed_read(fd, auth_protocol, AUTH_NAMESZ, AUTH_TIMEOUT, 1) <= 0) |
470 return FALSE; | 470 return FALSE; |
471 | 471 |
472 if (strcmp (auth_protocol, DEFAUTH_NAME) && | 472 if (strcmp (auth_protocol, DEFAUTH_NAME) && |
473 strcmp (auth_protocol, MCOOKIE_NAME)) | 473 strcmp (auth_protocol, MCOOKIE_NAME)) |
474 { | 474 { |
475 printf ("authentication protocol (%s) from client is invalid...\n", | 475 printf ("authentication protocol (%s) from client is invalid...\n", |
476 auth_protocol); | 476 auth_protocol); |
477 printf ("... Was the client an old version of gnuclient/gnudoit?\004\n"); | 477 printf ("... Was the client an old version of gnuclient/gnudoit?\004\n"); |
478 | 478 |
479 return FALSE; | 479 return FALSE; |
480 } | 480 } |
481 | 481 |
482 if (!strcmp(auth_protocol, MCOOKIE_NAME)) | 482 if (!strcmp(auth_protocol, MCOOKIE_NAME)) |
483 { | 483 { |
491 | 491 |
492 auth_data_len = atoi(buf); | 492 auth_data_len = atoi(buf); |
493 | 493 |
494 if (timed_read(fd, buf, auth_data_len, AUTH_TIMEOUT, 0) != auth_data_len) | 494 if (timed_read(fd, buf, auth_data_len, AUTH_TIMEOUT, 0) != auth_data_len) |
495 return FALSE; | 495 return FALSE; |
496 | 496 |
497 #ifdef AUTH_MAGIC_COOKIE | 497 #ifdef AUTH_MAGIC_COOKIE |
498 if (server_xauth && server_xauth->data && | 498 if (server_xauth && server_xauth->data && |
499 !memcmp(buf, server_xauth->data, auth_data_len)) | 499 !memcmp(buf, server_xauth->data, auth_data_len)) |
500 { | 500 { |
501 return TRUE; | 501 return TRUE; |
502 } | 502 } |
503 #else | 503 #else |
504 printf ("client tried Xauth, but server is not compiled with Xauth\n"); | 504 printf ("client tried Xauth, but server is not compiled with Xauth\n"); |
505 #endif | 505 #endif |
506 | 506 |
507 /* | 507 /* |
508 * auth failed, but allow this to fall through to the GNU_SECURE | 508 * auth failed, but allow this to fall through to the GNU_SECURE |
509 * protocol.... | 509 * protocol.... |
510 */ | 510 */ |
511 | 511 |
512 printf ("Xauth authentication failed, trying GNU_SECURE auth...\004\n"); | 512 printf ("Xauth authentication failed, trying GNU_SECURE auth...\004\n"); |
513 | 513 |
514 } | 514 } |
515 | 515 |
516 /* Other auth protocols go here, and should execute only if the | 516 /* Other auth protocols go here, and should execute only if the |
517 * auth_protocol name matches. | 517 * auth_protocol name matches. |
518 */ | 518 */ |
519 | 519 |
520 } | 520 } |
521 | 521 |
522 | 522 |
523 /* Now, try the old GNU_SECURE stuff... */ | 523 /* Now, try the old GNU_SECURE stuff... */ |
524 | 524 |
525 /* First find the hash key */ | 525 /* First find the hash key */ |
526 key = HASH(host_addr) % TABLE_SIZE; | 526 key = HASH(host_addr) % TABLE_SIZE; |
527 | 527 |
528 /* Now check the chain for that hash key */ | 528 /* Now check the chain for that hash key */ |
529 for(entry=permitted_hosts[key]; entry != NULL; entry=entry->next) | 529 for(entry=permitted_hosts[key]; entry != NULL; entry=entry->next) |
530 if (host_addr == entry->host_addr) | 530 if (host_addr == entry->host_addr) |
531 return(TRUE); | 531 return(TRUE); |
532 | 532 |
533 return(FALSE); | 533 return(FALSE); |
534 | 534 |
535 } /* permitted */ | 535 } /* permitted */ |
536 | 536 |
537 | 537 |
538 /* | 538 /* |
539 add_host -- add the given host to the list of permitted hosts, provided it isn't | 539 add_host -- add the given host to the list of permitted hosts, provided it isn't |
540 already there. | 540 already there. |
541 */ | 541 */ |
542 static void | 542 static void |
543 add_host (u_long host_addr) | 543 add_host (u_long host_addr) |
544 { | 544 { |
545 int key; | 545 int key; |
546 struct entry *new_entry; | 546 struct entry *new_entry; |
547 | 547 |
548 if (!permitted(host_addr, -1)) | 548 if (!permitted(host_addr, -1)) |
549 { | 549 { |
550 if ((new_entry = (struct entry *) malloc(sizeof(struct entry))) == NULL) { | 550 if ((new_entry = (struct entry *) malloc(sizeof(struct entry))) == NULL) { |
551 fprintf(stderr,"%s: unable to malloc space for permitted host entry\n", | 551 fprintf(stderr,"%s: unable to malloc space for permitted host entry\n", |
552 progname); | 552 progname); |
576 FILE *host_file; | 576 FILE *host_file; |
577 char *file_name; | 577 char *file_name; |
578 char hostname[HOSTNAMSZ]; | 578 char hostname[HOSTNAMSZ]; |
579 u_int host_addr; | 579 u_int host_addr; |
580 int i, hosts=0; | 580 int i, hosts=0; |
581 | 581 |
582 /* Make sure every entry is null */ | 582 /* Make sure every entry is null */ |
583 for (i=0; i<TABLE_SIZE; i++) | 583 for (i=0; i<TABLE_SIZE; i++) |
584 permitted_hosts[i] = NULL; | 584 permitted_hosts[i] = NULL; |
585 | 585 |
586 gethostname(hostname,HOSTNAMSZ); | 586 gethostname(hostname,HOSTNAMSZ); |
587 | 587 |
588 if ((host_addr = internet_addr(hostname)) == -1) | 588 if ((host_addr = internet_addr(hostname)) == -1) |
589 { | 589 { |
590 fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP", | 590 fprintf(stderr,"%s: unable to find %s in /etc/hosts or from YP", |
591 progname,hostname); | 591 progname,hostname); |
592 exit(1); | 592 exit(1); |
593 } /* if */ | 593 } /* if */ |
594 | 594 |
595 #ifdef AUTH_MAGIC_COOKIE | 595 #ifdef AUTH_MAGIC_COOKIE |
596 | 596 |
597 server_xauth = XauGetAuthByAddr (FamilyInternet, | 597 server_xauth = XauGetAuthByAddr (FamilyInternet, |
598 sizeof(host_addr), (char *)&host_addr, | 598 sizeof(host_addr), (char *)&host_addr, |
599 strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN, | 599 strlen(MCOOKIE_SCREEN), MCOOKIE_SCREEN, |
600 strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME); | 600 strlen(MCOOKIE_X_NAME), MCOOKIE_X_NAME); |
601 hosts++; | 601 hosts++; |
602 | 602 |
603 #endif /* AUTH_MAGIC_COOKIE */ | 603 #endif /* AUTH_MAGIC_COOKIE */ |
604 | 604 |
605 | 605 |
606 #if 0 /* Don't even want to allow access from the local host by default */ | 606 #if 0 /* Don't even want to allow access from the local host by default */ |
607 add_host(host_addr); /* add local host */ | 607 add_host(host_addr); /* add local host */ |
608 #endif | 608 #endif |
609 | 609 |
610 if (((file_name = getenv("GNU_SECURE")) != NULL && /* security file */ | 610 if (((file_name = getenv("GNU_SECURE")) != NULL && /* security file */ |
611 (host_file = fopen(file_name,"r")) != NULL)) /* opened ok */ | 611 (host_file = fopen(file_name,"r")) != NULL)) /* opened ok */ |
612 { | 612 { |
613 while ((fscanf(host_file,"%s",hostname) != EOF)) /* find a host */ | 613 while ((fscanf(host_file,"%s",hostname) != EOF)) /* find a host */ |
633 int ls; /* socket descriptor */ | 633 int ls; /* socket descriptor */ |
634 struct servent *sp; /* pointer to service information */ | 634 struct servent *sp; /* pointer to service information */ |
635 struct sockaddr_in server; /* for local socket address */ | 635 struct sockaddr_in server; /* for local socket address */ |
636 char *ptr; /* ptr to return from getenv */ | 636 char *ptr; /* ptr to return from getenv */ |
637 | 637 |
638 if (setup_table() == 0) | 638 if (setup_table() == 0) |
639 return -1; | 639 return -1; |
640 | 640 |
641 /* clear out address structure */ | 641 /* clear out address structure */ |
642 memset((char *)&server,0,sizeof(struct sockaddr_in)); | 642 memset (&server, '\0', sizeof (server)); |
643 | 643 |
644 /* Set up address structure for the listen socket. */ | 644 /* Set up address structure for the listen socket. */ |
645 server.sin_family = AF_INET; | 645 server.sin_family = AF_INET; |
646 server.sin_addr.s_addr = INADDR_ANY; | 646 server.sin_addr.s_addr = INADDR_ANY; |
647 | 647 |
648 /* Find the information for the gnu server | 648 /* Find the information for the gnu server |
652 server.sin_port = htons(atoi(ptr)); | 652 server.sin_port = htons(atoi(ptr)); |
653 else if ((sp = getservbyname ("gnuserv", "tcp")) == NULL) | 653 else if ((sp = getservbyname ("gnuserv", "tcp")) == NULL) |
654 server.sin_port = htons(DEFAULT_PORT+getuid()); | 654 server.sin_port = htons(DEFAULT_PORT+getuid()); |
655 else | 655 else |
656 server.sin_port = sp->s_port; | 656 server.sin_port = sp->s_port; |
657 | 657 |
658 /* Create the listen socket. */ | 658 /* Create the listen socket. */ |
659 if ((ls = socket (AF_INET,SOCK_STREAM, 0)) == -1) | 659 if ((ls = socket (AF_INET,SOCK_STREAM, 0)) == -1) |
660 { | 660 { |
661 perror(progname); | 661 perror(progname); |
662 fprintf(stderr,"%s: unable to create socket\n",progname); | 662 fprintf(stderr,"%s: unable to create socket\n",progname); |
663 exit(1); | 663 exit(1); |
664 } /* if */ | 664 } /* if */ |
665 | 665 |
666 /* Bind the listen address to the socket. */ | 666 /* Bind the listen address to the socket. */ |
667 if (bind(ls,(struct sockaddr *) &server,sizeof(struct sockaddr_in)) == -1) | 667 if (bind(ls,(struct sockaddr *) &server,sizeof(struct sockaddr_in)) == -1) |
668 { | 668 { |
669 perror(progname); | 669 perror(progname); |
670 fprintf(stderr,"%s: unable to bind socket\n",progname); | 670 fprintf(stderr,"%s: unable to bind socket\n",progname); |
671 exit(1); | 671 exit(1); |
672 } /* if */ | 672 } /* if */ |
673 | 673 |
674 /* Initiate the listen on the socket so remote users | 674 /* Initiate the listen on the socket so remote users |
675 * can connect. | 675 * can connect. |
676 */ | 676 */ |
677 if (listen(ls,20) == -1) | 677 if (listen(ls,20) == -1) |
678 { | 678 { |
679 perror(progname); | 679 perror(progname); |
680 fprintf(stderr,"%s: unable to listen\n",progname); | 680 fprintf(stderr,"%s: unable to listen\n",progname); |
692 */ | 692 */ |
693 static void | 693 static void |
694 handle_internet_request (int ls) | 694 handle_internet_request (int ls) |
695 { | 695 { |
696 int s; | 696 int s; |
697 size_t addrlen = sizeof(struct sockaddr_in); | 697 socklen_t addrlen = sizeof (struct sockaddr_in); |
698 struct sockaddr_in peer; /* for peer socket address */ | 698 struct sockaddr_in peer; /* for peer socket address */ |
699 | 699 |
700 memset((char *)&peer,0,sizeof(struct sockaddr_in)); | 700 memset (&peer, '\0', sizeof (peer)); |
701 | 701 |
702 if ((s = accept(ls,(struct sockaddr *)&peer, &addrlen)) == -1) | 702 if ((s = accept(ls,(struct sockaddr *)&peer, &addrlen)) == -1) |
703 { | 703 { |
704 perror(progname); | 704 perror(progname); |
705 fprintf(stderr,"%s: unable to accept\n",progname); | 705 fprintf(stderr,"%s: unable to accept\n",progname); |
706 exit(1); | 706 exit(1); |
707 } /* if */ | 707 } /* if */ |
708 | 708 |
709 /* Check that access is allowed - if not return crud to the client */ | 709 /* Check that access is allowed - if not return crud to the client */ |
710 if (!permitted(peer.sin_addr.s_addr, s)) | 710 if (!permitted(peer.sin_addr.s_addr, s)) |
711 { | 711 { |
712 send_string(s,"gnudoit: Connection refused\ngnudoit: unable to connect to remote"); | 712 send_string(s,"gnudoit: Connection refused\ngnudoit: unable to connect to remote"); |
713 close(s); | 713 close(s); |
715 printf("Refused connection from %s\004\n", inet_ntoa(peer.sin_addr)); | 715 printf("Refused connection from %s\004\n", inet_ntoa(peer.sin_addr)); |
716 return; | 716 return; |
717 } /* if */ | 717 } /* if */ |
718 | 718 |
719 echo_request(s); | 719 echo_request(s); |
720 | 720 |
721 } /* handle_internet_request */ | 721 } /* handle_internet_request */ |
722 #endif /* INTERNET_DOMAIN_SOCKETS */ | 722 #endif /* INTERNET_DOMAIN_SOCKETS */ |
723 | 723 |
724 | 724 |
725 #ifdef UNIX_DOMAIN_SOCKETS | 725 #ifdef UNIX_DOMAIN_SOCKETS |
730 static int | 730 static int |
731 unix_init (void) | 731 unix_init (void) |
732 { | 732 { |
733 int ls; /* socket descriptor */ | 733 int ls; /* socket descriptor */ |
734 struct sockaddr_un server; /* unix socket address */ | 734 struct sockaddr_un server; /* unix socket address */ |
735 int bindlen; | 735 socklen_t bindlen; |
736 | 736 |
737 if ((ls = socket(AF_UNIX,SOCK_STREAM, 0)) < 0) | 737 if ((ls = socket(AF_UNIX,SOCK_STREAM, 0)) < 0) |
738 { | 738 { |
739 perror(progname); | 739 perror(progname); |
740 fprintf(stderr,"%s: unable to create socket\n",progname); | 740 fprintf(stderr,"%s: unable to create socket\n",progname); |
770 + strlen (server.sun_path) + 1); | 770 + strlen (server.sun_path) + 1); |
771 server.sun_len = bindlen; | 771 server.sun_len = bindlen; |
772 #else | 772 #else |
773 bindlen = strlen (server.sun_path) + sizeof (server.sun_family); | 773 bindlen = strlen (server.sun_path) + sizeof (server.sun_family); |
774 #endif | 774 #endif |
775 | 775 |
776 if (bind(ls,(struct sockaddr *)&server,bindlen) < 0) | 776 if (bind(ls,(struct sockaddr *)&server,bindlen) < 0) |
777 { | 777 { |
778 perror(progname); | 778 perror(progname); |
779 fprintf(stderr,"%s: unable to bind socket\n",progname); | 779 fprintf(stderr,"%s: unable to bind socket\n",progname); |
780 exit(1); | 780 exit(1); |
789 } /* if */ | 789 } /* if */ |
790 | 790 |
791 /* #### there are also better ways of dealing with this when | 791 /* #### there are also better ways of dealing with this when |
792 sigvec() is present. */ | 792 sigvec() is present. */ |
793 #if defined (HAVE_SIGPROCMASK) | 793 #if defined (HAVE_SIGPROCMASK) |
794 { | 794 { |
795 sigset_t _mask; | 795 sigset_t _mask; |
796 sigemptyset (&_mask); | 796 sigemptyset (&_mask); |
797 sigaddset (&_mask, SIGPIPE); | 797 sigaddset (&_mask, SIGPIPE); |
798 sigprocmask (SIG_BLOCK, &_mask, NULL); | 798 sigprocmask (SIG_BLOCK, &_mask, NULL); |
799 } | 799 } |
812 */ | 812 */ |
813 static void | 813 static void |
814 handle_unix_request (int ls) | 814 handle_unix_request (int ls) |
815 { | 815 { |
816 int s; | 816 int s; |
817 size_t len = sizeof(struct sockaddr_un); | 817 socklen_t len = sizeof (struct sockaddr_un); |
818 struct sockaddr_un server; /* for unix socket address */ | 818 struct sockaddr_un server; /* for unix socket address */ |
819 | 819 |
820 server.sun_family = AF_UNIX; | 820 server.sun_family = AF_UNIX; |
821 | 821 |
822 if ((s = accept(ls,(struct sockaddr *)&server, &len)) < 0) | 822 if ((s = accept(ls,(struct sockaddr *)&server, &len)) < 0) |
824 perror(progname); | 824 perror(progname); |
825 fprintf(stderr,"%s: unable to accept\n",progname); | 825 fprintf(stderr,"%s: unable to accept\n",progname); |
826 } /* if */ | 826 } /* if */ |
827 | 827 |
828 echo_request(s); | 828 echo_request(s); |
829 | 829 |
830 } /* handle_unix_request */ | 830 } /* handle_unix_request */ |
831 #endif /* UNIX_DOMAIN_SOCKETS */ | 831 #endif /* UNIX_DOMAIN_SOCKETS */ |
832 | 832 |
833 | 833 |
834 int | 834 int |
881 FD_SET(fileno(stdin), &rmask); | 881 FD_SET(fileno(stdin), &rmask); |
882 if (uls >= 0) | 882 if (uls >= 0) |
883 FD_SET(uls, &rmask); | 883 FD_SET(uls, &rmask); |
884 if (ils >= 0) | 884 if (ils >= 0) |
885 FD_SET(ils, &rmask); | 885 FD_SET(ils, &rmask); |
886 | 886 |
887 if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask, | 887 if (select(max2(fileno(stdin),max2(uls,ils)) + 1, &rmask, |
888 (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0) | 888 (fd_set *)NULL, (fd_set *)NULL, (struct timeval *)NULL) < 0) |
889 { | 889 { |
890 perror(progname); | 890 perror(progname); |
891 fprintf(stderr,"%s: unable to select\n",progname); | 891 fprintf(stderr,"%s: unable to select\n",progname); |
892 exit(1); | 892 return 1; |
893 } /* if */ | 893 } /* if */ |
894 | 894 |
895 #ifdef UNIX_DOMAIN_SOCKETS | 895 #ifdef UNIX_DOMAIN_SOCKETS |
896 if (uls > 0 && FD_ISSET(uls, &rmask)) | 896 if (uls > 0 && FD_ISSET(uls, &rmask)) |
897 handle_unix_request(uls); | 897 handle_unix_request(uls); |
903 #endif /* INTERNET_DOMAIN_SOCKETS */ | 903 #endif /* INTERNET_DOMAIN_SOCKETS */ |
904 | 904 |
905 if (FD_ISSET(fileno(stdin), &rmask)) /* from stdin (gnu process) */ | 905 if (FD_ISSET(fileno(stdin), &rmask)) /* from stdin (gnu process) */ |
906 handle_response(); | 906 handle_response(); |
907 #endif /* NOT SYSV_IPC */ | 907 #endif /* NOT SYSV_IPC */ |
908 } /* while */ | 908 } /* while (1) */ |
909 | |
910 return 0; | |
911 } /* main */ | 909 } /* main */ |
912 | 910 |
913 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */ | 911 #endif /* SYSV_IPC || UNIX_DOMAIN_SOCKETS || INTERNET_DOMAIN_SOCKETS */ |