* process.c (run_exec_dup2): need to sort by reverted order when

restoring fds.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2008-12-04 15:35:08 +00:00
parent 49b10fd508
commit 80a3f22b77
2 changed files with 19 additions and 1 deletions

View File

@ -1,3 +1,8 @@
Fri Dec 5 00:34:10 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* process.c (run_exec_dup2): need to sort by reverted order when
restoring fds.
Fri Dec 5 00:17:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> Fri Dec 5 00:17:18 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (sym_to_proc): caches Symbol procs, based on a patch from * string.c (sym_to_proc): caches Symbol procs, based on a patch from

View File

@ -1767,7 +1767,11 @@ ttyprintf(const char *fmt, ...)
va_list ap; va_list ap;
FILE *tty; FILE *tty;
int save = errno; int save = errno;
#ifdef _WIN32
tty = fopen("con", "w");
#else
tty = fopen("/dev/tty", "w"); tty = fopen("/dev/tty", "w");
#endif
if (!tty) if (!tty)
return; return;
@ -1875,6 +1879,12 @@ intcmp(const void *a, const void *b)
return *(int*)a - *(int*)b; return *(int*)a - *(int*)b;
} }
static int
intrcmp(const void *a, const void *b)
{
return *(int*)b - *(int*)a;
}
static int static int
run_exec_dup2(VALUE ary, VALUE save) run_exec_dup2(VALUE ary, VALUE save)
{ {
@ -1900,7 +1910,10 @@ run_exec_dup2(VALUE ary, VALUE save)
} }
/* sort the table by oldfd: O(n log n) */ /* sort the table by oldfd: O(n log n) */
qsort(pairs, n, sizeof(struct fd_pair), intcmp); if (!save)
qsort(pairs, n, sizeof(struct fd_pair), intcmp);
else
qsort(pairs, n, sizeof(struct fd_pair), intrcmp);
/* initialize older_index and num_newer: O(n log n) */ /* initialize older_index and num_newer: O(n log n) */
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {