diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-31 14:04:03 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-31 14:04:03 +0100 |
commit | e1a3aebafca9a9447a393100db4fc45943551630 (patch) | |
tree | 39672297b576e967bd2448d6a795e5485f6995b7 /sinksh | |
parent | 77b2173e73f16f33648226543788ea67096fb6d6 (diff) | |
download | sink-e1a3aebafca9a9447a393100db4fc45943551630.tar.gz sink-e1a3aebafca9a9447a393100db4fc45943551630.zip |
Ensure we get an appropriate exit code when a resource crashes.
Diffstat (limited to 'sinksh')
-rw-r--r-- | sinksh/state.cpp | 2 | ||||
-rw-r--r-- | sinksh/syntax_modules/sink_sync.cpp | 4 | ||||
-rw-r--r-- | sinksh/syntaxtree.cpp | 10 | ||||
-rw-r--r-- | sinksh/syntaxtree.h | 2 |
4 files changed, 10 insertions, 8 deletions
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 | |||
139 | 139 | ||
140 | void State::commandFinished(int returnCode) const | 140 | void State::commandFinished(int returnCode) const |
141 | { | 141 | { |
142 | SinkTrace() << "Command finished"; | 142 | SinkTrace() << "Command finished. Exit code: " << returnCode; |
143 | if (!s_hasEventLoop) { | 143 | if (!s_hasEventLoop) { |
144 | QCoreApplication::exit(returnCode); | 144 | QCoreApplication::exit(returnCode); |
145 | } else { | 145 | } 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) | |||
67 | Sink::Store::synchronize(query) | 67 | Sink::Store::synchronize(query) |
68 | .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) | 68 | .then(Sink::ResourceControl::flushMessageQueue(query.getResourceFilter().ids)) |
69 | .then([state](const KAsync::Error &error) { | 69 | .then([state](const KAsync::Error &error) { |
70 | int exitCode = 0; | ||
70 | if (error) { | 71 | if (error) { |
71 | state.printLine("Synchronization failed!"); | 72 | state.printLine("Synchronization failed!"); |
73 | exitCode = 1; | ||
72 | } else { | 74 | } else { |
73 | state.printLine("Synchronization complete!"); | 75 | state.printLine("Synchronization complete!"); |
74 | } | 76 | } |
75 | state.commandFinished(); | 77 | state.commandFinished(exitCode); |
76 | }).exec(); | 78 | }).exec(); |
77 | 79 | ||
78 | return true; | 80 | 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 | |||
57 | return m_syntax; | 57 | return m_syntax; |
58 | } | 58 | } |
59 | 59 | ||
60 | bool SyntaxTree::run(const QStringList &commands) | 60 | int SyntaxTree::run(const QStringList &commands) |
61 | { | 61 | { |
62 | bool success = false; | 62 | int returnCode = 0; |
63 | m_timeElapsed.start(); | 63 | m_timeElapsed.start(); |
64 | Command command = match(commands); | 64 | Command command = match(commands); |
65 | if (command.first) { | 65 | if (command.first) { |
66 | if (command.first->lambda) { | 66 | if (command.first->lambda) { |
67 | success = command.first->lambda(command.second, m_state); | 67 | bool success = command.first->lambda(command.second, m_state); |
68 | if (success && command.first->interactivity == Syntax::EventDriven) { | 68 | if (success && command.first->interactivity == Syntax::EventDriven) { |
69 | success = m_state.commandStarted(); | 69 | returnCode = m_state.commandStarted(); |
70 | } | 70 | } |
71 | } else if (command.first->children.isEmpty()) { | 71 | } else if (command.first->children.isEmpty()) { |
72 | m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); | 72 | m_state.printError(QObject::tr("Broken command... sorry :("), "st_broken"); |
@@ -85,7 +85,7 @@ bool SyntaxTree::run(const QStringList &commands) | |||
85 | if (m_state.commandTiming()) { | 85 | if (m_state.commandTiming()) { |
86 | m_state.printLine(QObject::tr("Time elapsed: %1").arg(m_timeElapsed.elapsed())); | 86 | m_state.printLine(QObject::tr("Time elapsed: %1").arg(m_timeElapsed.elapsed())); |
87 | } | 87 | } |
88 | return false; | 88 | return returnCode; |
89 | } | 89 | } |
90 | 90 | ||
91 | SyntaxTree::Command SyntaxTree::match(const QStringList &commandLine) const | 91 | 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: | |||
63 | Command match(const QStringList &commands) const; | 63 | Command match(const QStringList &commands) const; |
64 | Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; | 64 | Syntax::List nearestSyntax(const QStringList &words, const QString &fragment) const; |
65 | State &state(); | 65 | State &state(); |
66 | bool run(const QStringList &commands); | 66 | int run(const QStringList &commands); |
67 | 67 | ||
68 | static QStringList tokenize(const QString &text); | 68 | static QStringList tokenize(const QString &text); |
69 | 69 | ||