[ekg2-commit] ekg2: sessions.c (HEAD) sessions.h (HEAD) [peres]

CVS commit cvs w toxygen.net
Czw, 3 Maj 2007, 13:40:41 CEST


Module name:	ekg2
Changes by:	peres	2007-05-03 13:40:39

Modified files:
	sessions.c sessions.h

Log message:
Be no-flock()-aware (then session_locks == 1 should work like == 2).

Index: sessions.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/sessions.c,v
diff -d -u -r1.125 -r1.126
--- sessions.c	3 May 2007 11:11:44 -0000	1.125
+++ sessions.c	3 May 2007 11:40:38 -0000	1.126
@@ -167,7 +167,9 @@
 	s->uid 		= xstrdup(uid);
 	s->status 	= EKG_STATUS_NA;
 	s->plugin 	= pl;
+#ifdef HAVE_FLOCK
 	s->lock_fd	= -1;
+#endif
 	
 	list_add_sorted(&sessions, s, 0, session_compare);
 
@@ -289,11 +291,13 @@
 	
 	if (s->connected)
 		command_exec_format(NULL, s, 1, ("/disconnect %s"), s->uid);
+#ifdef HAVE_FLOCK
 	if (s->lock_fd != -1) { /* this shouldn't happen */
 		flock(s->lock_fd, LOCK_UN);
 		close(s->lock_fd);
 			/* XXX: unlink then? */
 	}
+#endif
 
 	/* remove session watches */
 	for (l = watches; l; l = l->next) {
@@ -1269,10 +1273,12 @@
 			return 0;
 		}
 
+#ifdef HAVE_FLOCK
 		if (config_session_locks == 1 && s->lock_fd != -1) {
 			printq("session_locked", session_name(s));
 			return -1;
 		}
+#endif
 
 		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(s), "-lock")), 1);
 		xfree(tmp);
@@ -1295,6 +1301,7 @@
 			}
 		}
 
+#ifdef HAVE_FLOCK
 		if (config_session_locks == 1) {
 			if (flock(fd, LOCK_EX|LOCK_NB) == -1) {
 				int flock_errno = errno;
@@ -1311,13 +1318,16 @@
 			}
 			s->lock_fd = fd;
 		} else
+#endif
 			close(fd);
 		/* XXX, info about lock */
 		return 0;
 	}
 
 	if (match_arg(params[0], 'u', "unlock", 3)) {
+#ifdef HAVE_FLOCK
 		int fd;
+#endif
 		const char *path;
 		char *tmp;
 
@@ -1331,11 +1341,13 @@
 			return 0;
 		}
 
+#ifdef HAVE_FLOCK
 		if (config_session_locks == 1 && ((fd = session->lock_fd) != -1)) {
 			flock(fd, LOCK_UN);
 			close(fd);
 			session->lock_fd = -1;
 		}
+#endif
 
 		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(session), "-lock")), 0);
 		xfree(tmp);
@@ -1631,6 +1643,7 @@
 void changed_session_locks(char *varname) {
 	list_t l;
 
+#ifdef HAVE_FLOCK
 	if (config_session_locks != 1) {
 			/* unlock all files, close fds */
 		for (l = sessions; l; l = l->next) {
@@ -1643,6 +1656,7 @@
 			}
 		}
 	}
+#endif
 
 	if (!config_session_locks) {
 			/* unlink all lockfiles */
@@ -1661,7 +1675,11 @@
 		for (l = sessions; l; l = l->next) {
 			session_t *s = l->data;
 
-			if (s->connected && ((config_session_locks != 1) || (s->lock_fd == -1)))
+			if (s->connected
+#ifdef HAVE_FLOCK
+					&& ((config_session_locks != 1) || (s->lock_fd == -1))
+#endif
+					)
 				command_exec(NULL, s, "/session --lock", 1);
 		}
 	}

Index: sessions.h
===================================================================
RCS file: /home/cvs/ekg2/ekg/sessions.h,v
diff -d -u -r1.39 -r1.40
--- sessions.h	1 May 2007 14:09:07 -0000	1.39
+++ sessions.h	3 May 2007 11:40:38 -0000	1.40
@@ -60,7 +60,9 @@
 	int laststatus;			/**< user's status before going into autoaway */
 	char *lastdescr;		/**< user's description before going into autoaway */
 
+#ifdef HAVE_FLOCK /* XXX: -D for docs? */
 	int lock_fd;			/**< fd used for session locking */
+#endif
 } session_t;
 
 #ifndef EKG2_WIN32_NOFUNCTION


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