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