[Uludag-commits] r10051 - in trunk/comar/comar: include src

svn-uludag at uludag.org.tr svn-uludag at uludag.org.tr
1 Kas 2006 Çar 13:05:31 EET


Author: gurer
Date: Wed Nov  1 13:05:31 2006
New Revision: 10051

Modified:
   trunk/comar/comar/include/process.h
   trunk/comar/comar/src/main.c
   trunk/comar/comar/src/process.c
   trunk/comar/comar/src/rpc_unix.c
Log:
yeni stop mantığı:
sigterm gelince (elle yada service comar stop ile)

Ana süreç yeni çağrı başlatmayı keser, rpc sürecine CMD_SHUTDOWN yollar,
rpc ve event dışında çocuğu kalmadığında sonlanır.

Rpc süreci CMD_SHUTDOWN geldikten sonra yeni bağlantı kabul etmez,
dış soketini kapatır.

Böylece package-manager çomar üzerinden çomar güncellerken sorun
çıkmayacak. Package-manager'ın pisi işlemi dışarıya kapanan eski
çomarla devam ederken, pisi işleminden yapılan config çağrıları
yeni çomara bağlanarak güncel çomar üzerinden yapılacak.

comar --stop yada kill -9 (comarpid) ise eski mantıkla çalışıyor,
çocuk süreçlere sigterm'den sonra işlerini bitirmek için en fazla
3 saniye verip sonra sigkill ile kapatıyor.


Modified: trunk/comar/comar/include/process.h
=================================================================
--- trunk/comar/comar/include/process.h	(original)
+++ trunk/comar/comar/include/process.h	Wed Nov  1 13:05:31 2006
@@ -12,6 +12,8 @@
 
 #include "utility.h"
 
+extern int shutdown_activated;
+
 struct ipc_source {
 	void *chan;
 	unsigned int cookie;

Modified: trunk/comar/comar/src/main.c
=================================================================
--- trunk/comar/comar/src/main.c	(original)
+++ trunk/comar/comar/src/main.c	Wed Nov  1 13:05:31 2006
@@ -71,6 +71,7 @@
 	struct pack *pak;
 	int cmd;
 	int size;
+	int shut_rpc_flag = 0;
 
 	setlocale(LC_MESSAGES, "");
 	bindtextdomain("comar", "/usr/share/locale");
@@ -103,6 +104,14 @@
 
 	// Ready to run
 	while (1) {
+		if (shutdown_activated) {
+			if (!shut_rpc_flag) {
+				proc_put(proc_get_rpc(), CMD_SHUTDOWN, NULL, NULL);
+				shut_rpc_flag = 1;
+			}
+			if (my_proc.nr_children <= 2)
+				proc_finish();
+		}
 		if (1 == proc_listen(&p, &cmd, &size, 1)) {
 			log_debug(LOG_IPC, "Main switch, cmd=%d\n", cmd);
 			switch (cmd) {
@@ -119,7 +128,9 @@
 				case CMD_DUMP_PROFILE:
 				case CMD_EVENT:
 					proc_get(p, &ipc, pak, size);
-					job_start(cmd, &ipc, pak);
+					if (!shutdown_activated) {
+						job_start(cmd, &ipc, pak);
+					}
 					break;
 				case CMD_CANCEL:
 					proc_get(p, &ipc, pak, size);

Modified: trunk/comar/comar/src/process.c
=================================================================
--- trunk/comar/comar/src/process.c	(original)
+++ trunk/comar/comar/src/process.c	Wed Nov  1 13:05:31 2006
@@ -20,7 +20,7 @@
 #include "log.h"
 
 struct Proc my_proc;
-static int shutdown_activated = 0;
+int shutdown_activated = 0;
 static char *name_addr;
 static size_t name_size;
 
@@ -192,7 +192,8 @@
 proc_check_shutdown(void)
 {
 	if (shutdown_activated) {
-		proc_finish();
+		if (my_proc.parent.from != -1)
+			proc_finish();
 	}
 }
 
@@ -258,9 +259,7 @@
 	int i;
 	int max = 0;
 
-	if (shutdown_activated) {
-		proc_finish();
-	}
+	proc_check_shutdown();
 
 	FD_ZERO(fds);
 	sock = my_proc.parent.from;

Modified: trunk/comar/comar/src/rpc_unix.c
=================================================================
--- trunk/comar/comar/src/rpc_unix.c	(original)
+++ trunk/comar/comar/src/rpc_unix.c	Wed Nov  1 13:05:31 2006
@@ -49,6 +49,8 @@
 
 #define RPC_SHUTDOWN 42
 
+static int comar_shutting_down = 0;
+
 struct connection {
 	struct connection *next, *prev;
 	unsigned int cookie;
@@ -191,6 +193,9 @@
 	if (conns == c) conns = c->next;
 	if (c->notify_mask) free(c->notify_mask);
 	if (c->buffer) free(c->buffer);
+	if (comar_shutting_down) {
+		// FIXME: send a cancel all my jobs command here
+	}
 	free(c);
 }
 
@@ -458,8 +463,10 @@
 	struct connection *c;
 
 	// listening pipe
-	FD_SET(pipe_fd, fds);
-	if (pipe_fd >= max) max = pipe_fd + 1;
+	if (!comar_shutting_down) {
+		FD_SET(pipe_fd, fds);
+		if (pipe_fd >= max) max = pipe_fd + 1;
+	}
 	// current connections
 	for (c = conns; c; c = c->next) {
 		FD_SET(c->sock, fds);
@@ -474,7 +481,7 @@
 	struct connection *c;
 	int sock;
 
-	if (FD_ISSET(pipe_fd, fds)) {
+	if (!comar_shutting_down && FD_ISSET(pipe_fd, fds)) {
 		// new connection
 		struct sockaddr_un cname;
 		size_t size = sizeof(cname);
@@ -542,6 +549,11 @@
 		max = add_rpc_fds(&fds, max);
 		if (1 == proc_select_fds(&fds, max, &p, &cmd, &size, -1)) {
 			switch (cmd) {
+				case CMD_SHUTDOWN:
+					comar_shutting_down = 1;
+					close(pipe_fd);
+					pipe_fd = -1;
+					break;
 				case CMD_NOTIFY:
 					proc_get(p, &ipc, rpc_pak, size);
 					pack_get(rpc_pak, &s, &sz);


Uludag-commits mesaj listesiyle ilgili daha fazla bilgi