aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2007-12-16 12:09:48 +0100
committerWilly Tarreau <w@1wt.eu>2007-12-16 12:09:48 +0100
commit33952960121fab30f87581deb7876276786d877d (patch)
treec8425241ef649a4cc2094404be884126aa97eb34
parentinit: add the "br" command to branch without returning (diff)
downloadflxutils-33952960121fab30f87581deb7876276786d877d.tar.xz
init: add new commands "cd", "cr" and "sw"
cd <dir> does chdir(dir) cr <dir> does only chroot(dir) sw <dir> does chroot(dir), chdir(/) and reopens the console
-rw-r--r--init/init.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/init/init.c b/init/init.c
index a1949b0..abb8b42 100644
--- a/init/init.c
+++ b/init/init.c
@@ -306,6 +306,9 @@ enum {
TOK_CH, /* ch : make char devices */
TOK_FI, /* fi : make a fifo */
TOK_MA, /* ma : set umask */
+ TOK_CD, /* cd : chdir */
+ TOK_CR, /* cr : chroot (without chdir) */
+ TOK_SW, /* sw : switch root = chdir + chroot . + reopen console */
TOK_PR, /* pr : pivot root */
TOK_MV, /* mv : move a filesystem */
TOK_BI, /* bi : bind a directory */
@@ -329,7 +332,7 @@ enum {
};
/* counts from TOK_LN to TOK_DOT */
-#define NB_TOKENS 26
+#define NB_TOKENS 29
/* possible states for variable parsing */
enum {
@@ -360,6 +363,9 @@ static const __attribute__ ((__section__(STR_SECT),__aligned__(1))) struct {
"ch", 'C', 6, /* TOK_CH */
"fi", 'F', 4, /* TOK_FI */
"ma", 'U', 1, /* TOK_MA */
+ "cd", 0, 1, /* TOK_CD */
+ "cr", 0, 1, /* TOK_CR */
+ "sw", 0, 1, /* TOK_SW */
"pr", 'P', 2, /* TOK_PR */
"mv", 'K', 2, /* TOK_MV */
"bi", 'K', 2, /* TOK_BI */
@@ -1786,6 +1792,33 @@ int main(int argc, char **argv, char **envp) {
/* U <umask> : change umask */
umask(a2mode(cfg_args[1]));
break;
+ case TOK_CD:
+ /* cd <new_dir> : change current directory */
+ if (chdir(cfg_args[1]) == -1) {
+ error = 1;
+ print("cd : error during chdir()\n");
+ }
+ break;
+ case TOK_CR:
+ /* cr <new_root> : change root without chdir */
+ if (chroot(cfg_args[1]) == -1) {
+ error = 1;
+ print("cr (chroot) : error during chroot()\n");
+ }
+ break;
+ case TOK_SW:
+ /* sw <new_root> : switch root + reopen console from new root if it exists */
+ if (chroot(cfg_args[1]) == -1) {
+ error = 1;
+ print("cr (chroot) : error during chroot()\n");
+ }
+ if (chdir(root_dir) == -1) {
+ error = 1;
+ print("cd : error during chdir()\n");
+ }
+ /* replace stdin/stdout/stderr with newer ones */
+ reopen_console();
+ break;
case TOK_PR:
/* P <new_root> <put_old_relative> : pivot root */
if (chdir(cfg_args[1]) == -1) {