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

CVS commit cvs w toxygen.net
Czw, 3 Maj 2007, 16:17:55 CEST


Module name:	ekg2
Changes by:	peres	2007-05-03 16:17:52

Modified files:
	configfile.c plugins.c sessions.c stuff.c stuff.h

Log message:
- prepare_sapath() -> prepare_pathf() [old name was misleading],
- prepare_pathf() in session locking stuff.

Index: configfile.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/configfile.c,v
diff -d -u -r1.47 -r1.48
--- configfile.c	3 May 2007 12:29:58 -0000	1.47
+++ configfile.c	3 May 2007 14:17:51 -0000	1.48
@@ -320,7 +320,7 @@
 			plugin_t *p = l->data;
 			const char *tmp;
 			
-			if ((tmp = prepare_sapath("config-%s", p->name)))
+			if ((tmp = prepare_pathf("config-%s", p->name)))
 				config_read(tmp);
 		}
 	}
@@ -510,7 +510,7 @@
 		const char *tmp;
 		list_t lv;
 
-		if (!(tmp = prepare_sapath("config-%s", p->name)))
+		if (!(tmp = prepare_pathf("config-%s", p->name)))
 			return -1;
 
 		if (!(f = fopen(tmp, "w")))

Index: plugins.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/plugins.c,v
diff -d -u -r1.97 -r1.98
--- plugins.c	3 May 2007 13:44:25 -0000	1.97
+++ plugins.c	3 May 2007 14:17:52 -0000	1.98
@@ -305,9 +305,9 @@
 		const char *tmp;
 
 		in_autoexec = 1;
-		if ((tmp = prepare_sapath("config-%s", name)))
+		if ((tmp = prepare_pathf("config-%s", name)))
 			config_read(tmp);
-		if ((tmp = prepare_sapath("sessions-%s", name)))
+		if ((tmp = prepare_pathf("sessions-%s", name)))
 			session_read(tmp);
 
 		if (pl)

Index: sessions.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/sessions.c,v
diff -d -u -r1.127 -r1.128
--- sessions.c	3 May 2007 12:45:03 -0000	1.127
+++ sessions.c	3 May 2007 14:17:52 -0000	1.128
@@ -771,7 +771,7 @@
 			if (!p || p->pclass != PLUGIN_PROTOCOL)
 				continue;
 
-			if ((tmp = prepare_sapath("sessions-%s", p->name)))
+			if ((tmp = prepare_pathf("sessions-%s", p->name)))
 				session_read(tmp);
 		}
 		return ret;
@@ -838,7 +838,7 @@
 
 		if (p->pclass != PLUGIN_PROTOCOL) continue; /* skip no protocol plugins */
 
-		if (!(tmp = prepare_sapath("sessions-%s", p->name))) {
+		if (!(tmp = prepare_pathf("sessions-%s", p->name))) {
 			ret = -1;
 			continue;
 		}
@@ -1253,7 +1253,6 @@
 	if (match_arg(params[0], 'L', "lock", 2)) {
 		int fd;
 		const char *path;
-		char *tmp;
 		session_t *s;
 
 		if (params[1]) {
@@ -1280,15 +1279,16 @@
 		}
 #endif
 
-		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(s), "-lock")), 1);
-		xfree(tmp);
-		fd = open(path,
-				O_CREAT|O_WRONLY
-				| (config_session_locks != 1
-					? O_EXCL		/* if we don't use flock(), we just take care of file's existence */
-					: O_TRUNC
-						| O_NONBLOCK	/* if someone's set up shitpipe for us */
-				), S_IWUSR);
+		if ((path = prepare_pathf("%s-lock", session_uid_get(s))))
+			fd = open(path,
+					O_CREAT|O_WRONLY
+					| (config_session_locks != 1
+						? O_EXCL		/* if we don't use flock(), we just take care of file's existence */
+						: O_TRUNC
+							| O_NONBLOCK	/* if someone's set up shitpipe for us */
+					), S_IWUSR);
+		else
+			return 0;
 
 		if (fd == -1) {
 			if (errno == EEXIST) {
@@ -1329,7 +1329,6 @@
 		int fd;
 #endif
 		const char *path;
-		char *tmp;
 
 		if (!session) {
 			printq("invalid_session");
@@ -1349,9 +1348,8 @@
 		}
 #endif
 
-		path = prepare_path((tmp = saprintf("%s%s", session_uid_get(session), "-lock")), 0);
-		xfree(tmp);
-		unlink(path);
+		if ((path = prepare_pathf("%s-lock", session_uid_get(session))))
+			unlink(path);
 		/* XXX, info about unlock */
 		return 0;
 	}
@@ -1664,10 +1662,9 @@
 			session_t *s = l->data;
 
 			if (s->connected) { /* don't break locks of other copy of ekg2 */
-				char *tmp;
-				const char *path = prepare_path((tmp = saprintf("%s%s", session_uid_get(s), "-lock")), 0);
-				xfree(tmp);
-				unlink(path);
+				const char *path = prepare_pathf("%s-lock", session_uid_get(s));
+				if (path)
+					unlink(path);
 			}
 		}
 	} else {

Index: stuff.c
===================================================================
RCS file: /home/cvs/ekg2/ekg/stuff.c,v
diff -d -u -r1.194 -r1.195
--- stuff.c	3 May 2007 12:38:41 -0000	1.194
+++ stuff.c	3 May 2007 14:17:52 -0000	1.195
@@ -1510,13 +1510,13 @@
 }
 
 /**
- * prepare_sapath()
+ * prepare_pathf()
  *
  * Return path to configdir/profiledir (~/.ekg2 or ~/.ekg2/$PROFILE) and append @a filename (formated using vsnprintf()) 
  * If length of this string is larger than PATH_MAX (4096 on Linux) than unlike prepare_path() it'll return NULL
  */
 
-const char *prepare_sapath(const char *filename, ...) {
+const char *prepare_pathf(const char *filename, ...) {
 	static char path[PATH_MAX];
 	size_t len;
 	int fpassed = (filename && *filename);
@@ -1524,7 +1524,7 @@
 	len = strlcpy(path, config_dir ? config_dir : "", sizeof(path));
 
 	if (len + fpassed >= sizeof(path)) {
-		debug_error("prepare_sapath() LEVEL0 %d + %d >= %d\n", len, fpassed, sizeof(path));
+		debug_error("prepare_pathf() LEVEL0 %d + %d >= %d\n", len, fpassed, sizeof(path));
 		return NULL;
 	}
 
@@ -1539,7 +1539,7 @@
 		va_end(ap);
 
 		if (len2 == -1 || (len + len2) >= sizeof(path)) {	/* (len + len2 == sizeof(path)) ? */
-			debug_error("prepare_sapath() LEVEL1 %d | %d + %d >= %d\n", len2, len, len2, sizeof(path));
+			debug_error("prepare_pathf() LEVEL1 %d | %d + %d >= %d\n", len2, len, len2, sizeof(path));
 			return NULL;
 		}
 	}

Index: stuff.h
===================================================================
RCS file: /home/cvs/ekg2/ekg/stuff.h,v
diff -d -u -r1.101 -r1.102
--- stuff.h	2 May 2007 20:57:21 -0000	1.101
+++ stuff.h	3 May 2007 14:17:52 -0000	1.102
@@ -317,7 +317,7 @@
 int play_sound(const char *sound_path);
 
 const char *prepare_path(const char *filename, int do_mkdir);
-const char *prepare_sapath(const char *filename, ...);
+const char *prepare_pathf(const char *filename, ...);
 char *read_file(FILE *f, int alloc);
 
 const char *timestamp(const char *format);


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