diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-30 18:30:51 +0300 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2009-10-30 18:30:51 +0300 |
commit | bb1b1f7889abe5c98a7628ba82e07b70a2142658 (patch) | |
tree | ad51257652a78e63bc030d517ba6a55241a69e3f /src/util.c | |
parent | 1290cafef2180e5435cbbfd5a72527d0be2f4970 (diff) | |
download | rspamd-bb1b1f7889abe5c98a7628ba82e07b70a2142658.tar.gz rspamd-bb1b1f7889abe5c98a7628ba82e07b70a2142658.zip |
* Implement new system of managing rspamd processes
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 115 |
1 files changed, 105 insertions, 10 deletions
diff --git a/src/util.c b/src/util.c index 59de138aa..fbb5cb547 100644 --- a/src/util.c +++ b/src/util.c @@ -340,18 +340,19 @@ init_signals (struct sigaction *signals, sig_t sig_handler) sigaction (SIGPIPE, &sigpipe_act, NULL); } -void -pass_signal_worker (GList * workers, int signo) +static void +pass_signal_cb (gpointer key, gpointer value, gpointer ud) { - struct rspamd_worker *cur; - GList *l; + struct rspamd_worker *cur = value; + int signo = GPOINTER_TO_INT (ud); - l = workers; - while (l) { - cur = l->data; - kill (cur->pid, signo); - l = g_list_next (l); - } + kill (cur->pid, signo); +} + +void +pass_signal_worker (GHashTable * workers, int signo) +{ + g_hash_table_foreach (workers, pass_signal_cb, GINT_TO_POINTER (signo)); } void @@ -1036,6 +1037,100 @@ gperf_profiler_init (struct config_file *cfg, const char *descr) #endif } +#ifdef HAVE_FLOCK +/* Flock version */ +gboolean +lock_file (int fd, gboolean async) +{ + int flags; + + if (async) { + flags = LOCK_EX | LOCK_NB; + } + else { + flags = LOCK_EX; + } + + if (flock (fd, flags) == -1) { + if (async && errno == EAGAIN) { + return FALSE; + } + msg_warn ("lock_file: lock on file failed: %s", strerror (errno)); + return FALSE; + } + + return TRUE; +} + +gboolean +unlock_file (int fd, gboolean async) +{ + int flags; + + if (async) { + flags = LOCK_UN | LOCK_NB; + } + else { + flags = LOCK_UN; + } + + if (flock (fd, flags) == -1) { + if (async && errno == EAGAIN) { + return FALSE; + } + msg_warn ("lock_file: lock on file failed: %s", strerror (errno)); + return FALSE; + } + + return TRUE; + +} +#else +/* Fctnl version */ +gboolean +lock_file (int fd, gboolean async) +{ + struct flock fl = { + .l_type = F_WRLCK, + .l_whence = SEEK_SET, + .l_start = 0, + .l_len = 0 + }; + + if (fcntl (fd, async ? F_SETLK : F_SETLKW, &fl) == -1) { + if (async && (errno == EAGAIN || errno == EACCES)) { + return FALSE; + } + msg_warn ("lock_file: lock on file failed: %s", strerror (errno)); + return FALSE; + } + + return TRUE; +} + +gboolean +unlock_file (int fd, gboolean async) +{ + struct flock fl = { + .l_type = F_UNLCK, + .l_whence = SEEK_SET, + .l_start = 0, + .l_len = 0 + }; + + if (fcntl (fd, async ? F_SETLK : F_SETLKW, &fl) == -1) { + if (async && (errno == EAGAIN || errno == EACCES)) { + return FALSE; + } + msg_warn ("lock_file: lock on file failed: %s", strerror (errno)); + return FALSE; + } + + return TRUE; + +} +#endif + /* * vi:ts=4 */ |