[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/03: tests: Make 'close-on-exec.sh' systemd test more robus
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/03: tests: Make 'close-on-exec.sh' systemd test more robust. |
Date: |
Fri, 28 Apr 2023 18:40:39 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit 37322bd7b6b675a59effce37de6f891c70ced474
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Apr 28 22:55:40 2023 +0200
tests: Make 'close-on-exec.sh' systemd test more robust.
On some machines like relatively slow aarch64-linux boxes, the Guile
program spawned by 'connect_to_server 5556' would crash with ECONNRESET,
thus causing the test to fail. The fix here is to systematically accept
incoming connections for 'systemd-ctor', which should be deterministic.
* tests/close-on-exec.sh: Change C program to accept the client
connection when LISTEN_FDS is defined. Increase the expected FD count
for 'systemd-ctor'.
---
tests/close-on-exec.sh | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/tests/close-on-exec.sh b/tests/close-on-exec.sh
index 6c625db..20438eb 100644
--- a/tests/close-on-exec.sh
+++ b/tests/close-on-exec.sh
@@ -43,6 +43,8 @@ cat > "$c_file" <<EOF
#include <sys/types.h>
#include <dirent.h>
#include <string.h>
+#include <sys/socket.h>
+#include <assert.h>
int
main (int argc, char *argv[])
@@ -52,6 +54,14 @@ main (int argc, char *argv[])
size_t count;
FILE *log;
+ if (getenv ("LISTEN_FDS") != NULL) /* systemd */
+ {
+ struct sockaddr_storage address;
+ socklen_t len;
+ int fd = accept (3, (struct sockaddr *) &address, &len);
+ assert (fd >= 0);
+ }
+
dir = opendir ("/proc/self/fd");
chdir ("/proc/self/fd");
for (count = 0, ent = NULL; ent = readdir (dir), ent != NULL; )
@@ -170,13 +180,13 @@ do
connect_to_server 5555
test $(cat "$fd_count") -eq 4
- # Spawn the systemd service by starting it (it actually immediately stops
- # instead of calling 'accept', but it doesn't matter). This one must have
- # 4 open file descriptors, the 4th one being the socket.
+ # Spawn the systemd service by starting it. This one must have
+ # 5 open file descriptors: one for the listening socket, and one for the
+ # accepted client connection (plus one for /proc/self/fd).
$herd enable systemd-ctor
$herd start systemd-ctor
connect_to_server 5556
- test $(cat "$fd_count") -eq 5
+ test $(cat "$fd_count") -eq 6
$herd stop systemd-ctor
$herd restart forkexec-ctor