@@ -109,21 +109,21 @@ void sortInstances(QVector<InstanceLockInfo>& list, bool newestFirst) {
109109 });
110110};
111111
112- int selectInstance (CommandState& cmd, InstanceLockInfo* instance) {
112+ int selectInstance (CommandState& cmd, InstanceLockInfo* instance, bool deadFallback = false ) {
113113 auto * basePath = QsPaths::instance ()->baseRunDir ();
114114 if (!basePath) return -1 ;
115115
116116 QString path;
117117
118118 if (cmd.instance .pid != -1 ) {
119119 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 )) {
121121 qCInfo (logBare) << " No instance found for pid" << cmd.instance .pid ;
122122 return -1 ;
123123 }
124124 } else if (!cmd.instance .id ->isEmpty ()) {
125125 path = basePath->filePath (" by-pid" );
126- auto instances = QsPaths::collectInstances (path);
126+ auto instances = QsPaths::collectInstances (path, deadFallback );
127127
128128 instances.removeIf ([&](const InstanceLockInfo& info) {
129129 return !info.instance .instanceId .startsWith (*cmd.instance .id );
@@ -136,7 +136,8 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) {
136136 qCInfo (logBare) << " More than one instance starts with" << *cmd.instance .id ;
137137
138138 for (auto & instance: instances) {
139- qCInfo (logBare).noquote () << " -" << instance.instance .instanceId ;
139+ qCInfo (logBare).noquote () << " -" << instance.instance .instanceId
140+ << (instance.pid == -1 ? " (dead)" : " " );
140141 }
141142
142143 return -1 ;
@@ -153,8 +154,11 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance) {
153154
154155 path = QDir (basePath->filePath (" by-path" )).filePath (pathId);
155156
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+ );
158162
159163 if (instances.isEmpty ()) {
160164 qCInfo (logBare) << " No running instances for" << configFilePath;
@@ -172,7 +176,7 @@ int readLogFile(CommandState& cmd) {
172176
173177 if (path.isEmpty ()) {
174178 InstanceLockInfo instance;
175- auto r = selectInstance (cmd, &instance);
179+ auto r = selectInstance (cmd, &instance, true );
176180 if (r != 0 ) return r;
177181
178182 path = QDir (QsPaths::basePath (instance.instance .instanceId )).filePath (" log.qslog" );
0 commit comments