[PATCH 1/7] PID namespace translation support
Dmitry V. Levin
ldv at altlinux.org
Thu Jul 16 21:41:04 UTC 2020
On Sun, Jul 12, 2020 at 09:46:30PM +0200, Ákos Uzonyi wrote:
[...]
> +static const char *
> +pid_to_str(pid_t pid)
> +{
> + static char buf[sizeof("-2147483648")];
> + ssize_t ret;
> +
> + if (!pid)
> + return "self";
> +
> + ret = snprintf(buf, sizeof(buf), "%d", pid);
> +
> + if ((ret < 0) || ((size_t) ret >= sizeof(buf)))
> + perror_msg_and_die("pid_to_str: snprintf");
Consider using xsprintf.
> +static size_t
> +get_ns_hierarchy(int proc_pid, uint64_t *ns_buf, size_t ns_buf_size)
> +{
> + char path[PATH_MAX + 1];
> + struct stat st;
> + ssize_t ret;
> + size_t n = 0;
> + int fd;
> + int parent_fd;
> +
> + ret = snprintf(path, sizeof(path), "/proc/%s/ns/pid",
> + pid_to_str(proc_pid));
> +
> + if ((ret < 0) || ((size_t) ret >= sizeof(path)))
> + return 0;
Likewise.
--
ldv
More information about the Strace-devel
mailing list