Mercurial > masqmail
annotate src/online.c @ 337:fe00f7952a7c
Minor fixes in man pages, reported by lintian(1)
author | markus schnalke <meillo@marmaro.de> |
---|---|
date | Mon, 29 Aug 2011 19:32:38 +0200 (2011-08-29) |
parents | f10a56dc7481 |
children | 41958685480d |
rev | line source |
---|---|
0 | 1 /* MasqMail |
2 Copyright (C) 1999-2001 Oliver Kurth | |
279 | 3 Copyright (C) 2008, 2010 markus schnalke <meillo@marmaro.de> |
0 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2 of the License, or | |
8 (at your option) any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
16 along with this program; if not, write to the Free Software | |
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 */ | |
19 | |
20 #include <sys/wait.h> | |
15 | 21 |
0 | 22 #include "masqmail.h" |
23 #include "peopen.h" | |
24 | |
25 | |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
26 gchar* |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
27 online_query() |
279 | 28 { |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
29 gchar* pipe = conf.online_query; |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
30 pid_t pid; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
31 void (*old_signal) (int); |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
32 int status; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
33 FILE *in; |
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
34 gchar *name = NULL; |
0 | 35 |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
36 if (!conf.online_query) { |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
37 return NULL; |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
38 } |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
39 DEBUG(3) debugf("online query `%s'\n", pipe); |
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
40 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
41 old_signal = signal(SIGCHLD, SIG_DFL); |
0 | 42 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
43 in = peopen(pipe, "r", environ, &pid); |
310
f10a56dc7481
reworked online_detect to the simpler online_query
meillo@marmaro.de
parents:
279
diff
changeset
|
44 if (!in) { |
33 | 45 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno)); |
46 signal(SIGCHLD, old_signal); | |
47 return NULL; | |
48 } | |
49 | |
50 gchar output[256]; | |
51 if (fgets(output, 255, in)) { | |
52 g_strchomp(g_strchug(output)); | |
53 if (strlen(output) == 0) { | |
54 logwrite(LOG_ALERT, "only whitespace connection name\n"); | |
55 name = NULL; | |
18
99c09ed776c1
fixed empty or only-whitespace connection names
meillo@marmaro.de
parents:
15
diff
changeset
|
56 } else { |
33 | 57 name = g_strdup(output); |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
58 } |
33 | 59 } else { |
60 logwrite(LOG_ALERT, "nothing read from pipe %s\n", pipe); | |
61 name = NULL; | |
62 } | |
63 fclose(in); | |
64 waitpid(pid, &status, 0); | |
262
fc1c6425c024
s/EXIT_SUCCESS/0/ && s/EXIT_FAILURE/1/
markus schnalke <meillo@marmaro.de>
parents:
208
diff
changeset
|
65 if (WEXITSTATUS(status) != 0) { |
33 | 66 g_free(name); |
67 name = NULL; | |
68 } | |
0 | 69 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
70 signal(SIGCHLD, old_signal); |
0 | 71 |
10
26e34ae9a3e3
changed indention and line wrapping to a more consistent style
meillo@marmaro.de
parents:
0
diff
changeset
|
72 return name; |
0 | 73 } |