aboutsummaryrefslogtreecommitdiffstats
path: root/libselinux/src/procattr.c
diff options
context:
space:
mode:
authorStephen Smalley <sds@tycho.nsa.gov>2015-07-13 09:00:40 -0400
committerStephen Smalley <sds@tycho.nsa.gov>2015-07-13 09:13:00 -0400
commit3430519109c0423a49b9350aa8444beec798d5a7 (patch)
tree3560cb32ac210f1a9ceb6c8631654c8c78faaa14 /libselinux/src/procattr.c
parent0079008a54b18f2599d199bba03502ceede7d694 (diff)
downloadandroid_external_selinux-3430519109c0423a49b9350aa8444beec798d5a7.tar.gz
android_external_selinux-3430519109c0423a49b9350aa8444beec798d5a7.tar.bz2
android_external_selinux-3430519109c0423a49b9350aa8444beec798d5a7.zip
libselinux: use /proc/thread-self when available
Linux 3.17 introduced a /proc/thread-self symlink that can be used to reference the proc files of the current thread without needing to use gettid(2). Use this symlink when it exists, falling back to using gettid(2) when it does not. This is generally beneficial, but was specifically motivated by https://github.com/systemd/systemd/issues/475. Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
Diffstat (limited to 'libselinux/src/procattr.c')
-rw-r--r--libselinux/src/procattr.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libselinux/src/procattr.c b/libselinux/src/procattr.c
index f9903505..e444571c 100644
--- a/libselinux/src/procattr.c
+++ b/libselinux/src/procattr.c
@@ -95,6 +95,12 @@ static int openattr(pid_t pid, const char *attr, int flags)
if (pid > 0)
rc = asprintf(&path, "/proc/%d/attr/%s", pid, attr);
else {
+ rc = asprintf(&path, "/proc/thread-self/attr/%s", attr);
+ if (rc < 0)
+ return -1;
+ fd = open(path, flags | O_CLOEXEC);
+ if (fd >= 0 || errno != ENOENT)
+ goto out;
if (!tid)
tid = gettid();
rc = asprintf(&path, "/proc/self/task/%d/attr/%s", tid, attr);
@@ -103,6 +109,7 @@ static int openattr(pid_t pid, const char *attr, int flags)
return -1;
fd = open(path, flags | O_CLOEXEC);
+out:
free(path);
return fd;
}