[PATCH 25/33] Systemd Socket ID retrieval

From: Janani Venkataraman
Date: Thu Mar 20 2014 - 05:42:51 EST


The socket created by systemd, waits for connections. Once it accepts a
connection, it starts the service which handles the request for a dump.

>From this service, we fetch the socket ID and perform the dump.

This is not functional yet, due to the absence of the sd-daemon.h header file.
For this we need to have the correct version of systemd which has this socket
option enabled.

Signed-off-by: Janani Venkataraman <jananive@xxxxxxxxxxxxxxxxxx>
---
src/coredump.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)

diff --git a/src/coredump.c b/src/coredump.c
index ab120b9..98a7146 100755
--- a/src/coredump.c
+++ b/src/coredump.c
@@ -39,6 +39,9 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <coredump.h>
+#if HAVE_SYSTEMD_SOCKET_SUPPORT
+#include <sd-daemon.h>
+#endif

/* Main Socket */
int socket_fd;
@@ -670,6 +673,35 @@ cleanup:
/* Systemd socket for self dump */
int socket_dump(void)
{
+ int n, ret;
+ char core_file[CORE_FILE_NAME_SZ];
+ struct ucred client_info;
+
+ /* Fetching the Socket ID from systemd */
+ n = sd_listen_fds(0);
+ if (n > 1) {
+ gencore_log("Too many file descriptors received.\n");
+ return -1;
+ } else if (n == 1)
+ new_sock = SD_LISTEN_FDS_START + 0;
+ else
+ return -1;
+
+ /* Receive the message */
+ ret = receive_core_filename(core_file);
+ if (ret)
+ return -1;
+
+ /* Fetch client PID */
+ ret = get_client_pid(&client_info);
+ if (ret)
+ return -1;
+
+ /* Dump process */
+ ret = dump_task(&client_info, core_file);
+ if (ret)
+ return -1;
+
return 0;
}
#endif

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/