aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Ginda <rginda@chromium.org>2015-08-14 16:13:53 -0700
committerRobert Ginda <rginda@chromium.org>2015-08-14 16:27:12 -0700
commitc90ce4497d2255dd05dd89ab77f1f95829dd7cc3 (patch)
treeae791715f4d7165232dba67b3d3f337cb82e89de
parentba42f48ab293072b0fb948375ed9048775eb60b1 (diff)
downloadavahi-c90ce4497d2255dd05dd89ab77f1f95829dd7cc3.tar.gz
Relax required defines
Made the following preprocessor defines optional: DAVAHI_DAEMON_RUNTIME_DIR Used as the parent of the the PID file. If left undefined, we just don't make or clean up a PID file. This will still be required if you're building with chroot support. AVAHI_SOCKET This was used for a simpler-than-dbus IPC mechanism over a domain socket. Now if left undefined, this simple_protocol code is not compiled in. AVAHI_CONFIG_DIR Was used to set up inotify watches to restart on config changes. Our main config file will be on a read-only partition. The services config file is still being watched via the AVAHI_SERVICE_DIR macro. AVAHI_DBUS_INTROSPECTION_DIR Location of the dbus xml files describing the avahi api. Now if left undefined we'll fail to respond to an introspection request over dbus. Change-Id: I509dfa393d6d6f0a4cdaff9fefa01adbf9d4216b
-rw-r--r--avahi-daemon/Android.mk11
-rw-r--r--avahi-daemon/chroot.c13
-rw-r--r--avahi-daemon/dbus-util.c2
-rw-r--r--avahi-daemon/main.c35
-rw-r--r--avahi-daemon/static-hosts.c2
5 files changed, 47 insertions, 16 deletions
diff --git a/avahi-daemon/Android.mk b/avahi-daemon/Android.mk
index 61509b4..689227c 100644
--- a/avahi-daemon/Android.mk
+++ b/avahi-daemon/Android.mk
@@ -10,7 +10,6 @@ LOCAL_REQUIRED_MODULES := init.$(LOCAL_INIT_SERVICE).rc
LOCAL_SRC_FILES := \
main.c \
- simple-protocol.c \
static-services.c \
static-hosts.c \
ini-file-parser.c \
@@ -73,13 +72,9 @@ LOCAL_CFLAGS := \
-Wno-cast-qual \
-fno-strict-aliasing \
-DDEBUG_TRAP=__asm__\(\"int\ $3\"\) \
- -DAVAHI_DAEMON_RUNTIME_DIR=\"/data/misc/avahi/daemon/\" \
- -DAVAHI_SOCKET=\"/dev/socket/avahi\" \
- -DAVAHI_SERVICE_DIR=\"/data/misc/avahi/services\" \
- -DAVAHI_CONFIG_FILE=\"/system/etc/avahi/avahi-daemon.conf\" \
- -DAVAHI_HOSTS_FILE=\"/system/etc/avahi/avahi-hosts\" \
- -DAVAHI_DBUS_INTROSPECTION_DIR=\"/usr/local/share/dbus/interfaces\" \
- -DAVAHI_CONFIG_DIR=\"/system/etc/avahi\" \
+ -DAVAHI_CONFIG_FILE=\"/system/etc/avahi-daemon.conf\" \
+ -DAVAHI_HOSTS_FILE=\"/data/misc/avahi/hosts\" \
+ -DAVAHI_SERVICE_DIR=\"/data/misc/avahi/services/\" \
-DUSE_EXPAT_H \
-DDBUS_VERSION_MAJOR=1 \
-DDBUS_VERSION_MINOR=6 \
diff --git a/avahi-daemon/chroot.c b/avahi-daemon/chroot.c
index ccd56be..c649bc1 100644
--- a/avahi-daemon/chroot.c
+++ b/avahi-daemon/chroot.c
@@ -81,8 +81,9 @@ static const char* const get_file_name_table[AVAHI_CHROOT_MAX] = {
static const char *const unlink_file_name_table[AVAHI_CHROOT_MAX] = {
NULL,
NULL,
- NULL,
+ NULL
#ifdef HAVE_DBUS
+ ,
NULL,
NULL,
NULL,
@@ -91,10 +92,16 @@ static const char *const unlink_file_name_table[AVAHI_CHROOT_MAX] = {
NULL,
NULL,
NULL,
- NULL,
+ NULL
+#endif
+#ifdef AVAHI_DAEMON_RUNTIME_DIR
+ ,
+ AVAHI_DAEMON_RUNTIME_DIR"/pid"
#endif
- AVAHI_DAEMON_RUNTIME_DIR"/pid",
+#ifdef AVAHI_SOCKET
+ ,
AVAHI_SOCKET
+#endif
};
static int helper_fd = -1;
diff --git a/avahi-daemon/dbus-util.c b/avahi-daemon/dbus-util.c
index 994c5d3..f4db04f 100644
--- a/avahi-daemon/dbus-util.c
+++ b/avahi-daemon/dbus-util.c
@@ -258,6 +258,7 @@ fail:
}
DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m, const char *fname) {
+#ifdef AVAHI_DBUS_INTROSPECTION_DIR
char *contents, *path;
DBusError error;
@@ -289,6 +290,7 @@ DBusHandlerResult avahi_dbus_handle_introspect(DBusConnection *c, DBusMessage *m
fail:
if (dbus_error_is_set(&error))
dbus_error_free(&error);
+#endif
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
diff --git a/avahi-daemon/main.c b/avahi-daemon/main.c
index dc30fda..d746fa6 100644
--- a/avahi-daemon/main.c
+++ b/avahi-daemon/main.c
@@ -74,12 +74,15 @@
#include "setproctitle.h"
#include "main.h"
-#include "simple-protocol.h"
#include "static-services.h"
#include "static-hosts.h"
#include "ini-file-parser.h"
#include "sd-daemon.h"
+#ifdef AVAHI_SOCKET
+#include "simple-protocol.h"
+#endif
+
#ifdef HAVE_DBUS
#include "dbus-protocol.h"
#endif
@@ -369,7 +372,9 @@ static void server_callback(AvahiServer *s, AvahiServerState state, void *userda
if (c->publish_dns_servers && c->publish_dns_servers[0])
dns_servers_entry_group = add_dns_servers(s, dns_servers_entry_group, c->publish_dns_servers);
+#ifdef AVAHI_SOCKET
simple_protocol_restart_queries();
+#endif
break;
case AVAHI_SERVER_COLLISION: {
@@ -921,11 +926,15 @@ static void add_inotify_watches(void) {
|IN_ONLYDIR
#endif
);
+
+#ifdef AVAHI_CONFIG_DIR
inotify_add_watch(inotify_fd, c ? "/" : AVAHI_CONFIG_DIR, IN_CLOSE_WRITE|IN_DELETE|IN_DELETE_SELF|IN_MOVED_FROM|IN_MOVED_TO|IN_MOVE_SELF
#ifdef IN_ONLYDIR
|IN_ONLYDIR
#endif
);
+#endif
+
}
#endif
@@ -947,7 +956,10 @@ static void add_kqueue_watches(void) {
c = config.use_chroot;
#endif
+#ifdef AVAHI_CONFIG_DIR
add_kqueue_watch(c ? "/" : AVAHI_CONFIG_DIR);
+#endif
+
add_kqueue_watch(c ? "/services" : AVAHI_SERVICE_DIR);
}
@@ -1154,8 +1166,10 @@ static int run_server(DaemonConfig *c) {
goto finish;
}
+#ifdef AVAHI_SOCKET
if (simple_protocol_setup(poll_api) < 0)
goto finish;
+#endif
#ifdef HAVE_DBUS
if (c->enable_dbus) {
@@ -1272,7 +1286,9 @@ finish:
remove_dns_server_entry_groups();
+#ifdef AVAHI_SOCKET
simple_protocol_shutdown();
+#endif
#ifdef HAVE_DBUS
if (c->enable_dbus)
@@ -1384,9 +1400,14 @@ static int drop_root(void) {
}
static const char* pid_file_proc(void) {
+#ifdef AVAHI_DAEMON_RUNTIME_DIR
return AVAHI_DAEMON_RUNTIME_DIR"/pid";
+#else
+ return NULL;
+#endif
}
+#ifdef AVAHI_DAEMON_RUNTIME_DIR
static int make_runtime_dir(void) {
int r = -1;
mode_t u;
@@ -1434,6 +1455,7 @@ fail:
umask(u);
return r;
}
+#endif
static void set_one_rlimit(int resource, rlim_t limit, const char *name) {
struct rlimit rl;
@@ -1628,8 +1650,10 @@ int main(int argc, char *argv[]) {
daemon_unblock_sigs(-1);
#endif
+#ifdef AVAHI_DAEMON_RUNTIME_DIR
if (make_runtime_dir() < 0)
goto finish;
+#endif
if (config.drop_root) {
#ifdef ENABLE_CHROOT
@@ -1649,11 +1673,14 @@ int main(int argc, char *argv[]) {
}
if (daemon_pid_file_create() < 0) {
- avahi_log_error("Failed to create PID file: %s", strerror(errno));
-
if (config.daemonize)
daemon_retval_send(1);
- goto finish;
+
+ if (pid_file_proc() != NULL) {
+ avahi_log_error("Failed to create PID file: %s",
+ strerror(errno));
+ goto finish;
+ }
} else
wrote_pid_file = 1;
diff --git a/avahi-daemon/static-hosts.c b/avahi-daemon/static-hosts.c
index 6e6def6..b57f0e5 100644
--- a/avahi-daemon/static-hosts.c
+++ b/avahi-daemon/static-hosts.c
@@ -171,7 +171,7 @@ void static_hosts_load(int in_chroot) {
FILE *f;
unsigned int line = 0;
StaticHost *h, *next;
- const char *filename = in_chroot ? "/hosts" : AVAHI_CONFIG_DIR "/hosts";
+ const char *filename = AVAHI_HOSTS_FILE;
if (!(f = fopen(filename, "r"))) {
if (errno != ENOENT)