Switch to unified view

a/src/utils/execmd.cpp b/src/utils/execmd.cpp
...
...
296
        m_parent->m_fromcmd.reset();
296
        m_parent->m_fromcmd.reset();
297
        pthread_sigmask(SIG_UNBLOCK, &m_parent->m_blkcld, 0);
297
        pthread_sigmask(SIG_UNBLOCK, &m_parent->m_blkcld, 0);
298
        m_parent->reset();
298
        m_parent->reset();
299
    }
299
    }
300
private:
300
private:
301
    ExecCmd::Internal *m_parent;
301
    ExecCmd::Internal *m_parent{nullptr};
302
    bool    m_active;
302
    bool    m_active{false};
303
};
303
};
304
304
305
ExecCmd::~ExecCmd()
305
ExecCmd::~ExecCmd()
306
{
306
{
307
    if (m) {
307
    ExecCmdRsrc(this->m);
308
        ExecCmdRsrc r(m);
309
    }
308
    if (m) {
310
    if (m) {
309
        delete m;
311
        delete m;
312
        m = nullptr;
310
    }
313
    }
311
}
314
}
312
315
313
// In child process. Set up pipes and exec command.
316
// In child process. Set up pipes and exec command.
314
// This must not return. _exit() on error.
317
// This must not return. _exit() on error.
...
...
453
        LOGDEB("ExecCmd::startExec: (" << has_input << "|" << has_output <<
456
        LOGDEB("ExecCmd::startExec: (" << has_input << "|" << has_output <<
454
               ") " << command << "\n");
457
               ") " << command << "\n");
455
    }
458
    }
456
459
457
    // The resource manager ensures resources are freed if we return early
460
    // The resource manager ensures resources are freed if we return early
458
    ExecCmdRsrc e(this->m);
461
    ExecCmdRsrc e(m);
459
462
460
    if (has_input && pipe(m->m_pipein) < 0) {
463
    if (has_input && pipe(m->m_pipein) < 0) {
461
        LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n" );
464
        LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n" );
462
        return -1;
465
        return -1;
463
    }
466
    }
...
...
744
    if (startExec(cmd, args, input != 0, output != 0) < 0) {
747
    if (startExec(cmd, args, input != 0, output != 0) < 0) {
745
        return -1;
748
        return -1;
746
    }
749
    }
747
750
748
    // Cleanup in case we return early
751
    // Cleanup in case we return early
749
    ExecCmdRsrc e(this->m);
752
    ExecCmdRsrc e(m);
750
    SelectLoop myloop;
753
    SelectLoop myloop;
751
    int ret = 0;
754
    int ret = 0;
752
    if (input || output) {
755
    if (input || output) {
753
        // Setup output
756
        // Setup output
754
        if (output) {
757
        if (output) {
...
...
946
// In case of need, using a semi-busy loop with short sleeps
949
// In case of need, using a semi-busy loop with short sleeps
947
// increasing from a few mS might work without creating too much
950
// increasing from a few mS might work without creating too much
948
// overhead.
951
// overhead.
949
int ExecCmd::wait()
952
int ExecCmd::wait()
950
{
953
{
951
    ExecCmdRsrc e(this->m);
954
    ExecCmdRsrc e(m);
952
    int status = -1;
955
    int status = -1;
953
    if (!m->m_killRequest && m->m_pid > 0) {
956
    if (!m->m_killRequest && m->m_pid > 0) {
954
        if (waitpid(m->m_pid, &status, 0) < 0) {
957
        if (waitpid(m->m_pid, &status, 0) < 0) {
955
            LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n");
958
            LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n");
956
            status = -1;
959
            status = -1;
...
...
962
    return status;
965
    return status;
963
}
966
}
964
967
965
bool ExecCmd::maybereap(int *status)
968
bool ExecCmd::maybereap(int *status)
966
{
969
{
967
    ExecCmdRsrc e(this->m);
970
    ExecCmdRsrc e(m);
968
    *status = -1;
971
    *status = -1;
969
972
970
    if (m->m_pid <= 0) {
973
    if (m->m_pid <= 0) {
971
        // Already waited for ??
974
        // Already waited for ??
972
        return true;
975
        return true;