summaryrefslogtreecommitdiff
path: root/src/shared/util.h
diff options
context:
space:
mode:
authorSimon Peeters <peeters.simon@gmail.com>2014-01-04 02:35:23 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-01-05 00:59:13 -0500
commitb68fa010f72599e6da5822feda5ae3a47a4e63d8 (patch)
tree046694049da4187b5a8bbe85d4bca92960f2fa3e /src/shared/util.h
parent9dddaedfcc70c6dc37ba6a48d1d8e27e12c0cb2e (diff)
shared: procfs_file_alloca: handle pid==0
when pid is set to 0 use /proc/self
Diffstat (limited to 'src/shared/util.h')
-rw-r--r--src/shared/util.h10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/shared/util.h b/src/shared/util.h
index d9720d0a36..8645654267 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -777,9 +777,13 @@ int unlink_noerrno(const char *path);
#define procfs_file_alloca(pid, field) \
({ \
pid_t _pid_ = (pid); \
- char *_r_; \
- _r_ = alloca(sizeof("/proc/") -1 + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
- sprintf(_r_, "/proc/"PID_FMT"/" field, _pid_); \
+ const char *_r_; \
+ if (_pid_ == 0) { \
+ _r_ = ("/proc/self/" field); \
+ } else { \
+ _r_ = alloca(strlen("/proc/") + DECIMAL_STR_MAX(pid_t) + 1 + sizeof(field)); \
+ sprintf((char*) _r_, "/proc/"PID_FMT"/" field, _pid_); \
+ } \
_r_; \
})