]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/main.c
* many trivial fix to make avahi compile on OpenBSD
[catta] / avahi-daemon / main.c
index f64524a730e85bcaf1c4289135197b52cd5f2033..6f0624d3ae96389ce30c5dcefa308331a9cbf429 100644 (file)
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 #include <sys/time.h>
 #include <sys/resource.h>
+#include <sys/socket.h>
 
 #include <libdaemon/dfork.h>
 #include <libdaemon/dsignal.h>
@@ -116,7 +117,7 @@ static int has_prefix(const char *s, const char *prefix) {
     return strlen(s) >= l && strncmp(s, prefix, l) == 0;
 }
 
-static int load_resolv_conf(const DaemonConfig *c) {
+static int load_resolv_conf(void) {
     int ret = -1;
     FILE *f;
     int i = 0;
@@ -129,9 +130,9 @@ static int load_resolv_conf(const DaemonConfig *c) {
         goto finish;
     }
 
-    resolv_conf = avahi_new0(char*, AVAHI_MAX_WIDE_AREA_SERVERS+1);
+    resolv_conf = avahi_new0(char*, AVAHI_WIDE_AREA_SERVERS_MAX+1);
 
-    while (!feof(f) && i < AVAHI_MAX_WIDE_AREA_SERVERS) {
+    while (!feof(f) && i < AVAHI_WIDE_AREA_SERVERS_MAX) {
         char ln[128];
         char *p;
 
@@ -203,11 +204,11 @@ static void remove_dns_server_entry_groups(void) {
 }
 
 static void update_wide_area_servers(void) {
-    AvahiAddress a[AVAHI_MAX_WIDE_AREA_SERVERS];
+    AvahiAddress a[AVAHI_WIDE_AREA_SERVERS_MAX];
     unsigned n = 0;
     char **p;
 
-    for (p = resolv_conf; *p && n < AVAHI_MAX_WIDE_AREA_SERVERS; p++) {
+    for (p = resolv_conf; *p && n < AVAHI_WIDE_AREA_SERVERS_MAX; p++) {
         if (!avahi_address_parse(*p, AVAHI_PROTO_UNSPEC, &a[n]))
             avahi_log_warn("Failed to parse address '%s', ignoring.", *p);
         else
@@ -229,7 +230,7 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda
     avahi_server = s;
     
 #ifdef HAVE_DBUS
-    if (c->enable_dbus)
+    if (c->enable_dbus && state != AVAHI_SERVER_INVALID && state != AVAHI_SERVER_FAILURE)
         dbus_protocol_server_state_changed(state);
 #endif
 
@@ -555,11 +556,11 @@ static void log_function(AvahiLogLevel level, const char *txt) {
     daemon_log(log_level_map[level], "%s", txt);
 }
 
-static void dump(const char *text, void* userdata) {
+static void dump(const char *text, AVAHI_GCC_UNUSED void* userdata) {
     avahi_log_info("%s", text);
 }
 
-static void signal_callback(AvahiWatch *watch, int fd, AvahiWatchEvent event, void *userdata) {
+static void signal_callback(AvahiWatch *watch, AVAHI_GCC_UNUSED int fd, AVAHI_GCC_UNUSED AvahiWatchEvent event, AVAHI_GCC_UNUSED void *userdata) {
     int sig;
     const AvahiPoll *poll_api;
     
@@ -593,7 +594,7 @@ static void signal_callback(AvahiWatch *watch, int fd, AvahiWatchEvent event, vo
             if (resolv_conf_entry_group)
                 avahi_s_entry_group_reset(resolv_conf_entry_group);
 
-            load_resolv_conf(&config);
+            load_resolv_conf();
 
             update_wide_area_servers();
             
@@ -616,8 +617,8 @@ static void signal_callback(AvahiWatch *watch, int fd, AvahiWatchEvent event, vo
 static int run_server(DaemonConfig *c) {
     int r = -1;
     int error;
-    const AvahiPoll *poll_api;
-    AvahiWatch *sig_watch;
+    const AvahiPoll *poll_api = NULL;
+    AvahiWatch *sig_watch = NULL;
 
     assert(c);
 
@@ -656,7 +657,7 @@ static int run_server(DaemonConfig *c) {
 #endif
     }
     
-    load_resolv_conf(c);
+    load_resolv_conf();
     static_service_load();
 
     if (!(avahi_server = avahi_server_new(poll_api, &c->server_config, server_callback, c, &error))) {
@@ -842,9 +843,10 @@ static void set_one_rlimit(int resource, rlim_t limit, const char *name) {
 }
 
 static void enforce_rlimits(void) {
-
+#ifdef RLIMIT_AS
     if (config.rlimit_as_set)
         set_one_rlimit(RLIMIT_AS, config.rlimit_as, "RLIMIT_AS");
+#endif
     if (config.rlimit_core_set)
         set_one_rlimit(RLIMIT_CORE, config.rlimit_core, "RLIMIT_CORE");
     if (config.rlimit_data_set)
@@ -985,7 +987,7 @@ int main(int argc, char *argv[]) {
                 /** Parent **/
 
                 if ((ret = daemon_retval_wait(20)) < 0) {
-                    avahi_log_error("Could not recieve return value from daemon process.");
+                    avahi_log_error("Could not receive return value from daemon process.");
                     goto finish;
                 }