From: Rutger Nijlunsing <rutger@nospam.com>
To: linux-kernel@vger.kernel.org, Paul Jakma <paul@clubi.ie>
Subject: Re: namespaces (was Re: [Q] don't allow tmpfs to page out)
Date: Thu, 15 Jul 2004 23:52:44 +0200 [thread overview]
Message-ID: <20040715215244.GA30119@nospam.com> (raw)
In-Reply-To: <20040715171909.GA5518@pclin040.win.tue.nl>
[-- Attachment #1: Type: text/plain, Size: 1474 bytes --]
On Thu, Jul 15, 2004 at 07:19:09PM +0200, Andries Brouwer wrote:
> On Thu, Jul 15, 2004 at 01:31:08PM +0100, Paul Jakma wrote:
>
> > speaking of which, how does one use namespaces exactly? The kernel
> > appears to maintain mount information per process, but how do you set
> > this up?
> >
> > neither 'man mount/namespace' nor 'appropos namespace' show up
> > anything.
>
> Try "man 2 clone" and look for CLONE_NEWNS.
>
> Somewhere else I wrote
>
> Since 2.4.19/2.5.2, the clone() system call, a generalization of
> Unix fork() and BSD vfork(), may have the CLONE_NEWNS flag, that
> says that all mount information must be copied. Afterwards, mount,
> chroot, pivotroot and similar namespace changing calls done by this
> new process do influence this process and its children, but not other
> processes. In particular, the virtual file /proc/mounts that lists the
> mounted filesystems, is now a symlink to /proc/self/mounts - different
> processes may live in entirely different file hierarchies.
>
> Andries
Or your page at
http://www.win.tue.nl/~aeb/linux/lk/lk-6.html
...which contains a working utility (section 6.3.3).
Attached an adopted version. Call like 'newnamespace /bin/bash' to
start bash in a new namespace.
--
Rutger Nijlunsing ---------------------------- rutger ed tux tmfweb nl
never attribute to a conspiracy which can be explained by incompetence
----------------------------------------------------------------------
[-- Attachment #2: newnamespace.c --]
[-- Type: text/plain, Size: 1166 bytes --]
/* newnamespace.c */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <signal.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/wait.h>
typedef struct {
char *path;
char **argv;
} FuncInfo;
int childfn(void *p) {
FuncInfo *fi = (FuncInfo *)p;
/* setenv("PS1", "@@ ", 1); */
execv(fi->path, fi->argv);
perror("execl");
fprintf(stderr, "Cannot exec '%s'\n", fi->path);
exit(1);
}
static char *default_path = "/bin/ash";
static char *default_argv[] = {"ash", NULL};
int main(int argc, char *argv[]) {
char buf[10000];
pid_t pid, p;
FuncInfo fi;
if (argc == 1) {
/* No arguments given */
fi.path = default_path;
fi.argv = default_argv;
} else {
int i;
argc--; argv++;
fi.path = *argv;
fi.argv = (char **)malloc(sizeof(char *) * (argc + 1));
for (i = 0; i < argc; i++) {
fi.argv[i] = argv[i];
}
fi.argv[argc] = NULL;
}
pid = clone(childfn, buf + 5000, CLONE_NEWNS | SIGCHLD, &fi);
if ((int) pid == -1) {
perror("clone");
exit(1);
}
p = waitpid(pid, NULL, 0);
if ((int) p == -1) {
perror("waitpid");
exit(1);
}
exit(0);
}
prev parent reply other threads:[~2004-07-15 21:52 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-15 7:58 [Q] don't allow tmpfs to page out christophe.varoqui
2004-07-15 8:00 ` Arjan van de Ven
2004-07-15 10:00 ` christophe.varoqui
2004-07-15 12:31 ` namespaces (was Re: [Q] don't allow tmpfs to page out) Paul Jakma
2004-07-15 12:31 ` Arjan van de Ven
2004-07-15 12:50 ` Paul Jakma
2004-07-15 22:35 ` [dm-devel] " christophe varoqui
2004-07-15 23:00 ` Chris Wedgwood
2004-07-15 17:19 ` Andries Brouwer
2004-07-15 21:52 ` Rutger Nijlunsing [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20040715215244.GA30119@nospam.com \
--to=rutger@nospam.com \
--cc=linux-kernel@tux.tmfweb.nl \
--cc=linux-kernel@vger.kernel.org \
--cc=paul@clubi.ie \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.