ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/util.C
(Generate patch)

Comparing gvpe/src/util.C (file contents):
Revision 1.15 by pcg, Fri Jun 11 15:56:34 2004 UTC vs.
Revision 1.19 by pcg, Wed Mar 23 21:55:39 2005 UTC

1/* 1/*
2 util.C -- process management and other utility functions 2 util.C -- process management and other utility functions
3 Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com> 3 Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de>
4 4
5 Some of these are taken from tinc, see the AUTHORS file. 5 Some of these are taken from tinc, see the AUTHORS file.
6 6
7 This file is part of GVPE.
8
7 This program is free software; you can redistribute it and/or modify 9 GVPE is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or 11 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version. 12 (at your option) any later version.
11 13
12 This program is distributed in the hope that it will be useful, 14 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details. 17 GNU General Public License for more details.
16 18
17 You should have received a copy of the GNU General Public License 19 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software 20 along with gvpe; if not, write to the Free Software
19 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 21 Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20*/ 22*/
21 23
22#include "config.h" 24#include "config.h"
23 25
125 slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__); 127 slog (L_INFO, _("gvpe daemon %s (%s %s) starting"), VERSION, __DATE__, __TIME__);
126 128
127 return 0; 129 return 0;
128} 130}
129 131
130void run_script (const run_script_cb &cb, bool wait) 132bool run_script (const run_script_cb &cb, bool wait)
131{ 133{
132 int pid; 134 int pid;
133 135
134 if ((pid = fork ()) == 0) 136 if ((pid = fork ()) == 0)
135 { 137 {
136 char *filename; 138 execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0);
137 asprintf (&filename, "%s/%s", confbase, cb()); 139 exit (EXIT_FAILURE);
138 execl (filename, filename, (char *) 0);
139 exit (126);
140 } 140 }
141 else if (pid > 0) 141 else if (pid > 0)
142 { 142 {
143 if (wait) 143 if (wait)
144 { 144 {
145 int status;
146
145 waitpid (pid, 0, 0); 147 if (waitpid (pid, &status, 0) < 0)
146 /* TODO: check status */ 148 {
149 slog (L_WARN, _("waiting for an external command failed: %s."),
150 strerror (errno));
151 return false;
152 }
153 else if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS)
154 {
155 slog (L_WARN, _("external command returned with exit status %d (%04x)."),
156 WEXITSTATUS (status), status);
157 return false;
158 }
147 } 159 }
148 } 160 }
161
162 return true;
149} 163}
150 164
151#if ENABLE_HTTP_PROXY 165#if ENABLE_HTTP_PROXY
152// works like strdup 166// works like strdup
153u8 * 167u8 *

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines