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.9 by pcg, Fri Feb 13 13:28:17 2004 UTC

1#include "../config.h"
1#include "rxvtlib.h" 2#include "rxvt.h"
2#include "rxvtdaemon.h" 3#include "rxvtdaemon.h"
3#include "iom.h" 4#include "iom.h"
4 5
5#include <cstdio> 6#include <cstdio>
6#include <cstdlib> 7#include <cstdlib>
7#include <cstdarg> 8#include <cstdarg>
8#include <cstring> 9#include <cstring>
9 10
10#include <unistd.h> 11#include <unistd.h>
12#include <sys/types.h>
13#include <sys/stat.h>
11#include <sys/socket.h> 14#include <sys/socket.h>
12#include <sys/un.h> 15#include <sys/un.h>
13 16
14#include <cerrno> 17#include <cerrno>
15 18
26 } 29 }
27 30
28 void err (const char *format = 0, ...); 31 void err (const char *format = 0, ...);
29}; 32};
30 33
31struct listener { 34struct unix_listener {
32 int fd; 35 int fd;
33 36
34 void accept_cb (io_watcher &w, short revents); io_watcher accept_ev; 37 void accept_cb (io_watcher &w, short revents); io_watcher accept_ev;
35 38
36 listener (); 39 unix_listener (const char *sockname);
37}; 40};
38 41
39listener::listener () 42unix_listener::unix_listener (const char *sockname)
40: accept_ev (this, &listener::accept_cb) 43: accept_ev (this, &unix_listener::accept_cb)
41{ 44{
42 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0) 45 if ((fd = socket (PF_LOCAL, SOCK_STREAM, 0)) < 0)
43 { 46 {
44 perror ("unable to create listening socket"); 47 perror ("unable to create listening socket");
45 exit (EXIT_FAILURE); 48 exit (EXIT_FAILURE);
46 } 49 }
47 50
48 sockaddr_un sa; 51 sockaddr_un sa;
49 52
50 sa.sun_family = AF_UNIX; 53 sa.sun_family = AF_UNIX;
51 strcpy (sa.sun_path, rxvt_connection::unix_sockname ()); 54 strcpy (sa.sun_path, sockname);
52 55
53 unlink (rxvt_connection::unix_sockname ()); 56 unlink (rxvt_connection::unix_sockname ());
57
58 mode_t omask = umask (0077);
54 59
55 if (bind (fd, (sockaddr *)&sa, sizeof (sa))) 60 if (bind (fd, (sockaddr *)&sa, sizeof (sa)))
56 { 61 {
57 perror ("unable to bind listening socket"); 62 perror ("unable to bind listening socket");
58 exit (EXIT_FAILURE); 63 exit (EXIT_FAILURE);
59 } 64 }
65
66 umask (omask);
60 67
61 if (listen (fd, 5)) 68 if (listen (fd, 5))
62 { 69 {
63 perror ("unable to listen on socket"); 70 perror ("unable to listen on socket");
64 exit (EXIT_FAILURE); 71 exit (EXIT_FAILURE);
65 } 72 }
66 73
67 accept_ev.start (fd, EVENT_READ); 74 accept_ev.start (fd, EVENT_READ);
68} 75}
69 76
70void listener::accept_cb (io_watcher &w, short revents) 77void unix_listener::accept_cb (io_watcher &w, short revents)
71{ 78{
72 int fd2 = accept (fd, 0, 0); 79 int fd2 = accept (fd, 0, 0);
73 80
74 if (fd2 >= 0) 81 if (fd2 >= 0)
75 new server (fd2); 82 new server (fd2);
99 106
100 if (recv (tok)) 107 if (recv (tok))
101 { 108 {
102 if (!strcmp (tok, "NEW")) 109 if (!strcmp (tok, "NEW"))
103 { 110 {
104 stringvec argv; 111 stringvec *argv = new stringvec;
105 stringvec envv; 112 stringvec *envv = new stringvec;
106 113
107 for (;;) 114 for (;;)
108 { 115 {
109 if (!recv (tok)) 116 if (!recv (tok))
110 return err (); 117 return err ();
111 118
112 if (!strcmp (tok, "END")) 119 if (!strcmp (tok, "END"))
113 break; 120 break;
114 else if (!strcmp (tok, "ENV") && recv (tok)) 121 else if (!strcmp (tok, "ENV") && recv (tok))
115 envv.push_back (tok.get ()); 122 envv->push_back (tok.get ());
116 else if (!strcmp (tok, "CWD") && recv (tok)) 123 else if (!strcmp (tok, "CWD") && recv (tok))
117 { 124 {
118 if (chdir (tok)) 125 if (chdir (tok))
119 err ("unable to change to working directory to '%s': %s", 126 err ("unable to change to working directory to '%s': %s",
120 (char *)tok, strerror (errno)); 127 (char *)tok, strerror (errno));
121 } 128 }
122 else if (!strcmp (tok, "ARG") && recv (tok)) 129 else if (!strcmp (tok, "ARG") && recv (tok))
123 argv.push_back (tok.get ()); 130 argv->push_back (tok.get ());
124 else 131 else
125 return err ("protocol error: unexpected NEW token"); 132 return err ("protocol error: unexpected NEW token");
126 } 133 }
127 134
128 envv.push_back (0); 135 envv->push_back (0);
129 136
130 { 137 {
131 char **old_environ = environ; 138 char **old_environ = environ;
132 environ = envv.begin (); 139 environ = envv->begin ();
133 140
134 rxvt_init (argv.size (), argv.begin ()); 141 rxvt_term *term = rxvt_init (argv->size (), argv->begin ());
142
143 term->argv = argv;
144 term->envv = envv;
135 145
136 environ = old_environ; 146 environ = old_environ;
137 envv.clear (); // can't yet save the env 'cause rxvt modifies it :(
138 } 147 }
139 } 148 }
140 else 149 else
141 return err ("protocol error: request '%s' unsupported.", (char *)tok); 150 return err ("protocol error: request '%s' unsupported.", (char *)tok);
142 } 151 }
143 else 152 else
144 return err (); 153 return err ();
145} 154}
146 155
147int 156int
148main(int argc, const char *const *argv) 157main (int argc, const char *const *argv)
149{ 158{
150 listener l; 159 rxvt_init_signals ();
151 160
152 { 161 char *sockname = rxvt_connection::unix_sockname ();
153 sigset_t ss; 162 unix_listener l (sockname);
163 printf ("rxvtd listening on %s.\n", sockname);
164 free (sockname);
154 165
155 sigaddset (&ss, SIGHUP);
156 sigprocmask (SIG_BLOCK, &ss, 0);
157 }
158
159 printf ("rxvtd running.\n");
160 iom.loop (); 166 iom.loop ();
161 167
162#if 0 168#if 0
163 if (rxvt_init(argc, argv) == NULL) 169 if (rxvt_init (argc, argv) == NULL)
164 return EXIT_FAILURE; 170 return EXIT_FAILURE;
165 171
166 dR; 172 dR;
167 rxvt_main_loop(aR); /* main processing loop */ 173 rxvt_main_loop (aR); /* main processing loop */
168#endif 174#endif
169 return EXIT_SUCCESS; 175 return EXIT_SUCCESS;
170} 176}
177

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines