Fix freezing on VM shutdown

This commit is contained in:
MDMCK10
2023-02-11 18:52:45 +01:00
parent e7b56d18e6
commit 87cefdaaba
2 changed files with 18 additions and 1 deletions

View File

@@ -55,6 +55,10 @@ export default class QEMUVM extends EventEmitter {
this.processRestartErrorLevel = 0; this.processRestartErrorLevel = 0;
this.expectedExit = false; this.expectedExit = false;
this.qmpClient = new QMPClient(this.qmpSock, this.qmpType); this.qmpClient = new QMPClient(this.qmpSock, this.qmpType);
this.qmpClient.on('qmpshutdown', () => {
console.log("[INFO] QEMU requested shutdown, restarting...");
this.Restore();
});
this.qmpClient.on('connected', () => this.qmpConnected()); this.qmpClient.on('connected', () => this.qmpConnected());
this.qmpClient.on('close', () => this.qmpClosed()); this.qmpClient.on('close', () => this.qmpClosed());
} }

View File

@@ -65,7 +65,20 @@ export default class QMPClient extends EventEmitter {
} }
if (msg.return !== undefined) if (msg.return !== undefined)
this.emit("qmpreturn", msg.return); this.emit("qmpreturn", msg.return);
else else if(msg.event !== undefined) {
switch(msg.event) {
case "POWERDOWN":
case "STOP":
{
this.emit("qmpshutdown");
break
};
default: {
this.emit("qmpreturn", '');
break;
}
}
}else
// for now just return an empty string. // for now just return an empty string.
// This is a giant hack but avoids a deadlock // This is a giant hack but avoids a deadlock
this.emit("qmpreturn", ''); this.emit("qmpreturn", '');