Switch to unified view

a/src/execmd.cpp b/src/execmd.cpp
...
...
19
#include "autoconfig.h"
19
#include "autoconfig.h"
20
#else
20
#else
21
#include "config.h"
21
#include "config.h"
22
#endif
22
#endif
23
23
24
#include <map>
25
26
#include <stdio.h>
24
#include <stdio.h>
27
#include <stdlib.h>
25
#include <stdlib.h>
28
#include <unistd.h>
26
#include <unistd.h>
29
#include <sys/stat.h>
27
#include <sys/stat.h>
30
#include <sys/types.h>
28
#include <sys/types.h>
...
...
36
#include <errno.h>
34
#include <errno.h>
37
#include <signal.h>
35
#include <signal.h>
38
#include <time.h>
36
#include <time.h>
39
#include <string.h>
37
#include <string.h>
40
38
39
#include <map>
41
#include <vector>
40
#include <vector>
42
#include <string>
41
#include <string>
43
#include <stdexcept>
42
#include <stdexcept>
44
#ifdef HAVE_SPAWN_H
43
#ifdef HAVE_SPAWN_H
45
#ifndef __USE_GNU
44
#ifndef __USE_GNU
...
...
299
        m_parent->m_fromcmd.reset();
298
        m_parent->m_fromcmd.reset();
300
        pthread_sigmask(SIG_UNBLOCK, &m_parent->m_blkcld, 0);
299
        pthread_sigmask(SIG_UNBLOCK, &m_parent->m_blkcld, 0);
301
        m_parent->reset();
300
        m_parent->reset();
302
    }
301
    }
303
private:
302
private:
304
    ExecCmd::Internal *m_parent;
303
    ExecCmd::Internal *m_parent{nullptr};
305
    bool    m_active;
304
    bool    m_active{false};
306
};
305
};
307
306
308
ExecCmd::~ExecCmd()
307
ExecCmd::~ExecCmd()
309
{
308
{
309
    if (m) {
310
    ExecCmdRsrc(this->m);
310
        ExecCmdRsrc r(m);
311
    }
311
    if (m) {
312
    if (m) {
312
        delete m;
313
        delete m;
314
        m = nullptr;
313
    }
315
    }
314
}
316
}
315
317
316
// In child process. Set up pipes and exec command.
318
// In child process. Set up pipes and exec command.
317
// This must not return. _exit() on error.
319
// This must not return. _exit() on error.
...
...
456
        LOGDEB("ExecCmd::startExec: (" << has_input << "|" << has_output <<
458
        LOGDEB("ExecCmd::startExec: (" << has_input << "|" << has_output <<
457
               ") " << command << "\n");
459
               ") " << command << "\n");
458
    }
460
    }
459
461
460
    // The resource manager ensures resources are freed if we return early
462
    // The resource manager ensures resources are freed if we return early
461
    ExecCmdRsrc e(this->m);
463
    ExecCmdRsrc e(m);
462
464
463
    if (has_input && pipe(m->m_pipein) < 0) {
465
    if (has_input && pipe(m->m_pipein) < 0) {
464
        LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n" );
466
        LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n" );
465
        return -1;
467
        return -1;
466
    }
468
    }
...
...
767
    if (startExec(cmd, args, input != 0, output != 0) < 0) {
769
    if (startExec(cmd, args, input != 0, output != 0) < 0) {
768
        return -1;
770
        return -1;
769
    }
771
    }
770
772
771
    // Cleanup in case we return early
773
    // Cleanup in case we return early
772
    ExecCmdRsrc e(this->m);
774
    ExecCmdRsrc e(m);
773
    SelectLoop myloop;
775
    SelectLoop myloop;
774
    int ret = 0;
776
    int ret = 0;
775
    if (input || output) {
777
    if (input || output) {
776
        // Setup output
778
        // Setup output
777
        if (output) {
779
        if (output) {
...
...
969
// In case of need, using a semi-busy loop with short sleeps
971
// In case of need, using a semi-busy loop with short sleeps
970
// increasing from a few mS might work without creating too much
972
// increasing from a few mS might work without creating too much
971
// overhead.
973
// overhead.
972
int ExecCmd::wait()
974
int ExecCmd::wait()
973
{
975
{
974
    ExecCmdRsrc e(this->m);
976
    ExecCmdRsrc e(m);
975
    int status = -1;
977
    int status = -1;
976
    if (!m->m_killRequest && m->m_pid > 0) {
978
    if (!m->m_killRequest && m->m_pid > 0) {
977
        if (waitpid(m->m_pid, &status, 0) < 0) {
979
        if (waitpid(m->m_pid, &status, 0) < 0) {
978
            LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n");
980
            LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n");
979
            status = -1;
981
            status = -1;
...
...
985
    return status;
987
    return status;
986
}
988
}
987
989
988
bool ExecCmd::maybereap(int *status)
990
bool ExecCmd::maybereap(int *status)
989
{
991
{
990
    ExecCmdRsrc e(this->m);
992
    ExecCmdRsrc e(m);
991
    *status = -1;
993
    *status = -1;
992
994
993
    if (m->m_pid <= 0) {
995
    if (m->m_pid <= 0) {
994
        // Already waited for ??
996
        // Already waited for ??
995
        return true;
997
        return true;