- //unlink(controlsocketname);
- result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
-
- if(result < 0 && errno == EADDRINUSE) {
- result = connect(control_socket, (struct sockaddr *)&addr, sizeof addr);
- if(result < 0) {
- logger(LOG_WARNING, _("Removing old control socket."));
- unlink(controlsocketname);
- result = bind(control_socket, (struct sockaddr *)&addr, sizeof addr);
- } else {
- close(control_socket);
- if(netname)
- logger(LOG_ERR, _("Another tincd is already running for net `%s'."), netname);
- else
- logger(LOG_ERR, _("Another tincd is already running."));
- return false;
- }
+ struct sockaddr_un sa_un;
+ sa_un.sun_family = AF_UNIX;
+ strncpy(sa_un.sun_path, unixsocketname, sizeof sa_un.sun_path);
+
+ if(connect(unix_fd, (struct sockaddr *)&sa_un, sizeof sa_un) >= 0) {
+ logger(DEBUG_ALWAYS, LOG_ERR, "UNIX socket %s is still in use!", unixsocketname);
+ return false;