From: Vsevolod Stakhov Date: Wed, 29 Jun 2016 14:19:24 +0000 (+0100) Subject: [Feature] Add workaround for systems without sane shmem support X-Git-Tag: 1.3.0~216 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8c58447646bb27b357aed9c0f88db467dee233f3;p=rspamd.git [Feature] Add workaround for systems without sane shmem support OSX is so POSIX, such Unix, wow! --- diff --git a/src/libutil/http.c b/src/libutil/http.c index b87e02f15..cdd44abb8 100644 --- a/src/libutil/http.c +++ b/src/libutil/http.c @@ -1376,6 +1376,10 @@ rspamd_http_connection_read_message_common (struct rspamd_http_connection *conn, priv->msg = req; req->flags = flags; + if (flags & RSPAMD_HTTP_FLAG_SHMEM) { + req->body_buf.c.shared.shm_fd = -1; + } + if (priv->peer_key) { priv->msg->peer_key = priv->peer_key; priv->peer_key = NULL; @@ -2133,7 +2137,11 @@ rspamd_http_shname_dtor (void *p) { struct rspamd_storage_shmem *n = p; +#ifdef HAVE_SANE_SHMEM shm_unlink (n->shm_name); +#else + unlink (n->shm_name); +#endif g_free (n->shm_name); g_slice_free1 (sizeof (*n), n); } @@ -2167,8 +2175,14 @@ rspamd_http_message_set_body (struct rspamd_http_message *msg, if (msg->flags & RSPAMD_HTTP_FLAG_SHMEM) { storage->shared.name = g_slice_alloc (sizeof (*storage->shared.name)); REF_INIT_RETAIN (storage->shared.name, rspamd_http_shname_dtor); +#ifdef HAVE_SANE_SHMEM storage->shared.name->shm_name = g_strdup ("/rhm.XXXXXXXXXXXXXXXXXXXX"); storage->shared.shm_fd = rspamd_shmem_mkstemp (storage->shared.name->shm_name); +#else + /* XXX: assume that tempdir is /tmp */ + storage->shared.name->shm_name = g_strdup ("/tmp/rhm.XXXXXXXXXXXXXXXXXXXX"); + storage->shared.shm_fd = mkstemp (storage->shared.name->shm_name); +#endif if (storage->shared.shm_fd == -1) { return FALSE; diff --git a/src/libutil/util.c b/src/libutil/util.c index 21a05dadd..f87971980 100644 --- a/src/libutil/util.c +++ b/src/libutil/util.c @@ -2282,12 +2282,21 @@ rspamd_shmem_xmap (const char *fname, guint mode, g_assert (fname != NULL); g_assert (size != NULL); +#ifdef HAVE_SANE_SHMEM if (mode & PROT_WRITE) { fd = shm_open (fname, O_RDWR, 0); } else { fd = shm_open (fname, O_RDONLY, 0); } +#else + if (mode & PROT_WRITE) { + fd = open (fname, O_RDWR, 0); + } + else { + fd = open (fname, O_RDONLY, 0); + } +#endif if (fd == -1) { return NULL;