--- gvpe/src/util.C 2004/06/11 15:56:34 1.15 +++ gvpe/src/util.C 2005/03/23 21:55:39 1.19 @@ -1,10 +1,12 @@ /* util.C -- process management and other utility functions - Copyright (C) 2003-2004 Marc Lehmann + Copyright (C) 2003-2005 Marc Lehmann Some of these are taken from tinc, see the AUTHORS file. - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -15,7 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software + along with gvpe; if not, write to the Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ @@ -127,25 +129,37 @@ return 0; } -void run_script (const run_script_cb &cb, bool wait) +bool run_script (const run_script_cb &cb, bool wait) { int pid; if ((pid = fork ()) == 0) { - char *filename; - asprintf (&filename, "%s/%s", confbase, cb()); - execl (filename, filename, (char *) 0); - exit (126); + execl ("/bin/sh", "/bin/sh", "-c", cb (), (char *) 0); + exit (EXIT_FAILURE); } else if (pid > 0) { if (wait) { - waitpid (pid, 0, 0); - /* TODO: check status */ + int status; + + if (waitpid (pid, &status, 0) < 0) + { + slog (L_WARN, _("waiting for an external command failed: %s."), + strerror (errno)); + return false; + } + else if (!WIFEXITED (status) || WEXITSTATUS (status) != EXIT_SUCCESS) + { + slog (L_WARN, _("external command returned with exit status %d (%04x)."), + WEXITSTATUS (status), status); + return false; + } } } + + return true; } #if ENABLE_HTTP_PROXY