masqmail

view src/online.c @ 366:41958685480d

Switched to `type *name' style Andrew Koenig's ``C Traps and Pitfalls'' (Ch.2.1) convinced me that it is best to go with the way C had been designed. The ``declaration reflects use'' concept conflicts with a ``type* name'' notation. Hence I switched.
author markus schnalke <meillo@marmaro.de>
date Thu, 22 Sep 2011 15:07:40 +0200
parents f10a56dc7481
children b27f66555ba8
line source
1 /* MasqMail
2 Copyright (C) 1999-2001 Oliver Kurth
3 Copyright (C) 2008, 2010 markus schnalke <meillo@marmaro.de>
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.
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.
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 */
20 #include <sys/wait.h>
22 #include "masqmail.h"
23 #include "peopen.h"
26 gchar*
27 online_query()
28 {
29 gchar *pipe = conf.online_query;
30 pid_t pid;
31 void (*old_signal) (int);
32 int status;
33 FILE *in;
34 gchar *name = NULL;
36 if (!conf.online_query) {
37 return NULL;
38 }
39 DEBUG(3) debugf("online query `%s'\n", pipe);
41 old_signal = signal(SIGCHLD, SIG_DFL);
43 in = peopen(pipe, "r", environ, &pid);
44 if (!in) {
45 logwrite(LOG_ALERT, "could not open pipe '%s': %s\n", pipe, strerror(errno));
46 signal(SIGCHLD, old_signal);
47 return NULL;
48 }
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;
56 } else {
57 name = g_strdup(output);
58 }
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);
65 if (WEXITSTATUS(status) != 0) {
66 g_free(name);
67 name = NULL;
68 }
70 signal(SIGCHLD, old_signal);
72 return name;
73 }