libdaemon/libdaemon-0.11-stdarg-fix.patch

57 lines
1.2 KiB
Diff

--- libdaemon-0.11/libdaemon/dfork.c.debug 2007-06-11 11:36:11.000000000 -0400
+++ libdaemon-0.11/libdaemon/dfork.c 2007-07-02 14:49:35.000000000 -0400
@@ -354,31 +354,38 @@
int daemon_close_all(int except_fd, ...) {
va_list original_ap, ap;
- int n, i, r;
- int *p;
+ int n = 0, i = 0, r = -1;
+ int *p = NULL;
- va_start(original_ap, except_fd);
- va_copy(ap, original_ap);
+ if (except_fd >= 0) {
+ va_start(original_ap, except_fd);
+ va_copy(ap, original_ap);
- for (n = 0; va_arg(ap, int) >= 0; n++)
- ;
+ for (n = 0; va_arg(ap, int) >= 0; n++)
+ ;
- va_end(ap);
-
- if (!(p = malloc(sizeof(int) * (n+1)))) {
- va_end(original_ap);
- return -1;
+ va_end(ap);
}
- i = 0;
- while ((p[i++] = va_arg(original_ap, int)) >= 0)
- ;
+ if (!(p = malloc(sizeof(int) * (n+2))))
+ goto out;
+
+ p[i++] = except_fd;
+
+ if (except_fd >= 0) {
+ i = 1;
+ while ((p[i++] = va_arg(original_ap, int)) >= 0)
+ ;
+ }
p[i] = -1;
r = daemon_close_allv(p);
+
+out:
+ if (except_fd >= 0)
+ va_end(original_ap);
free(p);
-
return r;
}