From e1a3aebafca9a9447a393100db4fc45943551630 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 31 Oct 2017 14:04:03 +0100 Subject: Ensure we get an appropriate exit code when a resource crashes. --- sinksh/state.cpp | 2 +- sinksh/syntax_modules/sink_sync.cpp | 4 +++- sinksh/syntaxtree.cpp | 10 +++++----- sinksh/syntaxtree.h | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) (limited to 'sinksh') diff --git a/sinksh/state.cpp b/sinksh/state.cpp index 7e04d28..b7e8e5a 100644 --- a/sinksh/state.cpp +++ b/sinksh/state.cpp @@ -139,7 +139,7 @@ int State::commandStarted() const void State::commandFinished(int returnCode) const { - SinkTrace() << "Command finished"; + SinkTrace() << "Command finished. Exit code: " << returnCode; if (!s_hasEventLoop) { QCoreApplication::exit(returnCode); } else { diff --git a/sinksh/syntax_modules/sink_sync.cpp b/sinksh/syntax_modules/sink_sync.cpp index 2800af1..8b48785 100644 --- a/sinksh/syntax_modules/sink_sync.cpp +++ b/sinksh/syntax_modules/sink_sync.cpp @@ -67,12 +67,14 @@ bool sync(const QStringList &args, State &state) Sink::Store::synchronize(query) .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) .then([state](const KAsync::Error &error) { + int exitCode = 0; if (error) { state.printLine("Synchronization failed!"); + exitCode = 1; } else { state.printLine("Synchronization complete!"); } - state.commandFinished(); + state.commandFinished(exitCode); }).exec(); return true; diff --git a/sinksh/syntaxtree.cpp b/sinksh/syntaxtree.cpp index ee9d6f8..65eb769 100644 --- a/sinksh/syntaxtree.cpp +++ b/sinksh/syntaxtree.cpp @@ -57,16 +57,16 @@ Syntax::List SyntaxTree::syntax() const return m_syntax; } -bool SyntaxTree::run(const QStringList &commands) +int SyntaxTree::run(const QStringList &commands) { - bool success = false; + int returnCode = 0; m_timeElapsed.start(); Command command = match(commands); if (command.first) { if (command.first->lambda) { - success = command.first->lambda(command.second, m_state); + bool success = command.first->lambda(command.second, m_state); if (success && command.first->interactivity == Syntax::EventDriven) { - success = m_state.commandStarted(); + returnCode = m_state.commandStarted(); } } else if (command.first->children.isEmpty()) { m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); @@ -85,7 +85,7 @@ bool SyntaxTree::run(const QStringList &commands) if (m_state.commandTiming()) { m_state.printLine(QObject::tr("Time elapsed: %1").arg(m_timeElapsed.elapsed())); } - return false; + return returnCode; } SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const diff --git a/sinksh/syntaxtree.h b/sinksh/syntaxtree.h index 6624388..8fbbd01 100644 --- a/sinksh/syntaxtree.h +++ b/sinksh/syntaxtree.h @@ -63,7 +63,7 @@ public: Command match(const QStringList &commands) const; Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; State &state(); - bool run(const QStringList &commands); + int run(const QStringList &commands); static QStringList tokenize(const QString &text); -- cgit v1.2.3