@@ -109,21 +109,21 @@ void sortInstances(QVector<InstanceLockInfo>& list, bool newestFirst) {
109
109
});
110
110
};
111
111
112
- int selectInstance (CommandState& cmd, InstanceLockInfo* instance) {
112
+ int selectInstance (CommandState& cmd, InstanceLockInfo* instance, bool deadFallback = false ) {
113
113
auto * basePath = QsPaths::instance ()->baseRunDir ();
114
114
if (!basePath) return -1 ;
115
115
116
116
QString path;
117
117
118
118
if (cmd.instance .pid != -1 ) {
119
119
path = QDir (basePath->filePath (" by-pid" )).filePath (QString::number (cmd.instance .pid ));
120
- if (!QsPaths::checkLock (path, instance)) {
120
+ if (!QsPaths::checkLock (path, instance, deadFallback )) {
121
121
qCInfo (logBare) << " No instance found for pid" << cmd.instance .pid ;
122
122
return -1 ;
123
123
}
124
124
} else if (!cmd.instance .id ->isEmpty ()) {
125
125
path = basePath->filePath (" by-pid" );
126
- auto instances = QsPaths::collectInstances (path);
126
+ auto instances = QsPaths::collectInstances (path, deadFallback );
127
127
128
128
instances.removeIf ([&](const InstanceLockInfo& info) {
129
129
return !info.instance .instanceId .startsWith (*cmd.instance .id );
@@ -136,7 +136,8 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) {
136
136
qCInfo (logBare) << " More than one instance starts with" << *cmd.instance .id ;
137
137
138
138
for (auto & instance: instances) {
139
- qCInfo (logBare).noquote () << " -" << instance.instance .instanceId ;
139
+ qCInfo (logBare).noquote () << " -" << instance.instance .instanceId
140
+ << (instance.pid == -1 ? " (dead)" : " " );
140
141
}
141
142
142
143
return -1 ;
@@ -153,8 +154,11 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) {
153
154
154
155
path = QDir (basePath->filePath (" by-path" )).filePath (pathId);
155
156
156
- auto instances = QsPaths::collectInstances (path);
157
- sortInstances (instances, cmd.config .newest );
157
+ auto instances = QsPaths::collectInstances (path, deadFallback);
158
+ sortInstances (
159
+ instances,
160
+ cmd.config .newest || (!instances.empty () && instances.first ().pid == -1 )
161
+ );
158
162
159
163
if (instances.isEmpty ()) {
160
164
qCInfo (logBare) << " No running instances for" << configFilePath;
@@ -172,7 +176,7 @@ int readLogFile(CommandState& cmd) {
172
176
173
177
if (path.isEmpty ()) {
174
178
InstanceLockInfo instance;
175
- auto r = selectInstance (cmd, &instance);
179
+ auto r = selectInstance (cmd, &instance, true );
176
180
if (r != 0 ) return r;
177
181
178
182
path = QDir (QsPaths::basePath (instance.instance .instanceId )).filePath (" log.qslog" );
0 commit comments