Debian Codegraph @

mod_notionflux/mod_notionflux.c

raw symbols SCIP
1 /*
2 * mod_notionflux/mod_notionflux/mod_notionflux.c
3 *
4 * Copyright (c) Tuomo Valkonen 2004-2005.
5 * Copyright (c) The Notion development team 2019
6 *
7 * This is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 */
12
13 #include <errno.h>
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include <fcntl.h>
18 #include <string.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <sys/socket.h>
22 #include <sys/un.h>
23
24 #include <ioncore/../version.h>cxx . . $ `<file>/version.h`/
25 #include <ioncore/common.h>cxx . . $ `<file>/ioncore/common.h`/
26 #include <ioncore/global.h>cxx . . $ `<file>/ioncore/global.h`/
27 #include <ioncore/property.h>cxx . . $ `<file>/ioncore/property.h`/
28 #include <ioncore/tempdir.h>cxx . . $ `<file>/ioncore/tempdir.h`/
29 #include <libmainloop/select.h>cxx . . $ `<file>/libmainloop/select.h`/
30 #include <libtu/errorlog.h>cxx . . $ `<file>/libtu/errorlog.h`/
31 #include <libextl/extl.h>cxx . . $ `<file>/libextl/extl.h`/
32 #include <libextl/luaextl.h>cxx . . $ `<file>/libextl/luaextl.h`/
33
34 #include "notionflux.h"cxx . . $ `<file>/mod_notionflux/notionflux.h`/
35 #include "exports.h"cxx . . $ `<file>/mod_notionflux/exports.h`/
36
37 typedef structcxx . . $ $anonymous_type_31a386bf9bbf180a_0#{
38 int fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.;
39 FILEcxx . . $ FILE# *stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.;
40 int ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.;
41 char *datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.;
42 } Bufcxx . . $ Buf#;
43
44 Bufcxx . . $ Buf# bufscxx . . $ bufs.[MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!];
45
46 static int listenfdcxx . . $ listenfd.=-1;
47 static char *listenfilecxx . . $ listenfile.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
48 static ExtlFncxx . . $ ExtlFn# tostringfncxx . . $ tostringfn.;
49
50 static void writescxx . . $ writes(66835f578de1bcb3).(int fd, const char *s)
51 {
52 if(s!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
53 ignore_valuecxx . . $ `libtu/misc.h:35:10`!(write(fd, s, strlen(s)));
54 }
55
56
57 static void close_conncxx . . $ close_conn(5a316ace020d12cc).(Bufcxx . . $ Buf# *buf)
58 {
59 if(buf->fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.<0)
60 return;
61
62 mainloop_unregister_input_fdcxx . . $ mainloop_unregister_input_fd(d4f767463ce0a6b3).(buf->fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.);
63
64 closecxx . . $ close(7864480464b09eea).(buf->fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.);
65 buf->fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.=-1;
66 buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.=0;
67 if(buf->stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
68 fclosecxx . . $ fclose(89bc1efcdac0ca22).(buf->stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.);
69 buf->stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
70 }
71 if(buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
72 freecxx . . $ free(5d22bdacc48458e8).(buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.);
73 buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
74 }
75 }
76
77 /* Receive file descriptors from a unix domain socket.
78 See unix(4), unix(7), sendmsg(2), cmsg(3) */
79 static int unix_recv_fdcxx . . $ unix_recv_fd(7864480464b09eea).(int unix)
80 {
81 /* tasty, tasty boilerplate. */
82 struct msghdrcxx . . $ msghdr# msg={0};
83 struct cmsghdrcxx . . $ cmsghdr# *cmsg;
84 struct ioveccxx . . $ iovec# iov;
85 unsigned char magic[4]={23, 42, 128, 7};
86 char iov_buf[4];
87 int fd=-1;
88 unioncxx . . $ unix_recv_fd(7864480464b09eea).$anonymous_type_1# { /* alignment, alignment, cmsg(3) */
89 char bufcxx . . $ unix_recv_fd(7864480464b09eea).$anonymous_type_1#buf.[CMSG_SPACEcxx . . $ `<external>/8962547315054503424/socket.h:309:9`!(sizeof(fd))];
90 struct cmsghdrcxx . . $ cmsghdr# aligncxx . . $ unix_recv_fd(7864480464b09eea).$anonymous_type_1#align.;
91 } u;
92 int iter=0, rv;
93
94 iov.iov_lencxx . . $ iovec#iov_len.=sizeof(iov_buf);
95 iov.iov_basecxx . . $ iovec#iov_base.=&iov_buf;
96
97 msg.msg_namecxx . . $ msghdr#msg_name.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
98 msg.msg_namelencxx . . $ msghdr#msg_namelen.=0;
99 msg.msg_iovcxx . . $ msghdr#msg_iov.=&iov;
100 msg.msg_iovlencxx . . $ msghdr#msg_iovlen.=1;
101
102 msg.msg_controlcxx . . $ msghdr#msg_control.=&u.bufcxx . . $ unix_recv_fd(7864480464b09eea).$anonymous_type_1#buf.;
103 msg.msg_controllencxx . . $ msghdr#msg_controllen.=sizeof(u.bufcxx . . $ unix_recv_fd(7864480464b09eea).$anonymous_type_1#buf.);
104
105 rv=recvmsgcxx . . $ recvmsg(616999ca12de9af7).(unix, &msg, MSG_CMSG_CLOEXECcxx . . $ `<external>/8962547315054503424/socket.h:259:9`!);
106 if (rv== -1){
107 warncxx . . $ warn(326aeb464d16410c).("Failed to receive fd from unix domain socket.");
108 return -1;
109 }else if(rv==0){ /* remote socket was shut down */
110 return -2;
111 }
112 if(memcmpcxx . . $ memcmp(36f949851efa3055).(iov_buf, magic, sizeof(magic))!=0)
113 return -3;
114
115 for (cmsg=CMSG_FIRSTHDRcxx . . $ `<external>/8962547315054503424/socket.h:304:9`!(&msg); cmsg!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; cmsg=CMSG_NXTHDRcxx . . $ `<external>/8962547315054503424/socket.h:303:9`!(&msg, cmsg)) {
116 if(iter>0){
117 warncxx . . $ warn(326aeb464d16410c).("notionflux client is sending us unexpected packets");
118 }else if(cmsg->cmsg_levelcxx . . $ cmsghdr#cmsg_level. == SOL_SOCKETcxx . . $ `<external>/11669433886605212396/socket-constants.h:25:9`!
119 && cmsg->cmsg_typecxx . . $ cmsghdr#cmsg_type. == SCM_RIGHTScxx . . $ `<external>/8962547315054503424/socket.h:369:9`!
120 && cmsg->cmsg_lencxx . . $ cmsghdr#cmsg_len. == CMSG_LENcxx . . $ `<external>/8962547315054503424/socket.h:311:9`!(sizeof(fd))){
121 unsigned char const *data=CMSG_DATAcxx . . $ `<external>/8962547315054503424/socket.h:299:10`!(cmsg);
122 int newfd=*((int *)data);
123 if (newfd == -1) {
124 warncxx . . $ warn(326aeb464d16410c).("notionflux managed to send invalid fd.");
125 }else if (fd != -1 && newfd != fd) {
126 warncxx . . $ warn(326aeb464d16410c).("notionflux client is spamming us with fds, ignoring.");
127 closecxx . . $ close(7864480464b09eea).(newfd); /* only want one fd from this connection */
128 } else {
129 fd = newfd;
130 }
131 }else{
132 warncxx . . $ warn(326aeb464d16410c).("Unknown control message on unix domain socket.");
133 }
134 iter++;
135 }
136
137 return fd;
138 }
139
140 static void receive_datacxx . . $ receive_data(6ca3d68f5c5f0975).(int fd, void *buf_)
141 {
142 Bufcxx . . $ Buf# *buf=(Bufcxx . . $ Buf#*)buf_;
143 boolcxx . . $ `libtu/types.h:75:9`! end=FALSEcxx . . $ `libtu/types.h:20:9`!;
144 ErrorLogcxx . . $ ErrorLog# el;
145 ExtlFncxx . . $ ExtlFn# fn;
146 int i, n;
147 boolcxx . . $ `libtu/types.h:75:9`! success=FALSEcxx . . $ `libtu/types.h:20:9`!;
148 int idx=buf-bufscxx . . $ bufs.;
149
150 if(buf->stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){ /* no fd received yet, must be the very beginning */
151 int stdoutput_fd=unix_recv_fdcxx . . $ unix_recv_fd(7864480464b09eea).(fd);
152 if(stdoutput_fd==-2)
153 goto closefd;
154 if(stdoutput_fd==-3){
155 char const *err="Magic number mismatch on notionflux socket - "
156 "is notionflux the same version as notion?";
157 writescxx . . $ writes(66835f578de1bcb3).(fd, "E");
158 writescxx . . $ writes(66835f578de1bcb3).(fd, err);
159 warncxx . . $ warn(326aeb464d16410c).(err);
160 goto closefd;
161 }
162
163 if(stdoutput_fd==-1) {
164 if(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!==EWOULDBLOCKcxx . . $ `<external>/17922322188510340118/errno.h:22:9`! || errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!==EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`!)
165 return; /* try again later */
166 warncxx . . $ warn(326aeb464d16410c).("No file descriptor received from notionflux, closing.");
167 goto closefd;
168 }
169 if((buf->stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.=fdopencxx . . $ fdopen(8f4e2d7350ebd077).(stdoutput_fd, "w"))==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) {
170 warncxx . . $ warn(326aeb464d16410c).("fdopen() failed on fd from notionflux");
171 goto closefd;
172 }
173 }
174
175 n=readcxx . . $ read(7e34d0a36f355389).(fd, buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.+buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata., MAX_DATAcxx . . $ `mod_notionflux/notionflux.h:18:9`!-buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.);
176
177 if(n==0){
178 warncxx . . $ warn(326aeb464d16410c).("Connection closed prematurely.");
179 goto closefd;
180 }
181
182 if(n<0){
183 if(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!!=EAGAINcxx . . $ `<external>/8987895939074593727/errno-base.h:15:9`! && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!!=EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!){
184 writescxx . . $ writes(66835f578de1bcb3).(fd, "Error: I/O");
185 close_conncxx . . $ close_conn(5a316ace020d12cc).(buf);
186 }
187 return;
188 }
189
190 for(i=0; i<n; i++){
191 if(buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.[buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.+i]=='\0')
192 end=TRUEcxx . . $ `libtu/types.h:16:9`!;
193 }
194
195 buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.+=n;
196
197 if(!end && buf->ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.+n==MAX_DATAcxx . . $ `mod_notionflux/notionflux.h:18:9`!){
198 writescxx . . $ writes(66835f578de1bcb3).(fd, "Error: too much data\n");
199 goto closefd;
200 }
201
202 if(!end)
203 return;
204
205 errorlog_begincxx . . $ errorlog_begin(fe4c60067dc76ab9).(&el);
206
207 if(!extl_lookup_global_valuecxx . . $ extl_lookup_global_value(417aebe4441fb56c).(&tostringfncxx . . $ tostringfn., 'f', "mod_notionflux", "run_lua", NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)){
208 warncxx . . $ warn(326aeb464d16410c).("mod_notionflux.run_lua() function is missing");
209 return;
210 }
211 if(extl_loadstringcxx . . $ extl_loadstring(7436bf38bddd805d).(buf->datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data., &fn)){
212 char *retstr=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
213 if(extl_callcxx . . $ extl_call(b011acbbe10078c9).(tostringfncxx . . $ tostringfn., "fi", "s", fn, idx, &retstr)){
214 success=TRUEcxx . . $ `libtu/types.h:16:9`!;
215 writescxx . . $ writes(66835f578de1bcb3).(fd, "S");
216 writescxx . . $ writes(66835f578de1bcb3).(fd, retstr);
217 writescxx . . $ writes(66835f578de1bcb3).(fd, "\n");
218 freecxx . . $ free(5d22bdacc48458e8).(retstr);
219 }
220 extl_unref_fncxx . . $ extl_unref_fn(7864480464b09eea).(fn);
221 }
222 extl_unref_fncxx . . $ extl_unref_fn(7864480464b09eea).(tostringfncxx . . $ tostringfn.);
223 errorlog_endcxx . . $ errorlog_end(be4aeadca46714c).(&el);
224 if(el.msgscxx . . $ ErrorLog_struct#msgs.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && !success){
225 writescxx . . $ writes(66835f578de1bcb3).(fd, "E");
226 writescxx . . $ writes(66835f578de1bcb3).(fd, el.msgscxx . . $ ErrorLog_struct#msgs.);
227 }
228 errorlog_deinitcxx . . $ errorlog_deinit(fe4c60067dc76ab9).(&el);
229
230 closefd:
231 close_conncxx . . $ close_conn(5a316ace020d12cc).(buf);
232 return;
233 }
234
235 /**EXTL_DOC
236 * Write \var{str} to the output file descriptor associated with client \var{idx}
237 */
238 EXTL_SAFEcxx . . $ `libextl/extl.h:23:9`!
239 EXTL_EXPORTcxx . . $ `libextl/extl.h:19:9`!
240 boolcxx . . $ `libtu/types.h:75:9`! mod_notionflux_xwritecxx . . $ mod_notionflux_xwrite(95e580389a7cc305).(int idx, const char *str)
241 {
242 if (idx<0 || idx>=MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`! || bufscxx . . $ bufs.[idx].stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
243 return FALSEcxx . . $ `libtu/types.h:20:9`!;
244 return fputscxx . . $ fputs(874fa6a5e59ab9bd).(str, bufscxx . . $ bufs.[idx].stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.)!=EOFcxx . . $ `<external>/232824719582829767/stdio.h:105:9`!;
245 }
246
247 static void connection_attemptcxx . . $ connection_attempt(6ca3d68f5c5f0975).(int lfd, void *UNUSEDcxx . . $ `libtu/misc.h:28:11`!(data))
248 {
249 int i, fd;
250 struct sockaddr_uncxx . . $ sockaddr_un# from;
251 socklen_tcxx . . $ socklen_t# fromlen=sizeof(from);
252
253 fd=acceptcxx . . $ accept(46fcd054f4a4d98b).(lfd, (struct sockaddrcxx . . $ sockaddr#*)&from, &fromlen);
254
255 if(fd<0){
256 warn_errcxx . . $ warn_err(d878ad36e69247c7).();
257 return;
258 }
259
260 /* unblock */ {
261 int fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_GETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:168:9`!);
262 if(fl!=-1)
263 fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_SETFLcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:169:9`!, fl|O_NONBLOCKcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:62:10`!);
264 if(fl==-1){
265 warn_errcxx . . $ warn_err(d878ad36e69247c7).();
266 closecxx . . $ close(7864480464b09eea).(fd);
267 return;
268 }
269 }
270
271 /* close socket on exec */ {
272 int fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_GETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:166:9`!);
273 if(fl!=-1)
274 fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(fd, F_SETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:167:9`!, fl|FD_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:219:9`!);
275 if(fl==-1){
276 warn_errcxx . . $ warn_err(d878ad36e69247c7).();
277 closecxx . . $ close(7864480464b09eea).(fd);
278 return;
279 }
280
281 }
282
283 for(i=0; i<MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!; i++){
284 if(bufscxx . . $ bufs.[i].fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.<0)
285 break;
286 }
287
288 if(i==MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!){
289 writescxx . . $ writes(66835f578de1bcb3).(fd, "Error: busy\n");
290 closecxx . . $ close(7864480464b09eea).(fd);
291 return;
292 }
293
294 assertcxx . . $ `<external>/4398592474888995393/assert.h:108:11`!(bufs[i].data==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! && bufs[i].ndata==0);
295
296 bufscxx . . $ bufs.[i].datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.=ALLOC_Ncxx . . $ `libtu/misc.h:19:9`!(char, MAX_DATAcxx . . $ `mod_notionflux/notionflux.h:18:9`!);
297
298 if(bufscxx . . $ bufs.[i].datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
299 if(mainloop_register_input_fdcxx . . $ mainloop_register_input_fd(2364b3f4c7697d49).(fd, &(bufscxx . . $ bufs.[i]), receive_datacxx . . $ receive_data(6ca3d68f5c5f0975).)){
300 bufscxx . . $ bufs.[i].fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.=fd;
301 return;
302 }
303 }
304
305 writescxx . . $ writes(66835f578de1bcb3).(fd, "Error: malloc\n");
306 closecxx . . $ close(7864480464b09eea).(fd);
307 }
308
309 static boolcxx . . $ `libtu/types.h:75:9`! start_listeningcxx . . $ start_listening(d1b40a211a1a4e4c).()
310 {
311 struct sockaddr_uncxx . . $ sockaddr_un# addr;
312 char const *tempdir=ioncore_tempdircxx . . $ ioncore_tempdir(87c6ae427bbae0f6).();
313 char const *filename="notionflux.socket";
314
315 listenfilecxx . . $ listenfile. = ALLOC_Ncxx . . $ `libtu/misc.h:19:9`!(char, strlen(tempdir)+strlen(filename)+1);
316 if(!listenfilecxx . . $ listenfile. || !tempdir)
317 goto err;
318
319 strcatcxx . . $ strcat(b7b3a83273496486).(listenfilecxx . . $ listenfile., tempdir);
320 strcatcxx . . $ strcat(b7b3a83273496486).(listenfilecxx . . $ listenfile., filename);
321
322 if(strlencxx . . $ strlen(751346f8406fd082).(listenfilecxx . . $ listenfile.)>sizeof(addr.sun_pathcxx . . $ sockaddr_un#sun_path.)-1){
323 warncxx . . $ warn(326aeb464d16410c).("Socket path too long");
324 goto err;
325 }
326
327 listenfdcxx . . $ listenfd.=socketcxx . . $ socket(2326284602b0bb2d).(AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!, SOCK_STREAMcxx . . $ `<external>/5956532346368192945/socket_type.h:28:9`!, 0);
328 if(listenfdcxx . . $ listenfd.<0)
329 goto errwarn;
330
331 if(fchmodcxx . . $ fchmod(b223e862534b1804).(listenfdcxx . . $ listenfd., S_IRUSRcxx . . $ `<external>/531885356569766532/stat.h:168:9`!|S_IWUSRcxx . . $ `<external>/531885356569766532/stat.h:169:9`!)<0)
332 goto errwarn;
333
334 addr.sun_familycxx . . $ sockaddr_un#sun_family.=AF_UNIXcxx . . $ `<external>/8962547315054503424/socket.h:95:9`!;
335
336 strcpycxx . . $ strcpy(b7b3a83273496486).(addr.sun_pathcxx . . $ sockaddr_un#sun_path., listenfilecxx . . $ listenfile.);
337
338 {
339 int fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(listenfdcxx . . $ listenfd., F_GETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:166:9`!);
340 if(fl!=-1)
341 fl=fcntlcxx . . $ fcntl(cac4efb70f20a0fb).(listenfdcxx . . $ listenfd., F_SETFDcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:167:9`!, fl|FD_CLOEXECcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:219:9`!);
342 if(fl==-1)
343 goto errwarn;
344 }
345
346 if(bindcxx . . $ bind(1ce9971e209c3c95).(listenfdcxx . . $ listenfd., (struct sockaddrcxx . . $ sockaddr#*) &addr, sizeof(addr))<0)
347 goto errwarn;
348
349 if(chmodcxx . . $ chmod(1df18506ef0a631b).(listenfilecxx . . $ listenfile., S_IRUSRcxx . . $ `<external>/531885356569766532/stat.h:168:9`!|S_IWUSRcxx . . $ `<external>/531885356569766532/stat.h:169:9`!)<0)
350 goto errwarn;
351
352 if(listencxx . . $ listen(9b79fb6aee4c0440).(listenfdcxx . . $ listenfd., MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!)<0)
353 goto errwarn;
354
355 if(!mainloop_register_input_fdcxx . . $ mainloop_register_input_fd(2364b3f4c7697d49).(listenfdcxx . . $ listenfd., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, connection_attemptcxx . . $ connection_attempt(6ca3d68f5c5f0975).))
356 goto err;
357
358 return TRUEcxx . . $ `libtu/types.h:16:9`!;
359
360 errwarn:
361 warn_err_objcxx . . $ warn_err_obj(85c52e162fed56f9).("mod_notionflux listening socket");
362 err:
363 if(listenfdcxx . . $ listenfd.>=0){
364 closecxx . . $ close(7864480464b09eea).(listenfdcxx . . $ listenfd.);
365 listenfdcxx . . $ listenfd.=-1;
366 }
367
368 if(listenfilecxx . . $ listenfile.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
369 freecxx . . $ free(5d22bdacc48458e8).(listenfilecxx . . $ listenfile.);
370 listenfilecxx . . $ listenfile.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
371 }
372
373 return FALSEcxx . . $ `libtu/types.h:20:9`!;
374 }
375
376 void close_connectionscxx . . $ close_connections(d878ad36e69247c7).()
377 {
378 int i;
379
380 if(listenfdcxx . . $ listenfd.>=0){
381 mainloop_unregister_input_fdcxx . . $ mainloop_unregister_input_fd(d4f767463ce0a6b3).(listenfdcxx . . $ listenfd.);
382 closecxx . . $ close(7864480464b09eea).(listenfdcxx . . $ listenfd.);
383 listenfdcxx . . $ listenfd.=-1;
384 }
385
386 if(listenfilecxx . . $ listenfile.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!){
387 unlinkcxx . . $ unlink(5c4306d8553b3696).(listenfilecxx . . $ listenfile.);
388 freecxx . . $ free(5d22bdacc48458e8).(listenfilecxx . . $ listenfile.);
389 listenfilecxx . . $ listenfile.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
390 }
391
392 for(i=0; i<MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!; i++){
393 if(bufscxx . . $ bufs.[i].fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.>=0)
394 close_conncxx . . $ close_conn(5a316ace020d12cc).(&(bufscxx . . $ bufs.[i]));
395 }
396
397 }
398
399 char mod_notionflux_ion_api_versioncxx . . $ mod_notionflux_ion_api_version.[]=ION_API_VERSIONcxx . . $ `version.h:5:9`!;
400
401 static Atomcxx . . $ Atom# flux_socketcxx . . $ flux_socket.=Nonecxx . . $ `<external>/1208737181511191802/X.h:115:9`!;
402
403 boolcxx . . $ `libtu/types.h:75:9`! mod_notionflux_initcxx . . $ mod_notionflux_init(d1b40a211a1a4e4c).()
404 {
405 int i;
406 WRootWincxx . . $ WRootWin# *rw;
407
408 if (!mod_notionflux_register_exportscxx . . $ mod_notionflux_register_exports(d1b40a211a1a4e4c).())
409 return FALSEcxx . . $ `libtu/types.h:20:9`!;
410
411 for(i=0; i<MAX_SERVEDcxx . . $ `mod_notionflux/notionflux.h:16:9`!; i++){
412 bufscxx . . $ bufs.[i].fdcxx . . $ $anonymous_type_31a386bf9bbf180a_0#fd.=-1;
413 bufscxx . . $ bufs.[i].stdoutputcxx . . $ $anonymous_type_31a386bf9bbf180a_0#stdoutput.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
414 bufscxx . . $ bufs.[i].datacxx . . $ $anonymous_type_31a386bf9bbf180a_0#data.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
415 bufscxx . . $ bufs.[i].ndatacxx . . $ $anonymous_type_31a386bf9bbf180a_0#ndata.=0;
416 }
417
418 if (!start_listeningcxx . . $ start_listening(d1b40a211a1a4e4c).())
419 goto err_listening;
420
421 flux_socketcxx . . $ flux_socket.=XInternAtomcxx . . $ XInternAtom(cce9092df7d5c4bb).(ioncore_gcxx . . $ ioncore_g..dpycxx . . $ WGlobal_struct#dpy., "_NOTION_MOD_NOTIONFLUX_SOCKET", Falsecxx . . $ `<external>/7073035915403465041/Xlib.h:81:9`!);
422
423 FOR_ALL_ROOTWINScxx . . $ `ioncore/rootwin.h:21:9`!(rw){
424 xwindow_set_string_propertycxx . . $ xwindow_set_string_property(24e91771e7e40ea4).(region_xwindowcxx . . $ region_xwindow(6ba0835100ce9252).((WRegioncxx . . $ WRegion#*)rw), flux_socketcxx . . $ flux_socket., listenfilecxx . . $ listenfile.);
425 }
426
427 return TRUEcxx . . $ `libtu/types.h:16:9`!;
428
429 err_listening:
430 close_connectionscxx . . $ close_connections(d878ad36e69247c7).();
431 return FALSEcxx . . $ `libtu/types.h:20:9`!;
432 }
433
434
435 void mod_notionflux_deinitcxx . . $ mod_notionflux_deinit(d878ad36e69247c7).()
436 {
437 WRootWincxx . . $ WRootWin# *rw;
438
439 if(flux_socketcxx . . $ flux_socket.!=Nonecxx . . $ `<external>/1208737181511191802/X.h:115:9`!){
440 FOR_ALL_ROOTWINScxx . . $ `ioncore/rootwin.h:21:9`!(rw){
441 XDeletePropertycxx . . $ XDeleteProperty(b373b037aa36b05f).(ioncore_gcxx . . $ ioncore_g..dpycxx . . $ WGlobal_struct#dpy., region_xwindowcxx . . $ region_xwindow(6ba0835100ce9252).((WRegioncxx . . $ WRegion#*)rw), flux_socketcxx . . $ flux_socket.);
442 }
443 }
444
445 close_connectionscxx . . $ close_connections(d878ad36e69247c7).();
446 }
447