Skip to content

Commit 36f45fd

Browse files
Wait until we get a successful shm connect before trying to set StartupTime. fixes crash
1 parent 3fbb8bd commit 36f45fd

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/zmc.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,20 +238,21 @@ int main(int argc, char *argv[]) {
238238
result = 0;
239239

240240
for (const std::shared_ptr<Monitor> &monitor : monitors) {
241+
std::string sql = stringtf(
242+
"INSERT INTO Monitor_Status (MonitorId,Status,CaptureFPS,AnalysisFPS,CaptureBandwidth)"
243+
" VALUES (%u, 'Running',0,0,0) ON DUPLICATE KEY UPDATE Status='Running',CaptureFPS=0,AnalysisFPS=0,CaptureBandwidth=0",
244+
monitor->Id());
245+
zmDbDo(sql);
246+
241247
monitor->LoadCamera();
242248

243-
if (!monitor->connect()) {
249+
while (!monitor->connect()) {
244250
Warning("Couldn't connect to monitor %d", monitor->Id());
251+
sleep(1);
245252
}
246253
SystemTimePoint now = std::chrono::system_clock::now();
247254
monitor->SetStartupTime(now);
248255

249-
std::string sql = stringtf(
250-
"INSERT INTO Monitor_Status (MonitorId,Status,CaptureFPS,AnalysisFPS,CaptureBandwidth)"
251-
" VALUES (%u, 'Running',0,0,0) ON DUPLICATE KEY UPDATE Status='Running',CaptureFPS=0,AnalysisFPS=0,CaptureBandwidth=0",
252-
monitor->Id());
253-
zmDbDo(sql);
254-
255256
if (monitor->StartupDelay() > 0) {
256257
Debug(1, "Doing startup sleep for %ds", monitor->StartupDelay());
257258
std::this_thread::sleep_for(Seconds(monitor->StartupDelay()));

0 commit comments

Comments
 (0)