Bug #18152 » 0001-Fix-theoretical-bug-with-signals-qsort-a.patch
process.c | ||
---|---|---|
return 0;
|
||
}
|
||
/*
|
||
* Sort an array of pairs via intcmp. Unlike qsort, this is async-signal-safe.
|
||
* Although this uses insertion sort and does not scale well,
|
||
* in practice n invariably is small so scaling is not a practical issue.
|
||
*/
|
||
static void
|
||
pairsort(struct run_exec_dup2_fd_pair *pairs, long n)
|
||
{
|
||
long i, j;
|
||
for (i = 1; i < n; i++) {
|
||
struct run_exec_dup2_fd_pair key = pairs[i];
|
||
for (j = i; j > 0 && intcmp(&key, &pairs[j - 1]) < 0; j--)
|
||
pairs[j] = pairs[j - 1];
|
||
pairs[j] = key;
|
||
}
|
||
}
|
||
/* This function should be async-signal-safe when sargp is NULL. Hopefully it is. */
|
||
static int
|
||
run_exec_dup2(VALUE ary, VALUE tmpbuf, struct rb_execarg *sargp, char *errmsg, size_t errmsg_buflen)
|
||
... | ... | |
/* sort the table by oldfd: O(n log n) */
|
||
if (!sargp)
|
||
qsort(pairs, n, sizeof(struct run_exec_dup2_fd_pair), intcmp); /* hopefully async-signal-safe */
|
||
pairsort(pairs, n); /* async-signal-safe */
|
||
else
|
||
qsort(pairs, n, sizeof(struct run_exec_dup2_fd_pair), intrcmp);
|
||
- « Previous
- 1
- 2
- Next »