]> granicus.if.org Git - sudo/commitdiff
Actually. qsort is fine since most versions fal back to a cheaper
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 3 Sep 2009 13:21:43 +0000 (13:21 +0000)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 3 Sep 2009 13:21:43 +0000 (13:21 +0000)
sort when the number of elements to sort is small (like in our case).

script.c

index cb90938e995b0be0b6e52d867a9afb2517fcf8d2..0b69fef7f0debbbf2596e0ed95e0d6d617e72805 100644 (file)
--- a/script.c
+++ b/script.c
@@ -268,24 +268,21 @@ script_duplow(fd)
     /* sort fds so we can dup them safely */
     for (i = 0; i < 5; i++)
        indices[i] = i;
-    /* XXX - qsort is overkill for this */
     qsort(indices, 5, sizeof(int), fdcompar);
 
     /* Move pty master/slave and session fds to low numbered fds. */
-    if (def_script) {
-       for (i = 0; i < 5; i++) {
-           j = indices[i];
-           if (script_fds[j] != fd) {
+    for (i = 0; i < 5; i++) {
+       j = indices[i];
+       if (script_fds[j] != fd) {
 #ifdef HAVE_DUP2
-               dup2(script_fds[j], fd);
+           dup2(script_fds[j], fd);
 #else
-               close(fd);
-               dup(script_fds[j]);
-               close(script_fds[j]);
+           close(fd);
+           dup(script_fds[j]);
+           close(script_fds[j]);
 #endif
-           }
-           script_fds[j] = fd++;
        }
+       script_fds[j] = fd++;
     }
     return(fd);
 }