Skip to content

Commit 3ddeca9

Browse files
committed
allow non-abstract socket name for infologgerD connect
1 parent cfed25c commit 3ddeca9

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

src/InfoLoggerClient.cxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,18 @@ InfoLoggerClient::InfoLoggerClient() {
110110
struct sockaddr_un socketAddrr;
111111
bzero(&socketAddrr, sizeof(socketAddrr));
112112
socketAddrr.sun_family = PF_LOCAL;
113-
if (cfg.txSocketPath->length()>sizeof(socketAddrr.sun_path)) {
114-
log.error("Socket name too long: max allowed is %d",(int)sizeof(socketAddrr.sun_path));
113+
if (cfg.txSocketPath->length()+2>sizeof(socketAddrr.sun_path)) {
114+
log.error("Socket name too long: max allowed is %d",(int)sizeof(socketAddrr.sun_path)-2);
115115
throw __LINE__;
116116
}
117-
// leave first char 0, to get abstract socket name - see man 7 unix
118-
strncpy(&socketAddrr.sun_path[1], cfg.txSocketPath->c_str(), cfg.txSocketPath->length());
117+
// if name starts with '/', use normal socket name. if not, use an abstract socket name
118+
// this is to allow non-abstract sockets on systems not supporting them.
119+
if (cfg.txSocketPath->c_str()[0]=='/') {
120+
strncpy(&socketAddrr.sun_path[0], cfg.txSocketPath->c_str(), cfg.txSocketPath->length());
121+
} else {
122+
// leave first char 0, to get abstract socket name - see man 7 unix
123+
strncpy(&socketAddrr.sun_path[1], cfg.txSocketPath->c_str(), cfg.txSocketPath->length());
124+
}
119125
if (connect(txSocket, (struct sockaddr *)&socketAddrr, sizeof(socketAddrr))) {
120126
log.error("Failed to connect to infoLoggerD: %s",strerror(errno));
121127
throw __LINE__;

src/infoLoggerD.cxx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)