git-svn: trunk@2889
Tomasz Kojm authored on 2007/03/02 03:18:22... | ... |
@@ -1,3 +1,7 @@ |
1 |
+Thu Mar 1 17:23:31 CET 2007 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav/lockdb.c: fix handling of read locks |
|
4 |
+ |
|
1 | 5 |
Thu Mar 1 16:21:48 CET 2007 (tk) |
2 | 6 |
--------------------------------- |
3 | 7 |
* shared/output.c: fix handling of special characters in mprintf (bb#360) |
... | ... |
@@ -193,6 +193,7 @@ static int cli_lockdb(const char *dbdirpath, int wait, int writelock) |
193 | 193 |
#ifndef C_WINDOWS |
194 | 194 |
struct flock fl; |
195 | 195 |
mode_t old_mask; |
196 |
+ unsigned int existing = 0; |
|
196 | 197 |
#else |
197 | 198 |
DWORD LastError; |
198 | 199 |
SECURITY_ATTRIBUTES saAttr; |
... | ... |
@@ -227,11 +228,13 @@ static int cli_lockdb(const char *dbdirpath, int wait, int writelock) |
227 | 227 |
old_mask = umask(0); |
228 | 228 |
if(-1 == (lock->lock_fd = open(lock->lock_file, O_RDWR|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IROTH))) { |
229 | 229 |
if((writelock) || |
230 |
- (-1 == (lock->lock_fd = open(lock->lock_file, O_RDWR, 0)))) { |
|
230 |
+ (-1 == (lock->lock_fd = open(lock->lock_file, O_RDONLY)))) { |
|
231 | 231 |
cli_dbgmsg("Can't %s Lock file for Database Directory: %s\n", (writelock ? "create" : "open"), dbdirpath); |
232 | 232 |
umask(old_mask); |
233 | 233 |
pthread_mutex_unlock(&lock_mutex); |
234 | 234 |
return CL_EIO; /* or CL_EACCESS */ |
235 |
+ } else { |
|
236 |
+ existing = 1; |
|
235 | 237 |
} |
236 | 238 |
} |
237 | 239 |
umask(old_mask); |
... | ... |
@@ -268,7 +271,9 @@ static int cli_lockdb(const char *dbdirpath, int wait, int writelock) |
268 | 268 |
if(errno != EACCES && errno != EAGAIN) { |
269 | 269 |
close(lock->lock_fd); |
270 | 270 |
lock->lock_fd=-1; |
271 |
- unlink(lock->lock_file); |
|
271 |
+ if(!existing) |
|
272 |
+ unlink(lock->lock_file); |
|
273 |
+ cli_errmsg("Can't acquire %s lock: %s\n", writelock ? "write" : "read", strerror(errno)); |
|
272 | 274 |
return CL_EIO; |
273 | 275 |
} |
274 | 276 |
#endif |