~ubuntu-branches/ubuntu/trusty/util-linux/trusty-proposed

« back to all changes in this revision

Viewing changes to sys-utils/switch_root.c

  • Committer: Package Import Robot
  • Author(s): LaMont Jones
  • Date: 2011-11-03 15:38:23 UTC
  • mto: (4.5.5 sid) (1.6.4)
  • mto: This revision was merged to the branch mainline in revision 85.
  • Revision ID: package-import@ubuntu.com-20111103153823-10sx16jprzxlhkqf
ImportĀ upstreamĀ versionĀ 2.20.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <errno.h>
33
33
#include <ctype.h>
34
34
#include <dirent.h>
35
 
#include <err.h>
 
35
#include "c.h"
36
36
 
37
37
#ifndef MS_MOVE
38
38
#define MS_MOVE 8192
111
111
static int switchroot(const char *newroot)
112
112
{
113
113
        /*  Don't try to unmount the old "/", there's no way to do it. */
114
 
        const char *umounts[] = { "/dev", "/proc", "/sys", NULL };
 
114
        const char *umounts[] = { "/dev", "/proc", "/sys", "/run", NULL };
115
115
        int i;
116
116
        int cfd;
117
117
        pid_t pid;
 
118
        struct stat newroot_stat, sb;
 
119
 
 
120
        if (stat(newroot, &newroot_stat) != 0) {
 
121
                warn("failed to stat directory %s", newroot);
 
122
                return -1;
 
123
        }
118
124
 
119
125
        for (i = 0; umounts[i] != NULL; i++) {
120
126
                char newmount[PATH_MAX];
121
127
 
122
128
                snprintf(newmount, sizeof(newmount), "%s%s", newroot, umounts[i]);
123
129
 
 
130
                if ((stat(newmount, &sb) != 0) || (sb.st_dev != newroot_stat.st_dev)) {
 
131
                        /* mount point seems to be mounted already or stat failed */
 
132
                        umount(umounts[i]);
 
133
                        continue;
 
134
                }
 
135
 
124
136
                if (mount(umounts[i], newmount, NULL, MS_MOVE, NULL) < 0) {
125
137
                        warn("failed to mount moving %s to %s",
126
138
                                umounts[i], newmount);