NetworkBlockDevice / nbd

Network Block Device
GNU General Public License v2.0
459 stars 119 forks source link

nbd-server fails silently with unixsock existing #123

Closed ari-s closed 1 year ago

ari-s commented 3 years ago

when configured with unixsock = /run/nbd-test.sock and the location /run/nbd-test.sock exists, nbd-server silently fails. Only when non-forking

# [ -e /run/nbd-test.sock ] && echo /run/nbd-test.sock existing 
/run/nbd-test.sock existing
# nbd-server ; echo $? ; ps aux|grep nbd
0
root       20820  0.0  0.0   6180   552 pts/0    S+   11:59   0:00 grep nbd

# nbd-server -d; echo $?
1

systemctl start nbd-server "succeeds" even though nbd-server itself isn't actually started

This is related to #122

yoe commented 1 year ago

If you compile nbd-server with --enable-syslog, you should actually encounter this message in your syslog:

           if(open_unix(unixsock, &gerror) == -1) {
                   msg(LOG_ERR, "failed to setup servers: %s",
                                   gerror->message);
                   g_clear_error(&gerror);
                   exit(EXIT_FAILURE);

(this is line 3729 of nbd-server.c)

which should be filled out with one of these messages:

   sock = socket(AF_UNIX, SOCK_STREAM, 0);
   if(sock < 0) {
           g_set_error(gerror, NBDS_ERR, NBDS_ERR_SOCKET,
                           "failed to open a unix socket: "
                           "failed to create socket: %s",
                           strerror(errno));
           goto out;
   }
   if(bind(sock, (struct sockaddr*)&sa, sizeof(struct sockaddr_un))<0) {
           g_set_error(gerror, NBDS_ERR, NBDS_ERR_BIND,
                           "failed to open a unix socket: "
                           "failed to bind to address %s: %s",
                           sockname, strerror(errno));
           goto out;
   }
   if(listen(sock, 10)<0) {
           g_set_error(gerror, NBDS_ERR, NBDS_ERR_BIND,
                           "failed to open a unix socket: "
                           "failed to start listening: %s",
                           strerror(errno));
           goto out;
   }

(in open_unix).

Please double-check that this is the case; if not, feel free to reopen.

I will look at #122 though.