X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-dnsconfd%2Fmain.c;h=7fed84969a10f79151204687a9cdc4104d2c933c;hb=b11f583f822269d5cbd3e54a76ff6a428556ad9a;hp=957c91e6d7ae834e8fd6a3df1f7f1afd095efe86;hpb=7540df5ed6b383ec93f5a4f10ab2d08f9b9869e4;p=catta diff --git a/avahi-dnsconfd/main.c b/avahi-dnsconfd/main.c index 957c91e..7fed849 100644 --- a/avahi-dnsconfd/main.c +++ b/avahi-dnsconfd/main.c @@ -39,7 +39,6 @@ #include -#include #include #include @@ -116,6 +115,20 @@ static DNSServerInfo* new_server_info(gint interface, guchar protocol, const gch return i; } +static int set_cloexec(int fd) { + int n; + + assert(fd >= 0); + + if ((n = fcntl(fd, F_GETFD)) < 0) + return -1; + + if (n & FD_CLOEXEC) + return 0; + + return fcntl(fd, F_SETFD, n|FD_CLOEXEC); +} + static int open_socket(void) { int fd = -1; struct sockaddr_un sa; @@ -125,7 +138,7 @@ static int open_socket(void) { goto fail; } - if (avahi_set_cloexec(fd) < 0) { + if (set_cloexec(fd) < 0) { daemon_log(LOG_ERR, "fcntl(): %s", strerror(errno)); goto fail; } @@ -224,11 +237,12 @@ finish: static void run_script(gboolean new, gint interface, guchar protocol, const gchar *address) { gchar *p; - g_assert(interface > 0); gint ret; gchar ia[16], pa[16]; gchar name[IFNAMSIZ+1]; + g_assert(interface > 0); + if (!getifname(interface, name, sizeof(name))) return; @@ -611,7 +625,6 @@ gint main(gint argc, gchar *argv[]) { r = (daemon_pid_file_is_running() >= 0) ? 0 : 1; - finish: if (daemonize)