Mercurial > masqmail
comparison src/listen.c @ 262:fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
The constants are all to bulky.
We should have different, meaningful exit codes anyway.
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Thu, 02 Dec 2010 17:11:25 -0300 |
parents | dcb315792513 |
children | 63efd381e27b |
comparison
equal
deleted
inserted
replaced
261:0afe18a9ee03 | 262:fc1c6425c024 |
---|---|
36 pid_t pid; | 36 pid_t pid; |
37 int status; | 37 int status; |
38 | 38 |
39 pid = waitpid(0, &status, 0); | 39 pid = waitpid(0, &status, 0); |
40 if (pid > 0) { | 40 if (pid > 0) { |
41 if (WEXITSTATUS(status) != EXIT_SUCCESS) | 41 if (WEXITSTATUS(status) != 0) |
42 logwrite(LOG_WARNING, "process %d exited with %d\n", pid, WEXITSTATUS(status)); | 42 logwrite(LOG_WARNING, "process %d exited with %d\n", pid, WEXITSTATUS(status)); |
43 if (WIFSIGNALED(status)) | 43 if (WIFSIGNALED(status)) |
44 logwrite(LOG_WARNING, "process with pid %d got signal: %d\n", pid, WTERMSIG(status)); | 44 logwrite(LOG_WARNING, "process with pid %d got signal: %d\n", pid, WTERMSIG(status)); |
45 } | 45 } |
46 signal(SIGCHLD, sigchld_handler); | 46 signal(SIGCHLD, sigchld_handler); |
77 out = fdopen(sock, "w"); | 77 out = fdopen(sock, "w"); |
78 in = fdopen(dup_sock, "r"); | 78 in = fdopen(dup_sock, "r"); |
79 | 79 |
80 smtp_in(in, out, rem_host, ident); | 80 smtp_in(in, out, rem_host, ident); |
81 | 81 |
82 _exit(EXIT_SUCCESS); | 82 _exit(0); |
83 } else if (pid < 0) { | 83 } else if (pid < 0) { |
84 logwrite(LOG_WARNING, "could not fork for incoming smtp connection: %s\n", strerror(errno)); | 84 logwrite(LOG_WARNING, "could not fork for incoming smtp connection: %s\n", strerror(errno)); |
85 } | 85 } |
86 #ifdef ENABLE_IDENT | 86 #ifdef ENABLE_IDENT |
87 if (ident != NULL) | 87 if (ident != NULL) |
116 g_list_free_1(node); | 116 g_list_free_1(node); |
117 continue; | 117 continue; |
118 } | 118 } |
119 if (listen(sock, 1) < 0) { | 119 if (listen(sock, 1) < 0) { |
120 logwrite(LOG_ALERT, "listen: (terminating): %s\n", strerror(errno)); | 120 logwrite(LOG_ALERT, "listen: (terminating): %s\n", strerror(errno)); |
121 exit(EXIT_FAILURE); | 121 exit(1); |
122 } | 122 } |
123 logwrite(LOG_NOTICE, "listening on interface %s:%d\n", iface->address, iface->port); | 123 logwrite(LOG_NOTICE, "listening on interface %s:%d\n", iface->address, iface->port); |
124 DEBUG(5) debugf("sock = %d\n", sock); | 124 DEBUG(5) debugf("sock = %d\n", sock); |
125 FD_SET(sock, &active_fd_set); | 125 FD_SET(sock, &active_fd_set); |
126 } | 126 } |
131 | 131 |
132 /* now that we have our socket(s), we can give up root privileges */ | 132 /* now that we have our socket(s), we can give up root privileges */ |
133 if (!conf.run_as_user) { | 133 if (!conf.run_as_user) { |
134 if (setegid(conf.mail_gid) != 0) { | 134 if (setegid(conf.mail_gid) != 0) { |
135 logwrite(LOG_ALERT, "could not change gid to %d: %s\n", conf.mail_gid, strerror(errno)); | 135 logwrite(LOG_ALERT, "could not change gid to %d: %s\n", conf.mail_gid, strerror(errno)); |
136 exit(EXIT_FAILURE); | 136 exit(1); |
137 } | 137 } |
138 if (seteuid(conf.mail_uid) != 0) { | 138 if (seteuid(conf.mail_uid) != 0) { |
139 logwrite(LOG_ALERT, "could not change uid to %d: %s\n", conf.mail_uid, strerror(errno)); | 139 logwrite(LOG_ALERT, "could not change uid to %d: %s\n", conf.mail_uid, strerror(errno)); |
140 exit(EXIT_FAILURE); | 140 exit(1); |
141 } | 141 } |
142 } | 142 } |
143 | 143 |
144 /* sel_ret = 0; */ | 144 /* sel_ret = 0; */ |
145 time(&time_before); | 145 time(&time_before); |
171 or signal arrives, or queuing interval time elapsed (if qival > 0) */ | 171 or signal arrives, or queuing interval time elapsed (if qival > 0) */ |
172 read_fd_set = active_fd_set; | 172 read_fd_set = active_fd_set; |
173 if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL, qival > 0 ? &tm : NULL)) < 0) { | 173 if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL, qival > 0 ? &tm : NULL)) < 0) { |
174 if (errno != EINTR) { | 174 if (errno != EINTR) { |
175 logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno)); | 175 logwrite(LOG_ALERT, "select: (terminating): %s\n", strerror(errno)); |
176 exit(EXIT_FAILURE); | 176 exit(1); |
177 } else { | 177 } else { |
178 if (sighup_seen) { | 178 if (sighup_seen) { |
179 logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n"); | 179 logwrite(LOG_NOTICE, "HUP signal received. Restarting daemon\n"); |
180 | 180 |
181 for (i = 0; i < FD_SETSIZE; i++) | 181 for (i = 0; i < FD_SETSIZE; i++) |
182 if (FD_ISSET(i, &active_fd_set)) | 182 if (FD_ISSET(i, &active_fd_set)) |
183 close(i); | 183 close(i); |
184 | 184 |
185 execv(argv[0], &(argv[0])); | 185 execv(argv[0], &(argv[0])); |
186 logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno)); | 186 logwrite(LOG_ALERT, "restarting failed: %s\n", strerror(errno)); |
187 exit(EXIT_FAILURE); | 187 exit(1); |
188 } | 188 } |
189 } | 189 } |
190 } else if (sel_ret > 0) { | 190 } else if (sel_ret > 0) { |
191 for (i = 0; i < FD_SETSIZE; i++) { | 191 for (i = 0; i < FD_SETSIZE; i++) { |
192 if (FD_ISSET(i, &read_fd_set)) { | 192 if (FD_ISSET(i, &read_fd_set)) { |
206 int pid; | 206 int pid; |
207 signal(SIGCHLD, sigchld_handler); | 207 signal(SIGCHLD, sigchld_handler); |
208 if ((pid = fork()) == 0) { | 208 if ((pid = fork()) == 0) { |
209 queue_run(); | 209 queue_run(); |
210 | 210 |
211 _exit(EXIT_SUCCESS); | 211 _exit(0); |
212 } else if (pid < 0) { | 212 } else if (pid < 0) { |
213 logwrite(LOG_ALERT, "could not fork for queue run"); | 213 logwrite(LOG_ALERT, "could not fork for queue run"); |
214 } | 214 } |
215 } | 215 } |
216 } | 216 } |