ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rxvtd.C
(Generate patch)

Comparing rxvt-unicode/src/rxvtd.C (file contents):
Revision 1.4 by pcg, Tue Nov 25 17:34:47 2003 UTC vs.
Revision 1.5 by pcg, Thu Nov 27 10:12:10 2003 UTC

6#include <cstdlib> 6#include <cstdlib>
7#include <cstdarg> 7#include <cstdarg>
8#include <cstring> 8#include <cstring>
9 9
10#include <unistd.h> 10#include <unistd.h>
11#include <sys/types.h>
12#include <sys/stat.h>
11#include <sys/socket.h> 13#include <sys/socket.h>
12#include <sys/un.h> 14#include <sys/un.h>
13 15
14#include <cerrno> 16#include <cerrno>
15 17
26 } 28 }
27 29
28 void err (const char *format = 0, ...); 30 void err (const char *format = 0, ...);
29}; 31};
30 32
31struct listener { 33struct unix_listener {
32 int fd; 34 int fd;
33 35
34 void accept_cb (io_watcher &w, short revents); io_watcher accept_ev; 36 void accept_cb (io_watcher &w, short revents); io_watcher accept_ev;
35 37
36 listener (); 38 unix_listener (const char *sockname);
37}; 39};
38 40
39listener::listener () 41unix_listener::unix_listener (const char *sockname)
40: accept_ev (this, &listener::accept_cb) 42: accept_ev (this, &unix_listener::accept_cb)
41{ 43{
42 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) 44 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0)
43 { 45 {
44 perror ("unable to create listening socket"); 46 perror ("unable to create listening socket");
45 exit (EXIT_FAILURE); 47 exit (EXIT_FAILURE);
46 } 48 }
47 49
48 sockaddr_un sa; 50 sockaddr_un sa;
49 51
50 sa.sun_family = AF_UNIX; 52 sa.sun_family = AF_UNIX;
51 strcpy (sa.sun_path, rxvt_connection::unix_sockname ()); 53 strcpy (sa.sun_path, sockname);
52 54
53 unlink (rxvt_connection::unix_sockname ()); 55 unlink (rxvt_connection::unix_sockname ());
56
57 mode_t omask = umask (0077);
54 58
55 if (bind (fd, (sockaddr *)&sa, sizeof (sa))) 59 if (bind (fd, (sockaddr *)&sa, sizeof (sa)))
56 { 60 {
57 perror ("unable to bind listening socket"); 61 perror ("unable to bind listening socket");
58 exit (EXIT_FAILURE); 62 exit (EXIT_FAILURE);
59 } 63 }
64
65 umask (omask);
60 66
61 if (listen (fd, 5)) 67 if (listen (fd, 5))
62 { 68 {
63 perror ("unable to listen on socket"); 69 perror ("unable to listen on socket");
64 exit (EXIT_FAILURE); 70 exit (EXIT_FAILURE);
65 } 71 }
66 72
67 accept_ev.start (fd, EVENT_READ); 73 accept_ev.start (fd, EVENT_READ);
68} 74}
69 75
70void listener::accept_cb (io_watcher &w, short revents) 76void unix_listener::accept_cb (io_watcher &w, short revents)
71{ 77{
72 int fd2 = accept (fd, 0, 0); 78 int fd2 = accept (fd, 0, 0);
73 79
74 if (fd2 >= 0) 80 if (fd2 >= 0)
75 new server (fd2); 81 new server (fd2);
145} 151}
146 152
147int 153int
148main(int argc, const char *const *argv) 154main(int argc, const char *const *argv)
149{ 155{
150 listener l;
151
152 { 156 {
153 sigset_t ss; 157 sigset_t ss;
154 158
155 sigaddset (&ss, SIGHUP); 159 sigaddset (&ss, SIGHUP);
160 sigaddset (&ss, SIGPIPE);
156 sigprocmask (SIG_BLOCK, &ss, 0); 161 sigprocmask (SIG_BLOCK, &ss, 0);
157 } 162 }
158 163
159 printf ("rxvtd running.\n"); 164 rxvt_init_signals ();
165
166 char *sockname = rxvt_connection::unix_sockname ();
167 unix_listener l (sockname);
168 printf ("rxvtd listening on %s.\n", sockname);
169 free (sockname);
170
160 iom.loop (); 171 iom.loop ();
161 172
162#if 0 173#if 0
163 if (rxvt_init(argc, argv) == NULL) 174 if (rxvt_init(argc, argv) == NULL)
164 return EXIT_FAILURE; 175 return EXIT_FAILURE;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines