Add option "host-name-from-machine-id=" (from upstream).

This commit is contained in:
ajacoutot 2014-02-07 07:48:03 +00:00
parent 520c2a9bc0
commit 8628796481
3 changed files with 91 additions and 6 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.99 2013/11/28 10:53:28 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.100 2014/02/07 07:48:03 ajacoutot Exp $
ONLY_FOR_ARCHS-mono= ${MONO_ARCHS}
@ -26,7 +26,7 @@ PKGNAME-qt3= avahi-qt3-${V}
PKGNAME-qt4= avahi-qt4-${V}
PKGNAME-ui= avahi-ui-${V}
REVISION-main= 12
REVISION-main= 13
REVISION-gtk= 5
REVISION-gtk3= 5
REVISION-gui= 8
@ -260,6 +260,9 @@ pre-configure:
perl -pi -e 's,-ldl,,g' ${WRKSRC}/configure \
${WRKSRC}/avahi-client/Makefile.in \
${WRKSRC}/avahi-daemon/Makefile.in
perl -pi -e "s,/var/lib/dbus,/var/db/dbus,g;" \
-e "s,/etc/machine-id,${SYSCONFDIR}/machine-id,g" \
${WRKSRC}/avahi-daemon/main.c
for i in ${PC_FILES}; do \
perl -pi -e 's,Libs:,Libs: -pthread,;' \
-e 's,Cflags:,Cflags: -pthread,' ${WRKSRC}/$${i}.in; done

View File

@ -1,7 +1,67 @@
$OpenBSD: patch-avahi-daemon_main_c,v 1.7 2013/01/26 10:25:31 ajacoutot Exp $
--- avahi-daemon/main.c.orig Thu Nov 18 04:00:26 2010
+++ avahi-daemon/main.c Sat Jan 26 10:40:53 2013
@@ -1101,8 +1101,10 @@ static int run_server(DaemonConfig *c) {
$OpenBSD: patch-avahi-daemon_main_c,v 1.8 2014/02/07 07:48:03 ajacoutot Exp $
From 147cdce70b22ae7cee9fb4fe123db40952f31c9e Mon Sep 17 00:00:00 2001
From: David Zeuthen <zeuthen@chromium.org>
Date: Tue, 5 Mar 2013 11:52:38 -0800
Subject: [PATCH] avahi-daemon: add option "host-name-from-machine-id="
--- avahi-daemon/main.c.orig Fri Feb 7 08:37:36 2014
+++ avahi-daemon/main.c Fri Feb 7 08:37:45 2014
@@ -65,6 +65,7 @@
#include <avahi-core/publish.h>
#include <avahi-core/dns-srv-rr.h>
#include <avahi-core/log.h>
+#include <avahi-core/util.h>
#ifdef ENABLE_CHROOT
#include "chroot.h"
@@ -576,6 +577,29 @@ static int parse_usec(const char *s, AvahiUsec *u) {
return 0;
}
+static char *get_machine_id(void) {
+ int fd;
+ char buf[32];
+
+ fd = open("/etc/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ if (fd == -1 && errno == ENOENT)
+ fd = open("/var/lib/dbus/machine-id", O_RDONLY|O_CLOEXEC|O_NOCTTY);
+ if (fd == -1)
+ return NULL;
+
+ /* File is on a filesystem so we never get EINTR or partial reads */
+ if (read(fd, buf, sizeof buf) != sizeof buf) {
+ close(fd);
+ return NULL;
+ }
+ close(fd);
+
+ /* Contents can be lower, upper and even mixed case so normalize */
+ avahi_strdown(buf);
+
+ return avahi_strndup(buf, sizeof buf);
+}
+
static int load_config_file(DaemonConfig *c) {
int r = -1;
AvahiIniFile *f;
@@ -631,6 +655,15 @@ static int load_config_file(DaemonConfig *c) {
c->server_config.use_iff_running = is_yes(p->value);
else if (strcasecmp(p->key, "disallow-other-stacks") == 0)
c->server_config.disallow_other_stacks = is_yes(p->value);
+ else if (strcasecmp(p->key, "host-name-from-machine-id") == 0) {
+ if (*(p->value) == 'y' || *(p->value) == 'Y') {
+ char *machine_id = get_machine_id();
+ if (machine_id != NULL) {
+ avahi_free(c->server_config.host_name);
+ c->server_config.host_name = machine_id;
+ }
+ }
+ }
#ifdef HAVE_DBUS
else if (strcasecmp(p->key, "enable-dbus") == 0) {
@@ -1101,8 +1134,10 @@ static int run_server(DaemonConfig *c) {
ignore_signal(SIGPIPE);

View File

@ -0,0 +1,22 @@
$OpenBSD: patch-man_avahi-daemon_conf_5_xml_in,v 1.1 2014/02/07 07:48:03 ajacoutot Exp $
From 147cdce70b22ae7cee9fb4fe123db40952f31c9e Mon Sep 17 00:00:00 2001
From: David Zeuthen <zeuthen@chromium.org>
Date: Tue, 5 Mar 2013 11:52:38 -0800
Subject: [PATCH] avahi-daemon: add option "host-name-from-machine-id="
--- man/avahi-daemon.conf.5.xml.in.orig Fri Feb 18 19:36:33 2011
+++ man/avahi-daemon.conf.5.xml.in Fri Feb 7 08:37:45 2014
@@ -40,6 +40,12 @@
</option>
<option>
+ <p><opt>host-name-from-machine-id=</opt> Takes a boolean
+ value ("yes" or "no"). If set to "yes" avahi-daemon
+ will use the machine-id as name on the LAN.</p>
+ </option>
+
+ <option>
<p><opt>domain-name=</opt> Set the default domain name avahi-daemon
tries to register its host name and services on the LAN in. If
omitted defaults to ".local".</p>