Changeset: 1c520e489e77 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=1c520e489e77
Modified Files:
        MonetDB.spec
        buildtools/selinux/monetdb.te
        clients/Tests/exports.stable.out
        gdk/gdk_system.c
        gdk/gdk_system.h
        gdk/gdk_utils.c
        monetdb5/mal/mal_exception.c
        sql/backends/monet5/sql_execute.c
        sql/server/sql_mvc.c
        tools/merovingian/daemon/config/monetdbd.service.in
Branch: default
Log Message:

Merge with Apr2019 branch.


diffs (truncated from 675 to 300 lines):

diff --git a/MonetDB.spec b/MonetDB.spec
--- a/MonetDB.spec
+++ b/MonetDB.spec
@@ -895,7 +895,10 @@ automatic index management, extensibilit
 accelerators.  It also has an SQL frontend.
 
 This package contains the SELinux policy for running MonetDB under
-control of systemd.
+control of systemd.  There is one tunable parameter, mserver5_can_read_home,
+which can be set using "setsebool -P mserver5_can_read_home=true" to allow
+an mserver5 process started by monetdbd under the control of systemd to
+read files in users' home directories.
 
 %post selinux
 for selinuxvariant in %{selinux_variants}
diff --git a/buildtools/selinux/monetdb.te b/buildtools/selinux/monetdb.te
--- a/buildtools/selinux/monetdb.te
+++ b/buildtools/selinux/monetdb.te
@@ -1,4 +1,4 @@
-policy_module(monetdb, 0.3)
+policy_module(monetdb, 0.4)
 # The above line declares that this file is a SELinux policy file. Its
 # name is monetdb, so the file should be saved as monetdb.te
 
@@ -7,6 +7,7 @@ require {
        type proc_net_t;
        type tmp_t;
        type var_t;
+       type user_home_t;
        class dir { read };
        class fd { use };
        class fifo_file { getattr read write };
@@ -119,4 +120,9 @@ manage_sock_files_pattern(mserver5_t, ms
 allow mserver5_t monetdbd_t:fifo_file { read write getattr };
 allow mserver5_t monetdbd_t:unix_stream_socket { read write getopt shutdown };
 allow mserver5_t var_t:dir { read };
+gen_tunable(mserver5_can_read_home, false)
+tunable_policy(`mserver5_can_read_home', `
+    userdom_search_user_home_dirs(mserver5_t)
+    allow mserver5_t user_home_t:file read_file_perms;
+')
 allow monetdbd_t mserver5_t:unix_stream_socket { connectto };
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -313,8 +313,11 @@ void *MT_mmap(const char *path, int mode
 int MT_munmap(void *p, size_t len);
 bool MT_path_absolute(const char *path);
 void MT_sleep_ms(unsigned int ms);
+void *MT_thread_getdata(void);
+const char *MT_thread_getname(void);
+struct thread_info *MT_thread_info(int *nthreads);
 bool MT_thread_init(void);
-const char *MT_thread_name(void);
+void MT_thread_setdata(void *data);
 void MT_thread_setname(const char *name);
 void OIDXdestroy(BAT *b);
 ssize_t OIDfromStr(const char *src, size_t *len, oid **dst, bool external);
diff --git a/gdk/gdk_system.c b/gdk/gdk_system.c
--- a/gdk/gdk_system.c
+++ b/gdk/gdk_system.c
@@ -159,10 +159,13 @@ static struct winthread {
        HANDLE hdl;
        DWORD tid;
        void (*func) (void *);
-       void *arg;
+       void *data;
        bool exited:1, detached:1, waiting:1;
        const char *threadname;
 } *winthreads = NULL;
+static struct winthread mainthread = {
+       .threadname = "main thread",
+};
 
 static CRITICAL_SECTION winthread_cs;
 static DWORD threadslot = TLS_OUT_OF_INDEXES;
@@ -174,7 +177,8 @@ MT_thread_init(void)
                threadslot = TlsAlloc();
                if (threadslot == TLS_OUT_OF_INDEXES)
                        return false;
-               if (TlsSetValue(threadslot, NULL) == 0) {
+               mainthread.tid = GetCurrentThreadId();
+               if (TlsSetValue(threadslot, &mainthread) == 0) {
                        TlsFree(threadslot);
                        threadslot = TLS_OUT_OF_INDEXES;
                        return false;
@@ -205,10 +209,10 @@ find_winthread(DWORD tid)
 }
 
 const char *
-MT_thread_name(void)
+MT_thread_getname(void)
 {
        struct winthread *w = TlsGetValue(threadslot);
-       return w ? w->threadname ? w->threadname : "unknown thread" : "main 
thread";
+       return w && w->threadname ? w->threadname : "unknown thread";
 }
 
 void
@@ -224,6 +228,23 @@ MT_thread_setname(const char *name)
 }
 
 void
+MT_thread_setdata(void *data)
+{
+       struct winthread *w = TlsGetValue(threadslot);
+
+       if (w)
+               w->data = data;
+}
+
+void *
+MT_thread_getdata(void)
+{
+       struct winthread *w = TlsGetValue(threadslot);
+
+       return w ? w->data : NULL;
+}
+
+void
 gdk_system_reset(void)
 {
        assert(threadslot != TLS_OUT_OF_INDEXES);
@@ -250,9 +271,11 @@ static DWORD WINAPI
 thread_starter(LPVOID arg)
 {
        struct winthread *w = (struct winthread *) arg;
+       void *data = w->data;
 
+       w->data = NULL;
        TlsSetValue(threadslot, w);
-       (*w->func)(w->arg);
+       (*w->func)(data);
        EnterCriticalSection(&winthread_cs);
        w->exited = true;
        LeaveCriticalSection(&winthread_cs);
@@ -320,7 +343,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
        w->func = f;
        w->hdl = NULL;
        w->tid = 0;
-       w->arg = arg;
+       w->data = arg;
        w->exited = false;
        w->waiting = false;
        w->detached = (d == MT_THR_DETACHED);
@@ -335,6 +358,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
                rm_winthread(w);
                return -1;
        }
+       /* must not fail after this: the thread has been started */
        *t = (MT_Id) w->tid;
        return 0;
 }
@@ -362,6 +386,7 @@ MT_join_thread(MT_Id t)
 {
        struct winthread *w;
 
+       assert(t != mainthread.tid);
        join_threads();
        w = find_winthread((DWORD) t);
        if (w == NULL || w->hdl == NULL)
@@ -379,6 +404,7 @@ MT_kill_thread(MT_Id t)
 {
        struct winthread *w;
 
+       assert(t != mainthread.tid);
        join_threads();
        w = find_winthread((DWORD) t);
        if (w == NULL)
@@ -465,14 +491,18 @@ pthread_sema_down(pthread_sema_t *s)
 static struct posthread {
        struct posthread *next;
        void (*func)(void *);
-       void *arg;
+       void *data;
        const char *threadname;
        pthread_t tid;
        MT_Id mtid;
        bool exited:1, detached:1, waiting:1;
 } *posthreads = NULL;
+static struct posthread mainthread = {
+       .threadname = "main thread",
+       .mtid = 1,
+};
 static pthread_mutex_t posthread_lock = PTHREAD_MUTEX_INITIALIZER;
-static MT_Id MT_thread_id = 0;
+static MT_Id MT_thread_id = 1;
 
 static pthread_key_t threadkey;
 
@@ -487,7 +517,8 @@ MT_thread_init(void)
                        "failed: %s\n", strerror(ret));
                return false;
        }
-       if ((ret = pthread_setspecific(threadkey, NULL)) != 0) {
+       mainthread.tid = pthread_self();
+       if ((ret = pthread_setspecific(threadkey, &mainthread)) != 0) {
                fprintf(stderr,
                        "#MT_thread_init: setting specific value failed: %s\n",
                        strerror(ret));
@@ -519,12 +550,29 @@ MT_thread_setname(const char *name)
 }
 
 const char *
-MT_thread_name(void)
+MT_thread_getname(void)
 {
        struct posthread *p;
 
        p = pthread_getspecific(threadkey);
-       return p ? p->threadname ? p->threadname : "unknown thread" : "main 
thread";
+       return p && p->threadname ? p->threadname : "unknown thread";
+}
+
+void
+MT_thread_setdata(void *data)
+{
+       struct posthread *p = pthread_getspecific(threadkey);
+
+       if (p)
+               p->data = data;
+}
+
+void *
+MT_thread_getdata(void)
+{
+       struct posthread *p = pthread_getspecific(threadkey);
+
+       return p ? p->data : NULL;
 }
 
 #ifdef HAVE_PTHREAD_SIGMASK
@@ -563,9 +611,11 @@ static void *
 thread_starter(void *arg)
 {
        struct posthread *p = (struct posthread *) arg;
+       void *data = p->data;
 
+       p->data = NULL;
        pthread_setspecific(threadkey, p);
-       (*p->func)(p->arg);
+       (*p->func)(data);
        pthread_mutex_lock(&posthread_lock);
        p->exited = true;
        pthread_mutex_unlock(&posthread_lock);
@@ -649,7 +699,7 @@ MT_create_thread(MT_Id *t, void (*f) (vo
        }
        p->tid = 0;
        p->func = f;
-       p->arg = arg;
+       p->data = arg;
        p->exited = false;
        p->waiting = false;
        p->detached = (d == MT_THR_DETACHED);
@@ -671,6 +721,8 @@ MT_create_thread(MT_Id *t, void (*f) (vo
                        strerror(ret));
                rm_posthread(p);
                ret = -1;
+       } else {
+               /* must not fail after this: the thread has been started */
        }
 #ifdef HAVE_PTHREAD_SIGMASK
        MT_thread_sigmask(&orig_mask, NULL);
@@ -706,6 +758,7 @@ MT_join_thread(MT_Id t)
        struct posthread *p;
        int ret;
 
+       assert(t > 1);
        join_threads();
        p = find_posthread(t);
        if (p == NULL)
@@ -723,6 +776,7 @@ MT_join_thread(MT_Id t)
 int
 MT_kill_thread(MT_Id t)
 {
+       assert(t > 1);
 #ifdef HAVE_PTHREAD_KILL
        struct posthread *p;
 
diff --git a/gdk/gdk_system.h b/gdk/gdk_system.h
--- a/gdk/gdk_system.h
+++ b/gdk/gdk_system.h
@@ -116,8 +116,10 @@ gdk_export bool MT_thread_init(void);
 gdk_export int MT_create_thread(MT_Id *t, void (*function) (void *),
                                void *arg, enum MT_thr_detach d,
                                const char *threadname);
-gdk_export const char *MT_thread_name(void);
+gdk_export const char *MT_thread_getname(void);
 gdk_export void MT_thread_setname(const char *name);
+gdk_export void *MT_thread_getdata(void);
+gdk_export void MT_thread_setdata(void *data);
 gdk_export void MT_exiting_thread(void);
 gdk_export MT_Id MT_getpid(void);
 gdk_export int MT_join_thread(MT_Id t);
@@ -231,7 +233,7 @@ gdk_export ATOMIC_TYPE volatile GDKlockc
 gdk_export ATOMIC_TYPE volatile GDKlockcontentioncnt;
 gdk_export ATOMIC_TYPE volatile GDKlocksleepcnt;
 #define _DBG_LOCK_COUNT_0(l, n)                (void) ATOMIC_INC(GDKlockcnt, 
dummy)
-#define _DBG_LOCK_LOCKER(l, n)         ((l)->locker = (n), (l)->thread = 
MT_thread_name())
+#define _DBG_LOCK_LOCKER(l, n)         ((l)->locker = (n), (l)->thread = 
MT_thread_getname())
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to