From 3a9d7f7cb6397665307d2b1713b0e5346047b015 Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sat, 8 Jan 2022 15:44:21 +0100 Subject: [PATCH] execmd statusAsString --- src/doc/user/usermanual.html | 6 +++--- src/testmains/Makefile.am | 10 ++-------- src/utils/execmd.cpp | 21 ++++++++++++++++++++- src/utils/execmd.h | 2 ++ src/windows/execmd_w.cpp | 31 ++++++++++++++++++++----------- 5 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/doc/user/usermanual.html b/src/doc/user/usermanual.html index e679932c..389427e1 100644 --- a/src/doc/user/usermanual.html +++ b/src/doc/user/usermanual.html @@ -10,7 +10,7 @@ + "Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found at the following location: GNU web site. This document introduces full text search notions and describes the installation and use of the Recoll application. This version describes Recoll 1.32."> @@ -53,7 +53,7 @@ alink="#0000FF"> and describes the installation and use of the Recoll application. This version describes Recoll 1.31.

+ "application">Recoll 1.32.

@@ -443,7 +443,7 @@ alink="#0000FF">

This document introduces full text search notions and describes the installation and use of the Recoll application. It is updated for - Recoll 1.31.

+ Recoll 1.32.

Recoll was for a long time dedicated to Unix-like systems. It was only lately (2015) ported to MS-Windows. diff --git a/src/testmains/Makefile.am b/src/testmains/Makefile.am index 6cd274ba..c2d72caa 100644 --- a/src/testmains/Makefile.am +++ b/src/testmains/Makefile.am @@ -38,8 +38,8 @@ AM_CPPFLAGS = -Wall -Wno-unused -std=c++11 \ -D_GNU_SOURCE \ $(DEFS) -noinst_PROGRAMS = plaintorich textsplit utf8iter fstreewalk rclconfig hldata unac mbox \ - circache wipedir mimetype pathut fileudi x11mon trqrstore ecrontab +noinst_PROGRAMS = plaintorich textsplit fstreewalk rclconfig hldata unac mbox \ + circache wipedir mimetype fileudi x11mon trqrstore ecrontab ecrontab_SOURCES = trecrontab.cpp ecrontab_LDADD = ../librecoll.la @@ -62,9 +62,6 @@ mbox_LDADD = ../librecoll.la mimetype_SOURCES = trmimetype.cpp mimetype_LDADD = ../librecoll.la -pathut_SOURCES = trpathut.cpp -pathut_LDADD = ../librecoll.la - rclconfig_SOURCES = trrclconfig.cpp rclconfig_LDADD = ../librecoll.la @@ -77,9 +74,6 @@ plaintorich_LDADD = ../librecoll.la unac_SOURCES = trunac.cpp unac_LDADD = ../librecoll.la -utf8iter_SOURCES = trutf8iter.cpp -utf8iter_LDADD = ../librecoll.la - wipedir_SOURCES = trwipedir.cpp wipedir_LDADD = ../librecoll.la diff --git a/src/utils/execmd.cpp b/src/utils/execmd.cpp index eb5a7603..6a6fd510 100644 --- a/src/utils/execmd.cpp +++ b/src/utils/execmd.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #ifdef HAVE_SPAWN_H #ifndef __USE_GNU #define __USE_GNU @@ -994,7 +995,8 @@ int ExecCmd::wait() LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n"); status = -1; } - LOGDEB("ExecCmd::wait: got status 0x" << (status) << "\n"); + LOGDEB("ExecCmd::wait: got status 0x" << std::hex << status << std::dec << ": " << + waitStatusAsString(status) << "\n"); m->m_pid = -1; } // Let the ExecCmdRsrc cleanup, it will do the killing/waiting if needed @@ -1043,6 +1045,23 @@ bool ExecCmd::backtick(const vector cmd, string& out) return status == 0; } +std::string ExecCmd::waitStatusAsString(int wstatus) +{ + std::ostringstream oss; + if (WIFEXITED(wstatus)) { + oss << "Exit status: " << WEXITSTATUS(wstatus); + } else { + if (WIFSIGNALED(wstatus)) { + oss << strsignal(WTERMSIG(wstatus)) << " "; + } + if (WCOREDUMP(wstatus)) { + oss << "(core dumped)"; + } + } + return oss.str(); +} + + /// ReExec class methods /////////////////////////////////////////////////// ReExec::ReExec(int argc, char *args[]) { diff --git a/src/utils/execmd.h b/src/utils/execmd.h index 623569c1..987a9e7f 100644 --- a/src/utils/execmd.h +++ b/src/utils/execmd.h @@ -247,6 +247,8 @@ public: */ static bool backtick(const std::vector cmd, std::string& out); + static std::string waitStatusAsString(int wstatus); + class Internal; private: Internal *m; diff --git a/src/windows/execmd_w.cpp b/src/windows/execmd_w.cpp index 8f140216..8e5ad2a5 100644 --- a/src/windows/execmd_w.cpp +++ b/src/windows/execmd_w.cpp @@ -1100,17 +1100,6 @@ bool ExecCmd::maybereap(int *status) } } -// Static -bool ExecCmd::backtick(const vector cmd, string& out) -{ - vector::const_iterator it = cmd.begin(); - it++; - vector args(it, cmd.end()); - ExecCmd mexec; - int status = mexec.doexec(*cmd.begin(), args, 0, &out); - return status == 0; -} - int ExecCmd::doexec(const string &cmd, const vector& args, const string *input, string *output) { @@ -1159,3 +1148,23 @@ int ExecCmd::doexec(const string &cmd, const vector& args, cleaner.inactivate(); return wait(); } + +// Static +bool ExecCmd::backtick(const vector cmd, string& out) +{ + vector::const_iterator it = cmd.begin(); + it++; + vector args(it, cmd.end()); + ExecCmd mexec; + int status = mexec.doexec(*cmd.begin(), args, 0, &out); + return status == 0; +} + +// Static. Unimplemented on windows for now +std::string ExecCmd::waitStatusAsString(int wstatus) +{ + std::ostringstream oss; + oss << std::hex << "0x" << wstatus << std::dec; + return oss.str(); +} +