]> git.meshlink.io Git - catta/blobdiff - avahi-daemon/static-services.c
Apply fedora init script fix from http://cvs.fedora.redhat.com/viewcvs/devel/avahi...
[catta] / avahi-daemon / static-services.c
index 5eba8b2059a8f2461e13a75be9ba91b8eaa65a9e..b9a852cc362b0e685ba8d075c4d46d52c95b8296 100644 (file)
@@ -175,7 +175,7 @@ static void static_service_group_free(StaticServiceGroup *g) {
     avahi_free(g);
 }
 
-static void entry_group_callback(AvahiServer *s, AvahiSEntryGroup *eg, AvahiEntryGroupState state, void* userdata) {
+static void entry_group_callback(AvahiServer *s, AVAHI_GCC_UNUSED AvahiSEntryGroup *eg, AvahiEntryGroupState state, void* userdata) {
     StaticServiceGroup *g = userdata;
     
     assert(s);
@@ -222,7 +222,9 @@ static void add_static_service_group_to_server(StaticServiceGroup *g) {
         /* This service group is already registered in the server */
         return;
     
-    if (!g->chosen_name) {
+    if (!g->chosen_name || (g->replace_wildcards && strstr(g->name, "%h"))) {
+
+        avahi_free(g->chosen_name);
         
         if (g->replace_wildcards)
             g->chosen_name = replacestr(g->name, "%h", avahi_server_get_host_name(avahi_server));
@@ -302,6 +304,10 @@ struct xml_userdata {
     char *buf;
 };
 
+#ifndef XMLCALL
+#define XMLCALL
+#endif
+
 static void XMLCALL xml_start(void *data, const char *el, const char *attr[]) {
     struct xml_userdata *u = data;
     
@@ -402,7 +408,7 @@ invalid_attr:
     return;
 }
     
-static void XMLCALL xml_end(void *data, const char *el) {
+static void XMLCALL xml_end(void *data, AVAHI_GCC_UNUSED const char *el) {
     struct xml_userdata *u = data;
     assert(u);
 
@@ -609,7 +615,7 @@ static int static_service_group_load(StaticServiceGroup *g) {
         }
 
         if (!XML_ParseBuffer(parser, n, n == 0)) {
-            avahi_log_error("XML_ParseBuffer() failed at line %d: %s.\n", XML_GetCurrentLineNumber(parser), XML_ErrorString(XML_GetErrorCode(parser)));
+            avahi_log_error("XML_ParseBuffer() failed at line %d: %s.\n", (int) XML_GetCurrentLineNumber(parser), XML_ErrorString(XML_GetErrorCode(parser)));
             goto finish;
         }
 
@@ -648,9 +654,10 @@ static void load_file(char *n) {
     }
 }
 
-void static_service_load(void) {
+void static_service_load(int in_chroot) {
     StaticServiceGroup *g, *n;
     glob_t globbuf;
+    int globret;
     char **p;
 
     for (g = groups; g; g = n) {
@@ -677,8 +684,25 @@ void static_service_load(void) {
     }
 
     memset(&globbuf, 0, sizeof(globbuf));
-    if (glob(AVAHI_SERVICE_DIR "/*.service", GLOB_ERR, NULL, &globbuf) != 0)
-        avahi_log_error("Failed to read service directory.");
+    
+    if ((globret = glob(in_chroot ? "/services/*.service" : AVAHI_SERVICE_DIR "/*.service", GLOB_ERR, NULL, &globbuf)) != 0)
+        
+        switch (globret) {
+#ifdef GLOB_NOSPACE
+           case GLOB_NOSPACE:
+               avahi_log_error("Not enough memory to read service directory "AVAHI_SERVICE_DIR".");
+               break;
+#endif
+#ifdef GLOB_NOMATCH
+            case GLOB_NOMATCH:
+               avahi_log_info("No service file found in "AVAHI_SERVICE_DIR".");
+               break;
+#endif
+            default:
+               avahi_log_error("Failed to read "AVAHI_SERVICE_DIR".");
+               break;
+        }
+    
     else {
         for (p = globbuf.gl_pathv; *p; p++)
             load_file(*p);