diff options
Diffstat (limited to 'util-linux/switch_root.c')
-rw-r--r-- | util-linux/switch_root.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index 6034485d7..f18e8a5ce 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c | |||
@@ -141,10 +141,12 @@ int switch_root_main(int argc UNUSED_PARAM, char **argv) | |||
141 | 141 | ||
142 | // If a new console specified, redirect stdin/stdout/stderr to it | 142 | // If a new console specified, redirect stdin/stdout/stderr to it |
143 | if (console) { | 143 | if (console) { |
144 | close(0); | 144 | int fd = open_or_warn(console, O_RDWR); |
145 | xopen(console, O_RDWR); | 145 | if (fd >= 0) { |
146 | xdup2(0, 1); | 146 | xmove_fd(fd, 0); |
147 | xdup2(0, 2); | 147 | xdup2(0, 1); |
148 | xdup2(0, 2); | ||
149 | } | ||
148 | } | 150 | } |
149 | 151 | ||
150 | // Exec real init | 152 | // Exec real init |
@@ -181,7 +183,7 @@ So there's a step that needs to be sort of atomic but can't be as a shell | |||
181 | script. (You can work around this with static linking or very carefully laid | 183 | script. (You can work around this with static linking or very carefully laid |
182 | out paths and sequencing, but it's brittle, ugly, and non-obvious.) | 184 | out paths and sequencing, but it's brittle, ugly, and non-obvious.) |
183 | 185 | ||
184 | 2) The "find | rm" bit will acually delete everything because the mount points | 186 | 2) The "find | rm" bit will actually delete everything because the mount points |
185 | still show up (even if their contents don't), and rm -rf will then happily zap | 187 | still show up (even if their contents don't), and rm -rf will then happily zap |
186 | that. So the first line is an oversimplification of what you need to do _not_ | 188 | that. So the first line is an oversimplification of what you need to do _not_ |
187 | to descend into other filesystems and delete their contents. | 189 | to descend into other filesystems and delete their contents. |