Skip to content

Commit

Permalink
Fix when monitor is not on
Browse files Browse the repository at this point in the history
  • Loading branch information
JC-comp committed Oct 18, 2023
1 parent 764fb38 commit 7ece476
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
37 changes: 23 additions & 14 deletions src/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -852,25 +852,34 @@ int main(string[] cliArgs) {
}

if(performMonitor) {
// Start the worker and wait for event
if(!filesystemMonitor.isWorking()) {
workerTid.send(1);
}

int res = 1;
auto nextCheckTime = lastCheckTime + checkOnlineInterval;
currentTime = MonoTime.currTime();
receiveTimeout(nextCheckTime - currentTime, (int msg) {
res = msg;
});
if(res == -1) {
log.error("Error: Monitor worker failed.");
monitorFailures = true;
performMonitor = false;
auto sleepTime = nextCheckTime - currentTime;
if(filesystemMonitor.initialised) {
// If local monitor is on
// start the worker and wait for event
if(!filesystemMonitor.isWorking()) {
workerTid.send(1);
}
int res = 1;

receiveTimeout(sleepTime, (int msg) {
res = msg;
});
if(res == -1) {
log.error("Error: Monitor worker failed.");
monitorFailures = true;
performMonitor = false;
}
} else {
// no hooks available, nothing to check
Thread.sleep(sleepTime);
}
}
}
workerTid.send(0); // exit signal
if (filesystemMonitor.initialised) {
workerTid.send(0); // exit signal
}
}
} else {
// Exit application as the sync engine could not be initialised
Expand Down
7 changes: 7 additions & 0 deletions src/monitor.d
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ final class Monitor {
bool skip_symlinks = false;
// check for .nosync if enabled
bool check_nosync = false;
// check if initialised
bool initialised = false;

// Configure Private Class Variables
shared(MonitorBackgroundWorker) worker;
Expand Down Expand Up @@ -204,6 +206,8 @@ final class Monitor {

// Shutdown the monitor class
void shutdown() {
if(!initialised)
return;
worker.shutdown();
wdToDirName = null;
}
Expand Down Expand Up @@ -352,6 +356,8 @@ final class Monitor {

// Update
void update(bool useCallbacks = true) {
if(!initialised)
return;

pollfd fds = {
fd: worker.fd,
Expand Down Expand Up @@ -495,6 +501,7 @@ final class Monitor {
}

Tid watch() {
initialised = true;
return spawn(&startMonitorJob, worker, thisTid);
}

Expand Down

0 comments on commit 7ece476

Please sign in to comment.