diff options
author | Stefan Metzmacher <metze@samba.org> | 2018-06-22 01:02:41 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2018-07-24 17:38:27 +0200 |
commit | 12a45ee1a66379ba7562729b835ce0e2e4bfb3b3 (patch) | |
tree | e71e6a536266960ab64a6504216da02e3fc498ef /lib/pthreadpool | |
parent | 65e4742d168454df6507d9e74993749063435dd6 (diff) | |
download | samba-12a45ee1a66379ba7562729b835ce0e2e4bfb3b3.tar.gz |
pthreadpool: add pthreadpool_tevent_[current_job_]per_thread_cwd()
This can be used to check if worker threads run with
unshare(CLONE_FS).
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Diffstat (limited to 'lib/pthreadpool')
-rw-r--r-- | lib/pthreadpool/pthreadpool_tevent.c | 26 | ||||
-rw-r--r-- | lib/pthreadpool/pthreadpool_tevent.h | 7 |
2 files changed, 33 insertions, 0 deletions
diff --git a/lib/pthreadpool/pthreadpool_tevent.c b/lib/pthreadpool/pthreadpool_tevent.c index 94b6b9ded8f..01e8586b384 100644 --- a/lib/pthreadpool/pthreadpool_tevent.c +++ b/lib/pthreadpool/pthreadpool_tevent.c @@ -210,6 +210,8 @@ struct pthreadpool_tevent_job { */ bool signaled; } needs_fence; + + bool per_thread_cwd; }; static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool); @@ -283,6 +285,15 @@ size_t pthreadpool_tevent_queued_jobs(struct pthreadpool_tevent *pool) return pthreadpool_queued_jobs(pool->pool); } +bool pthreadpool_tevent_per_thread_cwd(struct pthreadpool_tevent *pool) +{ + if (pool->pool == NULL) { + return false; + } + + return pthreadpool_per_thread_cwd(pool->pool); +} + static int pthreadpool_tevent_destructor(struct pthreadpool_tevent *pool) { struct pthreadpool_tevent_job *job = NULL; @@ -701,6 +712,7 @@ struct tevent_req *pthreadpool_tevent_job_send( return tevent_req_post(req, ev); } PTHREAD_TEVENT_JOB_THREAD_FENCE_INIT(job); + job->per_thread_cwd = pthreadpool_tevent_per_thread_cwd(pool); talloc_set_destructor(job, pthreadpool_tevent_job_destructor); DLIST_ADD_END(job->pool->jobs, job); job->state = state; @@ -772,6 +784,20 @@ bool pthreadpool_tevent_current_job_continue(void) return true; } +bool pthreadpool_tevent_current_job_per_thread_cwd(void) +{ + if (current_job == NULL) { + /* + * Should only be called from within + * the job function. + */ + abort(); + return false; + } + + return current_job->per_thread_cwd; +} + static void pthreadpool_tevent_job_fn(void *private_data) { struct pthreadpool_tevent_job *job = diff --git a/lib/pthreadpool/pthreadpool_tevent.h b/lib/pthreadpool/pthreadpool_tevent.h index 37e491e17c4..ff2ab7cfb73 100644 --- a/lib/pthreadpool/pthreadpool_tevent.h +++ b/lib/pthreadpool/pthreadpool_tevent.h @@ -31,6 +31,7 @@ int pthreadpool_tevent_init(TALLOC_CTX *mem_ctx, unsigned max_threads, size_t pthreadpool_tevent_max_threads(struct pthreadpool_tevent *pool); size_t pthreadpool_tevent_queued_jobs(struct pthreadpool_tevent *pool); +bool pthreadpool_tevent_per_thread_cwd(struct pthreadpool_tevent *pool); /* * return true - if tevent_req_cancel() was called. @@ -46,6 +47,12 @@ bool pthreadpool_tevent_current_job_orphaned(void); */ bool pthreadpool_tevent_current_job_continue(void); +/* + * return true if the current job can rely on a per thread + * current working directory. + */ +bool pthreadpool_tevent_current_job_per_thread_cwd(void); + struct tevent_req *pthreadpool_tevent_job_send( TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct pthreadpool_tevent *pool, |