Discussion:
[RFC 2/5] build: Use runstatedir instead of deriving it from localstatedir
(too old to reply)
Patrik Flykt
2015-10-30 10:44:41 UTC
Permalink
With $(runstatedir) being defined, use it instead of $(localstatedir)/run.
---
Makefile.am | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 4319c4c..96abab7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -161,8 +161,8 @@ endif

CLEANFILES = src/connman.conf $(BUILT_SOURCES) $(service_files)

-statedir = $(localstatedir)/run/connman
-vpn_statedir = $(localstatedir)/run/connman-vpn
+statedir = $(runstatedir)/connman
+vpn_statedir = $(runstatedir)/connman-vpn

if VPN
vpn_plugindir = $(libdir)/connman/plugins-vpn
--
2.1.4
Patrik Flykt
2015-10-30 10:44:40 UTC
Permalink
Provide an m4 macro defining runstatedir as $(localstatedir)/var. This
applies to automake versions < 2.70.
---
.gitignore | 2 ++
configure.ac | 4 ++++
m4/configmake.m4 | 15 +++++++++++++++
3 files changed, 21 insertions(+)
create mode 100644 m4/configmake.m4

diff --git a/.gitignore b/.gitignore
index bbb44c3..74acd7c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,6 +24,8 @@ missing
stamp-h1
autom4te.cache
test-driver
+m4/
+!m4/configmake.m4

connman.pc
include/connman
diff --git a/configure.ac b/configure.ac
index 69c0eeb..51482cb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,6 +1,8 @@
AC_PREREQ(2.60)
AC_INIT(connman, 1.30)

+AC_CONFIG_MACRO_DIR([m4])
+
AM_INIT_AUTOMAKE([foreign subdir-objects color-tests])
AC_CONFIG_HEADERS([config.h])

@@ -31,6 +33,8 @@ m4_ifdef([AC_LIBTOOL_TAGS], [AC_LIBTOOL_TAGS([])])
AC_DISABLE_STATIC
AC_PROG_LIBTOOL

+gl_CONFIGMAKE_PREP
+
AC_ARG_ENABLE(optimization, AC_HELP_STRING([--disable-optimization],
[disable code optimization through compiler]), [
if (test "${enableval}" = "no"); then
diff --git a/m4/configmake.m4 b/m4/configmake.m4
new file mode 100644
index 0000000..ef78ebe
--- /dev/null
+++ b/m4/configmake.m4
@@ -0,0 +1,15 @@
+# configmake.m4 serial 2
+dnl Copyright (C) 2010-2015 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+# gl_CONFIGMAKE_PREP
+# ------------------
+AC_DEFUN([gl_CONFIGMAKE_PREP],
+[
+ dnl Added in autoconf 2.70
+ if test "x$runstatedir" = x; then
+ AC_SUBST([runstatedir], ['${localstatedir}/run'])
+ fi
+])
--
2.1.4
Patrik Flykt
2015-10-30 10:44:42 UTC
Permalink
Create STATEDIR [/var]/run/connman and unconditionally write resolv.conf
to this directory.
---
src/main.c | 6 ++++++
src/resolver.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/main.c b/src/main.c
index e46fa7b..6cf6bc8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -623,6 +623,12 @@ int main(int argc, char *argv[])
perror("Failed to create storage directory");
}

+ if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+ if (errno != EEXIST)
+ perror("Failed to create storage directory");
+ }
+
umask(0077);

main_loop = g_main_loop_new(NULL, FALSE);
diff --git a/src/resolver.c b/src/resolver.c
index 6a64938..9db2756 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -130,7 +130,7 @@ static int resolvfile_export(void)

old_umask = umask(022);

- fd = open("/etc/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
+ fd = open(STATEDIR"/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
err = -errno;
--
2.1.4
Jukka Rissanen
2015-11-02 11:07:30 UTC
Permalink
Hi Patrik,
Post by Patrik Flykt
Create STATEDIR [/var]/run/connman and unconditionally write resolv.conf
to this directory.
---
src/main.c | 6 ++++++
src/resolver.c | 2 +-
2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/src/main.c b/src/main.c
index e46fa7b..6cf6bc8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -623,6 +623,12 @@ int main(int argc, char *argv[])
perror("Failed to create storage directory");
}
+ if (mkdir(STATEDIR, S_IRUSR | S_IWUSR | S_IXUSR |
+ S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) < 0) {
+ if (errno != EEXIST)
+ perror("Failed to create storage directory");
+ }
+
It might be better if the STATEDIR creation would be done in outside of
connman like by tmpfiles.d or similar. Then we could fallback to older
behaviour (== writing resolv.conf to /etc) if STATEDIR does not exist.
With the current code, the libc resolving might not work if user has not
managed to correctly setup /etc/resolv.conf to be link
into /var/run/connman/resolv.conf
Post by Patrik Flykt
umask(0077);
main_loop = g_main_loop_new(NULL, FALSE);
diff --git a/src/resolver.c b/src/resolver.c
index 6a64938..9db2756 100644
--- a/src/resolver.c
+++ b/src/resolver.c
@@ -130,7 +130,7 @@ static int resolvfile_export(void)
old_umask = umask(022);
- fd = open("/etc/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
+ fd = open(STATEDIR"/resolv.conf", O_RDWR | O_CREAT | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) {
Here could fallback to older behavior and write to /etc if the new
directory does not exist.
Post by Patrik Flykt
err = -errno;
Cheers,
Jukka
Patrik Flykt
2015-11-02 12:39:44 UTC
Permalink
Hi,
Post by Jukka Rissanen
It might be better if the STATEDIR creation would be done in outside
of connman like by tmpfiles.d or similar. Then we could fallback to
older behaviour (== writing resolv.conf to /etc) if STATEDIR does not
exist. With the current code, the libc resolving might not work if
user has not managed to correctly setup /etc/resolv.conf to be link
into /var/run/connman/resolv.conf
Yes, this is a safer option. I'll update the patch accordingly.

Cheers,

Patrik

Patrik Flykt
2015-10-30 10:44:43 UTC
Permalink
Add tmpfiles.d support for unconditionally creating a symlink from
[/var]/run/connman/resolv.conf to /etc/resolv.conf.

To keep the same behavior as before, the configuration file is
installed to tmpfiles.d. If /etc/resolv.conf behavior needs to be
specified differently by a distribution, do not install the
tmpfiles.d configuration file.
---
Makefile.am | 17 +++++++++++++----
configure.ac | 8 ++++++++
scripts/connman_resolvconf.conf.in | 1 +
3 files changed, 22 insertions(+), 4 deletions(-)
create mode 100644 scripts/connman_resolvconf.conf.in

diff --git a/Makefile.am b/Makefile.am
index 96abab7..95082c1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,9 +63,11 @@ endif

if SYSTEMD
systemdunitdir = @SYSTEMD_UNITDIR@
-
systemdunit_DATA = src/connman.service

+tmpfilesdir = @SYSTEMD_TMPFILESDIR@
+nodist_tmpfiles_DATA = scripts/connman_resolvconf.conf
+
if VPN
systemdunit_DATA += vpn/connman-vpn.service
endif
@@ -153,7 +155,8 @@ vpn_connman_vpnd_LDFLAGS = -Wl,--export-dynamic \
-Wl,--version-script=$(srcdir)/vpn/vpn.ver
endif

-BUILT_SOURCES = $(local_headers) src/builtin.h $(service_files) scripts/connman
+BUILT_SOURCES = $(local_headers) src/builtin.h $(service_files) \
+ scripts/connman scripts/connman_resolvconf.conf

if VPN
BUILT_SOURCES += vpn/builtin.h
@@ -386,7 +389,8 @@ EXTRA_DIST += doc/overview-api.txt doc/behavior-api.txt \
doc/connman.8.in doc/connman-vpn.8.in

EXTRA_DIST += src/main.conf \
- src/eduroam.config
+ src/eduroam.config \
+ scripts/connman_resolvconf.conf.in

MANUAL_PAGES += doc/connmanctl.1 doc/connman.conf.5 \
doc/connman-service.config.5 doc/connman-vpn.conf.5 \
@@ -457,7 +461,8 @@ do_subst = $(AM_V_GEN)$(SED) \
-e 's,[@]sysconfdir[@],$(sysconfdir),g' \
-e 's,[@]storagedir[@],$(storagedir),g' \
-e 's,[@]vpn_storagedir[@],$(vpn_storagedir),g' \
- -e 's,[@]localstatedir[@],$(localstatedir),g'
+ -e 's,[@]localstatedir[@],$(localstatedir),g' \
+ -e 's,[@]runstatedir[@],$(runstatedir),g'

%.1 : %.1.in
$(AM_V_at)$(MKDIR_P) $(dir $@)
@@ -479,6 +484,10 @@ scripts/connman: scripts/connman.in Makefile
$(AM_V_at)$(MKDIR_P) $(dir $@)
$(do_subst) < $< > $@

+scripts/connman_resolvconf.conf: scripts/connman_resolvconf.conf.in
+ $(AM_V_at)$(MKDIR_P) $(dir $@)
+ $(do_subst) < $< > $@
+
include/connman/version.h: include/version.h
$(AM_V_at)$(MKDIR_P) include/connman
$(AM_V_GEN)$(LN_S) $(abs_top_builddir)/$< $@
diff --git a/configure.ac b/configure.ac
index 51482cb..b51d6b3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -254,6 +254,14 @@ if (test -n "${path_systemdunit}"); then
fi
AM_CONDITIONAL(SYSTEMD, test -n "${path_systemdunit}")

+AC_ARG_WITH([tmpfilesdir], AC_HELP_STRING([--with-tmpfilesdir=DIR],
+ [path to systemd tmpfiles.d directory]), [path_tmpfiles=${withval}],
+ [path_tmpfiles="`$PKG_CONFIG --variable=tmpfilesdir systemd`"])
+if (test -n "${path_tmpfiles}"); then
+ SYSTEMD_TMPFILESDIR="${path_tmpfiles}"
+ AC_SUBST(SYSTEMD_TMPFILESDIR)
+fi
+
PKG_CHECK_MODULES(XTABLES, xtables >= 1.4.11, dummy=yes,
AC_MSG_ERROR(Xtables library is required))
AC_SUBST(XTABLES_CFLAGS)
diff --git a/scripts/connman_resolvconf.conf.in b/scripts/connman_resolvconf.conf.in
new file mode 100644
index 0000000..e47dc07
--- /dev/null
+++ b/scripts/connman_resolvconf.conf.in
@@ -0,0 +1 @@
+L+ /etc/resolv.conf - - - - @runstatedir@/connman/resolv.conf
--
2.1.4
Patrik Flykt
2015-10-30 10:44:44 UTC
Permalink
Add init script functionality to create a symlink by default from
[/var]/run/connman/resolv.conf to /etc/resolv.conf.
---
scripts/connman.in | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/scripts/connman.in b/scripts/connman.in
index 1692b95..9cc5895 100644
--- a/scripts/connman.in
+++ b/scripts/connman.in
@@ -9,6 +9,10 @@ if [ -f @sysconfdir@/default/connman ] ; then
. @sysconfdir@/default/connman
fi

+if [ "HANDLE_RESOLVCONF" != "no" ] ; then
+ ln -sf @runstatedir@/connman/resolv.conf /etc/
+fi
+
set -e

do_start() {
--
2.1.4
Loading...