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.9 by pcg, Fri Feb 13 13:28:17 2004 UTC vs.
Revision 1.12 by pcg, Sun Apr 4 23:52:37 2004 UTC

7#include <cstdlib> 7#include <cstdlib>
8#include <cstdarg> 8#include <cstdarg>
9#include <cstring> 9#include <cstring>
10 10
11#include <unistd.h> 11#include <unistd.h>
12#include <fcntl.h>
12#include <sys/types.h> 13#include <sys/types.h>
13#include <sys/stat.h> 14#include <sys/stat.h>
14#include <sys/socket.h> 15#include <sys/socket.h>
15#include <sys/un.h> 16#include <sys/un.h>
16 17
17#include <cerrno> 18#include <cerrno>
18 19
19extern char **environ; 20extern char **environ;
20 21
21struct server : rxvt_connection { 22struct server : rxvt_connection {
23 log_callback log_cb;
24
22 void read_cb (io_watcher &w, short revents); io_watcher read_ev; 25 void read_cb (io_watcher &w, short revents); io_watcher read_ev;
26 void log_msg (const char *msg);
23 27
24 server (int fd) 28 server (int fd)
25 : read_ev (this, &server::read_cb) 29 : read_ev (this, &server::read_cb),
30 log_cb (this, &server::log_msg)
26 { 31 {
27 this->fd = fd; 32 this->fd = fd;
28 read_ev.start (fd, EVENT_READ); 33 read_ev.start (fd, EVENT_READ);
29 } 34 }
30 35
46 { 51 {
47 perror ("unable to create listening socket"); 52 perror ("unable to create listening socket");
48 exit (EXIT_FAILURE); 53 exit (EXIT_FAILURE);
49 } 54 }
50 55
56 fcntl (fd, F_SETFD, FD_CLOEXEC);
57
51 sockaddr_un sa; 58 sockaddr_un sa;
52 59
53 sa.sun_family = AF_UNIX; 60 sa.sun_family = AF_UNIX;
54 strcpy (sa.sun_path, sockname); 61 strcpy (sa.sun_path, sockname);
55 62
77void unix_listener::accept_cb (io_watcher &w, short revents) 84void unix_listener::accept_cb (io_watcher &w, short revents)
78{ 85{
79 int fd2 = accept (fd, 0, 0); 86 int fd2 = accept (fd, 0, 0);
80 87
81 if (fd2 >= 0) 88 if (fd2 >= 0)
89 {
90 fcntl (fd2, F_SETFD, FD_CLOEXEC);
82 new server (fd2); 91 new server (fd2);
92 }
93}
94
95void server::log_msg (const char *msg)
96{
97 send ("MSG"), send (msg);
83} 98}
84 99
85void server::err (const char *format, ...) 100void server::err (const char *format, ...)
86{ 101{
87 if (format) 102 if (format)
91 va_list ap; 106 va_list ap;
92 va_start (ap, format); 107 va_start (ap, format);
93 vsnprintf (err, 1024, format, ap); 108 vsnprintf (err, 1024, format, ap);
94 va_end (ap); 109 va_end (ap);
95 110
96 send ("ERR"), send (err); 111 send ("MSG"), send (err);
97 } 112 }
98 113
114 send ("END", 0);
99 close (fd); 115 close (fd);
100 delete this; 116 delete this;
101} 117}
102 118
103void server::read_cb (io_watcher &w, short revents) 119void server::read_cb (io_watcher &w, short revents)
136 152
137 { 153 {
138 char **old_environ = environ; 154 char **old_environ = environ;
139 environ = envv->begin (); 155 environ = envv->begin ();
140 156
141 rxvt_term *term = rxvt_init (argv->size (), argv->begin ()); 157 rxvt_term *term = new rxvt_term;
142 158
159 term->log_hook = &log_cb;
143 term->argv = argv; 160 term->argv = argv;
144 term->envv = envv; 161 term->envv = envv;
145 162
163 bool success;
164
165 try
166 {
167 success = term->init (argv->size (), argv->begin ());
168 }
169 catch (const class rxvt_failure_exception &e)
170 {
171 success = false;
172 }
173
146 environ = old_environ; 174 environ = old_environ;
175
176 if (!success)
177 term->destroy ();
178
179 send ("END"); send (success ? 1 : 0);
147 } 180 }
148 } 181 }
149 else 182 else
150 return err ("protocol error: request '%s' unsupported.", (char *)tok); 183 return err ("protocol error: request '%s' unsupported.", (char *)tok);
151 } 184 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines