[systemd-devel] [RFC 1/6] proxy-discoveryd: Basic core added

Tomasz Bursztyka tomasz.bursztyka at linux.intel.com
Fri Apr 10 05:17:38 PDT 2015


This currently does nothing besides providing the basic skeleton for the
daemon to be developped.

proxy-discoveryd is a daemon that will manage the network proxy
configuration per-network interface. It will provide those through DBus,
and thus it will be possible for any application to know what proxies to
use, if any, when relevant.
---
 .gitignore                                     |  1 +
 Makefile.am                                    | 26 +++++++++++
 configure.ac                                   | 11 +++++
 src/proxy-discovery/proxy-discoveryd-manager.c | 65 ++++++++++++++++++++++++++
 src/proxy-discovery/proxy-discoveryd.c         | 65 ++++++++++++++++++++++++++
 src/proxy-discovery/proxy-discoveryd.h         | 38 +++++++++++++++
 units/.gitignore                               |  1 +
 units/systemd-proxy-discoveryd.service.in      | 18 +++++++
 8 files changed, 225 insertions(+)
 create mode 100644 src/proxy-discovery/proxy-discoveryd-manager.c
 create mode 100644 src/proxy-discovery/proxy-discoveryd.c
 create mode 100644 src/proxy-discovery/proxy-discoveryd.h
 create mode 100644 units/systemd-proxy-discoveryd.service.in

diff --git a/.gitignore b/.gitignore
index 875ada5..f479d37 100644
--- a/.gitignore
+++ b/.gitignore
@@ -108,6 +108,7 @@
 /systemd-notify
 /systemd-nspawn
 /systemd-path
+/systemd-proxy-discoveryd
 /systemd-pull
 /systemd-quotacheck
 /systemd-random-seed
diff --git a/Makefile.am b/Makefile.am
index 0a57389..3f4e4d3 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5889,6 +5889,32 @@ EXTRA_DIST += \
 endif
 
 # ------------------------------------------------------------------------------
+if ENABLE_PROXY_DISCOVERYD
+
+rootlibexec_PROGRAMS += \
+	systemd-proxy-discoveryd
+
+systemd_proxy_discoveryd_SOURCES = \
+	src/proxy-discovery/proxy-discoveryd.c \
+	src/proxy-discovery/proxy-discoveryd.h \
+	src/proxy-discovery/proxy-discoveryd-manager.c
+
+systemd_proxy_discoveryd_LDADD = \
+	libsystemd-internal.la \
+	libsystemd-shared.la
+
+nodist_systemunit_DATA += \
+	units/systemd-proxy-discoveryd.service
+
+EXTRA_DIST += \
+	units/systemd-proxy-discoveryd.service.in
+
+CLEANFILES += \
+	units/systemd-proxy-discoveryd.service
+
+endif
+
+# ------------------------------------------------------------------------------
 if ENABLE_LOGIND
 systemd_logind_SOURCES = \
 	src/login/logind.c \
diff --git a/configure.ac b/configure.ac
index 960b15d..3db3230 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1139,6 +1139,16 @@ AS_IF([test "x$enable_networkd" != "xno"], [
 AM_CONDITIONAL(ENABLE_NETWORKD, [test "x$have_networkd" = "xyes"])
 
 # ------------------------------------------------------------------------------
+have_proxy_discoveryd=no
+AC_ARG_ENABLE(proxy-discoveryd, AS_HELP_STRING([--disable-proxy-discoveryd], [disable proxy-discoveryd]))
+AS_IF([test "x$enable_proxy_discoveryd" != "xno"], [
+	AC_DEFINE(ENABLE_PROXY_DISCOVERYD, 1, [Define if proxy-discoveryd support is to be enabled])
+	have_proxy_discoveryd=yes
+	M4_DEFINES="$M4_DEFINES -DENABLE_PROXY_DISCOVERYD"
+])
+AM_CONDITIONAL(ENABLE_PROXY_DISCOVERYD, [test "x$have_proxy_discoveryd" = "xyes"])
+
+# ------------------------------------------------------------------------------
 have_efi=no
 AC_ARG_ENABLE(efi, AS_HELP_STRING([--disable-efi], [disable EFI support]))
 if test "x$enable_efi" != "xno"; then
@@ -1560,6 +1570,7 @@ AC_MSG_RESULT([
         localed:                 ${have_localed}
         networkd:                ${have_networkd}
         resolved:                ${have_resolved}
+	proxy-discoveryd:        ${have_proxy_discoveryd}
         default DNS servers:     ${DNS_SERVERS}
         coredump:                ${have_coredump}
         polkit:                  ${have_polkit}
diff --git a/src/proxy-discovery/proxy-discoveryd-manager.c b/src/proxy-discovery/proxy-discoveryd-manager.c
new file mode 100644
index 0000000..3aaec68
--- /dev/null
+++ b/src/proxy-discovery/proxy-discoveryd-manager.c
@@ -0,0 +1,65 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright (C) 2015 Intel Corporation. All rights reserved.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "proxy-discoveryd.h"
+
+int manager_new(Manager **ret) {
+        _cleanup_manager_free_ Manager *m = NULL;
+        int r;
+
+        assert(ret);
+
+        m = new0(Manager, 1);
+        if (!m)
+                return -ENOMEM;
+
+        r = sd_event_default(&m->event);
+        if (r < 0)
+                return r;
+
+        r = sd_event_set_watchdog(m->event, true);
+        if (r < 0)
+                return r;
+
+        r = sd_event_add_signal(m->event, NULL, SIGTERM, NULL, NULL);
+        if (r < 0)
+                return r;
+
+        r = sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL);
+        if (r < 0)
+                return r;
+
+        *ret = m;
+        m = NULL;
+
+        return 0;
+}
+
+Manager *manager_free(Manager *m) {
+        if (!m)
+                return NULL;
+
+        sd_event_unref(m->event);
+
+        free(m);
+
+        return NULL;
+}
diff --git a/src/proxy-discovery/proxy-discoveryd.c b/src/proxy-discovery/proxy-discoveryd.c
new file mode 100644
index 0000000..f023312
--- /dev/null
+++ b/src/proxy-discovery/proxy-discoveryd.c
@@ -0,0 +1,65 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+ This file is part of systemd.
+
+ Copyright (C) 2015 Intel Corporation. All rights reserved.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "sd-event.h"
+#include "sd-daemon.h"
+
+#include "proxy-discoveryd.h"
+
+int main(int argc, char *argv[]) {
+        _cleanup_manager_free_ Manager *m = NULL;
+        int r;
+
+        log_set_target(LOG_TARGET_AUTO);
+        log_parse_environment();
+        log_open();
+
+        if (argc != 1) {
+                log_error("This program takes no arguments.");
+                r = -EINVAL;
+                goto out;
+        }
+
+        r = manager_new(&m);
+        if (r < 0) {
+                log_error_errno(r, "Could not create manager: %m");
+                goto out;
+        }
+
+        sd_notify(false,
+                  "READY=1\n"
+                  "STATUS=Processing requests...");
+
+        r = sd_event_loop(m->event);
+        if (r < 0) {
+                log_error_errno(r, "Event loop failed: %m");
+                goto out;
+        }
+
+        sd_event_get_exit_code(m->event, &r);
+
+out:
+        sd_notify(false,
+                  "STOPPING=1\n"
+                  "STATUS=Shutting down...");
+
+        return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
+}
diff --git a/src/proxy-discovery/proxy-discoveryd.h b/src/proxy-discovery/proxy-discoveryd.h
new file mode 100644
index 0000000..125abc0
--- /dev/null
+++ b/src/proxy-discovery/proxy-discoveryd.h
@@ -0,0 +1,38 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright (C) 2015 Intel Corporation. All rights reserved.
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include "sd-event.h"
+
+#include "util.h"
+
+typedef struct Manager Manager;
+
+struct Manager {
+        sd_event *event;
+};
+
+int manager_new(Manager **ret);
+Manager *manager_free(Manager *m);
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
+#define _cleanup_manager_free_ _cleanup_(manager_freep)
diff --git a/units/.gitignore b/units/.gitignore
index ad469c1..63ae1af 100644
--- a/units/.gitignore
+++ b/units/.gitignore
@@ -51,6 +51,7 @@
 /systemd-networkd.service
 /systemd-nspawn at .service
 /systemd-poweroff.service
+/systemd-proxy-discoveryd.service
 /systemd-quotacheck.service
 /systemd-random-seed.service
 /systemd-reboot.service
diff --git a/units/systemd-proxy-discoveryd.service.in b/units/systemd-proxy-discoveryd.service.in
new file mode 100644
index 0000000..7ac02e0
--- /dev/null
+++ b/units/systemd-proxy-discoveryd.service.in
@@ -0,0 +1,18 @@
+# This file is part of systemd.
+#
+# systemd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or
+# (at your option) any later version.
+
+[Unit]
+Description=Proxy service
+DefaultDependencies=no
+Requires=dbus.socket
+After=dbus.socket
+Before=remote-fs.target
+
+[Service]
+Restart=on-failure
+ExecStart=@rootlibexecdir@/systemd-proxy-discoveryd
+StandardOutput=null
-- 
2.0.5



More information about the systemd-devel mailing list