lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140320094143.14878.80702.stgit@localhost.localdomain>
Date:	Thu, 20 Mar 2014 15:11:43 +0530
From:	Janani Venkataraman <jananive@...ux.vnet.ibm.com>
To:	linux-kernel@...r.kernel.org
Cc:	amwang@...hat.com, procps@...elists.org, rdunlap@...otime.net,
	james.hogan@...tec.com, aravinda@...ux.vnet.ibm.com, hch@....de,
	mhiramat@...hat.com, jeremy.fitzhardinge@...rix.com,
	xemul@...allels.com, d.hatayama@...fujitsu.com, coreutils@....org,
	kosaki.motohiro@...fujitsu.com, adobriyan@...il.com,
	util-linux@...r.kernel.org, tarundsk@...ux.vnet.ibm.com,
	vapier@...too.org, roland@...k.frob.com, ananth@...ux.vnet.ibm.com,
	gorcunov@...nvz.org, avagin@...nvz.org, oleg@...hat.com,
	eparis@...hat.com, suzuki@...ux.vnet.ibm.com, andi@...stfloor.org,
	tj@...nel.org, akpm@...ux-foundation.org,
	torvalds@...ux-foundation.org
Subject: [PATCH 20/33] Handling Requests

Accepting requests and then spawning a new thread to service them.

Signed-off-by: Janani Venkataraman <jananive@...ux.vnet.ibm.com>
---
 src/coredump.c |  110 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 110 insertions(+)
 mode change 100644 => 100755 src/coredump.c

diff --git a/src/coredump.c b/src/coredump.c
old mode 100644
new mode 100755
index d93f4b2..fadb7cd
--- a/src/coredump.c
+++ b/src/coredump.c
@@ -42,6 +42,11 @@
 /* Main Socket */
 int socket_fd;
 
+/* Accepted Socket */
+int new_sock;
+
+#define CORE_FILE_NAME_SZ 1000	/* Size of core file name */
+
 /* For logging all the messages */
 FILE *fp_log;
 
@@ -381,6 +386,100 @@ int block_on_request(void)
 	return 0;
 }
 
+/* Handles a SIGCHILD */
+void sigchild_handler(int sig)
+{
+	int pid;
+
+	pid = waitpid(0, &status, WNOHANG);
+
+	gencore_log("[%d]: Request handled by child with PID:%d and exited.\n",
+				pid_log, pid);
+}
+
+/* Sends message to client */
+int send_reply(int err)
+{
+	if (write(new_sock, &err , sizeof(err)) == -1) {
+		gencore_log("[%d]: Could not send message:%s\n",
+					pid_log, strerror(errno));
+		return -1;
+	}
+
+	gencore_log("[%d]: Message sent:%d\n", pid_log, err);
+
+	return 0;
+}
+
+/* Receive message from client */
+int receive_core_filename(char *core_file)
+{
+	memset(core_file, 0, CORE_FILE_NAME_SZ);
+	if (read(new_sock, core_file , CORE_FILE_NAME_SZ) == -1) {
+		send_reply(errno);
+		gencore_log("[%d]: Could not get Core file name:%s\n",
+					pid_log, strerror(errno));
+		return -1;
+	}
+
+	gencore_log("[%d]: Core file path received:%s\n", pid_log,
+						core_file);
+	/* Sending the acknowledgment */
+	send_reply(0);
+
+	return 0;
+}
+
+/* Services requests */
+int service_request(void)
+{
+	int ret;
+	char core_file[CORE_FILE_NAME_SZ];
+
+	/* Receive the message */
+	ret = receive_core_filename(core_file);
+	if (ret)
+		goto cleanup;
+
+cleanup:
+	close(new_sock);
+	if (ret == -1)
+		exit(EXIT_FAILURE);
+
+	exit(EXIT_SUCCESS);
+}
+
+/* Handles new requests */
+int handle_request(void)
+{
+	int pid_new;
+	struct sockaddr_un client_address;
+	socklen_t client_size = sizeof(client_address);
+
+	new_sock = accept(socket_fd, (struct sockaddr *) &client_address,
+							&client_size);
+	if (new_sock < 0) {
+		gencore_log("[%d]: Could not accept:%s\n", pid_log,
+							strerror(errno));
+		close(socket_fd);
+		fclose(fp_log);
+		return -1;
+	}
+
+	gencore_log("[%d]: Accepted.\n", pid_log);
+
+	gencore_log("[%d]: Handling request.\n", pid_log);
+
+	/* New thread to service request */
+	pid_new = fork();
+	if (pid_new == 0) {
+		pid_log = getpid();
+		service_request();
+	}
+
+	return 0;
+}
+
 /* Daemon for self dump */
 int daemon_dump(void)
 {
@@ -418,6 +517,9 @@ int daemon_dump(void)
 	/* Flush the log */
 	fflush(fp_log);
 
+	/* SIGCHILD - Signal handler */
+	signal(SIGCHLD, sigchild_handler);
+
 	while (1) {
 
 		/* Blocks on request */
@@ -427,6 +529,14 @@ int daemon_dump(void)
 
 		/* Flush the log */
 		fflush(fp_log);
+
+		/* Handle new connections */
+		ret = handle_request();
+		if (ret)
+			goto cleanup;
+
+		/* Flush the log */
+		fflush(fp_log);
 	}
 
 	return 0;

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ