Hi!
> +static int open_ns_fd(const char *pid, const char *ns)
> +{
> +     int fd;
> +     char file_buf[30];
> +
> +     sprintf(file_buf, "%s/%s/ns/%s", PROC_PATH, pid, ns);
> +
> +     fd = open(file_buf, O_RDONLY);
> +     if (fd > 0) {
> +             ns_fd[ns_fd_index] = fd;
> +             ++ns_fd_index;
> +             return 0;
> +     } else if (fd == -1 && errno != ENOENT) {
> +             tst_resm(TINFO | TERRNO, "open");
> +             return -1;
> +     }
> +
> +     return 0;
> +}
> +
> +static void close_ns_fd(void)
> +{
> +     int i;
> +
> +     for (i = 0; i < ns_fd_index; i++)
> +             close(ns_fd[i]);
> +}
> +
> +static int child_fn(void *arg)
> +{
> +     char **args = (char **)arg;
> +
> +     execvp(args[2], args+2);
> +     tst_resm(TINFO | TERRNO, "execvp");
> +     return 1;
> +}
> +
> +/*
> + * ./ns_exec <NS_PID> <PROGRAM> [ARGS]
> + */
> +int main(int argc, char *argv[])
> +{
> +     int i, rv, pid;
> +
> +     rv = syscall(__NR_setns, -1, 0);
> +     if (rv == -1 && errno == ENOSYS) {
> +             tst_resm(TINFO, "setns is not supported in the kernel");
> +             return 1;
> +     }
> +
> +     if (argc < 3) {
> +             tst_resm(TINFO, "%s <NS_PID> <PROGRAM> [ARGS]\n", argv[0]);
> +             return 1;
> +     }
> +
> +     rv = 0;
> +     memset(ns_fd, 0, sizeof(ns_fd));
> +     rv |= open_ns_fd(argv[1], "ipc");
> +     rv |= open_ns_fd(argv[1], "mnt");
> +     rv |= open_ns_fd(argv[1], "net");
> +     rv |= open_ns_fd(argv[1], "pid");
> +     rv |= open_ns_fd(argv[1], "user");
> +     rv |= open_ns_fd(argv[1], "uts");
> +     if (rv != 0)
> +             return 1;
> +
> +     if (ns_fd_index == 0) {
> +             tst_resm(TINFO, "no namespace entries in /proc/%s/ns/",
> +                      argv[1]);
> +             close_ns_fd();
> +             return 1;
> +     }
> +
> +     for (i = 0; i < ns_fd_index; i++) {
> +             if (syscall(__NR_setns, ns_fd[i], 0) == -1) {
> +                     tst_resm(TINFO | TERRNO, "setns");
> +                     close_ns_fd();

On SLES12 (kernel 3.12.28) setns() fails for the fd opened from "user"
namespace. I'm getting EINVAL here. Everything seems to work fine if I
comment the rf |= open_ns_fd(argv[1], "user"); line above.

Unfortunately EINVAL seems to be catch-all error for setns(), any idea
what is wrong here?

-- 
Cyril Hrubis
chru...@suse.cz

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to