]> source.dussan.org Git - rspamd.git/commitdiff
[Feature] Add workaround for systems without sane shmem support
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Jun 2016 14:19:24 +0000 (15:19 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 29 Jun 2016 14:19:24 +0000 (15:19 +0100)
OSX is so POSIX, such Unix, wow!

src/libutil/http.c
src/libutil/util.c

index b87e02f15b78c45e43acb832e1e1cf42e6e6a02e..cdd44abb89324f9380177e40345c59a92a422d09 100644 (file)
@@ -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;
index 21a05dadda78db452bd76f46393b30cf15ec3d77..f8797198053dc088db0a6c9cbd4842e63b29d1a5 100644 (file)
@@ -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;