[ekg2-commit] ekg2: sessions.c (HEAD) stuff.c (HEAD) themes.c (HEAD) [darkjames]

CVS commit cvs w toxygen.net
Śro, 2 Maj 2007, 16:23:57 CEST


Module name:	ekg2
Changes by:	darkjames	2007-05-02 16:23:54

Modified files:
	sessions.c stuff.c themes.c

Log message:
- Disable session locking by default.
- Fix /session --lock uid_of_session (use 's' variable instead of 'session' one. don't segv on no session)
- lock_fd -1, 0 is proper fd.
- always close fd when flock() fail, not only when EWOULDBLOCK
- fix segv on /session --unlock (when no session)
- fix info about /session --unlock usage
What todo/ to think:
 - if smb change config_session_locks value, what should we do?
 - on exit always close (session->lock_fd)
 - use fcntl() instead of flock() ?
 - info about locking/unlocking... && when session is not locked.

Index: sessions.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/sessions.c,v
diff -d -u -r1.122 -r1.123
--- sessions.c	1 May 2007 14:09:07 -0000	1.122
+++ sessions.c	2 May 2007 14:23:54 -0000	1.123
@@ -167,6 +167,7 @@
 	s->uid 		= xstrdup(uid);
 	s->status 	= EKG_STATUS_NA;
 	s->plugin 	= pl;
+	s->lock_fd	= -1;
 	
 	list_add_sorted(&sessions, s, 0, session_compare);
 
@@ -1251,16 +1252,24 @@
 				printq("session_doesnt_exist", params[1]);
 				return -1;
 			}
-		} else
-			s = session;
-		if (!config_session_locks)
+		} else s = session;
+
+		if (!s) {
+			printq("invalid_session");
+			return -1;
+		}
+
+		if (!config_session_locks) {
+/*			printq("var_not_set", name, "session_locks"); */
 			return 0;
-		if (config_session_locks == 1 && session->lock_fd) {
-			print("session_locked", session_name(session));
+		}
+
+		if (config_session_locks == 1 && s->lock_fd != -1) {
+			printq("session_locked", session_name(s));
 			return -1;
 		}
 
-		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(session), "-lock")), 1);
+		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(s), "-lock")), 1);
 		xfree(tmp);
 		fd = open(path,
 				O_CREAT|O_WRONLY
@@ -1272,7 +1281,7 @@
 
 		if (fd == -1) {
 			if (errno == EEXIST) {
-				print("session_locked", session_name(session));
+				printq("session_locked", session_name(s));
 				return -1;
 			} else if (errno != ENXIO) {
 					/* XXX, be more loud? */
@@ -1283,19 +1292,22 @@
 
 		if (config_session_locks == 1) {
 			if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
-				if (errno == EWOULDBLOCK) {
-					print("session_locked", session_name(session));
+				int flock_errno = errno;
+
+				close(fd);
+	
+				if (flock_errno == EWOULDBLOCK) {
+					printq("session_locked", session_name(s));
 					return -1;
 				} else {
-					debug_error("session_command(), lock's flock() failed with errno=%d\n", errno);
-					close(fd); /* if we can't lock, we don't need fd */
+					debug_error("session_command(), lock's flock() failed with errno=%d\n", flock_errno);
 					return 0;
 				}
 			}
-			session->lock_fd = fd;
+			s->lock_fd = fd;
 		} else
 			close(fd);
-
+		/* XXX, info about lock */
 		return 0;
 	}
 
@@ -1304,18 +1316,26 @@
 		const char *path;
 		char *tmp;
 
-		if (!config_session_locks)
+		if (!session) {
+			printq("invalid_session");
+			return -1;
+		}
+
+		if (!config_session_locks) {
+/*			printq("var_not_set", name, "session_locks"); */
 			return 0;
+		}
 
-		if (config_session_locks == 1 && (fd = session->lock_fd)) {
+		if (config_session_locks == 1 && ((fd = session->lock_fd) != -1)) {
 			flock(fd, LOCK_UN);
 			close(fd);
-			session->lock_fd = 0;
+			session->lock_fd = -1;
 		}
 
 		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(session), "-lock")), 0);
 		xfree(tmp);
 		unlink(path);
+		/* XXX, info about unlock */
 		return 0;
 	}
 

Index: stuff.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/stuff.c,v
diff -d -u -r1.187 -r1.188
--- stuff.c	1 May 2007 14:09:07 -0000	1.187
+++ stuff.c	2 May 2007 14:23:54 -0000	1.188
@@ -167,7 +167,7 @@
 int config_lastlog_display_all = 0;
 int config_version = 0;
 char *config_exit_exec = NULL;
-int config_session_locks = 1; /* flock() by default */
+int config_session_locks = 0;
 
 char *last_search_first_name = NULL;
 char *last_search_last_name = NULL;

Index: themes.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/themes.c,v
diff -d -u -r1.176 -r1.177
--- themes.c	1 May 2007 14:09:07 -0000	1.176
+++ themes.c	2 May 2007 14:23:54 -0000	1.177
@@ -1859,7 +1859,8 @@
 	format_add("session_format_alias", "%T%1%n/%2", 1);
 	format_add("session_cannot_change", _("%! Can't change session in query window%n\n"), 1);
 	format_add("session_password_changed", _("%> %|(%1) Looks like you're changing password in connected session. This does only set password on the client-side. If you want you change your account password, please use dedicated function (e.g. /passwd)."), 1);
-	format_add("session_locked", _("%! %|Session %T%1%n is currently locked. If there aren't any other copy of EKG2 using it, please call:\n\t%c/session --unlock %1%n\nto unlock it.\n"), 1);
+	format_add("session_locked", _("%! %|Session %T%1%n is currently locked. If there aren't any other copy of EKG2 using it, please call: %c/session --unlock%n to unlock it.\n"), 1);
+	format_add("session_not_locked", _("%! Session %T%1%n is not locked"), 1);
 
 	format_add("metacontact_list", "%> %T%1%n", 1);
 	format_add("metacontact_list_empty", "%! Metacontact list is empty\n", 1);


Więcej informacji o liście dyskusyjnej ekg2-commit