ruby-changes:6403
From: nobu <ko1@a...>
Date: Mon, 7 Jul 2008 02:05:12 +0900 (JST)
Subject: [ruby-changes:6403] Ruby:r17919 (mvm): * dir.c (dir_s_chdir): restore cwd by fchdir if possible.
nobu 2008-07-07 02:04:59 +0900 (Mon, 07 Jul 2008) New Revision: 17919 Modified files: branches/mvm/ChangeLog branches/mvm/configure.in branches/mvm/dir.c Log: * dir.c (dir_s_chdir): restore cwd by fchdir if possible. http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=17919 Index: mvm/configure.in =================================================================== --- mvm/configure.in (revision 17918) +++ mvm/configure.in (revision 17919) @@ -727,7 +727,7 @@ strlcpy strlcat) AC_CHECK_FUNCS(fmod killpg wait4 waitpid fork spawnv syscall chroot fsync getcwd eaccess\ truncate ftruncate chsize times utimes utimensat fcntl lockf lstat\ - link symlink readlink\ + link symlink readlink dirfd fchdir openat\ setitimer setruid seteuid setreuid setresuid setproctitle socketpair\ setrgid setegid setregid setresgid issetugid pause lchown lchmod\ getpgrp setpgrp getpgid setpgid initgroups getgroups setgroups\ Index: mvm/ChangeLog =================================================================== --- mvm/ChangeLog (revision 17918) +++ mvm/ChangeLog (revision 17919) @@ -1,3 +1,7 @@ +Mon Jul 7 02:04:57 2008 Nobuyoshi Nakada <nobu@r...> + + * dir.c (dir_s_chdir): restore cwd by fchdir if possible. + Mon Jul 7 01:24:43 2008 Nobuyoshi Nakada <nobu@r...> * file.c (rb_file_s_extname): fix for file name with spaces. Index: mvm/dir.c =================================================================== --- mvm/dir.c (revision 17918) +++ mvm/dir.c (revision 17919) @@ -756,6 +756,9 @@ struct chdir_data { VALUE old_path, new_path; +#if defined HAVE_DIRFD && defined HAVE_FCHDIR + DIR *old_dir; +#endif int done; }; @@ -777,11 +780,43 @@ chdir_blocking--; if (chdir_blocking == 0) chdir_thread = Qnil; +#if defined HAVE_DIRFD && defined HAVE_FCHDIR + if (fchdir(dirfd(args->old_dir)) < 0) { + closedir(args->old_dir); + rb_sys_fail(RSTRING_PTR(args->old_path)); + } + closedir(args->old_dir); +#else dir_chdir(args->old_path); +#endif } return Qnil; } +static void +dir_chdir_check(void) +{ + if (chdir_blocking > 0) { + if (!rb_block_given_p() || rb_thread_current() != chdir_thread) + rb_warn("conflicting chdir during another chdir block"); + } +} + +static VALUE +dir_chdir_block(VALUE path) +{ + struct chdir_data args; + char *cwd = my_getcwd(); + + args.old_path = rb_tainted_str_new2(cwd); xfree(cwd); + args.new_path = path; +#if defined HAVE_DIRFD && defined HAVE_FCHDIR + args.old_dir = opendir("."); +#endif + args.done = Qfalse; + return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)&args); +} + /* * call-seq: * Dir.chdir( [ string] ) => 0 @@ -839,20 +874,11 @@ path = rb_str_new2(dist); } - if (chdir_blocking > 0) { - if (!rb_block_given_p() || rb_thread_current() != chdir_thread) - rb_warn("conflicting chdir during another chdir block"); + dir_chdir_check(); + if (rb_block_given_p()) { + return dir_chdir_block(path); } - if (rb_block_given_p()) { - struct chdir_data args; - char *cwd = my_getcwd(); - - args.old_path = rb_tainted_str_new2(cwd); xfree(cwd); - args.new_path = path; - args.done = Qfalse; - return rb_ensure(chdir_yield, (VALUE)&args, chdir_restore, (VALUE)&args); - } dir_chdir(path); return INT2FIX(0); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/