u_char *map, *pos;
struct stat_file_block *block;
struct stat_file_header *header, *nh;
+ struct timespec sleep_ts = {
+ .tv_sec = 0,
+ .tv_nsec = 1000000
+ };
if (size <
sizeof (struct stat_file_header) + sizeof (struct stat_file_section) +
if (lock_fd == -1) {
/* Wait for lock */
- lock_fd = open (lock, O_RDONLY, 00600);
+ lock_fd = open (lock, O_WRONLY|O_CREAT|O_EXCL, 00600);
if (lock_fd != -1) {
- if (!rspamd_file_lock (lock_fd, TRUE)) {
- close (lock_fd);
- g_free (lock);
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
- return rspamd_mmaped_file_open (pool, filename, size, stcf);
- }
+ return rspamd_mmaped_file_open (pool, filename, size, stcf);
}
else {
- return rspamd_mmaped_file_open (pool, filename, size, stcf);
+ nanosleep (&sleep_ts, NULL);
}
}
- if (!rspamd_file_lock (lock_fd, TRUE)) {
- close (lock_fd);
- unlink (lock);
- g_free (lock);
-
- return rspamd_mmaped_file_open (pool, filename, size, stcf);
- }
-
old = rspamd_mmaped_file_open (pool, filename, old_size, stcf);
if (old == NULL) {
g_free (backup);
unlink (lock);
g_free (lock);
- rspamd_file_unlock (lock_fd, FALSE);
close (lock_fd);
return NULL;
g_free (backup);
unlink (lock);
g_free (lock);
- rspamd_file_unlock (lock_fd, FALSE);
close (lock_fd);
return NULL;
msg_err_pool ("cannot open file: %s", strerror (errno));
unlink (lock);
g_free (lock);
- rspamd_file_unlock (lock_fd, FALSE);
close (lock_fd);
g_free (backup);
return NULL;
close (fd);
unlink (lock);
g_free (lock);
- rspamd_file_unlock (lock_fd, FALSE);
close (lock_fd);
g_free (backup);
return NULL;
g_free (backup);
unlink (lock);
g_free (lock);
- rspamd_file_unlock (lock_fd, FALSE);
close (lock_fd);
- rspamd_file_unlock (new->fd, FALSE);
-
return new;
}
};
struct stat_file_block block = { 0, 0, 0 };
struct rspamd_stat_tokenizer *tokenizer;
- gint fd;
+ gint fd, lock_fd;
guint buflen = 0, nblocks;
- gchar *buf = NULL;
+ gchar *buf = NULL, *lock;
gpointer tok_conf;
gsize tok_conf_len;
+ struct timespec sleep_ts = {
+ .tv_sec = 0,
+ .tv_nsec = 1000000
+ };
if (size <
sizeof (struct stat_file_header) + sizeof (struct stat_file_section) +
return -1;
}
+ lock = g_strconcat (filename, ".lock", NULL);
+ lock_fd = open (lock, O_WRONLY|O_CREAT|O_EXCL, 00600);
+
+ if (lock_fd == -1) {
+ /* Wait for lock */
+ lock_fd = open (lock, O_WRONLY|O_CREAT|O_EXCL, 00600);
+ if (lock_fd != -1) {
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
+
+ return 0;
+ }
+ else {
+ nanosleep (&sleep_ts, NULL);
+ }
+ }
+
nblocks =
(size - sizeof (struct stat_file_header) -
sizeof (struct stat_file_section)) / sizeof (struct stat_file_block);
filename,
errno,
strerror (errno));
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
+
return -1;
}
errno,
strerror (errno));
close (fd);
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
return -1;
}
errno,
strerror (errno));
close (fd);
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
return -1;
}
strerror (errno));
close (fd);
g_free (buf);
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
return -1;
}
g_free (buf);
}
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
+
return -1;
}
nblocks--;
g_free (buf);
}
+ unlink (lock);
+ close (lock_fd);
+ g_free (lock);
+
return 0;
}
}
mf = rspamd_mmaped_file_open (cfg->cfg_pool, filename, size, stf);
- }
+ }
return (gpointer)mf;
}