Bläddra i källkod

vccd: add sigpipe and remove that silly monitor

intirain 4 år sedan
förälder
incheckning
ef09c3ed18
6 ändrade filer med 26 tillägg och 58 borttagningar
  1. 1 1
      Makefile
  2. 1 5
      include/config.h
  3. 2 2
      include/vcc/version.h
  4. 21 17
      main.c
  5. 0 32
      monitor.c
  6. 1 1
      vcc.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 1
 VCCD_MINOR 		= 6
-VCCD_PATCH 		= 3
+VCCD_PATCH 		= 4
 VCCD_STR 		= -rc 
 
 VCCD_COMPILE_TIME 	= $(shell date)

+ 1 - 5
include/config.h

@@ -22,13 +22,9 @@
 #ifndef __CONFIG_H
 #define __CONFIG_H
 
-/* See: monitor.c. We'll enable command debug if you set this as 1 or 
- * other non-zero values. */
-#define CONFIG_ENABLE_MONITOR 		1
-
 /* See: monitor.c. We'll record the information about each function 
  * which called amalloc(). */
-#define CONFIG_ADVANCED_AMALLOC 	1
+#define CONFIG_ADVANCED_AMALLOC 	0
 
 #endif
 

+ 2 - 2
include/vcc/version.h

@@ -1,2 +1,2 @@
-#define VCCD_VERSION "vccd 1.6.3 Mon Apr  4 16:27:51 CST 2022 root"
-#define VCCD_SEMVER "vccd 1.6.3-rc "
+#define VCCD_VERSION "vccd 1.6.4 Tue Apr  5 14:04:38 CST 2022 root"
+#define VCCD_SEMVER "vccd 1.6.4-rc "

+ 21 - 17
main.c

@@ -32,6 +32,7 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <poll.h>
+#include <signal.h>
 
 #include <vcc/vcc.h>
 #include <vcc/vccd.h>
@@ -85,6 +86,8 @@ int becomes_daemon(void) {
 	(void) dup(0);
 	(void) dup(0);
 
+	setsid();
+
 	if (unlikely(fd = open("/var/run/vccd.pid", O_WRONLY | O_CREAT, 0644)) < 0) {
 		perror("open(/var/run/vccd.pid)");
 
@@ -140,16 +143,24 @@ static int init_socket(void) {
 	fds[0].fd = fd;
 	fds[0].events = POLLIN;
 
-	fds[1].fd = 0;
-	fds[1].events = POLLIN;
-
-	next_fd = 2;
+	next_fd = 1;
 
 	return fd;
 }
 
-static inline int prompt(void) {
-	fputs("> ", stderr);
+void sigpipe_handler(int nr) {
+	(void) nr;
+
+	vcc_log("SIGPIPE caused. \n");
+}
+
+static int setup_signals(void) {
+	struct sigaction act;
+
+	memset(&act, 0, sizeof(struct sigaction));
+	act.sa_handler = sigpipe_handler;
+	
+	sigaction(SIGPIPE, &act, NULL);
 
 	return 0;
 }
@@ -171,7 +182,9 @@ int main(int argc, const char **argv) {
 	init_socket();
 	users_init();
 
-	nfds_total = 2;
+	setup_signals();
+
+	nfds_total = 1;
 
 	if (unlikely(!(buf = amalloc(REQ_SIZE)))) {
 		vcc_log("*** malloc() failed\n");
@@ -179,8 +192,6 @@ int main(int argc, const char **argv) {
 		return 1;
 	}
 
-	prompt();
-
 	for (;;) {
 		nfds_ready = poll(fds, nfds_total, -1);
 
@@ -216,14 +227,7 @@ int main(int argc, const char **argv) {
 			nfds_total++;
 		}
 
-		if (fds[1].revents & POLLIN) {
-			monitor_cmd();
-			prompt();
-
-			fds[1].revents = 0;
-		}
-
-		for (i = 2; i < nfds_total; i++) {
+		for (i = 1; i < nfds_total; i++) {
 			if (fds[i].fd == -1) 
 				continue;
 

+ 0 - 32
monitor.c

@@ -39,38 +39,6 @@ struct klist_node amalloc_log = KLIST_NODE_INIT(&amalloc_log);
 
 #endif
 
-struct cmdtab {
-	char 	*cmd;
-	int 	(* do_cmd) (char *);
-} cmdtable[] = {
-	{ "mminfo", amalloc_report }, 
-	{ NULL, NULL }
-};
-
-
-int monitor_cmd(void) {
-	char buf[128];
-
-	read(0, buf, 128);
-
-#if CONFIG_ENABLE_MONITOR
-
-	struct cmdtab 	*c;
-
-	for (c = cmdtable; c->cmd; c++) 
-		if (!strncmp(c->cmd, buf, strlen(c->cmd))) 
-			return c->do_cmd(buf);
-
-	vcc_log("*** unknow command '%s'", buf);
-
-	return 1;
-#else
-	vcc_log("--- monitor on stdin disabled. \n");
-
-	return 0;
-#endif
-}
-
 
 void *__amalloc(int nbytes, const char *fn) {
 	void *p;

+ 1 - 1
vcc.c

@@ -271,7 +271,7 @@ int vcc_new_msg(int fd, struct vcc_request *req) {
 
 		sid = ntohl(req->session);
 
-		vcc_log("(%d) New message: %s\n", sid, msg);
+		vcc_log("(%d) New message\n", sid);
 
 		if (!sid) 
 			vcc_message_broadcast(msg, req->usrname, fd);