[vhffs-dev] [1289] Fixed a fd leak in the case of an empty file.

[ Thread Index | Date Index | More vhffs.org/vhffs-dev Archives ]


Revision: 1289
Author:   gradator
Date:     2008-10-16 00:33:41 +0200 (Thu, 16 Oct 2008)

Log Message:
-----------
Fixed a fd leak in the case of an empty file. (create not followed by any write event)

Modified Paths:
--------------
    trunk/vhffs-fssync/vhffsfssync_master.c
    trunk/vhffs-fssync/vhffsfssync_slave.c


Modified: trunk/vhffs-fssync/vhffsfssync_master.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_master.c	2008-10-15 21:39:32 UTC (rev 1288)
+++ trunk/vhffs-fssync/vhffsfssync_master.c	2008-10-15 22:33:41 UTC (rev 1289)
@@ -405,7 +405,7 @@
 	// if the file is being sent, cancel it
 	vhffsfssync_net_remove_file(conn, pathname);
 	//printf("%d SENDING FILE %s\n", conn->fd, pathname);
-	vhffsfssync_net_send_event(conn, g_strdup_printf("create%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
+	vhffsfssync_net_send_event(conn, g_strdup_printf("open%c%s%c", '\0', pathname, '\0') , VHFFSFSSYNC_NET_PRIO_MEDIUM);
 
 	// the size of the file is the priority (small files are sent with more priority)
 	// but don't set the priority too low, low value can be used for anything else

Modified: trunk/vhffs-fssync/vhffsfssync_slave.c
===================================================================
--- trunk/vhffs-fssync/vhffsfssync_slave.c	2008-10-15 21:39:32 UTC (rev 1288)
+++ trunk/vhffs-fssync/vhffsfssync_slave.c	2008-10-15 22:33:41 UTC (rev 1289)
@@ -1,4 +1,3 @@
-
 #ifndef __linux__
 #error This software is only running on Linux-based OS, bye!
 #endif
@@ -348,6 +347,18 @@
 		char *pathname = args[1];
 		int fd;
 
+		fd = open(pathname, O_CREAT|O_WRONLY|O_TRUNC, 0644);
+		if(fd >= 0) {
+			close(fd);
+		}
+		else {
+			fprintf(stderr, "open() failed on %s: %s\n", pathname, strerror(errno));
+		}
+	}
+	else if(!strcmp(args[0], "open")) {
+		char *pathname = args[1];
+		int fd;
+
 		if( !g_hash_table_lookup(conn->openfiles, pathname) ) {
 			fd = open(pathname, O_CREAT|O_WRONLY|O_TRUNC, 0644);
 			if(fd >= 0) {


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/