|
Lines 44-50
Link Here
|
| 44 |
|
44 |
|
| 45 |
#include "sd-daemon.h" |
45 |
#include "sd-daemon.h" |
| 46 |
|
46 |
|
| 47 |
int sd_listen_fds(int unset_environment) { |
47 |
static int _sd_listen_fds(int unset_environment, int close_on_exec) { |
| 48 |
|
48 |
|
| 49 |
#if defined(DISABLE_SYSTEMD) || !defined(__linux__) |
49 |
#if defined(DISABLE_SYSTEMD) || !defined(__linux__) |
| 50 |
return 0; |
50 |
return 0; |
|
Lines 107-113
int sd_listen_fds(int unset_environment) {
Link Here
|
| 107 |
if (flags & FD_CLOEXEC) |
107 |
if (flags & FD_CLOEXEC) |
| 108 |
continue; |
108 |
continue; |
| 109 |
|
109 |
|
| 110 |
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { |
110 |
if (close_on_exec && fcntl(fd, F_SETFD, flags | FD_CLOEXEC) < 0) { |
| 111 |
r = -errno; |
111 |
r = -errno; |
| 112 |
goto finish; |
112 |
goto finish; |
| 113 |
} |
113 |
} |
|
Lines 125-130
finish:
Link Here
|
| 125 |
#endif |
125 |
#endif |
| 126 |
} |
126 |
} |
| 127 |
|
127 |
|
|
|
128 |
int sd_listen_fds(int unset_environment) { |
| 129 |
return _sd_listen_fds(unset_environment, 1); |
| 130 |
} |
| 131 |
|
| 132 |
int sd_listen_fds_check(void) { |
| 133 |
return _sd_listen_fds(0, 0); |
| 134 |
} |
| 135 |
|
| 136 |
void sd_listen_pid_inherit(void) { |
| 137 |
const char *env; |
| 138 |
|
| 139 |
/* |
| 140 |
Type=forking & systemd socket activation: |
| 141 |
fetch listen pid and update to ours, |
| 142 |
when it is set to pid of our parent. |
| 143 |
*/ |
| 144 |
if ((env = getenv("LISTEN_PID"))) { |
| 145 |
char *ptr; |
| 146 |
long l; |
| 147 |
|
| 148 |
errno = 0; |
| 149 |
l = strtol(env, &ptr, 10); |
| 150 |
if (errno != 0) |
| 151 |
return; |
| 152 |
if (ptr == env) |
| 153 |
return; |
| 154 |
if (*ptr != '\0') |
| 155 |
return; |
| 156 |
if (l < 0) |
| 157 |
return; |
| 158 |
if (getppid() == (pid_t)l) { |
| 159 |
char buf[24]; |
| 160 |
snprintf(buf, sizeof(buf), "%d", getpid()); |
| 161 |
setenv("LISTEN_PID", buf, 1); |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
|
| 128 |
int sd_is_fifo(int fd, const char *path) { |
166 |
int sd_is_fifo(int fd, const char *path) { |
| 129 |
struct stat st_fd; |
167 |
struct stat st_fd; |
| 130 |
|
168 |
|