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.8 by pcg, Fri Feb 13 12:16:21 2004 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);
132 environ = envv.begin (); 138 environ = envv.begin ();
133 139
134 rxvt_init (argv.size (), argv.begin ()); 140 rxvt_init (argv.size (), argv.begin ());
135 141
136 environ = old_environ; 142 environ = old_environ;
137 envv.clear (); // can't yet save the env 'cause rxvt modifies it :( 143 envv.clear (); // can't yet save the env 'cause rxvt modifies it : (
138 } 144 }
139 } 145 }
140 else 146 else
141 return err ("protocol error: request '%s' unsupported.", (char *)tok); 147 return err ("protocol error: request '%s' unsupported.", (char *)tok);
142 } 148 }
143 else 149 else
144 return err (); 150 return err ();
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; 156 rxvt_init_signals ();
151 157
152 { 158 char *sockname = rxvt_connection::unix_sockname ();
153 sigset_t ss; 159 unix_listener l (sockname);
160 printf ("rxvtd listening on %s.\n", sockname);
161 free (sockname);
154 162
155 sigaddset (&ss, SIGHUP);
156 sigprocmask (SIG_BLOCK, &ss, 0);
157 }
158
159 printf ("rxvtd running.\n");
160 iom.loop (); 163 iom.loop ();
161 164
162#if 0 165#if 0
163 if (rxvt_init(argc, argv) == NULL) 166 if (rxvt_init (argc, argv) == NULL)
164 return EXIT_FAILURE; 167 return EXIT_FAILURE;
165 168
166 dR; 169 dR;
167 rxvt_main_loop(aR); /* main processing loop */ 170 rxvt_main_loop (aR); /* main processing loop */
168#endif 171#endif
169 return EXIT_SUCCESS; 172 return EXIT_SUCCESS;
170} 173}
174

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines