Switch to unified view

a/src/utils/execmd.cpp b/src/utils/execmd.cpp
1
#ifndef lint
1
#ifndef lint
2
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.22 2007-02-19 18:14:13 dockes Exp $ (C) 2004 J.F.Dockes";
2
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.23 2007-05-21 13:30:22 dockes Exp $ (C) 2004 J.F.Dockes";
3
#endif
3
#endif
4
/*
4
/*
5
 *   This program is free software; you can redistribute it and/or modify
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
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
7
 *   the Free Software Foundation; either version 2 of the License, or
...
...
24
#include <sys/wait.h>
24
#include <sys/wait.h>
25
#include <sys/select.h>
25
#include <sys/select.h>
26
#include <fcntl.h>
26
#include <fcntl.h>
27
#include <errno.h>
27
#include <errno.h>
28
#include <signal.h>
28
#include <signal.h>
29
29
#ifdef PUTENV_ARG_NOT_CONST
30
#ifdef PUTENV_ARG_NOT_CONST
30
#include <string.h>
31
#include <string.h>
31
#endif
32
#endif
32
33
33
#include <list>
34
#include <list>
...
...
176
    LOGERR(("ExecCmd::doexec: fork(2) failed. errno %d\n", errno));
177
    LOGERR(("ExecCmd::doexec: fork(2) failed. errno %d\n", errno));
177
    return -1;
178
    return -1;
178
    }
179
    }
179
180
180
    if (e.pid) {
181
    if (e.pid) {
181
  // Ignore SIGPIPE and block SIGCHLD in here.
182
  void (*osig)(int);
183
  osig = signal(SIGPIPE, SIG_IGN);
184
  sigset_t blkcld;
185
  sigemptyset(&blkcld);
186
  sigaddset(&blkcld, SIGCHLD);
187
  sigprocmask(SIG_BLOCK, &blkcld, 0);
188
189
    // Father process
182
    // Father process
190
    if (input) {
183
    if (input) {
191
        close(e.pipein[0]);
184
        close(e.pipein[0]);
192
        e.pipein[0] = -1;
185
        e.pipein[0] = -1;
193
        fcntl(e.pipein[1], F_SETFL, O_NONBLOCK);
186
        fcntl(e.pipein[1], F_SETFL, O_NONBLOCK);
...
...
284
    int status = -1;
277
    int status = -1;
285
    if (!m_cancelRequest) {
278
    if (!m_cancelRequest) {
286
        (void)waitpid(e.pid, &status, 0);
279
        (void)waitpid(e.pid, &status, 0);
287
        e.pid = -1;
280
        e.pid = -1;
288
    }
281
    }
289
  signal(SIGPIPE, osig);
290
  sigprocmask(SIG_UNBLOCK, &blkcld, 0);
291
    LOGDEB1(("ExecCmd::doexec: father got status 0x%x\n", status));
282
    LOGDEB1(("ExecCmd::doexec: father got status 0x%x\n", status));
292
    return haderror ? -1 : status;
283
    return haderror ? -1 : status;
293
284
294
    } else {
285
    } else {
295
    // In child process. Set up pipes, environment, and exec command
286
    // In child process. Set up pipes, environment, and exec command