From: Jérémie Galarneau Date: Thu, 24 Sep 2015 01:47:13 +0000 (-0400) Subject: Add run_as_unlink implementation X-Git-Tag: v2.6.1~52 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d92d258f48168978efe96ac77393801c887bed81;p=lttng-tools.git Add run_as_unlink implementation run_as_unlink() is used by Fix: Relay daemon ownership and reference counting Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/runas.c b/src/common/runas.c index a8fe47e8e..c1d07b3a5 100644 --- a/src/common/runas.c +++ b/src/common/runas.c @@ -77,6 +77,10 @@ struct run_as_open_data { mode_t mode; }; +struct run_as_unlink_data { + const char *path; +}; + #ifdef VALGRIND static int use_clone(void) @@ -132,6 +136,20 @@ int _open(void *_data) return open(data->path, data->flags, data->mode); } +static +int _unlink(void *_data) +{ + int ret; + struct run_as_unlink_data *data = _data; + + ret = unlink(data->path); + if (ret < 0) { + ret = -errno; + } + + return ret; +} + static int child_run_as(void *_data) { @@ -343,3 +361,14 @@ int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid) data.mode = mode; return run_as(_open, &data, uid, gid); } + +LTTNG_HIDDEN +int run_as_unlink(const char *path, uid_t uid, gid_t gid) +{ + struct run_as_unlink_data data; + + DBG3("unlink() %s with for uid %d and gid %d", + path, uid, gid); + data.path = path; + return run_as(_unlink, &data, uid, gid); +} diff --git a/src/common/runas.h b/src/common/runas.h index 9840eb056..2516738bf 100644 --- a/src/common/runas.h +++ b/src/common/runas.h @@ -25,6 +25,7 @@ int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid); int run_as_mkdir(const char *path, mode_t mode, uid_t uid, gid_t gid); int run_as_open(const char *path, int flags, mode_t mode, uid_t uid, gid_t gid); +int run_as_unlink(const char *path, uid_t uid, gid_t gid); /* * We need to lock pthread exit, which deadlocks __nptl_setxid in the