minissdpd: unlink unix socket before binding

see http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=644510
This commit is contained in:
Thomas Bernard 2011-10-07 11:29:22 +02:00
parent e667e962ac
commit fd96a3ddcd
2 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,8 @@
$Id: Changelog.txt,v 1.19 2011/07/30 13:16:22 nanard Exp $
2011/10/07:
unlink unix socket before binding.
VERSION 1.1:
2011/07/30:

View File

@ -1,4 +1,4 @@
/* $Id: minissdpd.c,v 1.24 2011/07/30 13:10:05 nanard Exp $ */
/* $Id: minissdpd.c,v 1.25 2011/10/07 09:13:25 nanard Exp $ */
/* MiniUPnP project
* (c) 2007-2011 Thomas Bernard
* website : http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -462,12 +462,21 @@ OpenUnixSocket(const char * path)
{
struct sockaddr_un addr;
int s;
int rv;
s = socket(AF_UNIX, SOCK_STREAM, 0);
if(s < 0)
{
syslog(LOG_ERR, "socket(AF_UNIX): %m");
return -1;
}
/* unlink the socket pseudo file before binding */
rv = unlink(path);
if(rv < 0 && errno != ENOENT)
{
syslog(LOG_ERR, "unlink(unixsocket, \"%s\"): %m", path);
close(s);
return -1;
}
addr.sun_family = AF_UNIX;
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
if(bind(s, (struct sockaddr *)&addr,