mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Tom Horsley <tom.horsley@ccur.com>
To: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: bugsy <bugsy@ccur.com>
Subject: CLONE_NEWNS and mount command?
Date: Thu, 27 Apr 2006 08:57:20 -0400	[thread overview]
Message-ID: <1146142640.23667.9.camel@tweety> (raw)

[-- Attachment #1: Type: text/plain, Size: 965 bytes --]

I stumbled across the CLONE_NEWNS flag in the clone() man page and
thought I'd see if I could write a program that would let me do things
like run an sshd on my machine in a different "namespace" created
before any network filesystems were mounted (so I could run rpm
commands without NFS timeouts, etc).

In my experiments though, I got very confused. I created the attached
program, used it to exec an xterm, then in that xterm unmounted
a NFS filesystem.

It disappeared from the mounts listed by the "mount" command
in both the old and new namespace, but if I attempted to remount
the system in the old namespace I get an error telling me it is
already mounted (even though it doesn't show up). In the new
namespace where I unmounted it, I can remount it (then it shows
up again in the mount listing in both namespaces).

Should the /proc/mounts file be paying more attention to this
"namespace" thing? Is this a bug, or just the way things happen
to work out?

[-- Attachment #2: nomounts.c --]
[-- Type: text/x-csrc, Size: 917 bytes --]

/* Run a process in a new "namespace".
 */
#include <sched.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>

#define STACK_SIZE ((20*4096)/sizeof(double))
static double stack_space[STACK_SIZE];

int
do_new_namespace(void * arg) {
   char ** argv = (char **)arg;
   execvp(argv[0], argv);
   perror("execvp");
   _exit(2);
}

int
main(int argc, char ** argv) {
   int clone_id;
   int wstat;
   pid_t kid;

   clone_id = clone(do_new_namespace, &stack_space[STACK_SIZE-2], CLONE_NEWNS,
                    (void *)(argv + 1));
   if (clone_id == -1) {
      perror("clone");
      _exit(2);
   }
   kid = waitpid((pid_t)clone_id, &wstat, 0);
   if (kid == (pid_t)-1) {
      perror("waitpid");
      _exit(2);
   }
   if ((kid == (pid_t)clone_id) && WIFEXITED(wstat)) {
      _exit(WEXITSTATUS(wstat));
   } else {
      _exit(2);
   }
}

             reply	other threads:[~2006-04-27 12:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-04-27 12:57 Tom Horsley [this message]
2006-04-27 13:01 ` Al Viro
2006-04-27 13:05   ` Tom Horsley
2006-04-27 14:49     ` Michael Tokarev

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=1146142640.23667.9.camel@tweety \
    --to=tom.horsley@ccur.com \
    --cc=bugsy@ccur.com \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome