From e9c4b10446d5c3749f8bb851afa23f12e6f4fda8 Mon Sep 17 00:00:00 2001 From: Uchio KONDO Date: Fri, 10 Jun 2016 15:59:20 +0900 Subject: [PATCH 1/2] Implement Dir.chroot on mruby --- src/dir.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/dir.c b/src/dir.c index 1ea99eccf..00f2f0296 100644 --- a/src/dir.c +++ b/src/dir.c @@ -180,6 +180,29 @@ mrb_dir_chdir(mrb_state *mrb, mrb_value klass) return mrb_fixnum_value(0); } +mrb_value +mrb_dir_chroot(mrb_state *mrb, mrb_value self) +{ + #if defined(_WIN32) || defined(_WIN64) || defined(__android__) + mrb_raise(mrb, E_NOTIMP_ERROR, "chroot() unreliable on Win platforms"); + return mrb_fixnum_value(0); + #else + mrb_value spath; + char *path; + int res; + + mrb_get_args(mrb, "S", &spath); + path = mrb_str_to_cstr(mrb, spath); + res = chroot(path); + if (res == -1) { + perror("chroot"); + mrb_sys_fail(mrb, path); + } + + return mrb_fixnum_value(res); + #endif +} + mrb_value mrb_dir_read(mrb_state *mrb, mrb_value self) { @@ -266,6 +289,7 @@ mrb_mruby_dir_gem_init(mrb_state *mrb) mrb_define_class_method(mrb, d, "getwd", mrb_dir_getwd, MRB_ARGS_NONE()); mrb_define_class_method(mrb, d, "mkdir", mrb_dir_mkdir, MRB_ARGS_REQ(1)|MRB_ARGS_OPT(1)); mrb_define_class_method(mrb, d, "_chdir", mrb_dir_chdir, MRB_ARGS_REQ(1)); + mrb_define_class_method(mrb, d, "chroot", mrb_dir_chroot, MRB_ARGS_REQ(1)); mrb_define_method(mrb, d, "close", mrb_dir_close, MRB_ARGS_NONE()); mrb_define_method(mrb, d, "initialize", mrb_dir_init, MRB_ARGS_REQ(1)); From 7318ae59775b60b897f75f2f444ba4aee8d31ee2 Mon Sep 17 00:00:00 2001 From: Uchio KONDO Date: Mon, 13 Jun 2016 09:42:16 +0900 Subject: [PATCH 2/2] Remove perror --- src/dir.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/dir.c b/src/dir.c index 00f2f0296..e958ced8a 100644 --- a/src/dir.c +++ b/src/dir.c @@ -195,7 +195,6 @@ mrb_dir_chroot(mrb_state *mrb, mrb_value self) path = mrb_str_to_cstr(mrb, spath); res = chroot(path); if (res == -1) { - perror("chroot"); mrb_sys_fail(mrb, path); }