]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
socket: provide function for closing reusable sockets
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 20 Nov 2023 12:34:38 +0000 (13:34 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Tue, 21 Nov 2023 11:38:39 +0000 (12:38 +0100)
socket.c
socket.h

index ba4625da7391ecdf8aeee45df87a3029b34de83a..bc98a4fe53554eb58d937f1f4e7eb722d73e825e 100644 (file)
--- a/socket.c
+++ b/socket.c
@@ -1336,16 +1336,11 @@ SCK_Initialise(int family)
 void
 SCK_Finalise(void)
 {
-  int fd;
-
   ARR_DestroyInstance(recv_sck_messages);
   ARR_DestroyInstance(recv_headers);
   ARR_DestroyInstance(recv_messages);
 
-  for (fd = first_reusable_fd; fd < first_reusable_fd + reusable_fds; fd++)
-    close(fd);
-  reusable_fds = 0;
-  first_reusable_fd = 0;
+  SCK_CloseReusableSockets();
 
   initialised = 0;
 }
@@ -1495,6 +1490,19 @@ SCK_IsReusable(int fd)
 
 /* ================================================== */
 
+void
+SCK_CloseReusableSockets(void)
+{
+  int fd;
+
+  for (fd = first_reusable_fd; fd < first_reusable_fd + reusable_fds; fd++)
+    close(fd);
+  reusable_fds = 0;
+  first_reusable_fd = 0;
+}
+
+/* ================================================== */
+
 int
 SCK_SetIntOption(int sock_fd, int level, int name, int value)
 {
index a2a1fd334fd728e8715e2ba544fbbaa78f4e4d95..8b178e2f7afc7dcb2cce23d841706d866cc1661d 100644 (file)
--- a/socket.h
+++ b/socket.h
@@ -112,6 +112,9 @@ extern int SCK_OpenUnixSocketPair(int flags, int *other_fd);
 /* Check if a file descriptor was passed from the service manager */
 extern int SCK_IsReusable(int sock_fd);
 
+/* Close all reusable sockets before finalisation (e.g. in a helper process) */
+extern void SCK_CloseReusableSockets(void);
+
 /* Set and get a socket option of int size */
 extern int SCK_SetIntOption(int sock_fd, int level, int name, int value);
 extern int SCK_GetIntOption(int sock_fd, int level, int name, int *value);