Xen-Devel Archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 for-4.19 0/4] Drop libsystemd
@ 2024-05-16 18:58 Andrew Cooper
  2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 18:58 UTC (permalink / raw
  To: Xen-devel
  Cc: Andrew Cooper, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

On advise from the systemd leadership.

v2:
 * Import the free-standing example and use that to retain existing
   functionality.

Andrew Cooper (4):
  LICENSES: Add MIT-0 (MIT No Attribution)
  tools: Import standalone sd_notify() implementation from systemd
  tools/{c,o}xenstored: Don't link against libsystemd
  tools: Drop libsystemd as a dependency

 LICENSES/MIT-0                                |  31 +++
 automation/build/archlinux/current.dockerfile |   1 +
 .../build/suse/opensuse-leap.dockerfile       |   1 +
 .../build/suse/opensuse-tumbleweed.dockerfile |   1 +
 automation/build/ubuntu/focal.dockerfile      |   1 +
 config/Tools.mk.in                            |   2 -
 m4/systemd.m4                                 |   9 -
 tools/configure                               | 256 ------------------
 tools/include/xen-sd-notify.h                 |  98 +++++++
 tools/ocaml/xenstored/Makefile                |   2 -
 tools/ocaml/xenstored/systemd_stubs.c         |   2 +-
 tools/xenstored/Makefile                      |   5 -
 tools/xenstored/posix.c                       |   4 +-
 13 files changed, 136 insertions(+), 277 deletions(-)
 create mode 100644 LICENSES/MIT-0
 create mode 100644 tools/include/xen-sd-notify.h


base-commit: 977d98e67c2e929c62aa1f495fc4c6341c45abb5
-- 
2.30.2



^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution)
  2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
@ 2024-05-16 18:58 ` Andrew Cooper
  2024-05-16 22:14   ` Stefano Stabellini
  2024-05-17  8:07   ` Christian Lindig
  2024-05-16 18:58 ` [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd Andrew Cooper
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 18:58 UTC (permalink / raw
  To: Xen-devel
  Cc: Andrew Cooper, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

We are about to import code licensed under MIT-0.  It's compatible for us to
use, so identify it as a permitted license.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony@xenproject.org>
CC: Juergen Gross <jgross@suse.com>
CC: George Dunlap <George.Dunlap@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Christian Lindig <christian.lindig@citrix.com>
CC: Edwin Török <edwin.torok@cloud.com>

v2:
 * New
---
 LICENSES/MIT-0 | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 LICENSES/MIT-0

diff --git a/LICENSES/MIT-0 b/LICENSES/MIT-0
new file mode 100644
index 000000000000..70fb90ee3486
--- /dev/null
+++ b/LICENSES/MIT-0
@@ -0,0 +1,31 @@
+Valid-License-Identifier: MIT-0
+
+SPDX-URL: https://spdx.org/licenses/MIT-0.html
+
+Usage-Guide:
+
+  To use the MIT-0 License put the following SPDX tag/value pair into a
+  comment according to the placement guidelines in the licensing rules
+  documentation:
+    SPDX-License-Identifier: MIT-0
+
+License-Text:
+
+MIT No Attribution
+
+Copyright <year> <copyright holder>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd
  2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
  2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
@ 2024-05-16 18:58 ` Andrew Cooper
  2024-05-16 23:07   ` Marek Marczykowski-Górecki
  2024-05-23  8:21   ` Jürgen Groß
  2024-05-16 18:58 ` [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd Andrew Cooper
                   ` (2 subsequent siblings)
  4 siblings, 2 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 18:58 UTC (permalink / raw
  To: Xen-devel
  Cc: Andrew Cooper, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

... in order to avoid linking against the whole of libsystemd.

Only minimal changes to the upstream copy, to function as a drop-in
replacement for sd_notify() and as a header-only library.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony@xenproject.org>
CC: Juergen Gross <jgross@suse.com>
CC: George Dunlap <George.Dunlap@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Christian Lindig <christian.lindig@citrix.com>
CC: Edwin Török <edwin.torok@cloud.com>

v2:
 * New
---
 tools/include/xen-sd-notify.h | 98 +++++++++++++++++++++++++++++++++++
 1 file changed, 98 insertions(+)
 create mode 100644 tools/include/xen-sd-notify.h

diff --git a/tools/include/xen-sd-notify.h b/tools/include/xen-sd-notify.h
new file mode 100644
index 000000000000..eda9d8b22d9e
--- /dev/null
+++ b/tools/include/xen-sd-notify.h
@@ -0,0 +1,98 @@
+/* SPDX-License-Identifier: MIT-0 */
+
+/*
+ * Implement the systemd notify protocol without external dependencies.
+ * Supports both readiness notification on startup and on reloading,
+ * according to the protocol defined at:
+ * https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
+ * This protocol is guaranteed to be stable as per:
+ * https://systemd.io/PORTABILITY_AND_STABILITY/
+ *
+ * Differences from the upstream copy:
+ * - Rename/rework as a drop-in replacement for systemd/sd-daemon.h
+ * - Only take the subset Xen cares about
+ * - Respect -Wdeclaration-after-statement
+ */
+
+#ifndef XEN_SD_NOTIFY
+#define XEN_SD_NOTIFY
+
+#include <errno.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+static inline void xen_sd_closep(int *fd) {
+  if (!fd || *fd < 0)
+    return;
+
+  close(*fd);
+  *fd = -1;
+}
+
+static inline int xen_sd_notify(const char *message) {
+  union sockaddr_union {
+    struct sockaddr sa;
+    struct sockaddr_un sun;
+  } socket_addr = {
+    .sun.sun_family = AF_UNIX,
+  };
+  size_t path_length, message_length;
+  ssize_t written;
+  const char *socket_path;
+  int __attribute__((cleanup(sd_closep))) fd = -1;
+
+  /* Verify the argument first */
+  if (!message)
+    return -EINVAL;
+
+  message_length = strlen(message);
+  if (message_length == 0)
+    return -EINVAL;
+
+  /* If the variable is not set, the protocol is a noop */
+  socket_path = getenv("NOTIFY_SOCKET");
+  if (!socket_path)
+    return 0; /* Not set? Nothing to do */
+
+  /* Only AF_UNIX is supported, with path or abstract sockets */
+  if (socket_path[0] != '/' && socket_path[0] != '@')
+    return -EAFNOSUPPORT;
+
+  path_length = strlen(socket_path);
+  /* Ensure there is room for NUL byte */
+  if (path_length >= sizeof(socket_addr.sun.sun_path))
+    return -E2BIG;
+
+  memcpy(socket_addr.sun.sun_path, socket_path, path_length);
+
+  /* Support for abstract socket */
+  if (socket_addr.sun.sun_path[0] == '@')
+    socket_addr.sun.sun_path[0] = 0;
+
+  fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
+  if (fd < 0)
+    return -errno;
+
+  if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0)
+    return -errno;
+
+  written = write(fd, message, message_length);
+  if (written != (ssize_t) message_length)
+    return written < 0 ? -errno : -EPROTO;
+
+  return 1; /* Notified! */
+}
+
+static inline int sd_notify(int unset_environment, const char *message) {
+    int r = xen_sd_notify(message);
+
+    if (unset_environment)
+        unsetenv("NOTIFY_SOCKET");
+
+    return r;
+}
+
+#endif /* XEN_SD_NOTIFY */
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd
  2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
  2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
  2024-05-16 18:58 ` [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd Andrew Cooper
@ 2024-05-16 18:58 ` Andrew Cooper
  2024-05-23  8:22   ` Jürgen Groß
  2024-05-16 18:58 ` [PATCH v2 4/4] tools: Drop libsystemd as a dependency Andrew Cooper
  2024-05-17  8:06 ` [PATCH v2 for-4.19 0/4] Drop libsystemd Christian Lindig
  4 siblings, 1 reply; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 18:58 UTC (permalink / raw
  To: Xen-devel
  Cc: Andrew Cooper, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

Use the local freestanding wrapper instead.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony@xenproject.org>
CC: Juergen Gross <jgross@suse.com>
CC: George Dunlap <George.Dunlap@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Christian Lindig <christian.lindig@citrix.com>
CC: Edwin Török <edwin.torok@cloud.com>

v2:
 * Redo almost from scratch, using the freestanding wrapper instead.
---
 tools/ocaml/xenstored/Makefile        | 2 --
 tools/ocaml/xenstored/systemd_stubs.c | 2 +-
 tools/xenstored/Makefile              | 5 -----
 tools/xenstored/posix.c               | 4 ++--
 4 files changed, 3 insertions(+), 10 deletions(-)

diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
index e8aaecf2e630..a8b8bb64698e 100644
--- a/tools/ocaml/xenstored/Makefile
+++ b/tools/ocaml/xenstored/Makefile
@@ -4,8 +4,6 @@ include $(OCAML_TOPLEVEL)/common.make
 
 # Include configure output (config.h)
 CFLAGS += -include $(XEN_ROOT)/tools/config.h
-CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
-LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
 
 CFLAGS  += $(CFLAGS-y)
 CFLAGS  += $(APPEND_CFLAGS)
diff --git a/tools/ocaml/xenstored/systemd_stubs.c b/tools/ocaml/xenstored/systemd_stubs.c
index f4c875075abe..7dbbdd35bf30 100644
--- a/tools/ocaml/xenstored/systemd_stubs.c
+++ b/tools/ocaml/xenstored/systemd_stubs.c
@@ -25,7 +25,7 @@
 
 #if defined(HAVE_SYSTEMD)
 
-#include <systemd/sd-daemon.h>
+#include <xen-sd-notify.h>
 
 CAMLprim value ocaml_sd_notify_ready(value ignore)
 {
diff --git a/tools/xenstored/Makefile b/tools/xenstored/Makefile
index e0897ed1ba30..09adfe1d5064 100644
--- a/tools/xenstored/Makefile
+++ b/tools/xenstored/Makefile
@@ -9,11 +9,6 @@ xenstored: LDLIBS += $(LDLIBS_libxenctrl)
 xenstored: LDLIBS += -lrt
 xenstored: LDLIBS += $(SOCKET_LIBS)
 
-ifeq ($(CONFIG_SYSTEMD),y)
-$(XENSTORED_OBJS-y): CFLAGS += $(SYSTEMD_CFLAGS)
-xenstored: LDLIBS += $(SYSTEMD_LIBS)
-endif
-
 TARGETS := xenstored
 
 .PHONY: all
diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
index d88c82d972d7..6037d739d013 100644
--- a/tools/xenstored/posix.c
+++ b/tools/xenstored/posix.c
@@ -27,7 +27,7 @@
 #include <sys/socket.h>
 #include <sys/un.h>
 #if defined(HAVE_SYSTEMD)
-#include <systemd/sd-daemon.h>
+#include <xen-sd-notify.h>
 #endif
 #include <xen-tools/xenstore-common.h>
 
@@ -393,7 +393,7 @@ void late_init(bool live_update)
 #if defined(HAVE_SYSTEMD)
 	if (!live_update) {
 		sd_notify(1, "READY=1");
-		fprintf(stderr, SD_NOTICE "xenstored is ready\n");
+		fprintf(stderr, "xenstored is ready\n");
 	}
 #endif
 }
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [PATCH v2 4/4] tools: Drop libsystemd as a dependency
  2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
                   ` (2 preceding siblings ...)
  2024-05-16 18:58 ` [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd Andrew Cooper
@ 2024-05-16 18:58 ` Andrew Cooper
  2024-05-23  8:27   ` Jürgen Groß
  2024-05-23  8:44   ` Jürgen Groß
  2024-05-17  8:06 ` [PATCH v2 for-4.19 0/4] Drop libsystemd Christian Lindig
  4 siblings, 2 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 18:58 UTC (permalink / raw
  To: Xen-devel
  Cc: Andrew Cooper, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

There are no more users, and we want to disuade people from introducing new
users just for sd_notify() and friends.  Drop the dependency.

We still want the overall --with{,out}-systemd to gate the generation of the
service/unit/mount/etc files.

Rerun autogen.sh, and mark the dependency as removed in the build containers.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Anthony PERARD <anthony@xenproject.org>
CC: Juergen Gross <jgross@suse.com>
CC: George Dunlap <George.Dunlap@citrix.com>
CC: Jan Beulich <JBeulich@suse.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Christian Lindig <christian.lindig@citrix.com>
CC: Edwin Török <edwin.torok@cloud.com>

v2:
 * Only strip out the library check.
---
 automation/build/archlinux/current.dockerfile |   1 +
 .../build/suse/opensuse-leap.dockerfile       |   1 +
 .../build/suse/opensuse-tumbleweed.dockerfile |   1 +
 automation/build/ubuntu/focal.dockerfile      |   1 +
 config/Tools.mk.in                            |   2 -
 m4/systemd.m4                                 |   9 -
 tools/configure                               | 256 ------------------
 7 files changed, 4 insertions(+), 267 deletions(-)

diff --git a/automation/build/archlinux/current.dockerfile b/automation/build/archlinux/current.dockerfile
index 3e37ab5c40c1..d29f1358c2bd 100644
--- a/automation/build/archlinux/current.dockerfile
+++ b/automation/build/archlinux/current.dockerfile
@@ -37,6 +37,7 @@ RUN pacman -S --refresh --sysupgrade --noconfirm --noprogressbar --needed \
         sdl2 \
         spice \
         spice-protocol \
+        # systemd for Xen < 4.19
         systemd \
         transfig \
         usbredir \
diff --git a/automation/build/suse/opensuse-leap.dockerfile b/automation/build/suse/opensuse-leap.dockerfile
index 48d0d50d005d..3ef33458a07c 100644
--- a/automation/build/suse/opensuse-leap.dockerfile
+++ b/automation/build/suse/opensuse-leap.dockerfile
@@ -59,6 +59,7 @@ RUN zypper install -y --no-recommends \
         'pkgconfig(sdl2)' \
         python3-devel \
         python3-setuptools \
+        # systemd-devel for Xen < 4.19
         systemd-devel \
         tar \
         transfig \
diff --git a/automation/build/suse/opensuse-tumbleweed.dockerfile b/automation/build/suse/opensuse-tumbleweed.dockerfile
index 53542ba1f4d9..a793601c876d 100644
--- a/automation/build/suse/opensuse-tumbleweed.dockerfile
+++ b/automation/build/suse/opensuse-tumbleweed.dockerfile
@@ -60,6 +60,7 @@ RUN zypper install -y --no-recommends \
         'pkgconfig(sdl2)' \
         python3-devel \
         python3-setuptools \
+        # systemd-devel for Xen < 4.19
         systemd-devel \
         tar \
         transfig \
diff --git a/automation/build/ubuntu/focal.dockerfile b/automation/build/ubuntu/focal.dockerfile
index 7c6a4d07566b..078abd56d56f 100644
--- a/automation/build/ubuntu/focal.dockerfile
+++ b/automation/build/ubuntu/focal.dockerfile
@@ -34,6 +34,7 @@ RUN apt-get update && \
         libnl-3-dev \
         ocaml-nox \
         libfindlib-ocaml-dev \
+        # libsystemd-dev for Xen < 4.19
         libsystemd-dev \
         transfig \
         pandoc \
diff --git a/config/Tools.mk.in b/config/Tools.mk.in
index b54ab21f966b..50fbef841f3f 100644
--- a/config/Tools.mk.in
+++ b/config/Tools.mk.in
@@ -52,8 +52,6 @@ CONFIG_PYGRUB       := @pygrub@
 CONFIG_LIBFSIMAGE   := @libfsimage@
 
 CONFIG_SYSTEMD      := @systemd@
-SYSTEMD_CFLAGS      := @SYSTEMD_CFLAGS@
-SYSTEMD_LIBS        := @SYSTEMD_LIBS@
 XEN_SYSTEMD_DIR     := @SYSTEMD_DIR@
 XEN_SYSTEMD_MODULES_LOAD := @SYSTEMD_MODULES_LOAD@
 CONFIG_9PFS         := @ninepfs@
diff --git a/m4/systemd.m4 b/m4/systemd.m4
index 112dc11b5e05..e4fe51a8ba5f 100644
--- a/m4/systemd.m4
+++ b/m4/systemd.m4
@@ -41,15 +41,6 @@ AC_DEFUN([AX_ALLOW_SYSTEMD_OPTS], [
 ])
 
 AC_DEFUN([AX_CHECK_SYSTEMD_LIBS], [
-	PKG_CHECK_MODULES([SYSTEMD], [libsystemd-daemon],,
-		[PKG_CHECK_MODULES([SYSTEMD], [libsystemd >= 209])]
-        )
-	dnl pkg-config older than 0.24 does not set these for
-	dnl PKG_CHECK_MODULES() worth also noting is that as of version 208
-	dnl of systemd pkg-config --cflags currently yields no extra flags yet.
-	AC_SUBST([SYSTEMD_CFLAGS])
-	AC_SUBST([SYSTEMD_LIBS])
-
 	AS_IF([test "x$SYSTEMD_DIR" = x], [
 	    dnl In order to use the line below we need to fix upstream systemd
 	    dnl to properly ${prefix} for child variables in
diff --git a/tools/configure b/tools/configure
index 3d557234b319..b8faa1d520c5 100755
--- a/tools/configure
+++ b/tools/configure
@@ -9766,262 +9766,6 @@ $as_echo "#define HAVE_SYSTEMD 1" >>confdefs.h
 
 			systemd=y
 
-
-pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SYSTEMD" >&5
-$as_echo_n "checking for SYSTEMD... " >&6; }
-
-if test -n "$SYSTEMD_CFLAGS"; then
-    pkg_cv_SYSTEMD_CFLAGS="$SYSTEMD_CFLAGS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd-daemon" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-if test -n "$SYSTEMD_LIBS"; then
-    pkg_cv_SYSTEMD_LIBS="$SYSTEMD_LIBS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd-daemon\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd-daemon") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd-daemon" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-
-
-
-if test $pkg_failed = yes; then
-   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
-        _pkg_short_errors_supported=yes
-else
-        _pkg_short_errors_supported=no
-fi
-        if test $_pkg_short_errors_supported = yes; then
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
-        else
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd-daemon" 2>&1`
-        fi
-	# Put the nasty error message in config.log where it belongs
-	echo "$SYSTEMD_PKG_ERRORS" >&5
-
-
-pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SYSTEMD" >&5
-$as_echo_n "checking for SYSTEMD... " >&6; }
-
-if test -n "$SYSTEMD_CFLAGS"; then
-    pkg_cv_SYSTEMD_CFLAGS="$SYSTEMD_CFLAGS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd >= 209\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd >= 209") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd >= 209" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-if test -n "$SYSTEMD_LIBS"; then
-    pkg_cv_SYSTEMD_LIBS="$SYSTEMD_LIBS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd >= 209\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd >= 209") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd >= 209" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-
-
-
-if test $pkg_failed = yes; then
-   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
-        _pkg_short_errors_supported=yes
-else
-        _pkg_short_errors_supported=no
-fi
-        if test $_pkg_short_errors_supported = yes; then
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd >= 209" 2>&1`
-        else
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd >= 209" 2>&1`
-        fi
-	# Put the nasty error message in config.log where it belongs
-	echo "$SYSTEMD_PKG_ERRORS" >&5
-
-	as_fn_error $? "Package requirements (libsystemd >= 209) were not met:
-
-$SYSTEMD_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables SYSTEMD_CFLAGS
-and SYSTEMD_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
-elif test $pkg_failed = untried; then
-     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables SYSTEMD_CFLAGS
-and SYSTEMD_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
-else
-	SYSTEMD_CFLAGS=$pkg_cv_SYSTEMD_CFLAGS
-	SYSTEMD_LIBS=$pkg_cv_SYSTEMD_LIBS
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-elif test $pkg_failed = untried; then
-     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-pkg_failed=no
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for SYSTEMD" >&5
-$as_echo_n "checking for SYSTEMD... " >&6; }
-
-if test -n "$SYSTEMD_CFLAGS"; then
-    pkg_cv_SYSTEMD_CFLAGS="$SYSTEMD_CFLAGS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd >= 209\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd >= 209") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_CFLAGS=`$PKG_CONFIG --cflags "libsystemd >= 209" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-if test -n "$SYSTEMD_LIBS"; then
-    pkg_cv_SYSTEMD_LIBS="$SYSTEMD_LIBS"
- elif test -n "$PKG_CONFIG"; then
-    if test -n "$PKG_CONFIG" && \
-    { { $as_echo "$as_me:${as_lineno-$LINENO}: \$PKG_CONFIG --exists --print-errors \"libsystemd >= 209\""; } >&5
-  ($PKG_CONFIG --exists --print-errors "libsystemd >= 209") 2>&5
-  ac_status=$?
-  $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
-  test $ac_status = 0; }; then
-  pkg_cv_SYSTEMD_LIBS=`$PKG_CONFIG --libs "libsystemd >= 209" 2>/dev/null`
-		      test "x$?" != "x0" && pkg_failed=yes
-else
-  pkg_failed=yes
-fi
- else
-    pkg_failed=untried
-fi
-
-
-
-if test $pkg_failed = yes; then
-   	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-
-if $PKG_CONFIG --atleast-pkgconfig-version 0.20; then
-        _pkg_short_errors_supported=yes
-else
-        _pkg_short_errors_supported=no
-fi
-        if test $_pkg_short_errors_supported = yes; then
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --short-errors --print-errors --cflags --libs "libsystemd >= 209" 2>&1`
-        else
-	        SYSTEMD_PKG_ERRORS=`$PKG_CONFIG --print-errors --cflags --libs "libsystemd >= 209" 2>&1`
-        fi
-	# Put the nasty error message in config.log where it belongs
-	echo "$SYSTEMD_PKG_ERRORS" >&5
-
-	as_fn_error $? "Package requirements (libsystemd >= 209) were not met:
-
-$SYSTEMD_PKG_ERRORS
-
-Consider adjusting the PKG_CONFIG_PATH environment variable if you
-installed software in a non-standard prefix.
-
-Alternatively, you may set the environment variables SYSTEMD_CFLAGS
-and SYSTEMD_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details." "$LINENO" 5
-elif test $pkg_failed = untried; then
-     	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
-	{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
-$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
-as_fn_error $? "The pkg-config script could not be found or is too old.  Make sure it
-is in your PATH or set the PKG_CONFIG environment variable to the full
-path to pkg-config.
-
-Alternatively, you may set the environment variables SYSTEMD_CFLAGS
-and SYSTEMD_LIBS to avoid the need to call pkg-config.
-See the pkg-config man page for more details.
-
-To get pkg-config, see <http://pkg-config.freedesktop.org/>.
-See \`config.log' for more details" "$LINENO" 5; }
-else
-	SYSTEMD_CFLAGS=$pkg_cv_SYSTEMD_CFLAGS
-	SYSTEMD_LIBS=$pkg_cv_SYSTEMD_LIBS
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-else
-	SYSTEMD_CFLAGS=$pkg_cv_SYSTEMD_CFLAGS
-	SYSTEMD_LIBS=$pkg_cv_SYSTEMD_LIBS
-        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
-
-fi
-
-
-
 	if test "x$SYSTEMD_DIR" = x; then :
 
 	    	    	    	    	    	    	    	    	    	    	    	    	    SYSTEMD_DIR="\$(prefix)/lib/systemd/system/"
-- 
2.30.2



^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution)
  2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
@ 2024-05-16 22:14   ` Stefano Stabellini
  2024-05-17  8:07   ` Christian Lindig
  1 sibling, 0 replies; 15+ messages in thread
From: Stefano Stabellini @ 2024-05-16 22:14 UTC (permalink / raw
  To: Andrew Cooper
  Cc: Xen-devel, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

[-- Attachment #1: Type: text/plain, Size: 2296 bytes --]

On Thu, 16 May 2024, Andrew Cooper wrote:
> We are about to import code licensed under MIT-0.  It's compatible for us to
> use, so identify it as a permitted license.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>
> 
> v2:
>  * New
> ---
>  LICENSES/MIT-0 | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
>  create mode 100644 LICENSES/MIT-0
> 
> diff --git a/LICENSES/MIT-0 b/LICENSES/MIT-0
> new file mode 100644
> index 000000000000..70fb90ee3486
> --- /dev/null
> +++ b/LICENSES/MIT-0
> @@ -0,0 +1,31 @@
> +Valid-License-Identifier: MIT-0
> +
> +SPDX-URL: https://spdx.org/licenses/MIT-0.html
> +
> +Usage-Guide:
> +
> +  To use the MIT-0 License put the following SPDX tag/value pair into a
> +  comment according to the placement guidelines in the licensing rules
> +  documentation:
> +    SPDX-License-Identifier: MIT-0
> +
> +License-Text:
> +
> +MIT No Attribution
> +
> +Copyright <year> <copyright holder>
> +
> +Permission is hereby granted, free of charge, to any person obtaining a copy
> +of this software and associated documentation files (the "Software"), to deal
> +in the Software without restriction, including without limitation the rights
> +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> +copies of the Software, and to permit persons to whom the Software is
> +furnished to do so.
> +
> +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> +SOFTWARE.
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd
  2024-05-16 18:58 ` [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd Andrew Cooper
@ 2024-05-16 23:07   ` Marek Marczykowski-Górecki
  2024-05-16 23:09     ` Andrew Cooper
  2024-05-23  8:21   ` Jürgen Groß
  1 sibling, 1 reply; 15+ messages in thread
From: Marek Marczykowski-Górecki @ 2024-05-16 23:07 UTC (permalink / raw
  To: Andrew Cooper
  Cc: Xen-devel, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

[-- Attachment #1: Type: text/plain, Size: 1584 bytes --]

On Thu, May 16, 2024 at 07:58:02PM +0100, Andrew Cooper wrote:
> ... in order to avoid linking against the whole of libsystemd.
> 
> Only minimal changes to the upstream copy, to function as a drop-in
> replacement for sd_notify() and as a header-only library.

Maybe add explicit link to the original source?

> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>
> 
> v2:
>  * New
> ---
>  tools/include/xen-sd-notify.h | 98 +++++++++++++++++++++++++++++++++++
>  1 file changed, 98 insertions(+)
>  create mode 100644 tools/include/xen-sd-notify.h
> 
> diff --git a/tools/include/xen-sd-notify.h b/tools/include/xen-sd-notify.h
> new file mode 100644
> index 000000000000..eda9d8b22d9e
> --- /dev/null
> +++ b/tools/include/xen-sd-notify.h
> @@ -0,0 +1,98 @@

...

> +static inline void xen_sd_closep(int *fd) {

Static inline is one of the changes vs upstream, and gitlab-ci is not
happy about it:

/builds/xen-project/patchew/xen/tools/xenstored/../../tools/include/xen-sd-notify.h:45:3: error: cleanup argument not a function
   45 |   int __attribute__((cleanup(sd_closep))) fd = -1;
      |   ^~~

-- 
Best Regards,
Marek Marczykowski-Górecki
Invisible Things Lab

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd
  2024-05-16 23:07   ` Marek Marczykowski-Górecki
@ 2024-05-16 23:09     ` Andrew Cooper
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-16 23:09 UTC (permalink / raw
  To: Marek Marczykowski-Górecki
  Cc: Xen-devel, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török

On 17/05/2024 12:07 am, Marek Marczykowski-Górecki wrote:
> On Thu, May 16, 2024 at 07:58:02PM +0100, Andrew Cooper wrote:
>> ... in order to avoid linking against the whole of libsystemd.
>>
>> Only minimal changes to the upstream copy, to function as a drop-in
>> replacement for sd_notify() and as a header-only library.
> Maybe add explicit link to the original source?

Well, it is in the top of the file...

> diff --git a/tools/include/xen-sd-notify.h
> b/tools/include/xen-sd-notify.h new file mode 100644 index
> 000000000000..eda9d8b22d9e --- /dev/null +++
> b/tools/include/xen-sd-notify.h @@ -0,0 +1,98 @@ +/*
> SPDX-License-Identifier: MIT-0 */ + +/* + * Implement the systemd
> notify protocol without external dependencies. + * Supports both
> readiness notification on startup and on reloading, + * according to
> the protocol defined at: + *
> https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html+
> * This protocol is guaranteed to be stable as per: + *
> https://systemd.io/PORTABILITY_AND_STABILITY/+ *



>> +static inline void xen_sd_closep(int *fd) {
> Static inline is one of the changes vs upstream, and gitlab-ci is not
> happy about it:
>
> /builds/xen-project/patchew/xen/tools/xenstored/../../tools/include/xen-sd-notify.h:45:3: error: cleanup argument not a function
>    45 |   int __attribute__((cleanup(sd_closep))) fd = -1;
>       |   ^~~
>

Yes - victim of a last minute refactor.  I've fixed it up locally.

~Andrew


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 for-4.19 0/4] Drop libsystemd
  2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
                   ` (3 preceding siblings ...)
  2024-05-16 18:58 ` [PATCH v2 4/4] tools: Drop libsystemd as a dependency Andrew Cooper
@ 2024-05-17  8:06 ` Christian Lindig
  4 siblings, 0 replies; 15+ messages in thread
From: Christian Lindig @ 2024-05-17  8:06 UTC (permalink / raw
  To: Andrew Cooper
  Cc: Xen-devel, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török



> On 16 May 2024, at 19:58, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> On advise from the systemd leadership.
> 
> v2:
> * Import the free-standing example and use that to retain existing
>   functionality.
> 
> Andrew Cooper (4):
>  LICENSES: Add MIT-0 (MIT No Attribution)
>  tools: Import standalone sd_notify() implementation from systemd
>  tools/{c,o}xenstored: Don't link against libsystemd
>  tools: Drop libsystemd as a dependency
> 
> LICENSES/MIT-0                                |  31 +++
> automation/build/archlinux/current.dockerfile |   1 +
> .../build/suse/opensuse-leap.dockerfile       |   1 +
> .../build/suse/opensuse-tumbleweed.dockerfile |   1 +
> automation/build/ubuntu/focal.dockerfile      |   1 +
> config/Tools.mk.in                            |   2 -
> m4/systemd.m4                                 |   9 -
> tools/configure                               | 256 ------------------
> tools/include/xen-sd-notify.h                 |  98 +++++++
> tools/ocaml/xenstored/Makefile                |   2 -
> tools/ocaml/xenstored/systemd_stubs.c         |   2 +-
> tools/xenstored/Makefile                      |   5 -
> tools/xenstored/posix.c                       |   4 +-
> 13 files changed, 136 insertions(+), 277 deletions(-)
> create mode 100644 LICENSES/MIT-0
> create mode 100644 tools/include/xen-sd-notify.h
> 
> 
> base-commit: 977d98e67c2e929c62aa1f495fc4c6341c45abb5
> -- 
> 2.30.2
> 

Acked-by: Christian Lindig <christian.lindig@cloud.com>



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution)
  2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
  2024-05-16 22:14   ` Stefano Stabellini
@ 2024-05-17  8:07   ` Christian Lindig
  1 sibling, 0 replies; 15+ messages in thread
From: Christian Lindig @ 2024-05-17  8:07 UTC (permalink / raw
  To: Andrew Cooper
  Cc: Xen-devel, Anthony PERARD, Juergen Gross, George Dunlap,
	Jan Beulich, Stefano Stabellini, Julien Grall, Christian Lindig,
	Edwin Török



> On 16 May 2024, at 19:58, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> We are about to import code licensed under MIT-0.  It's compatible for us to
> use, so identify it as a permitted license.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>


Acked-by: Christian Lindig <christian.lindig@cloud.com>



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd
  2024-05-16 18:58 ` [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd Andrew Cooper
  2024-05-16 23:07   ` Marek Marczykowski-Górecki
@ 2024-05-23  8:21   ` Jürgen Groß
  1 sibling, 0 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-05-23  8:21 UTC (permalink / raw
  To: Andrew Cooper, Xen-devel
  Cc: Anthony PERARD, George Dunlap, Jan Beulich, Stefano Stabellini,
	Julien Grall, Christian Lindig, Edwin Török

On 16.05.24 20:58, Andrew Cooper wrote:
> ... in order to avoid linking against the whole of libsystemd.
> 
> Only minimal changes to the upstream copy, to function as a drop-in
> replacement for sd_notify() and as a header-only library.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

With s/cleanup(sd_closep)/cleanup(xen_sd_closep)/

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen

> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>
> 
> v2:
>   * New
> ---
>   tools/include/xen-sd-notify.h | 98 +++++++++++++++++++++++++++++++++++
>   1 file changed, 98 insertions(+)
>   create mode 100644 tools/include/xen-sd-notify.h
> 
> diff --git a/tools/include/xen-sd-notify.h b/tools/include/xen-sd-notify.h
> new file mode 100644
> index 000000000000..eda9d8b22d9e
> --- /dev/null
> +++ b/tools/include/xen-sd-notify.h
> @@ -0,0 +1,98 @@
> +/* SPDX-License-Identifier: MIT-0 */
> +
> +/*
> + * Implement the systemd notify protocol without external dependencies.
> + * Supports both readiness notification on startup and on reloading,
> + * according to the protocol defined at:
> + * https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
> + * This protocol is guaranteed to be stable as per:
> + * https://systemd.io/PORTABILITY_AND_STABILITY/
> + *
> + * Differences from the upstream copy:
> + * - Rename/rework as a drop-in replacement for systemd/sd-daemon.h
> + * - Only take the subset Xen cares about
> + * - Respect -Wdeclaration-after-statement
> + */
> +
> +#ifndef XEN_SD_NOTIFY
> +#define XEN_SD_NOTIFY
> +
> +#include <errno.h>
> +#include <stddef.h>
> +#include <stdlib.h>
> +#include <sys/socket.h>
> +#include <sys/un.h>
> +#include <unistd.h>
> +
> +static inline void xen_sd_closep(int *fd) {
> +  if (!fd || *fd < 0)
> +    return;
> +
> +  close(*fd);
> +  *fd = -1;
> +}
> +
> +static inline int xen_sd_notify(const char *message) {
> +  union sockaddr_union {
> +    struct sockaddr sa;
> +    struct sockaddr_un sun;
> +  } socket_addr = {
> +    .sun.sun_family = AF_UNIX,
> +  };
> +  size_t path_length, message_length;
> +  ssize_t written;
> +  const char *socket_path;
> +  int __attribute__((cleanup(sd_closep))) fd = -1;
> +
> +  /* Verify the argument first */
> +  if (!message)
> +    return -EINVAL;
> +
> +  message_length = strlen(message);
> +  if (message_length == 0)
> +    return -EINVAL;
> +
> +  /* If the variable is not set, the protocol is a noop */
> +  socket_path = getenv("NOTIFY_SOCKET");
> +  if (!socket_path)
> +    return 0; /* Not set? Nothing to do */
> +
> +  /* Only AF_UNIX is supported, with path or abstract sockets */
> +  if (socket_path[0] != '/' && socket_path[0] != '@')
> +    return -EAFNOSUPPORT;
> +
> +  path_length = strlen(socket_path);
> +  /* Ensure there is room for NUL byte */
> +  if (path_length >= sizeof(socket_addr.sun.sun_path))
> +    return -E2BIG;
> +
> +  memcpy(socket_addr.sun.sun_path, socket_path, path_length);
> +
> +  /* Support for abstract socket */
> +  if (socket_addr.sun.sun_path[0] == '@')
> +    socket_addr.sun.sun_path[0] = 0;
> +
> +  fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
> +  if (fd < 0)
> +    return -errno;
> +
> +  if (connect(fd, &socket_addr.sa, offsetof(struct sockaddr_un, sun_path) + path_length) != 0)
> +    return -errno;
> +
> +  written = write(fd, message, message_length);
> +  if (written != (ssize_t) message_length)
> +    return written < 0 ? -errno : -EPROTO;
> +
> +  return 1; /* Notified! */
> +}
> +
> +static inline int sd_notify(int unset_environment, const char *message) {
> +    int r = xen_sd_notify(message);
> +
> +    if (unset_environment)
> +        unsetenv("NOTIFY_SOCKET");
> +
> +    return r;
> +}
> +
> +#endif /* XEN_SD_NOTIFY */



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd
  2024-05-16 18:58 ` [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd Andrew Cooper
@ 2024-05-23  8:22   ` Jürgen Groß
  0 siblings, 0 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-05-23  8:22 UTC (permalink / raw
  To: Andrew Cooper, Xen-devel
  Cc: Anthony PERARD, George Dunlap, Jan Beulich, Stefano Stabellini,
	Julien Grall, Christian Lindig, Edwin Török

On 16.05.24 20:58, Andrew Cooper wrote:
> Use the local freestanding wrapper instead.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Juergen Gross <jgross@suse.com> # tools/xenstored


Juergen

> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>
> 
> v2:
>   * Redo almost from scratch, using the freestanding wrapper instead.
> ---
>   tools/ocaml/xenstored/Makefile        | 2 --
>   tools/ocaml/xenstored/systemd_stubs.c | 2 +-
>   tools/xenstored/Makefile              | 5 -----
>   tools/xenstored/posix.c               | 4 ++--
>   4 files changed, 3 insertions(+), 10 deletions(-)
> 
> diff --git a/tools/ocaml/xenstored/Makefile b/tools/ocaml/xenstored/Makefile
> index e8aaecf2e630..a8b8bb64698e 100644
> --- a/tools/ocaml/xenstored/Makefile
> +++ b/tools/ocaml/xenstored/Makefile
> @@ -4,8 +4,6 @@ include $(OCAML_TOPLEVEL)/common.make
>   
>   # Include configure output (config.h)
>   CFLAGS += -include $(XEN_ROOT)/tools/config.h
> -CFLAGS-$(CONFIG_SYSTEMD)  += $(SYSTEMD_CFLAGS)
> -LDFLAGS-$(CONFIG_SYSTEMD) += $(SYSTEMD_LIBS)
>   
>   CFLAGS  += $(CFLAGS-y)
>   CFLAGS  += $(APPEND_CFLAGS)
> diff --git a/tools/ocaml/xenstored/systemd_stubs.c b/tools/ocaml/xenstored/systemd_stubs.c
> index f4c875075abe..7dbbdd35bf30 100644
> --- a/tools/ocaml/xenstored/systemd_stubs.c
> +++ b/tools/ocaml/xenstored/systemd_stubs.c
> @@ -25,7 +25,7 @@
>   
>   #if defined(HAVE_SYSTEMD)
>   
> -#include <systemd/sd-daemon.h>
> +#include <xen-sd-notify.h>
>   
>   CAMLprim value ocaml_sd_notify_ready(value ignore)
>   {
> diff --git a/tools/xenstored/Makefile b/tools/xenstored/Makefile
> index e0897ed1ba30..09adfe1d5064 100644
> --- a/tools/xenstored/Makefile
> +++ b/tools/xenstored/Makefile
> @@ -9,11 +9,6 @@ xenstored: LDLIBS += $(LDLIBS_libxenctrl)
>   xenstored: LDLIBS += -lrt
>   xenstored: LDLIBS += $(SOCKET_LIBS)
>   
> -ifeq ($(CONFIG_SYSTEMD),y)
> -$(XENSTORED_OBJS-y): CFLAGS += $(SYSTEMD_CFLAGS)
> -xenstored: LDLIBS += $(SYSTEMD_LIBS)
> -endif
> -
>   TARGETS := xenstored
>   
>   .PHONY: all
> diff --git a/tools/xenstored/posix.c b/tools/xenstored/posix.c
> index d88c82d972d7..6037d739d013 100644
> --- a/tools/xenstored/posix.c
> +++ b/tools/xenstored/posix.c
> @@ -27,7 +27,7 @@
>   #include <sys/socket.h>
>   #include <sys/un.h>
>   #if defined(HAVE_SYSTEMD)
> -#include <systemd/sd-daemon.h>
> +#include <xen-sd-notify.h>
>   #endif
>   #include <xen-tools/xenstore-common.h>
>   
> @@ -393,7 +393,7 @@ void late_init(bool live_update)
>   #if defined(HAVE_SYSTEMD)
>   	if (!live_update) {
>   		sd_notify(1, "READY=1");
> -		fprintf(stderr, SD_NOTICE "xenstored is ready\n");
> +		fprintf(stderr, "xenstored is ready\n");
>   	}
>   #endif
>   }



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 4/4] tools: Drop libsystemd as a dependency
  2024-05-16 18:58 ` [PATCH v2 4/4] tools: Drop libsystemd as a dependency Andrew Cooper
@ 2024-05-23  8:27   ` Jürgen Groß
  2024-05-23  8:36     ` Andrew Cooper
  2024-05-23  8:44   ` Jürgen Groß
  1 sibling, 1 reply; 15+ messages in thread
From: Jürgen Groß @ 2024-05-23  8:27 UTC (permalink / raw
  To: Andrew Cooper, Xen-devel
  Cc: Anthony PERARD, George Dunlap, Jan Beulich, Stefano Stabellini,
	Julien Grall, Christian Lindig, Edwin Török

On 16.05.24 20:58, Andrew Cooper wrote:
> There are no more users, and we want to disuade people from introducing new
> users just for sd_notify() and friends.  Drop the dependency.
> 
> We still want the overall --with{,out}-systemd to gate the generation of the
> service/unit/mount/etc files.
> 
> Rerun autogen.sh, and mark the dependency as removed in the build containers.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: Anthony PERARD <anthony@xenproject.org>
> CC: Juergen Gross <jgross@suse.com>
> CC: George Dunlap <George.Dunlap@citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Christian Lindig <christian.lindig@citrix.com>
> CC: Edwin Török <edwin.torok@cloud.com>
> 
> v2:
>   * Only strip out the library check.
> ---
>   automation/build/archlinux/current.dockerfile |   1 +
>   .../build/suse/opensuse-leap.dockerfile       |   1 +
>   .../build/suse/opensuse-tumbleweed.dockerfile |   1 +
>   automation/build/ubuntu/focal.dockerfile      |   1 +
>   config/Tools.mk.in                            |   2 -
>   m4/systemd.m4                                 |   9 -
>   tools/configure                               | 256 ------------------
>   7 files changed, 4 insertions(+), 267 deletions(-)
> 
> diff --git a/automation/build/archlinux/current.dockerfile b/automation/build/archlinux/current.dockerfile
> index 3e37ab5c40c1..d29f1358c2bd 100644
> --- a/automation/build/archlinux/current.dockerfile
> +++ b/automation/build/archlinux/current.dockerfile
> @@ -37,6 +37,7 @@ RUN pacman -S --refresh --sysupgrade --noconfirm --noprogressbar --needed \
>           sdl2 \
>           spice \
>           spice-protocol \
> +        # systemd for Xen < 4.19

Does this work as intended? A comment between the parameters and no "\" at the
end of the line?


Juergen


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 4/4] tools: Drop libsystemd as a dependency
  2024-05-23  8:27   ` Jürgen Groß
@ 2024-05-23  8:36     ` Andrew Cooper
  0 siblings, 0 replies; 15+ messages in thread
From: Andrew Cooper @ 2024-05-23  8:36 UTC (permalink / raw
  To: Jürgen Groß, Xen-devel
  Cc: Anthony PERARD, George Dunlap, Jan Beulich, Stefano Stabellini,
	Julien Grall, Christian Lindig, Edwin Török

On 23/05/2024 9:27 am, Jürgen Groß wrote:
> On 16.05.24 20:58, Andrew Cooper wrote:
>> diff --git a/automation/build/archlinux/current.dockerfile
>> b/automation/build/archlinux/current.dockerfile
>> index 3e37ab5c40c1..d29f1358c2bd 100644
>> --- a/automation/build/archlinux/current.dockerfile
>> +++ b/automation/build/archlinux/current.dockerfile
>> @@ -37,6 +37,7 @@ RUN pacman -S --refresh --sysupgrade --noconfirm
>> --noprogressbar --needed \
>>           sdl2 \
>>           spice \
>>           spice-protocol \
>> +        # systemd for Xen < 4.19
>
> Does this work as intended? A comment between the parameters and no
> "\" at the
> end of the line?

Sadly, yes.

Comments are stripped out on a line-granuar basis, prior to Docker
interpreting the remainder.

This is the approved way to do comments in dockerfiles, and we already
have other examples of this in our dockerfiles.

See e.g. a0e29b316363d9 for what I'll be doing with these comments in
~3y time.

~Andrew


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH v2 4/4] tools: Drop libsystemd as a dependency
  2024-05-16 18:58 ` [PATCH v2 4/4] tools: Drop libsystemd as a dependency Andrew Cooper
  2024-05-23  8:27   ` Jürgen Groß
@ 2024-05-23  8:44   ` Jürgen Groß
  1 sibling, 0 replies; 15+ messages in thread
From: Jürgen Groß @ 2024-05-23  8:44 UTC (permalink / raw
  To: Andrew Cooper, Xen-devel
  Cc: Anthony PERARD, George Dunlap, Jan Beulich, Stefano Stabellini,
	Julien Grall, Christian Lindig, Edwin Török

On 16.05.24 20:58, Andrew Cooper wrote:
> There are no more users, and we want to disuade people from introducing new
> users just for sd_notify() and friends.  Drop the dependency.
> 
> We still want the overall --with{,out}-systemd to gate the generation of the
> service/unit/mount/etc files.
> 
> Rerun autogen.sh, and mark the dependency as removed in the build containers.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Juergen Gross <jgross@suse.com>


Juergen



^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2024-05-23  8:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-16 18:58 [PATCH v2 for-4.19 0/4] Drop libsystemd Andrew Cooper
2024-05-16 18:58 ` [PATCH v2 1/4] LICENSES: Add MIT-0 (MIT No Attribution) Andrew Cooper
2024-05-16 22:14   ` Stefano Stabellini
2024-05-17  8:07   ` Christian Lindig
2024-05-16 18:58 ` [PATCH v2 2/4] tools: Import standalone sd_notify() implementation from systemd Andrew Cooper
2024-05-16 23:07   ` Marek Marczykowski-Górecki
2024-05-16 23:09     ` Andrew Cooper
2024-05-23  8:21   ` Jürgen Groß
2024-05-16 18:58 ` [PATCH v2 3/4] tools/{c,o}xenstored: Don't link against libsystemd Andrew Cooper
2024-05-23  8:22   ` Jürgen Groß
2024-05-16 18:58 ` [PATCH v2 4/4] tools: Drop libsystemd as a dependency Andrew Cooper
2024-05-23  8:27   ` Jürgen Groß
2024-05-23  8:36     ` Andrew Cooper
2024-05-23  8:44   ` Jürgen Groß
2024-05-17  8:06 ` [PATCH v2 for-4.19 0/4] Drop libsystemd Christian Lindig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).