@@ -268,12 +268,18 @@ InfoLoggerD::InfoLoggerD(int argc,char * argv[]):Daemon(argc,argv) {
268268 struct sockaddr_un socketAddress;
269269 bzero (&socketAddress, sizeof (socketAddress));
270270 socketAddress.sun_family = PF_LOCAL;
271- if (configInfoLoggerD.rxSocketPath .length ()>sizeof (socketAddress.sun_path )) {
272- log.error (" Socket name too long: max allowed is %d" ,(int )sizeof (socketAddress.sun_path ));
271+ if (configInfoLoggerD.rxSocketPath .length ()+ 2 >sizeof (socketAddress.sun_path )) {
272+ log.error (" Socket name too long: max allowed is %d" ,(int )sizeof (socketAddress.sun_path )- 2 );
273273 throw __LINE__;
274274 }
275- // leave first char 0, to get abstract socket name - see man 7 unix
276- strncpy (&socketAddress.sun_path [1 ], configInfoLoggerD.rxSocketPath .c_str (), configInfoLoggerD.rxSocketPath .length ());
275+ // if name starts with '/', use normal socket name. if not, use an abstract socket name
276+ // this is to allow non-abstract sockets on systems not supporting them.
277+ if (configInfoLoggerD.rxSocketPath .c_str ()[0 ]==' /' ) {
278+ strncpy (&socketAddress.sun_path [0 ], configInfoLoggerD.rxSocketPath .c_str (), configInfoLoggerD.rxSocketPath .length ());
279+ } else {
280+ // leave first char 0, to get abstract socket name - see man 7 unix
281+ strncpy (&socketAddress.sun_path [1 ], configInfoLoggerD.rxSocketPath .c_str (), configInfoLoggerD.rxSocketPath .length ());
282+ }
277283 if (bind (rxSocket, (struct sockaddr *)&socketAddress, sizeof (socketAddress))==-1 ) {
278284 log.error (" bind() failed: %s" ,strerror (errno));
279285 throw __LINE__;
0 commit comments