int get_parent_of_pid(pid_t pid, pid_t *_ppid) {
int r;
_cleanup_fclose_ FILE *f = NULL;
- char fn[PATH_MAX], line[LINE_MAX], *p;
+ char fn[sizeof("/proc/")-1 + DECIMAL_STR_MAX(pid_t) + sizeof("/stat")], line[LINE_MAX], *p;
long unsigned ppid;
assert(pid > 0);
assert(_ppid);
assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
- char_array_0(fn);
f = fopen(fn, "re");
if (!f)
int get_starttime_of_pid(pid_t pid, unsigned long long *st) {
_cleanup_fclose_ FILE *f = NULL;
- char fn[PATH_MAX], line[LINE_MAX], *p;
+ char fn[sizeof("/proc/")-1 + DECIMAL_STR_MAX(pid_t) + sizeof("/stat")], line[LINE_MAX], *p;
assert(pid > 0);
assert(st);
assert_se(snprintf(fn, sizeof(fn)-1, "/proc/%lu/stat", (unsigned long) pid) < (int) (sizeof(fn)-1));
- char_array_0(fn);
f = fopen(fn, "re");
if (!f)
int get_ctty(pid_t pid, dev_t *_devnr, char **r) {
int k;
- char fn[PATH_MAX], *s, *b, *p;
+ char fn[sizeof("/dev/char/")-1 + 2*DECIMAL_STR_MAX(unsigned) + 1 + 1], *s, *b, *p;
dev_t devnr;
assert(r);
return k;
snprintf(fn, sizeof(fn), "/dev/char/%u:%u", major(devnr), minor(devnr));
- char_array_0(fn);
k = readlink_malloc(fn, &s);
if (k < 0) {
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
const char *signal_to_string(int signo) {
- static __thread char buf[12];
+ static __thread char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
const char *name;
name = __signal_to_string(signo);
return name;
if (signo >= SIGRTMIN && signo <= SIGRTMAX)
- snprintf(buf, sizeof(buf) - 1, "RTMIN+%d", signo - SIGRTMIN);
+ snprintf(buf, sizeof(buf), "RTMIN+%d", signo - SIGRTMIN);
else
- snprintf(buf, sizeof(buf) - 1, "%d", signo);
- char_array_0(buf);
+ snprintf(buf, sizeof(buf), "%d", signo);
+
return buf;
}
}
int getenv_for_pid(pid_t pid, const char *field, char **_value) {
- char path[sizeof("/proc/")-1+10+sizeof("/environ")], *value = NULL;
+ char path[sizeof("/proc/")-1 + DECIMAL_STR_MAX(pid_t) + sizeof("/environ")], *value = NULL;
int r;
FILE *f;
bool done = false;
pid = getpid();
snprintf(path, sizeof(path), "/proc/%lu/environ", (unsigned long) pid);
- char_array_0(path);
f = fopen(path, "re");
if (!f)