Show More
@@ -418,11 +418,7 b' hgclient_t *hgc_open(const char *socknam' | |||||
418 |
|
418 | |||
419 | /* don't keep fd on fork(), so that it can be closed when the parent |
|
419 | /* don't keep fd on fork(), so that it can be closed when the parent | |
420 | * process get terminated. */ |
|
420 | * process get terminated. */ | |
421 | int flags = fcntl(fd, F_GETFD); |
|
421 | fsetcloexec(fd); | |
422 | if (flags < 0) |
|
|||
423 | abortmsgerrno("cannot get flags of socket"); |
|
|||
424 | if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) |
|
|||
425 | abortmsgerrno("cannot set flags of socket"); |
|
|||
426 |
|
422 | |||
427 | struct sockaddr_un addr; |
|
423 | struct sockaddr_un addr; | |
428 | addr.sun_family = AF_UNIX; |
|
424 | addr.sun_family = AF_UNIX; |
@@ -8,6 +8,7 b'' | |||||
8 | */ |
|
8 | */ | |
9 |
|
9 | |||
10 | #include <errno.h> |
|
10 | #include <errno.h> | |
|
11 | #include <fcntl.h> | |||
11 | #include <signal.h> |
|
12 | #include <signal.h> | |
12 | #include <stdarg.h> |
|
13 | #include <stdarg.h> | |
13 | #include <stdio.h> |
|
14 | #include <stdio.h> | |
@@ -91,6 +92,15 b' void fchdirx(int dirfd)' | |||||
91 | abortmsgerrno("failed to fchdir"); |
|
92 | abortmsgerrno("failed to fchdir"); | |
92 | } |
|
93 | } | |
93 |
|
94 | |||
|
95 | void fsetcloexec(int fd) | |||
|
96 | { | |||
|
97 | int flags = fcntl(fd, F_GETFD); | |||
|
98 | if (flags < 0) | |||
|
99 | abortmsgerrno("cannot get flags of fd %d", fd); | |||
|
100 | if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) | |||
|
101 | abortmsgerrno("cannot set flags of fd %d", fd); | |||
|
102 | } | |||
|
103 | ||||
94 | void *mallocx(size_t size) |
|
104 | void *mallocx(size_t size) | |
95 | { |
|
105 | { | |
96 | void *result = malloc(size); |
|
106 | void *result = malloc(size); |
@@ -24,6 +24,7 b' void enabledebugmsg(void);' | |||||
24 | void debugmsg(const char *fmt, ...) PRINTF_FORMAT_; |
|
24 | void debugmsg(const char *fmt, ...) PRINTF_FORMAT_; | |
25 |
|
25 | |||
26 | void fchdirx(int dirfd); |
|
26 | void fchdirx(int dirfd); | |
|
27 | void fsetcloexec(int fd); | |||
27 | void *mallocx(size_t size); |
|
28 | void *mallocx(size_t size); | |
28 | void *reallocx(void *ptr, size_t size); |
|
29 | void *reallocx(void *ptr, size_t size); | |
29 |
|
30 |
General Comments 0
You need to be logged in to leave comments.
Login now