Browse code

improve lock files handling (bb#229)

git-svn: trunk@2627

Tomasz Kojm authored on 2007/01/15 09:22:30
Showing 2 changed files
... ...
@@ -1,3 +1,8 @@
1
+Mon Jan 15 01:16:40 CET 2007 (tk)
2
+---------------------------------
3
+  * libclamav/lockdb.c: improve lock files handling (bb#229), thanks to
4
+			Gianluigi Tiesi
5
+
1 6
 Mon Jan 15 00:45:00 CET 2007 (tk)
2 7
 ---------------------------------
3 8
   * libclamav/readdb.c: cli_loaddbdir_l fixes (bb#228), thanks to
... ...
@@ -131,9 +131,17 @@ int cli_unlockdb(const char *dbdirpath)
131 131
 #endif
132 132
 	cli_errmsg("Error Unlocking Database Directory %s\n", dbdirpath);
133 133
 	pthread_mutex_unlock(&lock_mutex);
134
+#ifndef C_WINDOWS
135
+	close(lock->lock_fd);
136
+	unlink(lock->lock_file);
137
+#endif
134 138
 	return CL_ELOCKDB;
135 139
     }
136 140
     lock->lock_type = -1;
141
+#ifndef C_WINDOWS
142
+    close(lock->lock_fd);
143
+    unlink(lock->lock_file);
144
+#endif
137 145
     pthread_mutex_unlock(&lock_mutex);
138 146
 
139 147
     return CL_SUCCESS;
... ...
@@ -216,9 +224,11 @@ static int cli_lockdb(const char *dbdirpath, int wait, int writelock)
216 216
 #ifndef C_WINDOWS
217 217
     memset(&fl, 0, sizeof(fl));
218 218
     fl.l_type = (writelock ? F_WRLCK : F_RDLCK);
219
-    cli_dbgmsg("przed fcntl: %d\n", lock->lock_fd);
220 219
     if(fcntl(lock->lock_fd, ((wait) ? F_SETLKW : F_SETLK), &fl) == -1) {
221
-	perror("FCNTL");
220
+#ifndef C_WINDOWS
221
+	close(lock->lock_fd);
222
+	unlink(lock->lock_file);
223
+#endif
222 224
 	return CL_ELOCKDB;
223 225
     }
224 226
 #else