Fix: add missing errno.h in pthread compat
[lttng-tools.git] / src / common / compat / getenv.h
CommitLineData
e8fa9fb0
MD
1#ifndef _COMPAT_GETENV_H
2#define _COMPAT_GETENV_H
3
4/*
ab5be9fa 5 * Copyright (C) 2015 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
e8fa9fb0 6 *
ab5be9fa 7 * SPDX-License-Identifier: GPL-2.0-only
e8fa9fb0 8 *
e8fa9fb0
MD
9 */
10
11#include <stdlib.h>
12#include <unistd.h>
13#include <sys/types.h>
14#include <common/error.h>
15
16static inline
17int lttng_is_setuid_setgid(void)
18{
19 return geteuid() != getuid() || getegid() != getgid();
20}
21
22static inline
23char *lttng_secure_getenv(const char *name)
24{
25 if (lttng_is_setuid_setgid()) {
26 WARN("Getting environment variable '%s' from setuid/setgid binary refused for security reasons.",
27 name);
28 return NULL;
29 }
30 return getenv(name);
31}
32
33#endif /* _COMPAT_GETENV_H */
This page took 0.038084 seconds and 4 git commands to generate.