annotate src/listen.c @ 421:f37384470855

Changed lockdir to /var/lock/masqmail; Create lockdir and piddir on startup. Moved the lockdir out of the spool dir. (When /var/lock is a ramdisk we do well to have the lock files there.) Added the new configure option --with-lockdir to change that location. Nontheless, if we run_as_user, then lock files are always stored in the spool dir directly. Instead of installing the lockdir and piddir at installation time, we create them on startup time now if they are missing. This is necessary if lockdir or piddir are a tmpfs.
author markus schnalke <meillo@marmaro.de>
date Wed, 30 May 2012 09:38:38 +0200
parents 4848c16ed1c1
children 180a7f6a9383
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
1 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
2 ** MasqMail
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
3 ** Copyright (C) 1999/2000 Oliver Kurth
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
4 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
5 ** This program is free software; you can redistribute it and/or modify
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
6 ** it under the terms of the GNU General Public License as published by
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
7 ** the Free Software Foundation; either version 2 of the License, or
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
8 ** (at your option) any later version.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
9 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
10 ** This program is distributed in the hope that it will be useful,
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
13 ** GNU General Public License for more details.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
14 **
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
15 ** You should have received a copy of the GNU General Public License
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
16 ** along with this program; if not, write to the Free Software
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
18 */
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
19
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
20 #include <sys/wait.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
21 #include <sys/types.h>
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
22
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
23 #include "masqmail.h"
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
24
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
25 static int volatile sighup_seen = 0;
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
26
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
27 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
28 sighup_handler(int sig)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
29 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
30 sighup_seen = 1;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
31 signal(SIGHUP, sighup_handler);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
32 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
33
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
34 static void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
35 sigchld_handler(int sig)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
36 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
37 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
38 int status;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
39
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
40 pid = waitpid(0, &status, 0);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
41 if (pid > 0) {
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
42 if (WEXITSTATUS(status) != 0) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
43 logwrite(LOG_WARNING, "process %d exited with %d\n",
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
44 pid, WEXITSTATUS(status));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
45 }
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
46 if (WIFSIGNALED(status)) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
47 logwrite(LOG_WARNING, "process %d got signal: %d\n",
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
48 pid, WTERMSIG(status));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
49 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
50 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
51 signal(SIGCHLD, sigchld_handler);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
52 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
53
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
54 void
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
55 accept_connect(int listen_sock, int sock, struct sockaddr_in *sock_addr)
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
56 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
57 pid_t pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
58 int dup_sock = dup(sock);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
59 FILE *out, *in;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
60 gchar *rem_host;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
61 gchar *ident = NULL;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
62
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
63 rem_host = g_strdup(inet_ntoa(sock_addr->sin_addr));
383
a2909de1818b Port number are unsigned. This corrects the logfile output.
markus schnalke <meillo@marmaro.de>
parents: 378
diff changeset
64 logwrite(LOG_NOTICE, "connect from host %s, port %hu\n",
a2909de1818b Port number are unsigned. This corrects the logfile output.
markus schnalke <meillo@marmaro.de>
parents: 378
diff changeset
65 rem_host, ntohs(sock_addr->sin_port));
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
66
207
dcb315792513 removed commented code and replaced // by /* */
meillo@marmaro.de
parents: 204
diff changeset
67 /* start child for connection: */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
68 signal(SIGCHLD, sigchld_handler);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
69 pid = fork();
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
70 if (pid < 0) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
71 logwrite(LOG_WARNING, "could not fork for incoming smtp "
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
72 "connection: %s\n", strerror(errno));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
73 } else if (pid == 0) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
74 /* child */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
75 close(listen_sock);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
76 out = fdopen(sock, "w");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
77 in = fdopen(dup_sock, "r");
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
78 smtp_in(in, out, rem_host, ident);
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 207
diff changeset
79 _exit(0);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
80 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
81
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
82 close(sock);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
83 close(dup_sock);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
84 }
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
85
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
86 void
366
41958685480d Switched to `type *name' style
markus schnalke <meillo@marmaro.de>
parents: 332
diff changeset
87 listen_port(GList *iface_list, gint qival, char *argv[])
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
88 {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
89 int i;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
90 fd_set active_fd_set, read_fd_set;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
91 struct timeval tm;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
92 time_t time_before, time_now;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
93 struct sockaddr_in clientname;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
94 size_t size;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
95 GList *node, *node_next;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
96 int sel_ret;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
97
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
98 /* Create the sockets and set them up to accept connections. */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
99 FD_ZERO(&active_fd_set);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
100 for (node = g_list_first(iface_list); node; node = node_next) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
101 interface *iface = (interface *) (node->data);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
102 int sock;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
103
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
104 node_next = g_list_next(node);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
105 if ((sock = make_server_socket(iface)) < 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
106 iface_list = g_list_remove_link(iface_list, node);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
107 g_list_free_1(node);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
108 continue;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
109 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
110 if (listen(sock, 1) < 0) {
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
111 logwrite(LOG_ALERT, "listen: (terminating): %s\n",
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
112 strerror(errno));
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 207
diff changeset
113 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
114 }
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
115 logwrite(LOG_NOTICE, "listening on interface %s:%d\n",
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
116 iface->address, iface->port);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
117 DEBUG(5) debugf("sock = %d\n", sock);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
118 FD_SET(sock, &active_fd_set);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
119 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
120
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
121 /* setup handler for HUP signal: */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
122 signal(SIGHUP, sighup_handler);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
123 signal(SIGCHLD, sigchld_handler);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
124
15
f671821d8222 code beautifying; 0 -> \0 if appropriate
meillo@marmaro.de
parents: 10
diff changeset
125 /* now that we have our socket(s), we can give up root privileges */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
126 if (!conf.run_as_user) {
332
63efd381e27b refactoring, partly also related to set_euidgid()
markus schnalke <meillo@marmaro.de>
parents: 262
diff changeset
127 set_euidgid(conf.mail_uid, conf.mail_gid, NULL, NULL);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
128 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
129
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
130 /* sel_ret = 0; */
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
131 time(&time_before);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
132 time_before -= qival;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
133 sel_ret = -1;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
134
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
135 while (1) {
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
136
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
137 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
138 ** if we were interrupted by an incoming connection (or a
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
139 ** signal) we have to recalculate the time until the next
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
140 ** queue run should occur. select may put a value into tm,
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
141 ** but doc for select() says we should not use it.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
142 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
143 if (qival > 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
144 time(&time_now);
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
145 if (!sel_ret) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
146 /* either just starting or after a queue run */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
147 tm.tv_sec = qival;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
148 tm.tv_usec = 0;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
149 time_before = time_now;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
150 } else {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
151 tm.tv_sec = qival - (time_now - time_before);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
152 tm.tv_usec = 0;
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
153
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
154 /* race condition, unlikely (but possible): */
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
155 if (tm.tv_sec < 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
156 tm.tv_sec = 0;
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
157 }
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
158 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
159 }
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
160 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
161 ** Block until input arrives on one or more active sockets,
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
162 ** or signal arrives, or queuing interval time elapsed
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
163 ** (if qival > 0)
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
164 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
165 read_fd_set = active_fd_set;
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
166 if ((sel_ret = select(FD_SETSIZE, &read_fd_set, NULL, NULL,
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
167 qival > 0 ? &tm : NULL)) < 0) {
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
168 if (errno != EINTR) {
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
169 logwrite(LOG_ALERT, "select: (terminating): "
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
170 "%s\n", strerror(errno));
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 207
diff changeset
171 exit(1);
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
172 } else if (sighup_seen) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
173 logwrite(LOG_NOTICE, "HUP signal received. "
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
174 "Restarting daemon\n");
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
175
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
176 for (i = 0; i < FD_SETSIZE; i++)
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
177 if (FD_ISSET(i, &active_fd_set))
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
178 close(i);
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
179
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
180 execv(argv[0], &(argv[0]));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
181 logwrite(LOG_ALERT, "restarting failed: %s\n",
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
182 strerror(errno));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
183 exit(1);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
184 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
185 } else if (sel_ret > 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
186 for (i = 0; i < FD_SETSIZE; i++) {
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
187 int sock = i;
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
188 int new;
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
189
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
190 if (!FD_ISSET(i, &read_fd_set)) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
191 continue;
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
192 }
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
193 size = sizeof(clientname);
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
194 new = accept(sock, (struct sockaddr *)
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
195 &clientname, &size);
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
196 if (new < 0) {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
197 logwrite(LOG_ALERT, "accept: (ignoring): %s\n", strerror(errno));
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
198 } else {
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
199 accept_connect(sock, new,
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
200 &clientname);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
201 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
202 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
203 } else {
367
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
204 /*
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
205 ** If select returns 0, the interval time has elapsed.
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
206 ** We start a new queue runner process
b27f66555ba8 Reformated multiline comments to have leading asterisks on each line
markus schnalke <meillo@marmaro.de>
parents: 366
diff changeset
207 */
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
208 int pid;
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
209 signal(SIGCHLD, sigchld_handler);
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
210 if ((pid = fork()) == 0) {
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
211 queue_run();
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
212
262
fc1c6425c024 s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents: 207
diff changeset
213 _exit(0);
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
214 } else if (pid < 0) {
384
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
215 logwrite(LOG_ALERT, "could not fork for "
4848c16ed1c1 Beautifying.
markus schnalke <meillo@marmaro.de>
parents: 383
diff changeset
216 "queue run");
10
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
217 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
218 }
26e34ae9a3e3 changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents: 0
diff changeset
219 }
0
08114f7dcc23 this is masqmail-0.2.21 from oliver kurth
meillo@marmaro.de
parents:
diff changeset
220 }