|
|
#undef open | #undef open |
#undef close | #undef close |
| |
|
#include <stdlib.h> |
|
#include <string.h> |
| |
#if !defined(BSD) && !defined(HAVE_SYSVIPC) |
#if !defined(HAVE_SOCKETS) && !defined(HAVE_SYSVIPC) |
#include <stdio.h> | #include <stdio.h> |
| |
main () | main () |
|
|
exit (1); | exit (1); |
} | } |
| |
#else /* BSD or HAVE_SYSVIPC */ |
#else /* HAVE_SOCKETS or HAVE_SYSVIPC */ |
| |
#if defined (BSD) && ! defined (HAVE_SYSVIPC) |
#if defined (HAVE_SOCKETS) |
/* BSD code is very different from SYSV IPC code */ | /* BSD code is very different from SYSV IPC code */ |
| |
#include <sys/file.h> | #include <sys/file.h> |
|
|
unlink (server.sun_path); | unlink (server.sun_path); |
#endif | #endif |
| |
if (bind (s, &server, strlen (server.sun_path) + 2) < 0) |
if (bind (s, (struct sockaddr *)&server, strlen (server.sun_path) + 2) < 0) |
{ | { |
perror ("bind"); | perror ("bind"); |
exit (1); | exit (1); |
|
|
signal (SIGPIPE, SIG_IGN); | signal (SIGPIPE, SIG_IGN); |
for (;;) | for (;;) |
{ | { |
int rmask = (1 << s) + 1; |
fd_set rmask; |
|
FD_ZERO (&rmask); |
|
FD_SET (0, &rmask); |
|
FD_SET (s, &rmask); |
if (select (s + 1, &rmask, 0, 0, 0) < 0) | if (select (s + 1, &rmask, 0, 0, 0) < 0) |
perror ("select"); | perror ("select"); |
if (rmask & (1 << s)) /* client sends list of filenames */ |
if (FD_ISSET (s, &rmask)) /* client sends list of filenames */ |
{ | { |
fromlen = sizeof (fromunix); | fromlen = sizeof (fromunix); |
fromunix.sun_family = AF_UNIX; | fromunix.sun_family = AF_UNIX; |
infd = accept (s, &fromunix, &fromlen); /* open socket fd */ |
infd = accept (s, (struct sockaddr *)&fromunix, &fromlen); |
|
/* open socket fd */ |
if (infd < 0) | if (infd < 0) |
{ | { |
if (errno == EMFILE || errno == ENFILE) | if (errno == EMFILE || errno == ENFILE) |
|
|
fflush (infile); | fflush (infile); |
continue; | continue; |
} | } |
else if (rmask & 1) /* emacs sends codeword, fd, and string message */ |
else if (FD_ISSET (0, &rmask)) |
|
/* emacs sends codeword, fd, and string message */ |
{ | { |
/* Read command codeword and fd */ | /* Read command codeword and fd */ |
clearerr (stdin); | clearerr (stdin); |
|
|
| |
#endif /* SYSV IPC */ | #endif /* SYSV IPC */ |
| |
#endif /* BSD && IPC */ |
#endif /* HAVE_SOCKETS && IPC */ |
|
|
|
|