indents etc
This commit is contained in:
parent
a777995946
commit
1acc059eea
@ -1,7 +1,7 @@
|
|||||||
#include "autoconfig.h"
|
#include "autoconfig.h"
|
||||||
|
|
||||||
#ifdef RCL_MONITOR
|
#ifdef RCL_MONITOR
|
||||||
/* Copyright (C) 2006 J.F.Dockes
|
/* Copyright (C) 2006-2022 J.F.Dockes
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
@ -122,7 +122,7 @@ struct DelayPat {
|
|||||||
*/
|
*/
|
||||||
class RclEQData {
|
class RclEQData {
|
||||||
public:
|
public:
|
||||||
int m_opts;
|
int m_opts{0};
|
||||||
// Queue for normal files (unlimited reindex)
|
// Queue for normal files (unlimited reindex)
|
||||||
queue_type m_iqueue;
|
queue_type m_iqueue;
|
||||||
// Queue for delayed reindex files
|
// Queue for delayed reindex files
|
||||||
@ -135,27 +135,21 @@ public:
|
|||||||
delays_type m_delays;
|
delays_type m_delays;
|
||||||
// Configured intervals for path patterns, read from the configuration.
|
// Configured intervals for path patterns, read from the configuration.
|
||||||
vector<DelayPat> m_delaypats;
|
vector<DelayPat> m_delaypats;
|
||||||
RclConfig *m_config;
|
RclConfig *m_config{nullptr};
|
||||||
bool m_ok;
|
bool m_ok{true};
|
||||||
|
|
||||||
std::mutex m_mutex;
|
std::mutex m_mutex;
|
||||||
std::condition_variable m_cond;
|
std::condition_variable m_cond;
|
||||||
|
|
||||||
RclEQData()
|
|
||||||
: m_config(0), m_ok(true)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void readDelayPats(int dfltsecs);
|
void readDelayPats(int dfltsecs);
|
||||||
DelayPat searchDelayPats(const string& path)
|
DelayPat searchDelayPats(const string& path) {
|
||||||
{
|
for (const auto& dpat: m_delaypats) {
|
||||||
for (vector<DelayPat>::iterator it = m_delaypats.begin();
|
if (fnmatch(dpat.pattern.c_str(), path.c_str(), 0) == 0) {
|
||||||
it != m_delaypats.end(); it++) {
|
return dpat;
|
||||||
if (fnmatch(it->pattern.c_str(), path.c_str(), 0) == 0) {
|
|
||||||
return *it;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return DelayPat();
|
|
||||||
}
|
}
|
||||||
|
return DelayPat();
|
||||||
|
}
|
||||||
void delayInsert(const queue_type::iterator &qit);
|
void delayInsert(const queue_type::iterator &qit);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -170,22 +164,21 @@ void RclEQData::readDelayPats(int dfltsecs)
|
|||||||
|
|
||||||
vector<string> dplist;
|
vector<string> dplist;
|
||||||
if (!stringToStrings(patstring, dplist)) {
|
if (!stringToStrings(patstring, dplist)) {
|
||||||
LOGERR("rclEQData: bad pattern list: [" << (patstring) << "]\n" );
|
LOGERR("rclEQData: bad pattern list: [" << patstring << "]\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (vector<string>::iterator it = dplist.begin();
|
for (const auto& entry : dplist) {
|
||||||
it != dplist.end(); it++) {
|
string::size_type pos = entry.find_last_of(":");
|
||||||
string::size_type pos = it->find_last_of(":");
|
|
||||||
DelayPat dp;
|
DelayPat dp;
|
||||||
dp.pattern = it->substr(0, pos);
|
dp.pattern = entry.substr(0, pos);
|
||||||
if (pos != string::npos && pos != it->size()-1) {
|
if (pos != string::npos && pos != entry.size() - 1) {
|
||||||
dp.seconds = atoi(it->substr(pos+1).c_str());
|
dp.seconds = atoi(entry.substr(pos+1).c_str());
|
||||||
} else {
|
} else {
|
||||||
dp.seconds = dfltsecs;
|
dp.seconds = dfltsecs;
|
||||||
}
|
}
|
||||||
m_delaypats.push_back(dp);
|
m_delaypats.push_back(dp);
|
||||||
LOGDEB2("rclmon::readDelayPats: add [" << (dp.pattern) << "] " << (dp.seconds) << "\n" );
|
LOGDEB2("rclmon::readDelayPats: add [" << dp.pattern << "] " << dp.seconds << "\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,10 +187,8 @@ void RclEQData::readDelayPats(int dfltsecs)
|
|||||||
// when necessary.
|
// when necessary.
|
||||||
void RclEQData::delayInsert(const queue_type::iterator &qit)
|
void RclEQData::delayInsert(const queue_type::iterator &qit)
|
||||||
{
|
{
|
||||||
MONDEB("RclEQData::delayInsert: minclock " << qit->second.m_minclock <<
|
MONDEB("RclEQData::delayInsert: minclock " << qit->second.m_minclock << "\n");
|
||||||
std::endl);
|
for (delays_type::iterator dit = m_delays.begin(); dit != m_delays.end(); dit++) {
|
||||||
for (delays_type::iterator dit = m_delays.begin();
|
|
||||||
dit != m_delays.end(); dit++) {
|
|
||||||
queue_type::iterator qit1 = *dit;
|
queue_type::iterator qit1 = *dit;
|
||||||
if ((*qit1).second.m_minclock > qit->second.m_minclock) {
|
if ((*qit1).second.m_minclock > qit->second.m_minclock) {
|
||||||
m_delays.insert(dit, qit);
|
m_delays.insert(dit, qit);
|
||||||
@ -230,7 +221,7 @@ std::unique_lock<std::mutex> RclMonEventQueue::wait(int seconds, bool *top)
|
|||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_data->m_mutex);
|
std::unique_lock<std::mutex> lock(m_data->m_mutex);
|
||||||
|
|
||||||
MONDEB("RclMonEventQueue::wait, seconds: " << seconds << std::endl);
|
MONDEB("RclMonEventQueue::wait, seconds: " << seconds << "\n");
|
||||||
if (!empty()) {
|
if (!empty()) {
|
||||||
MONDEB("RclMonEventQueue:: immediate return\n");
|
MONDEB("RclMonEventQueue:: immediate return\n");
|
||||||
return lock;
|
return lock;
|
||||||
@ -324,7 +315,7 @@ bool RclMonEventQueue::empty()
|
|||||||
RclMonEvent RclMonEventQueue::pop()
|
RclMonEvent RclMonEventQueue::pop()
|
||||||
{
|
{
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
MONDEB("RclMonEventQueue::pop(), now " << now << std::endl);
|
MONDEB("RclMonEventQueue::pop(), now " << now << "\n");
|
||||||
|
|
||||||
// Look at the delayed events, get rid of the expired/unactive
|
// Look at the delayed events, get rid of the expired/unactive
|
||||||
// ones, possibly return an expired/needidx one.
|
// ones, possibly return an expired/needidx one.
|
||||||
@ -332,7 +323,7 @@ RclMonEvent RclMonEventQueue::pop()
|
|||||||
delays_type::iterator dit = m_data->m_delays.begin();
|
delays_type::iterator dit = m_data->m_delays.begin();
|
||||||
queue_type::iterator qit = *dit;
|
queue_type::iterator qit = *dit;
|
||||||
MONDEB("RclMonEventQueue::pop(): in delays: evt minclock " <<
|
MONDEB("RclMonEventQueue::pop(): in delays: evt minclock " <<
|
||||||
qit->second.m_minclock << std::endl);
|
qit->second.m_minclock << "\n");
|
||||||
if (qit->second.m_minclock <= now) {
|
if (qit->second.m_minclock <= now) {
|
||||||
if (qit->second.m_needidx) {
|
if (qit->second.m_needidx) {
|
||||||
RclMonEvent ev = qit->second;
|
RclMonEvent ev = qit->second;
|
||||||
@ -371,7 +362,7 @@ RclMonEvent RclMonEventQueue::pop()
|
|||||||
// special processing to limit their reindexing rate.
|
// special processing to limit their reindexing rate.
|
||||||
bool RclMonEventQueue::pushEvent(const RclMonEvent &ev)
|
bool RclMonEventQueue::pushEvent(const RclMonEvent &ev)
|
||||||
{
|
{
|
||||||
MONDEB("RclMonEventQueue::pushEvent for " << ev.m_path << std::endl);
|
MONDEB("RclMonEventQueue::pushEvent for " << ev.m_path << "\n");
|
||||||
std::unique_lock<std::mutex> lock(m_data->m_mutex);
|
std::unique_lock<std::mutex> lock(m_data->m_mutex);
|
||||||
|
|
||||||
DelayPat pat = m_data->searchDelayPats(ev.m_path);
|
DelayPat pat = m_data->searchDelayPats(ev.m_path);
|
||||||
@ -381,8 +372,7 @@ bool RclMonEventQueue::pushEvent(const RclMonEvent &ev)
|
|||||||
queue_type::iterator qit = m_data->m_dqueue.find(ev.m_path);
|
queue_type::iterator qit = m_data->m_dqueue.find(ev.m_path);
|
||||||
if (qit == m_data->m_dqueue.end()) {
|
if (qit == m_data->m_dqueue.end()) {
|
||||||
// Not there yet, insert new
|
// Not there yet, insert new
|
||||||
qit =
|
qit = m_data->m_dqueue.insert(queue_type::value_type(ev.m_path, ev)).first;
|
||||||
m_data->m_dqueue.insert(queue_type::value_type(ev.m_path, ev)).first;
|
|
||||||
// Set the time to next index to "now" as it has not been
|
// Set the time to next index to "now" as it has not been
|
||||||
// indexed recently (otherwise it would still be in the
|
// indexed recently (otherwise it would still be in the
|
||||||
// queue), and add the iterator to the delay queue.
|
// queue), and add the iterator to the delay queue.
|
||||||
@ -491,7 +481,7 @@ bool startMonitor(RclConfig *conf, int opts)
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
bool x11dead = !(opts & RCLMON_NOX11) && !x11IsAlive();
|
bool x11dead = !(opts & RCLMON_NOX11) && !x11IsAlive();
|
||||||
if (x11dead)
|
if (x11dead)
|
||||||
LOGDEB("RclMonprc: x11 is dead\n" );
|
LOGDEB("RclMonprc: x11 is dead\n");
|
||||||
#else
|
#else
|
||||||
bool x11dead = false;
|
bool x11dead = false;
|
||||||
#endif
|
#endif
|
||||||
@ -512,26 +502,24 @@ bool startMonitor(RclConfig *conf, int opts)
|
|||||||
modified.push_back(ev.m_path);
|
modified.push_back(ev.m_path);
|
||||||
break;
|
break;
|
||||||
case RclMonEvent::RCLEVT_DELETE:
|
case RclMonEvent::RCLEVT_DELETE:
|
||||||
LOGDEB0("Monitor: Delete on " << (ev.m_path) << "\n" );
|
LOGDEB0("Monitor: Delete on " << ev.m_path << "\n");
|
||||||
// If this is for a directory (which the caller should
|
// If this is for a directory (which the caller should tell us because he
|
||||||
// tell us because he knows), we should purge the db
|
// knows), we should purge the db of all the subtree entries, because on a
|
||||||
// of all the subtree, because on a directory rename,
|
// directory rename, inotify will only generate one event for the renamed top,
|
||||||
// inotify will only generate one event for the
|
// not the subentries. The entries from the new subtree are updated when the
|
||||||
// renamed top, not the subentries. This is relatively
|
// monitor walks it on the DIRCREATE event.
|
||||||
// complicated to do though, and we currently do not
|
// If the monitor does not have the ISDIR info, we'll just wait for a restart to
|
||||||
// do it, and just wait for a restart to do a full run and
|
// do a full run and purge, no big deal.
|
||||||
// purge.
|
|
||||||
deleted.push_back(ev.m_path);
|
deleted.push_back(ev.m_path);
|
||||||
if (ev.evflags() & RclMonEvent::RCLEVT_ISDIR) {
|
if (ev.evflags() & RclMonEvent::RCLEVT_ISDIR) {
|
||||||
vector<string> paths;
|
vector<string> paths;
|
||||||
if (subtreelist(conf, ev.m_path, paths)) {
|
if (subtreelist(conf, ev.m_path, paths)) {
|
||||||
deleted.insert(deleted.end(),
|
deleted.insert(deleted.end(), paths.begin(), paths.end());
|
||||||
paths.begin(), paths.end());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
LOGDEB("Monitor: got Other on [" << (ev.m_path) << "]\n" );
|
LOGDEB("Monitor: got Other on [" << ev.m_path << "]\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -579,7 +567,7 @@ bool startMonitor(RclConfig *conf, int opts)
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
// Check for a config change
|
// Check for a config change
|
||||||
if (!(opts & RCLMON_NOCONFCHECK) && o_reexec && conf->sourceChanged()) {
|
if (!(opts & RCLMON_NOCONFCHECK) && o_reexec && conf->sourceChanged()) {
|
||||||
LOGDEB("Rclmonprc: config changed, reexecuting myself\n" );
|
LOGDEB("Rclmonprc: config changed, reexecuting myself\n");
|
||||||
// We never want to have a -n option after a config
|
// We never want to have a -n option after a config
|
||||||
// change. -n was added by the reexec after the initial
|
// change. -n was added by the reexec after the initial
|
||||||
// pass even if it was not given on the command line
|
// pass even if it was not given on the command line
|
||||||
@ -588,7 +576,7 @@ bool startMonitor(RclConfig *conf, int opts)
|
|||||||
}
|
}
|
||||||
#endif // ! _WIN32
|
#endif // ! _WIN32
|
||||||
}
|
}
|
||||||
LOGDEB("Rclmonprc: calling queue setTerminate\n" );
|
LOGDEB("Rclmonprc: calling queue setTerminate\n");
|
||||||
rclEQ.setTerminate();
|
rclEQ.setTerminate();
|
||||||
|
|
||||||
// We used to wait for the receiver thread here before returning,
|
// We used to wait for the receiver thread here before returning,
|
||||||
@ -596,9 +584,8 @@ bool startMonitor(RclConfig *conf, int opts)
|
|||||||
// during our limited time window for exiting. To be reviewed if
|
// during our limited time window for exiting. To be reviewed if
|
||||||
// we ever need several monitor invocations in the same process
|
// we ever need several monitor invocations in the same process
|
||||||
// (can't foresee any reason why we'd want to do this).
|
// (can't foresee any reason why we'd want to do this).
|
||||||
LOGDEB("Monitor: returning\n" );
|
LOGDEB("Monitor: returning\n");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // RCL_MONITOR
|
#endif // RCL_MONITOR
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user