if (detect_container(NULL) > 0)
return -ENOTSUP;
- if (pid == 0)
- p = "/proc/self/sessionid";
- else
- p = procfs_file_alloca(pid, "sessionid");
+ p = procfs_file_alloca(pid, "sessionid");
r = read_one_line_file(p, &s);
if (r < 0)
if (detect_container(NULL) > 0)
return -ENOTSUP;
- if (pid == 0)
- p = "/proc/self/loginuid";
- else
- p = procfs_file_alloca(pid, "loginuid");
+ p = procfs_file_alloca(pid, "loginuid");
r = read_one_line_file(p, &s);
if (r < 0)
assert(pid >= 0);
assert(st);
- if (pid == 0)
- p = "/proc/self/stat";
- else
- p = procfs_file_alloca(pid, "stat");
+ p = procfs_file_alloca(pid, "stat");
f = fopen(p, "re");
if (!f)
assert(name);
assert(pid >= 0);
- if (pid == 0)
- p = "/proc/self/comm";
- else
- p = procfs_file_alloca(pid, "comm");
+ p = procfs_file_alloca(pid, "comm");
r = read_one_line_file(p, name);
if (r == -ENOENT)
assert(line);
assert(pid >= 0);
- if (pid == 0)
- p = "/proc/self/cmdline";
- else
- p = procfs_file_alloca(pid, "cmdline");
+ p = procfs_file_alloca(pid, "cmdline");
f = fopen(p, "re");
if (!f)
assert(capeff);
assert(pid >= 0);
- if (pid == 0)
- p = "/proc/self/status";
- else
- p = procfs_file_alloca(pid, "status");
+ p = procfs_file_alloca(pid, "status");
return get_status_field(p, "\nCapEff:", capeff);
}
assert(pid >= 0);
assert(name);
- if (pid == 0)
- p = "/proc/self/exe";
- else
- p = procfs_file_alloca(pid, "exe");
+ p = procfs_file_alloca(pid, "exe");
r = readlink_malloc(p, name);
if (r < 0)
assert(pid >= 0);
- if (pid == 0)
- fn = "/proc/self/stat";
- else
- fn = procfs_file_alloca(pid, "stat");
+ fn = procfs_file_alloca(pid, "stat");
f = fopen(fn, "re");
if (!f)
assert(field);
assert(_value);
- if (pid == 0)
- path = "/proc/self/environ";
- else
- path = procfs_file_alloca(pid, "environ");
+ path = procfs_file_alloca(pid, "environ");
f = fopen(path, "re");
if (!f)
#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_; \
})