logging now uses c++ streams
This commit is contained in:
+61
-87
@@ -65,7 +65,7 @@ static ssize_t writev(int fd, const struct iovec *iov, int iovcnt)
|
||||
#include "cstr.h"
|
||||
#include "circache.h"
|
||||
#include "conftree.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "smallut.h"
|
||||
#include "md5.h"
|
||||
|
||||
@@ -237,32 +237,28 @@ public:
|
||||
bool khEnter(const string& udi, off_t ofs) {
|
||||
UdiH h(udi);
|
||||
|
||||
LOGDEB2(("Circache::khEnter: h %s offs %lu udi [%s]\n",
|
||||
h.asHexString().c_str(), (ULONG)ofs, udi.c_str()));
|
||||
LOGDEB2("Circache::khEnter: h " << (h.asHexString()) << " offs " << ((ULONG)ofs) << " udi [" << (udi) << "]\n" );
|
||||
|
||||
pair<kh_type::iterator, kh_type::iterator> p = m_ofskh.equal_range(h);
|
||||
|
||||
if (p.first != m_ofskh.end() && p.first->first == h) {
|
||||
for (kh_type::iterator it = p.first; it != p.second; it++) {
|
||||
LOGDEB2(("Circache::khEnter: col h %s, ofs %lu\n",
|
||||
it->first.asHexString().c_str(),
|
||||
(ULONG)it->second));
|
||||
LOGDEB2("Circache::khEnter: col h " << (it->first.asHexString()) << ", ofs " << ((ULONG)it->second) << "\n" );
|
||||
if (it->second == ofs) {
|
||||
// (h,offs) already there. Happens
|
||||
LOGDEB2(("Circache::khEnter: already there\n"));
|
||||
LOGDEB2("Circache::khEnter: already there\n" );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_ofskh.insert(kh_value_type(h, ofs));
|
||||
LOGDEB2(("Circache::khEnter: inserted\n"));
|
||||
LOGDEB2("Circache::khEnter: inserted\n" );
|
||||
return true;
|
||||
}
|
||||
void khDump() {
|
||||
for (kh_type::const_iterator it = m_ofskh.begin();
|
||||
it != m_ofskh.end(); it++) {
|
||||
LOGDEB(("Circache::KHDUMP: %s %d\n",
|
||||
it->first.asHexString().c_str(), (ULONG)it->second));
|
||||
LOGDEB("Circache::KHDUMP: " << (it->first.asHexString()) << " " << ((ULONG)it->second) << "\n" );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -274,22 +270,19 @@ public:
|
||||
|
||||
UdiH h(udi);
|
||||
|
||||
LOGDEB2(("Circache::khFind: h %s udi [%s]\n",
|
||||
h.asHexString().c_str(), udi.c_str()));
|
||||
LOGDEB2("Circache::khFind: h " << (h.asHexString()) << " udi [" << (udi) << "]\n" );
|
||||
|
||||
pair<kh_type::iterator, kh_type::iterator> p = m_ofskh.equal_range(h);
|
||||
|
||||
#if 0
|
||||
if (p.first == m_ofskh.end()) {
|
||||
LOGDEB(("KHFIND: FIRST END()\n"));
|
||||
LOGDEB("KHFIND: FIRST END()\n" );
|
||||
}
|
||||
if (p.second == m_ofskh.end()) {
|
||||
LOGDEB(("KHFIND: SECOND END()\n"));
|
||||
LOGDEB("KHFIND: SECOND END()\n" );
|
||||
}
|
||||
if (!(p.first->first == h))
|
||||
LOGDEB(("KHFIND: NOKEY: %s %s\n",
|
||||
p.first->first.asHexString().c_str(),
|
||||
p.second->first.asHexString().c_str()));
|
||||
LOGDEB("KHFIND: NOKEY: " << (p.first->first.asHexString()) << " " << (p.second->first.asHexString()) << "\n" );
|
||||
#endif
|
||||
|
||||
if (p.first == m_ofskh.end() || !(p.first->first == h)) {
|
||||
@@ -503,8 +496,7 @@ public:
|
||||
offset << " [" << bf << "]";
|
||||
return CCScanHook::Error;
|
||||
}
|
||||
LOGDEB2(("Circache:readEntryHeader: dcsz %u dtsz %u pdsz %u flgs %hu\n",
|
||||
d.dicsize, d.datasize, d.padsize, d.flags));
|
||||
LOGDEB2("Circache:readEntryHeader: dcsz " << (d.dicsize) << " dtsz " << (d.datasize) << " pdsz " << (d.padsize) << " flgs " << (d.flags) << "\n" );
|
||||
return CCScanHook::Continue;
|
||||
}
|
||||
|
||||
@@ -638,7 +630,7 @@ public:
|
||||
}
|
||||
|
||||
if (hd.flags & EFDataCompressed) {
|
||||
LOGDEB1(("Circache:readdicdata: data compressed\n"));
|
||||
LOGDEB1("Circache:readdicdata: data compressed\n" );
|
||||
void *uncomp;
|
||||
unsigned int uncompsize;
|
||||
if (!inflateToDynBuf(bf, hd.datasize, &uncomp, &uncompsize)) {
|
||||
@@ -648,7 +640,7 @@ public:
|
||||
data->assign((char *)uncomp, uncompsize);
|
||||
free(uncomp);
|
||||
} else {
|
||||
LOGDEB1(("Circache:readdicdata: data NOT compressed\n"));
|
||||
LOGDEB1("Circache:readdicdata: data NOT compressed\n" );
|
||||
data->assign(bf, hd.datasize);
|
||||
}
|
||||
} else {
|
||||
@@ -663,7 +655,7 @@ CirCache::CirCache(const string& dir)
|
||||
: m_dir(dir)
|
||||
{
|
||||
m_d = new CirCacheInternal;
|
||||
LOGDEB0(("CirCache: [%s]\n", m_dir.c_str()));
|
||||
LOGDEB0("CirCache: [" << (m_dir) << "]\n" );
|
||||
}
|
||||
|
||||
CirCache::~CirCache()
|
||||
@@ -691,8 +683,7 @@ public:
|
||||
const EntryHeaderData& d) {
|
||||
headoffs = offs;
|
||||
padsize = d.padsize;
|
||||
LOGDEB2(("CCScanHookRecord::takeone: offs %s padsize %s\n",
|
||||
lltodecstr(headoffs).c_str(), lltodecstr(padsize).c_str()));
|
||||
LOGDEB2("CCScanHookRecord::takeone: offs " << (lltodecstr(headoffs)) << " padsize " << (lltodecstr(padsize)) << "\n" );
|
||||
return Continue;
|
||||
}
|
||||
};
|
||||
@@ -704,10 +695,9 @@ string CirCache::getpath()
|
||||
|
||||
bool CirCache::create(off_t maxsize, int flags)
|
||||
{
|
||||
LOGDEB(("CirCache::create: [%s] maxsz %s flags 0x%x\n",
|
||||
m_dir.c_str(), lltodecstr((long long)maxsize).c_str(), flags));
|
||||
LOGDEB("CirCache::create: [" << (m_dir) << "] maxsz " << (lltodecstr((long long)maxsize)) << " flags 0x" << (flags) << "\n" );
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::create: null data\n"));
|
||||
LOGERR("CirCache::create: null data\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -729,7 +719,7 @@ bool CirCache::create(off_t maxsize, int flags)
|
||||
}
|
||||
if (maxsize == m_d->m_maxsize &&
|
||||
((flags & CC_CRUNIQUE) != 0) == m_d->m_uniquentries) {
|
||||
LOGDEB(("Header unchanged, no rewrite\n"));
|
||||
LOGDEB("Header unchanged, no rewrite\n" );
|
||||
return true;
|
||||
}
|
||||
// If the new maxsize is bigger than current size, we need
|
||||
@@ -746,13 +736,7 @@ bool CirCache::create(off_t maxsize, int flags)
|
||||
}
|
||||
m_d->m_maxsize = maxsize;
|
||||
m_d->m_uniquentries = ((flags & CC_CRUNIQUE) != 0);
|
||||
LOGDEB2(("CirCache::create: rewriting header with "
|
||||
"maxsize %s oheadoffs %s nheadoffs %s "
|
||||
"npadsize %d unient %d\n",
|
||||
lltodecstr(m_d->m_maxsize).c_str(),
|
||||
lltodecstr(m_d->m_oheadoffs).c_str(),
|
||||
lltodecstr(m_d->m_nheadoffs).c_str(),
|
||||
m_d->m_npadsize, int(m_d->m_uniquentries)));
|
||||
LOGDEB2("CirCache::create: rewriting header with maxsize " << (lltodecstr(m_d->m_maxsize)) << " oheadoffs " << (lltodecstr(m_d->m_oheadoffs)) << " nheadoffs " << (lltodecstr(m_d->m_nheadoffs)) << " npadsize " << (m_d->m_npadsize) << " unient " << (int(m_d->m_uniquentries)) << "\n" );
|
||||
return m_d->writefirstblock();
|
||||
}
|
||||
// Else fallthrough to create file
|
||||
@@ -783,7 +767,7 @@ bool CirCache::create(off_t maxsize, int flags)
|
||||
bool CirCache::open(OpMode mode)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::open: null data\n"));
|
||||
LOGERR("CirCache::open: null data\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -854,10 +838,7 @@ public:
|
||||
|
||||
virtual status takeone(off_t offs, const string& udi,
|
||||
const EntryHeaderData& d) {
|
||||
LOGDEB2(("Circache:Scan: off %ld udi [%s] dcsz %u dtsz %u pdsz %u "
|
||||
" flgs %hu\n",
|
||||
long(offs), udi.c_str(), (UINT)d.dicsize,
|
||||
(UINT)d.datasize, (UINT)d.padsize, d.flags));
|
||||
LOGDEB2("Circache:Scan: off " << (long(offs)) << " udi [" << (udi) << "] dcsz " << ((UINT)d.dicsize) << " dtsz " << ((UINT)d.datasize) << " pdsz " << ((UINT)d.padsize) << " flgs " << (d.flags) << "\n" );
|
||||
if (!m_udi.compare(udi)) {
|
||||
m_instance++;
|
||||
m_offs = offs;
|
||||
@@ -879,21 +860,21 @@ bool CirCache::get(const string& udi, string& dic, string *data, int instance)
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGDEB0(("CirCache::get: udi [%s], instance %d\n", udi.c_str(), instance));
|
||||
LOGDEB0("CirCache::get: udi [" << (udi) << "], instance " << (instance) << "\n" );
|
||||
|
||||
// If memory map is up to date, use it:
|
||||
if (m_d->m_ofskhcplt) {
|
||||
LOGDEB1(("CirCache::get: using ofskh\n"));
|
||||
LOGDEB1("CirCache::get: using ofskh\n" );
|
||||
//m_d->khDump();
|
||||
vector<off_t> ofss;
|
||||
if (m_d->khFind(udi, ofss)) {
|
||||
LOGDEB1(("Circache::get: h found, colls %d\n", ofss.size()));
|
||||
LOGDEB1("Circache::get: h found, colls " << (ofss.size()) << "\n" );
|
||||
int finst = 1;
|
||||
EntryHeaderData d_good;
|
||||
off_t o_good = 0;
|
||||
for (vector<off_t>::iterator it = ofss.begin();
|
||||
it != ofss.end(); it++) {
|
||||
LOGDEB1(("Circache::get: trying offs %lu\n", (ULONG)*it));
|
||||
LOGDEB1("Circache::get: trying offs " << ((ULONG)*it) << "\n" );
|
||||
EntryHeaderData d;
|
||||
string fudi;
|
||||
if (!m_d->readHUdi(*it, d, fudi)) {
|
||||
@@ -915,8 +896,7 @@ bool CirCache::get(const string& udi, string& dic, string *data, int instance)
|
||||
// Did we read an appropriate entry ?
|
||||
if (o_good != 0 && (instance == -1 || instance == finst)) {
|
||||
bool ret = m_d->readDicData(o_good, d_good, dic, data);
|
||||
LOGDEB0(("Circache::get: hfound, %d mS\n",
|
||||
chron.millis()));
|
||||
LOGDEB0("Circache::get: hfound, " << (chron.millis()) << " mS\n" );
|
||||
return ret;
|
||||
}
|
||||
// Else try to scan anyway.
|
||||
@@ -935,7 +915,7 @@ bool CirCache::get(const string& udi, string& dic, string *data, int instance)
|
||||
return false;
|
||||
}
|
||||
bool bret = m_d->readDicData(getter.m_offs, getter.m_hd, dic, data);
|
||||
LOGDEB0(("Circache::get: scanfound, %d mS\n", chron.millis()));
|
||||
LOGDEB0("Circache::get: scanfound, " << (chron.millis()) << " mS\n" );
|
||||
|
||||
return bret;
|
||||
}
|
||||
@@ -943,7 +923,7 @@ bool CirCache::get(const string& udi, string& dic, string *data, int instance)
|
||||
bool CirCache::erase(const string& udi, bool reallyclear)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::erase: null data\n"));
|
||||
LOGERR("CirCache::erase: null data\n" );
|
||||
return false;
|
||||
}
|
||||
if (m_d->m_fd < 0) {
|
||||
@@ -951,7 +931,7 @@ bool CirCache::erase(const string& udi, bool reallyclear)
|
||||
return false;
|
||||
}
|
||||
|
||||
LOGDEB0(("CirCache::erase: udi [%s]\n", udi.c_str()));
|
||||
LOGDEB0("CirCache::erase: udi [" << (udi) << "]\n" );
|
||||
|
||||
// If the mem cache is not up to date, update it, we're too lazy
|
||||
// to do a scan
|
||||
@@ -959,7 +939,7 @@ bool CirCache::erase(const string& udi, bool reallyclear)
|
||||
string dic;
|
||||
get("nosuchudi probably exists", dic);
|
||||
if (!m_d->m_ofskhcplt) {
|
||||
LOGERR(("CirCache::erase : cache not updated after get\n"));
|
||||
LOGERR("CirCache::erase : cache not updated after get\n" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -967,27 +947,27 @@ bool CirCache::erase(const string& udi, bool reallyclear)
|
||||
vector<off_t> ofss;
|
||||
if (!m_d->khFind(udi, ofss)) {
|
||||
// Udi not in there, erase ok
|
||||
LOGDEB(("CirCache::erase: khFind returns none\n"));
|
||||
LOGDEB("CirCache::erase: khFind returns none\n" );
|
||||
return true;
|
||||
}
|
||||
|
||||
for (vector<off_t>::iterator it = ofss.begin(); it != ofss.end(); it++) {
|
||||
LOGDEB2(("CirCache::erase: reading at %lu\n", (unsigned long)*it));
|
||||
LOGDEB2("CirCache::erase: reading at " << ((unsigned long)*it) << "\n" );
|
||||
EntryHeaderData d;
|
||||
string fudi;
|
||||
if (!m_d->readHUdi(*it, d, fudi)) {
|
||||
return false;
|
||||
}
|
||||
LOGDEB2(("CirCache::erase: found fudi [%s]\n", fudi.c_str()));
|
||||
LOGDEB2("CirCache::erase: found fudi [" << (fudi) << "]\n" );
|
||||
if (!fudi.compare(udi)) {
|
||||
EntryHeaderData nd;
|
||||
nd.padsize = d.dicsize + d.datasize + d.padsize;
|
||||
LOGDEB2(("CirCache::erase: rewrite at %lu\n", (unsigned long)*it));
|
||||
LOGDEB2("CirCache::erase: rewrite at " << ((unsigned long)*it) << "\n" );
|
||||
if (*it == m_d->m_nheadoffs) {
|
||||
m_d->m_npadsize = nd.padsize;
|
||||
}
|
||||
if (!m_d->writeEntryHeader(*it, nd, reallyclear)) {
|
||||
LOGERR(("CirCache::erase: write header failed\n"));
|
||||
LOGERR("CirCache::erase: write header failed\n" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1010,8 +990,7 @@ public:
|
||||
|
||||
virtual status takeone(off_t offs, const string& udi,
|
||||
const EntryHeaderData& d) {
|
||||
LOGDEB2(("Circache:ScanSpacer:off %u dcsz %u dtsz %u pdsz %u udi[%s]\n",
|
||||
(UINT)offs, d.dicsize, d.datasize, d.padsize, udi.c_str()));
|
||||
LOGDEB2("Circache:ScanSpacer:off " << ((UINT)offs) << " dcsz " << (d.dicsize) << " dtsz " << (d.datasize) << " pdsz " << (d.padsize) << " udi[" << (udi) << "]\n" );
|
||||
sizeseen += CIRCACHE_HEADER_SIZE + d.dicsize + d.datasize + d.padsize;
|
||||
squashed_udis.push_back(make_pair(udi, offs));
|
||||
if (sizeseen >= sizewanted) {
|
||||
@@ -1025,7 +1004,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
const string& data, unsigned int iflags)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::put: null data\n"));
|
||||
LOGERR("CirCache::put: null data\n" );
|
||||
return false;
|
||||
}
|
||||
if (m_d->m_fd < 0) {
|
||||
@@ -1037,15 +1016,14 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
string dic;
|
||||
if (!iconf || !iconf->get("udi", dic) || dic.empty() || dic.compare(udi)) {
|
||||
m_d->m_reason << "No/bad 'udi' entry in input dic";
|
||||
LOGERR(("Circache::put: no/bad udi: DIC:[%s] UDI [%s]\n",
|
||||
dic.c_str(), udi.c_str()));
|
||||
LOGERR("Circache::put: no/bad udi: DIC:[" << (dic) << "] UDI [" << (udi) << "]\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
// Possibly erase older entries. Need to do this first because we may be
|
||||
// able to reuse the space if the same udi was last written
|
||||
if (m_d->m_uniquentries && !erase(udi)) {
|
||||
LOGERR(("CirCache::put: can't erase older entries\n"));
|
||||
LOGERR("CirCache::put: can't erase older entries\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1085,7 +1063,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
off_t npadsize = 0;
|
||||
bool extending = false;
|
||||
|
||||
LOGDEB(("CirCache::put: nsz %d oheadoffs %d\n", nsize, m_d->m_oheadoffs));
|
||||
LOGDEB("CirCache::put: nsz " << (nsize) << " oheadoffs " << (m_d->m_oheadoffs) << "\n" );
|
||||
|
||||
// Check if we can recover some pad space from the (physically) previous
|
||||
// entry.
|
||||
@@ -1107,7 +1085,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
// the header, we're going to write on it.
|
||||
recovpadsize += CIRCACHE_HEADER_SIZE;
|
||||
} else {
|
||||
LOGDEB(("CirCache::put: recov. prev. padsize %d\n", pd.padsize));
|
||||
LOGDEB("CirCache::put: recov. prev. padsize " << (pd.padsize) << "\n" );
|
||||
pd.padsize = 0;
|
||||
if (!m_d->writeEntryHeader(m_d->m_nheadoffs, pd)) {
|
||||
return false;
|
||||
@@ -1120,7 +1098,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
if (nsize <= recovpadsize) {
|
||||
// If the new entry fits entirely in the pad area from the
|
||||
// latest one, no need to recycle stuff
|
||||
LOGDEB(("CirCache::put: new fits in old padsize %d\n", recovpadsize));
|
||||
LOGDEB("CirCache::put: new fits in old padsize " << (recovpadsize) << "\n" );
|
||||
npadsize = recovpadsize - nsize;
|
||||
} else if (st.st_size < m_d->m_maxsize) {
|
||||
// Still growing the file.
|
||||
@@ -1130,13 +1108,11 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
// Scan the file until we have enough space for the new entry,
|
||||
// and determine the pad size up to the 1st preserved entry
|
||||
off_t scansize = nsize - recovpadsize;
|
||||
LOGDEB(("CirCache::put: scanning for size %d from offs %u\n",
|
||||
scansize, (UINT)m_d->m_oheadoffs));
|
||||
LOGDEB("CirCache::put: scanning for size " << (scansize) << " from offs " << ((UINT)m_d->m_oheadoffs) << "\n" );
|
||||
CCScanHookSpacer spacer(scansize);
|
||||
switch (m_d->scan(m_d->m_oheadoffs, &spacer)) {
|
||||
case CCScanHook::Stop:
|
||||
LOGDEB(("CirCache::put: Scan ok, sizeseen %d\n",
|
||||
spacer.sizeseen));
|
||||
LOGDEB("CirCache::put: Scan ok, sizeseen " << (spacer.sizeseen) << "\n" );
|
||||
npadsize = spacer.sizeseen - scansize;
|
||||
break;
|
||||
case CCScanHook::Eof:
|
||||
@@ -1151,8 +1127,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
m_d->khClear(spacer.squashed_udis);
|
||||
}
|
||||
|
||||
LOGDEB(("CirCache::put: writing %d at %d padsize %d\n",
|
||||
nsize, nwriteoffs, npadsize));
|
||||
LOGDEB("CirCache::put: writing " << (nsize) << " at " << (nwriteoffs) << " padsize " << (npadsize) << "\n" );
|
||||
|
||||
if (lseek(m_d->m_fd, nwriteoffs, 0) != nwriteoffs) {
|
||||
m_d->m_reason << "CirCache::put: lseek failed: " << errno;
|
||||
@@ -1196,7 +1171,7 @@ bool CirCache::put(const string& udi, const ConfSimple *iconf,
|
||||
bool CirCache::rewind(bool& eof)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::rewind: null data\n"));
|
||||
LOGERR("CirCache::rewind: null data\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1204,7 +1179,7 @@ bool CirCache::rewind(bool& eof)
|
||||
|
||||
off_t fsize = lseek(m_d->m_fd, 0, SEEK_END);
|
||||
if (fsize == (off_t) - 1) {
|
||||
LOGERR(("CirCache::rewind: seek to EOF failed\n"));
|
||||
LOGERR("CirCache::rewind: seek to EOF failed\n" );
|
||||
return false;
|
||||
}
|
||||
// Read oldest header. This is either at the position pointed to
|
||||
@@ -1231,7 +1206,7 @@ bool CirCache::rewind(bool& eof)
|
||||
bool CirCache::next(bool& eof)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::next: null data\n"));
|
||||
LOGERR("CirCache::next: null data\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1268,7 +1243,7 @@ bool CirCache::next(bool& eof)
|
||||
bool CirCache::getCurrentUdi(string& udi)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::getCurrentUdi: null data\n"));
|
||||
LOGERR("CirCache::getCurrentUdi: null data\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1281,7 +1256,7 @@ bool CirCache::getCurrentUdi(string& udi)
|
||||
bool CirCache::getCurrent(string& udi, string& dic, string *data)
|
||||
{
|
||||
if (m_d == 0) {
|
||||
LOGERR(("CirCache::getCurrent: null data\n"));
|
||||
LOGERR("CirCache::getCurrent: null data\n" );
|
||||
return false;
|
||||
}
|
||||
if (!m_d->readDicData(m_d->m_itoffs, m_d->m_ithd, dic, data)) {
|
||||
@@ -1317,7 +1292,7 @@ static bool inflateToDynBuf(void* inp, UINT inlen, void **outpp, UINT *outlenp)
|
||||
{
|
||||
z_stream d_stream; /* decompression stream */
|
||||
|
||||
LOGDEB0(("inflateToDynBuf: inlen %u\n", inlen));
|
||||
LOGDEB0("inflateToDynBuf: inlen " << (inlen) << "\n" );
|
||||
|
||||
d_stream.zalloc = (alloc_func)0;
|
||||
d_stream.zfree = (free_func)0;
|
||||
@@ -1336,24 +1311,21 @@ static bool inflateToDynBuf(void* inp, UINT inlen, void **outpp, UINT *outlenp)
|
||||
|
||||
int err;
|
||||
if ((err = inflateInit(&d_stream)) != Z_OK) {
|
||||
LOGERR(("Inflate: inflateInit: err %d msg %s\n", err, d_stream.msg));
|
||||
LOGERR("Inflate: inflateInit: err " << (err) << " msg " << (d_stream.msg) << "\n" );
|
||||
free(outp);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
LOGDEB2(("InflateToDynBuf: avail_in %d total_in %d avail_out %d "
|
||||
"total_out %d\n", d_stream.avail_in, d_stream.total_in,
|
||||
d_stream.avail_out, d_stream.total_out));
|
||||
LOGDEB2("InflateToDynBuf: avail_in " << (d_stream.avail_in) << " total_in " << (d_stream.total_in) << " avail_out " << (d_stream.avail_out) << " total_out " << (d_stream.total_out) << "\n" );
|
||||
if (d_stream.avail_out == 0) {
|
||||
if ((outp = (char*)allocmem(outp, inlen, &alloc,
|
||||
imul, mxinc)) == 0) {
|
||||
LOGERR(("Inflate: out of memory, current alloc %d\n",
|
||||
alloc * inlen));
|
||||
LOGERR("Inflate: out of memory, current alloc " << (alloc * inlen) << "\n" );
|
||||
inflateEnd(&d_stream);
|
||||
return false;
|
||||
} else {
|
||||
LOGDEB2(("inflateToDynBuf: realloc(%d) ok\n", alloc * inlen));
|
||||
LOGDEB2("inflateToDynBuf: realloc(" << (alloc * inlen) << ") ok\n" );
|
||||
}
|
||||
d_stream.avail_out = alloc * inlen - d_stream.total_out;
|
||||
d_stream.next_out = (Bytef*)(outp + d_stream.total_out);
|
||||
@@ -1363,7 +1335,7 @@ static bool inflateToDynBuf(void* inp, UINT inlen, void **outpp, UINT *outlenp)
|
||||
break;
|
||||
}
|
||||
if (err != Z_OK) {
|
||||
LOGERR(("Inflate: error %d msg %s\n", err, d_stream.msg));
|
||||
LOGERR("Inflate: error " << (err) << " msg " << (d_stream.msg) << "\n" );
|
||||
inflateEnd(&d_stream);
|
||||
free(outp);
|
||||
return false;
|
||||
@@ -1373,10 +1345,10 @@ static bool inflateToDynBuf(void* inp, UINT inlen, void **outpp, UINT *outlenp)
|
||||
*outpp = (Bytef *)outp;
|
||||
|
||||
if ((err = inflateEnd(&d_stream)) != Z_OK) {
|
||||
LOGERR(("Inflate: inflateEnd error %d msg %s\n", err, d_stream.msg));
|
||||
LOGERR("Inflate: inflateEnd error " << (err) << " msg " << (d_stream.msg) << "\n" );
|
||||
return false;
|
||||
}
|
||||
LOGDEB0(("inflateToDynBuf: ok, output size %d\n", d_stream.total_out));
|
||||
LOGDEB0("inflateToDynBuf: ok, output size " << (d_stream.total_out) << "\n" );
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1478,7 +1450,8 @@ int CirCache::append(const string ddir, const string& sdir, string *reason)
|
||||
#include "fileudi.h"
|
||||
#include "conftree.h"
|
||||
#include "readfile.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "smallut.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -1706,3 +1679,4 @@ b1:
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include <cstring>
|
||||
|
||||
#include "copyfile.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -46,7 +46,7 @@ bool copyfile(const char *src, const char *dst, string &reason, int flags)
|
||||
char buf[CPBSIZ];
|
||||
int oflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY;
|
||||
|
||||
LOGDEB(("copyfile: %s to %s\n", src, dst));
|
||||
LOGDEB("copyfile: " << (src) << " to " << (dst) << "\n" );
|
||||
|
||||
if ((sfd = ::open(src, O_RDONLY, 0)) < 0) {
|
||||
reason += string("open ") + src + ": " + strerror(errno);
|
||||
@@ -94,12 +94,12 @@ out:
|
||||
bool stringtofile(const string& dt, const char *dst, string& reason,
|
||||
int flags)
|
||||
{
|
||||
LOGDEB(("stringtofile:\n"));
|
||||
LOGDEB("stringtofile:\n" );
|
||||
int dfd = -1;
|
||||
bool ret = false;
|
||||
int oflags = O_WRONLY|O_CREAT|O_TRUNC|O_BINARY;
|
||||
|
||||
LOGDEB(("stringtofile: %u bytes to %s\n", (unsigned int)dt.size(), dst));
|
||||
LOGDEB("stringtofile: " << ((unsigned int)dt.size()) << " bytes to " << (dst) << "\n" );
|
||||
|
||||
if (flags & COPYFILE_EXCL) {
|
||||
oflags |= O_EXCL;
|
||||
@@ -262,3 +262,4 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,484 +0,0 @@
|
||||
/* Copyright (C) 2006 J.F.Dockes
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef TEST_DEBUGLOG
|
||||
|
||||
#define __USE_GNU
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <safefcntl.h> // in case O_APPEND is in there
|
||||
#ifdef INCLUDE_NEW_H
|
||||
#include <new.h>
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <set>
|
||||
using std::set;
|
||||
using std::string;
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "pathut.h"
|
||||
#include "smallut.h"
|
||||
#include "ptmutex.h"
|
||||
|
||||
#ifndef freeZ
|
||||
#define freeZ(X) {if (X) {free(X);X=0;}}
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
namespace DebugLog {
|
||||
|
||||
bool DebugLog::isspecialname(const char *logname)
|
||||
{
|
||||
return !strcmp(logname, "stdout") || !strcmp(logname, "stderr");
|
||||
}
|
||||
|
||||
class DebugLogWriter {
|
||||
public:
|
||||
virtual ~DebugLogWriter() {}
|
||||
virtual int put(const char *s) = 0;
|
||||
};
|
||||
|
||||
class DLFWImpl {
|
||||
char *filename;
|
||||
FILE *fp;
|
||||
int truncate;
|
||||
public:
|
||||
// Open output file if needed, return 0 if ok
|
||||
void maybeopenfp() {
|
||||
if (fp)
|
||||
return;
|
||||
if (filename == 0)
|
||||
return;
|
||||
if (!strcmp(filename, "stdout")) {
|
||||
fp = stdout;
|
||||
} else if (!strcmp(filename, "stderr")) {
|
||||
fp = stderr;
|
||||
} else {
|
||||
fp = fopen(filename, (truncate) ? "w" : "a");
|
||||
if (fp) {
|
||||
setvbuf(fp, 0, _IOLBF, BUFSIZ);
|
||||
#if defined(O_APPEND) && !defined(_WIN32)
|
||||
{
|
||||
int flgs = 0;
|
||||
fcntl(fileno(fp), F_GETFL, &flgs);
|
||||
fcntl(fileno(fp), F_SETFL, flgs|O_APPEND);
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
fprintf(stderr, "Debuglog: could not open [%s] errno %d\n",
|
||||
filename, errno);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
void maybeclosefp() {
|
||||
#ifdef DEBUGDEBUG
|
||||
fprintf(stderr, "DebugLogImpl::maybeclosefp: filename %p, fp %p\n",
|
||||
filename, fp);
|
||||
#endif
|
||||
// Close current file if open, and not stdout/stderr
|
||||
if (fp && (filename == 0 ||
|
||||
(strcmp(filename, "stdout") &&
|
||||
strcmp(filename, "stderr")))) {
|
||||
fclose(fp);
|
||||
}
|
||||
fp = 0;
|
||||
freeZ(filename);
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
DLFWImpl()
|
||||
: filename(0), fp(0), truncate(1)
|
||||
{
|
||||
setfilename("stderr", 0);
|
||||
}
|
||||
~DLFWImpl() {
|
||||
maybeclosefp();
|
||||
}
|
||||
int setfilename(const char *fn, int trnc) {
|
||||
maybeclosefp();
|
||||
filename = strdup(fn);
|
||||
truncate = trnc;
|
||||
maybeopenfp();
|
||||
return 0;
|
||||
}
|
||||
const char *getfilename() {
|
||||
return filename;
|
||||
}
|
||||
int put(const char *s) {
|
||||
maybeopenfp();
|
||||
if (fp)
|
||||
return fputs(s, fp);
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
|
||||
class DebugLogFileWriter : public DebugLogWriter {
|
||||
DLFWImpl *impl;
|
||||
PTMutexInit loglock;
|
||||
public:
|
||||
DebugLogFileWriter()
|
||||
{
|
||||
impl = new DLFWImpl;
|
||||
}
|
||||
|
||||
virtual ~DebugLogFileWriter()
|
||||
{
|
||||
delete impl;
|
||||
}
|
||||
|
||||
virtual int setfilename(const char *fn, int trnc)
|
||||
{
|
||||
PTMutexLocker lock(loglock);
|
||||
return impl ? impl->setfilename(fn, trnc) : -1;
|
||||
}
|
||||
virtual const char *getfilename()
|
||||
{
|
||||
PTMutexLocker lock(loglock);
|
||||
return impl ? impl->getfilename() : 0;
|
||||
}
|
||||
virtual int reopen()
|
||||
{
|
||||
PTMutexLocker lock(loglock);
|
||||
if (!impl)
|
||||
return -1;
|
||||
string fn = impl->getfilename();
|
||||
return impl->setfilename(fn.c_str(), 1);
|
||||
}
|
||||
virtual int put(const char *s)
|
||||
{
|
||||
PTMutexLocker lock(loglock);
|
||||
return impl ? impl->put(s) : -1;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
static set<string> yesfiles;
|
||||
static void initfiles()
|
||||
{
|
||||
const char *cp = getenv("DEBUGLOG_FILES");
|
||||
if (!cp)
|
||||
return;
|
||||
vector<string> files;
|
||||
stringToTokens(cp, files, ",");
|
||||
yesfiles.insert(files.begin(), files.end());
|
||||
}
|
||||
static bool fileInFiles(const string& file)
|
||||
{
|
||||
string sf = path_getsimple(file);
|
||||
if (yesfiles.find(sf) != yesfiles.end()) {
|
||||
//fprintf(stderr, "Debug ON: %s \n", file.c_str());
|
||||
return true;
|
||||
}
|
||||
//fprintf(stderr, "Debug OFF: %s \n", file.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
static void datestring(char *d, int sz) {
|
||||
SYSTEMTIME buf;
|
||||
GetLocalTime(&buf);
|
||||
int year = buf.wYear % 100;
|
||||
|
||||
snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, int(buf.wMonth),
|
||||
int(buf.wDay), int(buf.wHour), int(buf.wMinute), int(buf.wSecond));
|
||||
}
|
||||
#define vsnprintf _vsnprintf
|
||||
|
||||
#else // !WINDOWS ->
|
||||
|
||||
#include <time.h>
|
||||
static void datestring(char *d, int sz)
|
||||
{
|
||||
struct tm *tmp;
|
||||
time_t tim = time((time_t*)0);
|
||||
tmp = localtime(&tim);
|
||||
int year = tmp->tm_year % 100;
|
||||
snprintf(d, sz, "%02d%02d%02d%02d%02d%02d", year, tmp->tm_mon+1,
|
||||
tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
|
||||
}
|
||||
|
||||
#endif // !WINDOWS
|
||||
|
||||
void
|
||||
DebugLog::prolog(int lev, const char *f, int line)
|
||||
{
|
||||
if (!writer)
|
||||
return;
|
||||
if (!yesfiles.empty() && !fileInFiles(f)) {
|
||||
fileyes = false;
|
||||
return;
|
||||
} else {
|
||||
fileyes = true;
|
||||
}
|
||||
if (dodate) {
|
||||
char dts[100];
|
||||
datestring(dts, 100);
|
||||
writer->put(dts);
|
||||
}
|
||||
char buf[100];
|
||||
sprintf(buf, ":%d:", lev);
|
||||
writer->put(buf);
|
||||
#if DEBUGLOG_SHOW_PID
|
||||
sprintf(buf, "%d:", getpid());
|
||||
writer->put(buf);
|
||||
#endif
|
||||
#if DEBUGLOG_SHOW_THREAD
|
||||
sprintf(buf, "%lx:", (unsigned long)pthread_self());
|
||||
writer->put(buf);
|
||||
#endif
|
||||
writer->put(f);
|
||||
sprintf(buf, ":%d:", line);
|
||||
writer->put(buf);
|
||||
}
|
||||
|
||||
void
|
||||
DebugLog::log(const char *s ...)
|
||||
{
|
||||
if (!writer || !fileyes)
|
||||
return;
|
||||
va_list ap;
|
||||
va_start(ap,s);
|
||||
|
||||
#ifdef HAVE_VASPRINTF_nono // not sure vasprintf is really such a great idea
|
||||
char *buf;
|
||||
vasprintf(&buf, s, ap);
|
||||
if (buf) {
|
||||
#else
|
||||
char buf[4096];
|
||||
// It's possible that they also wouldn't have vsnprintf but what then ?
|
||||
vsnprintf(buf, 4096, s, ap);
|
||||
{
|
||||
#endif
|
||||
writer->put(buf);
|
||||
}
|
||||
|
||||
#ifdef HAVE_VASPRINTF_nono
|
||||
if (buf)
|
||||
free(buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
DebugLog::setloglevel(int lev)
|
||||
{
|
||||
debuglevel = lev;
|
||||
while (!levels.empty())
|
||||
levels.pop();
|
||||
pushlevel(lev);
|
||||
}
|
||||
|
||||
void DebugLog::pushlevel(int lev)
|
||||
{
|
||||
debuglevel = lev;
|
||||
levels.push(lev);
|
||||
}
|
||||
|
||||
void DebugLog::poplevel()
|
||||
{
|
||||
if (levels.empty())
|
||||
debuglevel = 0;
|
||||
if (levels.size() > 1)
|
||||
levels.pop();
|
||||
debuglevel = levels.top();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Global functions
|
||||
//////////////////////////////////////
|
||||
static DebugLogFileWriter lwriter;
|
||||
static DebugLogFileWriter *theWriter = &lwriter;
|
||||
|
||||
const char *getfilename()
|
||||
{
|
||||
return theWriter ? theWriter->getfilename() : 0;
|
||||
}
|
||||
|
||||
int setfilename(const char *fname, int trnc)
|
||||
{
|
||||
return theWriter ? theWriter->setfilename(fname, trnc) : -1;
|
||||
}
|
||||
|
||||
int reopen()
|
||||
{
|
||||
return theWriter ? theWriter->reopen() : -1;
|
||||
|
||||
}
|
||||
|
||||
#if DEBUGLOG_USE_THREADS
|
||||
#include <pthread.h>
|
||||
static pthread_key_t dbl_key;
|
||||
static pthread_once_t key_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void thrdatadel(void *data)
|
||||
{
|
||||
// fprintf(stderr, "DebugLog:: thrdatadel: %p\n", data);
|
||||
DebugLog *dbl = (DebugLog *)data;
|
||||
delete dbl;
|
||||
pthread_setspecific(dbl_key, 0);
|
||||
}
|
||||
static void once_routine(void)
|
||||
{
|
||||
int status;
|
||||
status = pthread_key_create(&dbl_key, thrdatadel);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "debuglog: cant initialize pthread "
|
||||
"thread private storage key\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
DebugLog *getdbl()
|
||||
{
|
||||
int status = pthread_once(&key_once, once_routine);
|
||||
if (status != 0) {
|
||||
fprintf(stderr, "debuglog: cant initialize pthread "
|
||||
"thread private storage key (pthread_once)\n");
|
||||
abort();
|
||||
}
|
||||
DebugLog *dbl;
|
||||
if (!(dbl = (DebugLog *)pthread_getspecific(dbl_key))) {
|
||||
if ((dbl = new DebugLog) == 0) {
|
||||
fprintf(stderr, "debuglog: new DebugLog returned 0! ");
|
||||
abort();
|
||||
}
|
||||
|
||||
dbl->setwriter(theWriter);
|
||||
initfiles();
|
||||
status = pthread_setspecific(dbl_key, dbl);
|
||||
if (status) {
|
||||
fprintf(stderr, "debuglog: cant initialize pthread "
|
||||
"thread private storage key (pthread_setspecific)\n");
|
||||
abort();
|
||||
}
|
||||
}
|
||||
return dbl;
|
||||
}
|
||||
|
||||
#else // No threads ->
|
||||
|
||||
static DebugLog *dbl;
|
||||
DebugLog *getdbl()
|
||||
{
|
||||
if (!dbl) {
|
||||
dbl = new DebugLog;
|
||||
dbl->setwriter(theWriter);
|
||||
initfiles();
|
||||
}
|
||||
return dbl;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////// TEST DRIVER //////////////////
|
||||
#else /* TEST_DEBUGLOG */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
static inline unsigned int sleep(unsigned int s) {Sleep(s * 1000); return 0;}
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
|
||||
#include "debuglog.h"
|
||||
|
||||
#if DEBUGLOG_USE_THREADS
|
||||
//#define TEST_THREADS
|
||||
#endif
|
||||
|
||||
#ifdef TEST_THREADS
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
const int iloop = 5;
|
||||
void *thread_test(void *data)
|
||||
{
|
||||
const char *s = (const char *)data;
|
||||
int lev = atoi(s);
|
||||
DebugLog::getdbl()->setloglevel(DEBDEB);
|
||||
for (int i = 1; i < iloop;i++) {
|
||||
switch (lev) {
|
||||
case 1: LOGFATAL(("Thread: %s count: %d\n", s, i));break;
|
||||
case 2: LOGERR(("Thread: %s count: %d\n", s, i));break;
|
||||
default:
|
||||
case 3: LOGINFO(("Thread: %s count: %d\n", s, i));break;
|
||||
}
|
||||
sleep(1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
#ifdef TEST_THREADS
|
||||
pthread_t t1, t2, t3;
|
||||
|
||||
char name1[20];
|
||||
strcpy(name1, "1");
|
||||
pthread_create(&t1, 0, thread_test, name1);
|
||||
|
||||
char name2[20];
|
||||
strcpy(name2, "2");
|
||||
pthread_create(&t2, 0, thread_test, name2);
|
||||
|
||||
char name3[20];
|
||||
strcpy(name3, "3");
|
||||
pthread_create(&t3, 0, thread_test, name3);
|
||||
|
||||
DebugLog::getdbl()->setloglevel(DEBDEB);
|
||||
for (int i = 1; i < iloop;i++) {
|
||||
LOGINFO(("LOGGING FROM MAIN\n"));
|
||||
sleep(1);
|
||||
}
|
||||
sleep(2);
|
||||
exit(0);
|
||||
#else
|
||||
LOGFATAL(("FATAL\n","Val"));
|
||||
DebugLog::getdbl()->logdate(1);
|
||||
LOGERR(("ERR\n","Val"));
|
||||
LOGINFO(("INFO\n","Val"));
|
||||
LOGDEB0(("DEBUG %s\n","valeur"));
|
||||
|
||||
int lev;
|
||||
printf("Testing push. Initial level: %d\n", DebugLog::getdbl()->getlevel());
|
||||
for (lev = 0; lev < 4;lev++) {
|
||||
DebugLog::getdbl()->pushlevel(lev);
|
||||
printf("Lev now %d\n", DebugLog::getdbl()->getlevel());
|
||||
}
|
||||
printf("Testing pop\n");
|
||||
for (lev = 0; lev < 7;lev++) {
|
||||
DebugLog::getdbl()->poplevel();
|
||||
printf("Lev now %d\n", DebugLog::getdbl()->getlevel());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#endif /* TEST_DEBUGLOG */
|
||||
@@ -1,112 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef _DEBUGLOG_H_
|
||||
#define _DEBUGLOG_H_
|
||||
/* Macros for log and debug messages */
|
||||
#include <stack>
|
||||
|
||||
namespace DebugLog {
|
||||
|
||||
#ifndef DEBUGLOG_USE_THREADS
|
||||
#define DEBUGLOG_USE_THREADS 1
|
||||
#endif
|
||||
|
||||
#define DEBFATAL 1
|
||||
#define DEBERR 2
|
||||
#define DEBINFO 3
|
||||
#define DEBDEB 4
|
||||
#define DEBDEB0 5
|
||||
#define DEBDEB1 6
|
||||
#define DEBDEB2 7
|
||||
#define DEBDEB3 8
|
||||
|
||||
#ifndef STATICVERBOSITY
|
||||
#define STATICVERBOSITY DEBDEB0
|
||||
#endif
|
||||
|
||||
class DebugLogWriter;
|
||||
|
||||
class DebugLog {
|
||||
std::stack<int> levels;
|
||||
int debuglevel;
|
||||
int dodate;
|
||||
DebugLogWriter *writer;
|
||||
bool fileyes;
|
||||
public:
|
||||
DebugLog() : debuglevel(10), dodate(0), writer(0), fileyes(true) {}
|
||||
DebugLog(DebugLogWriter *w) : debuglevel(-1), dodate(0), writer(w),
|
||||
fileyes(true) {}
|
||||
virtual ~DebugLog() {}
|
||||
virtual void setwriter(DebugLogWriter *w) {writer = w;}
|
||||
virtual DebugLogWriter *getwriter() {return writer;}
|
||||
virtual void prolog(int lev, const char *srcfname, int line);
|
||||
virtual void log(const char *s ...);
|
||||
virtual void setloglevel(int lev);
|
||||
inline int getlevel() {return debuglevel;}
|
||||
virtual void pushlevel(int lev);
|
||||
virtual void poplevel();
|
||||
virtual void logdate(int onoff) {dodate = onoff;}
|
||||
static bool isspecialname(const char *logname);
|
||||
};
|
||||
|
||||
extern DebugLog *getdbl();
|
||||
extern const char *getfilename();
|
||||
extern int setfilename(const char *fname, int trnc = 1);
|
||||
extern int reopen();
|
||||
|
||||
#if STATICVERBOSITY >= DEBFATAL
|
||||
#define LOGFATAL(X) {if (DebugLog::getdbl()->getlevel()>=DEBFATAL){DebugLog::getdbl()->prolog(DEBFATAL,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGFATAL(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBERR
|
||||
#define LOGERR(X) {if (DebugLog::getdbl()->getlevel()>=DEBERR){DebugLog::getdbl()->prolog(DEBERR,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGERR(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBINFO
|
||||
#define LOGINFO(X) {if (DebugLog::getdbl()->getlevel()>=DEBINFO){DebugLog::getdbl()->prolog(DEBINFO,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGINFO(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBDEB
|
||||
#define LOGDEB(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB){DebugLog::getdbl()->prolog(DEBDEB,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGDEB(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBDEB0
|
||||
#define LOGDEB0(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB0){DebugLog::getdbl()->prolog(DEBDEB0,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGDEB0(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBDEB1
|
||||
#define LOGDEB1(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB1){DebugLog::getdbl()->prolog(DEBDEB1,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGDEB1(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBDEB2
|
||||
#define LOGDEB2(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB2){DebugLog::getdbl()->prolog(DEBDEB2,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGDEB2(X)
|
||||
#endif
|
||||
#if STATICVERBOSITY >= DEBDEB3
|
||||
#define LOGDEB3(X) {if (DebugLog::getdbl()->getlevel()>=DEBDEB3){DebugLog::getdbl()->prolog(DEBDEB3,__FILE__,__LINE__) ;DebugLog::getdbl()->log X;}}
|
||||
#else
|
||||
#define LOGDEB3(X)
|
||||
#endif
|
||||
}
|
||||
#endif /* _DEBUGLOG_H_ */
|
||||
@@ -22,7 +22,7 @@
|
||||
#include "ecrontab.h"
|
||||
#include "execmd.h"
|
||||
#include "smallut.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
// Read crontab file and split it into lines.
|
||||
static bool eCrontabGetLines(vector<string>& lines)
|
||||
@@ -128,8 +128,7 @@ bool checkCrontabUnmanaged(const string& marker, const string& data)
|
||||
bool getCrontabSched(const string& marker, const string& id,
|
||||
vector<string>& sched)
|
||||
{
|
||||
LOGDEB0(("getCrontabSched: marker[%s], id[%s]\n",
|
||||
marker.c_str(), id.c_str()));
|
||||
LOGDEB0("getCrontabSched: marker[" << (marker) << "], id[" << (id) << "]\n" );
|
||||
vector<string> lines;
|
||||
if (!eCrontabGetLines(lines)) {
|
||||
// No crontab, answer is no
|
||||
@@ -270,3 +269,4 @@ int main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
#endif // TEST
|
||||
|
||||
|
||||
+64
-78
@@ -50,33 +50,15 @@
|
||||
#endif
|
||||
|
||||
#include "execmd.h"
|
||||
|
||||
#include "netcon.h"
|
||||
#include "closefrom.h"
|
||||
#include "smallut.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
extern char **environ;
|
||||
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "debuglog.h"
|
||||
|
||||
#else
|
||||
// If compiling outside of recoll, make the file as standalone as reasonable.
|
||||
|
||||
#define LOGFATAL(X)
|
||||
#define LOGERR(X)
|
||||
#define LOGINFO(X)
|
||||
#define LOGDEB(X)
|
||||
#define LOGDEB0(X)
|
||||
#define LOGDEB1(X)
|
||||
#define LOGDEB2(X)
|
||||
#define LOGDEB3(X)
|
||||
#define LOGDEB4(X)
|
||||
|
||||
#endif // BUILDING_RECOLL
|
||||
|
||||
class ExecCmd::Internal {
|
||||
public:
|
||||
Internal()
|
||||
@@ -267,7 +249,7 @@ public:
|
||||
if (!m_active || !m_parent) {
|
||||
return;
|
||||
}
|
||||
LOGDEB1(("~ExecCmdRsrc: working. mypid: %d\n", (int)getpid()));
|
||||
LOGDEB1("~ExecCmdRsrc: working. mypid: " << getpid() << "\n");
|
||||
|
||||
// Better to close the descs first in case the child is waiting in read
|
||||
if (m_parent->m_pipein[0] >= 0) {
|
||||
@@ -289,7 +271,7 @@ public:
|
||||
// definitely tried to call killpg(-1,) from time to time.
|
||||
pid_t grp;
|
||||
if (m_parent->m_pid > 0 && (grp = getpgid(m_parent->m_pid)) > 0) {
|
||||
LOGDEB(("ExecCmd: killpg(%d, SIGTERM)\n", grp));
|
||||
LOGDEB("ExecCmd: killpg(" << (grp) << ", SIGTERM)\n");
|
||||
int ret = killpg(grp, SIGTERM);
|
||||
if (ret == 0) {
|
||||
for (int i = 0; i < 3; i++) {
|
||||
@@ -300,14 +282,14 @@ public:
|
||||
break;
|
||||
}
|
||||
if (i == 2) {
|
||||
LOGDEB(("ExecCmd: killpg(%d, SIGKILL)\n", grp));
|
||||
LOGDEB("ExecCmd: killpg(" << (grp) << ", SIGKILL)\n");
|
||||
killpg(grp, SIGKILL);
|
||||
(void)waitpid(m_parent->m_pid, &status, WNOHANG);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LOGERR(("ExecCmd: error killing process group %d: %d\n",
|
||||
grp, errno));
|
||||
LOGERR("ExecCmd: error killing process group " << (grp) <<
|
||||
": " << errno << "\n");
|
||||
}
|
||||
}
|
||||
m_parent->m_tocmd.reset();
|
||||
@@ -347,8 +329,8 @@ inline void ExecCmd::Internal::dochild(const string& cmd, const char **argv,
|
||||
{
|
||||
// Start our own process group
|
||||
if (setpgid(0, getpid())) {
|
||||
LOGINFO(("ExecCmd::DOCHILD: setpgid(0, %d) failed: errno %d\n",
|
||||
getpid(), errno));
|
||||
LOGINFO("ExecCmd::DOCHILD: setpgid(0, " << getpid() <<
|
||||
") failed: errno " << errno << "\n");
|
||||
}
|
||||
|
||||
// Restore SIGTERM to default. Really, signal handling should be
|
||||
@@ -364,7 +346,7 @@ inline void ExecCmd::Internal::dochild(const string& cmd, const char **argv,
|
||||
// to mess with the global process signal disposition.
|
||||
|
||||
if (signal(SIGTERM, SIG_DFL) == SIG_ERR) {
|
||||
//LOGERR(("ExecCmd::DOCHILD: signal() failed, errno %d\n", errno));
|
||||
//LOGERR("ExecCmd::DOCHILD: signal() failed, errno " << errno << "\n");
|
||||
}
|
||||
sigset_t sset;
|
||||
sigfillset(&sset);
|
||||
@@ -415,10 +397,12 @@ inline void ExecCmd::Internal::dochild(const string& cmd, const char **argv,
|
||||
close(m_pipeout[0]);
|
||||
if (m_pipeout[1] != 1) {
|
||||
if (dup2(m_pipeout[1], 1) < 0) {
|
||||
LOGERR(("ExecCmd::DOCHILD: dup2() failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::DOCHILD: dup2() failed. errno " <<
|
||||
errno << "\n");
|
||||
}
|
||||
if (close(m_pipeout[1]) < 0) {
|
||||
LOGERR(("ExecCmd::DOCHILD: close() failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::DOCHILD: close() failed. errno " <<
|
||||
errno << "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -446,8 +430,8 @@ inline void ExecCmd::Internal::dochild(const string& cmd, const char **argv,
|
||||
// Hu ho. This should never have happened as we checked the
|
||||
// existence of the executable before calling dochild... Until we
|
||||
// did this check, this was the chief cause of LOG mutex deadlock
|
||||
LOGERR(("ExecCmd::DOCHILD: execve(%s) failed. errno %d\n", cmd.c_str(),
|
||||
errno));
|
||||
LOGERR("ExecCmd::DOCHILD: execve(" << cmd << ") failed. errno " <<
|
||||
errno << "\n");
|
||||
_exit(127);
|
||||
}
|
||||
|
||||
@@ -466,19 +450,19 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
it != args.end(); it++) {
|
||||
command += "{" + *it + "} ";
|
||||
}
|
||||
LOGDEB(("ExecCmd::startExec: (%d|%d) %s\n",
|
||||
has_input, has_output, command.c_str()));
|
||||
LOGDEB("ExecCmd::startExec: (" << has_input << "|" << has_output <<
|
||||
") " << command << "\n");
|
||||
}
|
||||
|
||||
// The resource manager ensures resources are freed if we return early
|
||||
ExecCmdRsrc e(this->m);
|
||||
|
||||
if (has_input && pipe(m->m_pipein) < 0) {
|
||||
LOGERR(("ExecCmd::startExec: pipe(2) failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n" );
|
||||
return -1;
|
||||
}
|
||||
if (has_output && pipe(m->m_pipeout) < 0) {
|
||||
LOGERR(("ExecCmd::startExec: pipe(2) failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::startExec: pipe(2) failed. errno " << errno << "\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -494,7 +478,7 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
Ccharp *argv;
|
||||
argv = (Ccharp *)malloc((args.size() + 2) * sizeof(char *));
|
||||
if (argv == 0) {
|
||||
LOGERR(("ExecCmd::doexec: malloc() failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::doexec: malloc() failed. errno " << errno << "\n");
|
||||
return -1;
|
||||
}
|
||||
// Fill up argv
|
||||
@@ -514,7 +498,7 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
}
|
||||
envv = (Ccharp *)malloc((envsize + m->m_env.size() + 2) * sizeof(char *));
|
||||
if (envv == 0) {
|
||||
LOGERR(("ExecCmd::doexec: malloc() failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::doexec: malloc() failed. errno " << errno << "\n");
|
||||
free(argv);
|
||||
return -1;
|
||||
}
|
||||
@@ -531,7 +515,7 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
// As we are going to use execve, not execvp, do the PATH thing.
|
||||
string exe;
|
||||
if (!which(cmd, exe)) {
|
||||
LOGERR(("ExecCmd::startExec: %s not found\n", cmd.c_str()));
|
||||
LOGERR("ExecCmd::startExec: " << (cmd) << " not found\n");
|
||||
free(argv);
|
||||
free(envv);
|
||||
return -1;
|
||||
@@ -590,7 +574,7 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
posix_spawn_file_actions_addopen(&facts, 2, m->m_stderrFile.c_str(),
|
||||
oflags, 0600);
|
||||
}
|
||||
LOGDEB1(("using SPAWN\n"));
|
||||
LOGDEB1("using SPAWN\n");
|
||||
|
||||
// posix_spawn() does not have any standard way to ask for
|
||||
// calling closefrom(). Afaik there is a solaris extension for this,
|
||||
@@ -604,22 +588,22 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
posix_spawnattr_destroy(&attrs);
|
||||
posix_spawn_file_actions_destroy(&facts);
|
||||
if (ret) {
|
||||
LOGERR(("ExecCmd::startExec: posix_spawn() failed. errno %d\n",
|
||||
ret));
|
||||
LOGERR("ExecCmd::startExec: posix_spawn() failed. errno " << ret <<
|
||||
"\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (Internal::o_useVfork) {
|
||||
LOGDEB1(("using VFORK\n"));
|
||||
LOGDEB1("using VFORK\n");
|
||||
m->m_pid = vfork();
|
||||
} else {
|
||||
LOGDEB1(("using FORK\n"));
|
||||
LOGDEB1("using FORK\n");
|
||||
m->m_pid = fork();
|
||||
}
|
||||
if (m->m_pid < 0) {
|
||||
LOGERR(("ExecCmd::startExec: fork(2) failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::startExec: fork(2) failed. errno " << errno << "\n");
|
||||
return -1;
|
||||
}
|
||||
if (m->m_pid == 0) {
|
||||
@@ -645,8 +629,8 @@ int ExecCmd::startExec(const string& cmd, const vector<string>& args,
|
||||
if (setpgid(m->m_pid, m->m_pid)) {
|
||||
// This can fail with EACCES if the son has already done execve
|
||||
// (linux at least)
|
||||
LOGDEB2(("ExecCmd: father setpgid(son)(%d,%d) errno %d (ok)\n",
|
||||
m->m_pid, m->m_pid, errno));
|
||||
LOGDEB2("ExecCmd: father setpgid(son)(" << m->m_pid << "," <<
|
||||
m->m_pid << ") errno " << errno << " (ok)\n");
|
||||
}
|
||||
|
||||
sigemptyset(&m->m_blkcld);
|
||||
@@ -690,8 +674,8 @@ public:
|
||||
if (!m_input) {
|
||||
return -1;
|
||||
}
|
||||
LOGDEB1(("ExecWriter: input m_cnt %d input length %d\n", m_cnt,
|
||||
m_input->length()));
|
||||
LOGDEB1("ExecWriter: input m_cnt " << m_cnt << " input length " <<
|
||||
m_input->length() << "\n");
|
||||
if (m_cnt >= m_input->length()) {
|
||||
// Fd ready for more but we got none. Try to get data, else
|
||||
// shutdown;
|
||||
@@ -707,14 +691,14 @@ public:
|
||||
// Ready with new buffer, reset use count
|
||||
m_cnt = 0;
|
||||
}
|
||||
LOGDEB2(("ExecWriter: provide m_cnt %d input length %d\n",
|
||||
m_cnt, m_input->length()));
|
||||
LOGDEB2("ExecWriter: provide m_cnt " << m_cnt <<
|
||||
" input length " << m_input->length() << "\n");
|
||||
}
|
||||
int ret = con->send(m_input->c_str() + m_cnt,
|
||||
m_input->length() - m_cnt);
|
||||
LOGDEB2(("ExecWriter: wrote %d to command\n", ret));
|
||||
LOGDEB2("ExecWriter: wrote " << (ret) << " to command\n");
|
||||
if (ret <= 0) {
|
||||
LOGERR(("ExecWriter: data: can't write\n"));
|
||||
LOGERR("ExecWriter: data: can't write\n");
|
||||
return -1;
|
||||
}
|
||||
m_cnt += ret;
|
||||
@@ -736,9 +720,9 @@ public:
|
||||
virtual int data(NetconData *con, Netcon::Event reason) {
|
||||
char buf[8192];
|
||||
int n = con->receive(buf, 8192);
|
||||
LOGDEB1(("ExecReader: got %d from command\n", n));
|
||||
LOGDEB1("ExecReader: got " << (n) << " from command\n");
|
||||
if (n < 0) {
|
||||
LOGERR(("ExecCmd::doexec: receive failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::doexec: receive failed. errno " << errno << "\n");
|
||||
} else if (n > 0) {
|
||||
m_output->append(buf, n);
|
||||
if (m_advise) {
|
||||
@@ -770,7 +754,7 @@ int ExecCmd::doexec(const string& cmd, const vector<string>& args,
|
||||
if (output) {
|
||||
NetconCli *oclicon = m->m_fromcmd.get();
|
||||
if (!oclicon) {
|
||||
LOGERR(("ExecCmd::doexec: no connection from command\n"));
|
||||
LOGERR("ExecCmd::doexec: no connection from command\n");
|
||||
return -1;
|
||||
}
|
||||
oclicon->setcallback(STD_SHARED_PTR<NetconWorker>
|
||||
@@ -783,7 +767,7 @@ int ExecCmd::doexec(const string& cmd, const vector<string>& args,
|
||||
if (input) {
|
||||
NetconCli *iclicon = m->m_tocmd.get();
|
||||
if (!iclicon) {
|
||||
LOGERR(("ExecCmd::doexec: no connection from command\n"));
|
||||
LOGERR("ExecCmd::doexec: no connection from command\n");
|
||||
return -1;
|
||||
}
|
||||
iclicon->setcallback(STD_SHARED_PTR<NetconWorker>
|
||||
@@ -796,16 +780,16 @@ int ExecCmd::doexec(const string& cmd, const vector<string>& args,
|
||||
// Do the actual reading/writing/waiting
|
||||
myloop.setperiodichandler(0, 0, m->m_timeoutMs);
|
||||
while ((ret = myloop.doLoop()) > 0) {
|
||||
LOGDEB(("ExecCmd::doexec: selectloop returned %d\n", ret));
|
||||
LOGDEB("ExecCmd::doexec: selectloop returned " << (ret) << "\n");
|
||||
if (m->m_advise) {
|
||||
m->m_advise->newData(0);
|
||||
}
|
||||
if (m->m_killRequest) {
|
||||
LOGINFO(("ExecCmd::doexec: cancel request\n"));
|
||||
LOGINFO("ExecCmd::doexec: cancel request\n");
|
||||
break;
|
||||
}
|
||||
}
|
||||
LOGDEB0(("ExecCmd::doexec: selectloop returned %d\n", ret));
|
||||
LOGDEB0("ExecCmd::doexec: selectloop returned " << (ret) << "\n");
|
||||
// Check for interrupt request: we won't want to waitpid()
|
||||
if (m->m_advise) {
|
||||
m->m_advise->newData(0);
|
||||
@@ -838,7 +822,7 @@ int ExecCmd::send(const string& data)
|
||||
{
|
||||
NetconCli *con = m->m_tocmd.get();
|
||||
if (con == 0) {
|
||||
LOGERR(("ExecCmd::send: outpipe is closed\n"));
|
||||
LOGERR("ExecCmd::send: outpipe is closed\n");
|
||||
return -1;
|
||||
}
|
||||
unsigned int nwritten = 0;
|
||||
@@ -848,7 +832,7 @@ int ExecCmd::send(const string& data)
|
||||
}
|
||||
int n = con->send(data.c_str() + nwritten, data.length() - nwritten);
|
||||
if (n < 0) {
|
||||
LOGERR(("ExecCmd::send: send failed\n"));
|
||||
LOGERR("ExecCmd::send: send failed\n");
|
||||
return -1;
|
||||
}
|
||||
nwritten += n;
|
||||
@@ -860,7 +844,7 @@ int ExecCmd::receive(string& data, int cnt)
|
||||
{
|
||||
NetconCli *con = m->m_fromcmd.get();
|
||||
if (con == 0) {
|
||||
LOGERR(("ExecCmd::receive: inpipe is closed\n"));
|
||||
LOGERR("ExecCmd::receive: inpipe is closed\n");
|
||||
return -1;
|
||||
}
|
||||
const int BS = 4096;
|
||||
@@ -870,13 +854,13 @@ int ExecCmd::receive(string& data, int cnt)
|
||||
int toread = cnt > 0 ? MIN(cnt - ntot, BS) : BS;
|
||||
int n = con->receive(buf, toread);
|
||||
if (n < 0) {
|
||||
LOGERR(("ExecCmd::receive: error\n"));
|
||||
LOGERR("ExecCmd::receive: error\n");
|
||||
return -1;
|
||||
} else if (n > 0) {
|
||||
ntot += n;
|
||||
data.append(buf, n);
|
||||
} else {
|
||||
LOGDEB(("ExecCmd::receive: got 0\n"));
|
||||
LOGDEB("ExecCmd::receive: got 0\n");
|
||||
break;
|
||||
}
|
||||
} while (cnt > 0 && ntot < cnt);
|
||||
@@ -887,7 +871,7 @@ int ExecCmd::getline(string& data)
|
||||
{
|
||||
NetconCli *con = m->m_fromcmd.get();
|
||||
if (con == 0) {
|
||||
LOGERR(("ExecCmd::receive: inpipe is closed\n"));
|
||||
LOGERR("ExecCmd::receive: inpipe is closed\n");
|
||||
return -1;
|
||||
}
|
||||
const int BS = 1024;
|
||||
@@ -904,17 +888,17 @@ again:
|
||||
int n = con->getline(buf, BS, timeosecs);
|
||||
if (n < 0) {
|
||||
if (con->timedout()) {
|
||||
LOGDEB(("ExecCmd::getline: timeout\n"));
|
||||
LOGDEB("ExecCmd::getline: timeout\n");
|
||||
if (m->m_advise) {
|
||||
m->m_advise->newData(0);
|
||||
}
|
||||
goto again;
|
||||
}
|
||||
LOGERR(("ExecCmd::getline: error\n"));
|
||||
LOGERR("ExecCmd::getline: error\n");
|
||||
} else if (n > 0) {
|
||||
data.append(buf, n);
|
||||
} else {
|
||||
LOGDEB(("ExecCmd::getline: got 0\n"));
|
||||
LOGDEB("ExecCmd::getline: got 0\n");
|
||||
}
|
||||
return n;
|
||||
}
|
||||
@@ -968,10 +952,10 @@ int ExecCmd::wait()
|
||||
int status = -1;
|
||||
if (!m->m_killRequest && m->m_pid > 0) {
|
||||
if (waitpid(m->m_pid, &status, 0) < 0) {
|
||||
LOGERR(("ExecCmd::waitpid: returned -1 errno %d\n", errno));
|
||||
LOGERR("ExecCmd::waitpid: returned -1 errno " << errno << "\n");
|
||||
status = -1;
|
||||
}
|
||||
LOGDEB(("ExecCmd::wait: got status 0x%x\n", status));
|
||||
LOGDEB("ExecCmd::wait: got status 0x" << (status) << "\n");
|
||||
m->m_pid = -1;
|
||||
}
|
||||
// Let the ExecCmdRsrc cleanup, it will do the killing/waiting if needed
|
||||
@@ -990,15 +974,15 @@ bool ExecCmd::maybereap(int *status)
|
||||
|
||||
pid_t pid = waitpid(m->m_pid, status, WNOHANG);
|
||||
if (pid < 0) {
|
||||
LOGERR(("ExecCmd::maybereap: returned -1 errno %d\n", errno));
|
||||
LOGERR("ExecCmd::maybereap: returned -1 errno " << errno << "\n");
|
||||
m->m_pid = -1;
|
||||
return true;
|
||||
} else if (pid == 0) {
|
||||
LOGDEB1(("ExecCmd::maybereap: not exited yet\n"));
|
||||
LOGDEB1("ExecCmd::maybereap: not exited yet\n");
|
||||
e.inactivate();
|
||||
return false;
|
||||
} else {
|
||||
LOGDEB(("ExecCmd::maybereap: got status 0x%x\n", status));
|
||||
LOGDEB("ExecCmd::maybereap: got status 0x" << (status) << "\n");
|
||||
m->m_pid = -1;
|
||||
return true;
|
||||
}
|
||||
@@ -1008,7 +992,7 @@ bool ExecCmd::maybereap(int *status)
|
||||
bool ExecCmd::backtick(const vector<string> cmd, string& out)
|
||||
{
|
||||
if (cmd.empty()) {
|
||||
LOGERR(("ExecCmd::backtick: empty command\n"));
|
||||
LOGERR("ExecCmd::backtick: empty command\n");
|
||||
return false;
|
||||
}
|
||||
vector<string>::const_iterator it = cmd.begin();
|
||||
@@ -1108,9 +1092,9 @@ void ReExec::reexec()
|
||||
|
||||
// Try to get back to the initial working directory
|
||||
if (m_cfd < 0 || fchdir(m_cfd) < 0) {
|
||||
LOGINFO(("ReExec::reexec: fchdir failed, trying chdir\n"));
|
||||
LOGINFO("ReExec::reexec: fchdir failed, trying chdir\n");
|
||||
if (!m_curdir.empty() && chdir(m_curdir.c_str())) {
|
||||
LOGERR(("ReExec::reexec: chdir failed\n"));
|
||||
LOGERR("ReExec::reexec: chdir failed\n");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1122,7 +1106,7 @@ void ReExec::reexec()
|
||||
Ccharp *argv;
|
||||
argv = (Ccharp *)malloc((m_argv.size() + 1) * sizeof(char *));
|
||||
if (argv == 0) {
|
||||
LOGERR(("ExecCmd::doexec: malloc() failed. errno %d\n", errno));
|
||||
LOGERR("ExecCmd::doexec: malloc() failed. errno " << errno << "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1151,7 +1135,8 @@ void ReExec::reexec()
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "execmd.h"
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "smallut.h"
|
||||
@@ -1505,3 +1490,4 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
}
|
||||
#endif // TEST
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
#include <set>
|
||||
|
||||
#include "cstr.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "pathut.h"
|
||||
#include "fstreewalk.h"
|
||||
|
||||
@@ -335,7 +335,7 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
|
||||
|
||||
int curdepth = slashcount(top) - data->basedepth;
|
||||
if (data->maxdepth >= 0 && curdepth >= data->maxdepth) {
|
||||
LOGDEB1(("FsTreeWalker::iwalk: Maxdepth reached: [%s]\n", top.c_str()));
|
||||
LOGDEB1("FsTreeWalker::iwalk: Maxdepth reached: [" << (top) << "]\n" );
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -351,8 +351,7 @@ FsTreeWalker::Status FsTreeWalker::iwalk(const string &top,
|
||||
if (data->options & FtwFollow) {
|
||||
DirId dirid(stp->st_dev, stp->st_ino);
|
||||
if (data->donedirs.find(dirid) != data->donedirs.end()) {
|
||||
LOGINFO(("Not processing [%s] (already seen as other path)\n",
|
||||
top.c_str()));
|
||||
LOGINFO("Not processing [" << (top) << "] (already seen as other path)\n" );
|
||||
return status;
|
||||
}
|
||||
data->donedirs.insert(dirid);
|
||||
@@ -634,3 +633,4 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
|
||||
#endif // TEST_FSTREEWALK
|
||||
|
||||
|
||||
+11
-9
@@ -25,7 +25,7 @@
|
||||
#include <sstream>
|
||||
|
||||
#include "idfile.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -76,7 +76,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
input.getline(cline, LL-1);
|
||||
if (input.fail()) {
|
||||
if (input.bad()) {
|
||||
LOGERR(("idfile: error while reading [%s]\n", fn));
|
||||
LOGERR("idfile: error while reading [" << (fn) << "]\n" );
|
||||
return string();
|
||||
}
|
||||
// Must be eof ?
|
||||
@@ -88,7 +88,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
if (ll > 0)
|
||||
gotnonempty = true;
|
||||
|
||||
LOGDEB2(("idfile: lnum %d ll %u: [%s]\n", lnum, (unsigned int)ll, cline));
|
||||
LOGDEB2("idfile: lnum " << (lnum) << " ll " << ((unsigned int)ll) << ": [" << (cline) << "]\n" );
|
||||
|
||||
// Check for a few things that can't be found in a mail file,
|
||||
// (optimization to get a quick negative)
|
||||
@@ -98,7 +98,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
// Accept a few empty lines at the beginning of the file,
|
||||
// otherwise this is the end of headers
|
||||
if (gotnonempty || lnum > 10) {
|
||||
LOGDEB2(("Got empty line\n"));
|
||||
LOGDEB2("Got empty line\n" );
|
||||
break;
|
||||
} else {
|
||||
// Don't increment the line counter for initial empty lines.
|
||||
@@ -109,7 +109,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
|
||||
// emacs vm can insert VERY long header lines.
|
||||
if (ll > LL - 20) {
|
||||
LOGDEB2(("idFile: Line too long\n"));
|
||||
LOGDEB2("idFile: Line too long\n" );
|
||||
return string();
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
if (lnum == 1 && !strncmp("From ", cline, 5)) {
|
||||
if (treat_mbox_as_rfc822 == -1) {
|
||||
line1HasFrom = true;
|
||||
LOGDEB2(("idfile: line 1 has From_\n"));
|
||||
LOGDEB2("idfile: line 1 has From_\n" );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ static string idFileInternal(istream& input, const char *fn)
|
||||
if (!isspace((unsigned char)cline[0])) {
|
||||
char *cp = strchr(cline, ':');
|
||||
if (cp == 0 || (cp - cline) > 70) {
|
||||
LOGDEB2(("idfile: can't be mail header line: [%s]\n", cline));
|
||||
LOGDEB2("idfile: can't be mail header line: [" << (cline) << "]\n" );
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -160,7 +160,7 @@ string idFile(const char *fn)
|
||||
ifstream input;
|
||||
input.open(fn, ios::in);
|
||||
if (!input.is_open()) {
|
||||
LOGERR(("idFile: could not open [%s]\n", fn));
|
||||
LOGERR("idFile: could not open [" << (fn) << "]\n" );
|
||||
return string();
|
||||
}
|
||||
return idFileInternal(input, fn);
|
||||
@@ -184,7 +184,8 @@ string idFileMem(const string& data)
|
||||
|
||||
using namespace std;
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "idfile.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -203,3 +204,4 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/* Copyright (C) 2014 J.F.Dockes
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "log.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fstream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
Logger::Logger(const std::string& fn)
|
||||
: m_tocerr(false), m_loglevel(LLDEB), m_fn(fn)
|
||||
{
|
||||
reopen(fn);
|
||||
}
|
||||
|
||||
bool Logger::reopen(const std::string& fn)
|
||||
{
|
||||
#if LOGGER_THREADSAFE
|
||||
std::unique_lock<std::mutex> lock(m_mutex);
|
||||
#endif
|
||||
if (!fn.empty()) {
|
||||
m_fn = fn;
|
||||
}
|
||||
if (!m_tocerr && m_stream.is_open()) {
|
||||
m_stream.close();
|
||||
}
|
||||
if (!m_fn.empty() && m_fn.compare("stderr")) {
|
||||
m_stream.open(m_fn, std::fstream::out | std::ofstream::trunc);
|
||||
if (!m_stream.is_open()) {
|
||||
cerr << "Logger::Logger: log open failed: for [" <<
|
||||
fn << "] errno " << errno << endl;
|
||||
m_tocerr = true;
|
||||
} else {
|
||||
m_tocerr = false;
|
||||
}
|
||||
} else {
|
||||
m_tocerr = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
static Logger *theLog;
|
||||
|
||||
Logger *Logger::getTheLog(const string& fn)
|
||||
{
|
||||
if (theLog == 0)
|
||||
theLog = new Logger(fn);
|
||||
return theLog;
|
||||
}
|
||||
|
||||
+180
@@ -0,0 +1,180 @@
|
||||
/* Copyright (C) 2014 J.F.Dockes
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the
|
||||
* Free Software Foundation, Inc.,
|
||||
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
#ifndef _LOG_H_X_INCLUDED_
|
||||
#define _LOG_H_X_INCLUDED_
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <mutex>
|
||||
|
||||
#ifndef LOGGER_THREADSAFE
|
||||
#define LOGGER_THREADSAFE 1
|
||||
#endif
|
||||
|
||||
#if LOGGER_THREADSAFE
|
||||
#include <mutex>
|
||||
#endif
|
||||
|
||||
// Can't use the symbolic Logger::LLXX names in preproc. 6 is LLDEB1
|
||||
#ifndef LOGGER_STATICVERBOSITY
|
||||
#define LOGGER_STATICVERBOSITY 5
|
||||
#endif
|
||||
|
||||
class Logger {
|
||||
public:
|
||||
/** Initialize logging to file name. Use "stderr" for stderr
|
||||
output. Creates the singleton logger object */
|
||||
static Logger *getTheLog(const std::string& fn);
|
||||
|
||||
bool reopen(const std::string& fn);
|
||||
|
||||
std::ostream& getstream() {
|
||||
return m_tocerr ? std::cerr : m_stream;
|
||||
}
|
||||
enum LogLevel {LLNON=0, LLFAT=1, LLERR=2, LLINF=3, LLDEB=4,
|
||||
LLDEB0=5, LLDEB1=6, LLDEB2=7};
|
||||
void setLogLevel(LogLevel level) {
|
||||
m_loglevel = level;
|
||||
}
|
||||
int getloglevel() {
|
||||
return m_loglevel;
|
||||
}
|
||||
|
||||
#if LOGGER_THREADSAFE
|
||||
std::mutex& getmutex() {
|
||||
return m_mutex;
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
bool m_tocerr;
|
||||
int m_loglevel;
|
||||
std::string m_fn;
|
||||
std::ofstream m_stream;
|
||||
#if LOGGER_THREADSAFE
|
||||
std::mutex m_mutex;
|
||||
#endif
|
||||
|
||||
Logger(const std::string& fn);
|
||||
Logger(const Logger &);
|
||||
Logger& operator=(const Logger &);
|
||||
};
|
||||
|
||||
#define LOGGER_PRT (Logger::getTheLog("")->getstream())
|
||||
|
||||
#if LOGGER_THREADSAFE
|
||||
#define LOGGER_LOCK \
|
||||
std::unique_lock<std::mutex> lock(Logger::getTheLog("")->getmutex())
|
||||
#else
|
||||
#define LOGGER_LOCK
|
||||
#endif
|
||||
|
||||
#ifndef LOGGER_LOCAL_LOGINC
|
||||
#define LOGGER_LOCAL_LOGINC 0
|
||||
#endif
|
||||
|
||||
#define LOGGER_LEVEL (Logger::getTheLog("")->getloglevel() + \
|
||||
LOGGER_LOCAL_LOGINC)
|
||||
|
||||
#define LOGGER_DOLOG(L,X) LOGGER_PRT << ":" << L << ":" << \
|
||||
__FILE__ << ":" << __LINE__ << "::" << X
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 7
|
||||
#define LOGDEB2(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLDEB2) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLDEB2, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGDEB2(X)
|
||||
#endif
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 6
|
||||
#define LOGDEB1(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLDEB1) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLDEB1, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGDEB1(X)
|
||||
#endif
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 5
|
||||
#define LOGDEB0(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLDEB0) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLDEB0, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGDEB0(X)
|
||||
#endif
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 4
|
||||
#define LOGDEB(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLDEB) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLDEB, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGDEB(X)
|
||||
#endif
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 3
|
||||
#define LOGINF(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLINF) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLINF, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGINF(X)
|
||||
#endif
|
||||
#define LOGINFO LOGINF
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 2
|
||||
#define LOGERR(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLERR) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLERR, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGERR(X)
|
||||
#endif
|
||||
|
||||
#if LOGGER_STATICVERBOSITY >= 1
|
||||
#define LOGFAT(X) { \
|
||||
if (LOGGER_LEVEL >= Logger::LLFAT) { \
|
||||
LOGGER_LOCK; \
|
||||
LOGGER_DOLOG(Logger::LLFAT, X); \
|
||||
} \
|
||||
}
|
||||
#else
|
||||
#define LOGFAT(X)
|
||||
#endif
|
||||
#define LOGFATAL LOGFAT
|
||||
|
||||
#endif /* _LOG_H_X_INCLUDED_ */
|
||||
+77
-103
@@ -17,7 +17,6 @@
|
||||
|
||||
// Wrapper classes for the socket interface
|
||||
|
||||
|
||||
#ifndef TEST_NETCON
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "autoconfig.h"
|
||||
@@ -25,6 +24,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "netcon.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -46,24 +47,7 @@
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
#ifdef BUILDING_RECOLL
|
||||
#include "debuglog.h"
|
||||
|
||||
#else
|
||||
|
||||
#define LOGFATAL(X)
|
||||
#define LOGERR(X)
|
||||
#define LOGINFO(X)
|
||||
#define LOGDEB(X)
|
||||
#define LOGDEB0(X)
|
||||
#define LOGDEB1(X)
|
||||
#define LOGDEB2(X)
|
||||
#define LOGDEB3(X)
|
||||
#define LOGDEB4(X)
|
||||
#endif
|
||||
|
||||
#include "netcon.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -84,15 +68,15 @@ using namespace std;
|
||||
static const int one = 1;
|
||||
static const int zero = 0;
|
||||
|
||||
#define LOGSYSERR(who, call, spar) \
|
||||
LOGERR(("%s: %s(%s) errno %d (%s)\n", who, call, \
|
||||
spar, errno, strerror(errno)))
|
||||
#define LOGSYSERR(who, call, spar) \
|
||||
LOGERR((who) << ": " << (call) << "(" << (spar) << ") errno " << \
|
||||
(errno) << " (" << (strerror(errno)) << ")\n")
|
||||
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (a<b?a:b)
|
||||
#define MIN(a,b) ((a)<(b)?(a):(b))
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (a>b?a:b)
|
||||
#define MAX(a,b) ((a)>(b)?(a):(b))
|
||||
#endif
|
||||
#ifndef freeZ
|
||||
#define freeZ(X) if (X) {free(X);X=0;}
|
||||
@@ -121,7 +105,7 @@ int Netcon::select1(int fd, int timeo, int write)
|
||||
ret = select(fd + 1, &rd, 0, 0, &tv);
|
||||
}
|
||||
if (!FD_ISSET(fd, &rd)) {
|
||||
LOGDEB2(("Netcon::select1: fd %d timeout\n", fd));
|
||||
LOGDEB2("Netcon::select1: fd " << (fd) << " timeout\n" );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -188,7 +172,7 @@ int SelectLoop::doLoop()
|
||||
for (;;) {
|
||||
if (m_selectloopDoReturn) {
|
||||
m_selectloopDoReturn = false;
|
||||
LOGDEB(("Netcon::selectloop: returning on request\n"));
|
||||
LOGDEB("Netcon::selectloop: returning on request\n" );
|
||||
return m_selectloopReturnValue;
|
||||
}
|
||||
int nfds;
|
||||
@@ -203,7 +187,7 @@ int SelectLoop::doLoop()
|
||||
it != m_polldata.end(); it++) {
|
||||
NetconP& pll = it->second;
|
||||
int fd = it->first;
|
||||
LOGDEB2(("Selectloop: fd %d flags 0x%x\n", fd, pll->m_wantedEvents));
|
||||
LOGDEB2("Selectloop: fd " << (fd) << " flags 0x" << (pll->m_wantedEvents) << "\n" );
|
||||
if (pll->m_wantedEvents & Netcon::NETCONPOLL_READ) {
|
||||
FD_SET(fd, &rd);
|
||||
nfds = MAX(nfds, fd + 1);
|
||||
@@ -223,11 +207,11 @@ int SelectLoop::doLoop()
|
||||
// Just in case there would still be open fds in there
|
||||
// (with no r/w flags set). Should not be needed, but safer
|
||||
m_polldata.clear();
|
||||
LOGDEB1(("Netcon::selectloop: no fds\n"));
|
||||
LOGDEB1("Netcon::selectloop: no fds\n" );
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOGDEB2(("Netcon::selectloop: selecting, nfds = %d\n", nfds));
|
||||
LOGDEB2("Netcon::selectloop: selecting, nfds = " << (nfds) << "\n" );
|
||||
|
||||
// Compute the next timeout according to what might need to be
|
||||
// done apart from waiting for data
|
||||
@@ -235,7 +219,7 @@ int SelectLoop::doLoop()
|
||||
periodictimeout(&tv);
|
||||
// Wait for something to happen
|
||||
int ret = select(nfds, &rd, &wd, 0, &tv);
|
||||
LOGDEB2(("Netcon::selectloop: select returns %d\n", ret));
|
||||
LOGDEB2("Netcon::selectloop: select returns " << (ret) << "\n" );
|
||||
if (ret < 0) {
|
||||
LOGSYSERR("Netcon::selectloop", "select", "");
|
||||
return -1;
|
||||
@@ -268,9 +252,7 @@ int SelectLoop::doLoop()
|
||||
int canread = FD_ISSET(fd, &rd);
|
||||
int canwrite = FD_ISSET(fd, &wd);
|
||||
bool none = !canread && !canwrite;
|
||||
LOGDEB2(("Netcon::selectloop: fd %d %s %s %s\n", fd,
|
||||
none ? "blocked" : "can" , canread ? "read" : "",
|
||||
canwrite ? "write" : ""));
|
||||
LOGDEB2("Netcon::selectloop: fd " << (fd) << " " << (none ? "blocked" : "can") << " " << (canread ? "read" : "") << " " << (canwrite ? "write" : "") << "\n" );
|
||||
if (none) {
|
||||
continue;
|
||||
}
|
||||
@@ -278,7 +260,7 @@ int SelectLoop::doLoop()
|
||||
map<int, NetconP>::iterator it = m_polldata.find(fd);
|
||||
if (it == m_polldata.end()) {
|
||||
/// This should not happen actually
|
||||
LOGDEB2(("Netcon::selectloop: fd %d not found\n", fd));
|
||||
LOGDEB2("Netcon::selectloop: fd " << (fd) << " not found\n" );
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -292,14 +274,13 @@ int SelectLoop::doLoop()
|
||||
pll->m_wantedEvents &= ~Netcon::NETCONPOLL_WRITE;
|
||||
}
|
||||
if (!(pll->m_wantedEvents & (Netcon::NETCONPOLL_WRITE | Netcon::NETCONPOLL_READ))) {
|
||||
LOGDEB0(("Netcon::selectloop: fd %d has 0x%x mask, erasing\n",
|
||||
it->first, it->second->m_wantedEvents));
|
||||
LOGDEB0("Netcon::selectloop: fd " << (it->first) << " has 0x" << (it->second->m_wantedEvents) << " mask, erasing\n" );
|
||||
m_polldata.erase(it);
|
||||
}
|
||||
} // fd sweep
|
||||
|
||||
} // forever loop
|
||||
LOGERR(("SelectLoop::doLoop: got out of loop !\n"));
|
||||
LOGERR("SelectLoop::doLoop: got out of loop !\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -309,7 +290,7 @@ int SelectLoop::addselcon(NetconP con, int events)
|
||||
if (!con) {
|
||||
return -1;
|
||||
}
|
||||
LOGDEB1(("Netcon::addselcon: fd %d\n", con->m_fd));
|
||||
LOGDEB1("Netcon::addselcon: fd " << (con->m_fd) << "\n" );
|
||||
con->set_nonblock(1);
|
||||
con->setselevents(events);
|
||||
m_polldata[con->m_fd] = con;
|
||||
@@ -323,10 +304,10 @@ int SelectLoop::remselcon(NetconP con)
|
||||
if (!con) {
|
||||
return -1;
|
||||
}
|
||||
LOGDEB1(("Netcon::remselcon: fd %d\n", con->m_fd));
|
||||
LOGDEB1("Netcon::remselcon: fd " << (con->m_fd) << "\n" );
|
||||
map<int, NetconP>::iterator it = m_polldata.find(con->m_fd);
|
||||
if (it == m_polldata.end()) {
|
||||
LOGDEB1(("Netcon::remselcon: con not found for fd %d\n", con->m_fd));
|
||||
LOGDEB1("Netcon::remselcon: con not found for fd " << (con->m_fd) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
con->setloop(0);
|
||||
@@ -369,9 +350,9 @@ void Netcon::setpeer(const char *hostname)
|
||||
|
||||
int Netcon::settcpnodelay(int on)
|
||||
{
|
||||
LOGDEB2(("Netcon::settcpnodelay\n"));
|
||||
LOGDEB2("Netcon::settcpnodelay\n" );
|
||||
if (m_fd < 0) {
|
||||
LOGERR(("Netcon::settcpnodelay: connection not opened\n"));
|
||||
LOGERR("Netcon::settcpnodelay: connection not opened\n" );
|
||||
return -1;
|
||||
}
|
||||
char *cp = on ? (char *)&one : (char *)&zero;
|
||||
@@ -408,14 +389,14 @@ NetconData::~NetconData()
|
||||
|
||||
int NetconData::send(const char *buf, int cnt, int expedited)
|
||||
{
|
||||
LOGDEB2(("NetconData::send: fd %d cnt %d expe %d\n", m_fd, cnt, expedited));
|
||||
LOGDEB2("NetconData::send: fd " << (m_fd) << " cnt " << (cnt) << " expe " << (expedited) << "\n" );
|
||||
int flag = 0;
|
||||
if (m_fd < 0) {
|
||||
LOGERR(("NetconData::send: connection not opened\n"));
|
||||
LOGERR("NetconData::send: connection not opened\n" );
|
||||
return -1;
|
||||
}
|
||||
if (expedited) {
|
||||
LOGDEB2(("NetconData::send: expedited data, count %d bytes\n", cnt));
|
||||
LOGDEB2("NetconData::send: expedited data, count " << (cnt) << " bytes\n" );
|
||||
flag = MSG_OOB;
|
||||
}
|
||||
int ret;
|
||||
@@ -439,9 +420,9 @@ int NetconData::send(const char *buf, int cnt, int expedited)
|
||||
// Test for data available
|
||||
int NetconData::readready()
|
||||
{
|
||||
LOGDEB2(("NetconData::readready\n"));
|
||||
LOGDEB2("NetconData::readready\n" );
|
||||
if (m_fd < 0) {
|
||||
LOGERR(("NetconData::readready: connection not opened\n"));
|
||||
LOGERR("NetconData::readready: connection not opened\n" );
|
||||
return -1;
|
||||
}
|
||||
return select1(m_fd, 0);
|
||||
@@ -450,9 +431,9 @@ int NetconData::readready()
|
||||
// Test for writable
|
||||
int NetconData::writeready()
|
||||
{
|
||||
LOGDEB2(("NetconData::writeready\n"));
|
||||
LOGDEB2("NetconData::writeready\n" );
|
||||
if (m_fd < 0) {
|
||||
LOGERR(("NetconData::writeready: connection not opened\n"));
|
||||
LOGERR("NetconData::writeready: connection not opened\n" );
|
||||
return -1;
|
||||
}
|
||||
return select1(m_fd, 0, 1);
|
||||
@@ -461,10 +442,9 @@ int NetconData::writeready()
|
||||
// Receive at most cnt bytes (maybe less)
|
||||
int NetconData::receive(char *buf, int cnt, int timeo)
|
||||
{
|
||||
LOGDEB2(("NetconData::receive: cnt %d timeo %d m_buf 0x%x m_bufbytes %d\n",
|
||||
cnt, timeo, m_buf, m_bufbytes));
|
||||
LOGDEB2("NetconData::receive: cnt " << (cnt) << " timeo " << (timeo) << " m_buf 0x" << (m_buf) << " m_bufbytes " << (m_bufbytes) << "\n" );
|
||||
if (m_fd < 0) {
|
||||
LOGERR(("NetconData::receive: connection not opened\n"));
|
||||
LOGERR("NetconData::receive: connection not opened\n" );
|
||||
return -1;
|
||||
}
|
||||
int fromibuf = 0;
|
||||
@@ -476,7 +456,7 @@ int NetconData::receive(char *buf, int cnt, int timeo)
|
||||
m_bufbytes -= fromibuf;
|
||||
m_bufbase += fromibuf;
|
||||
cnt -= fromibuf;
|
||||
LOGDEB2(("NetconData::receive: transferred %d from mbuf\n", fromibuf));
|
||||
LOGDEB2("NetconData::receive: transferred " << (fromibuf) << " from mbuf\n" );
|
||||
if (cnt <= 0) {
|
||||
return fromibuf;
|
||||
}
|
||||
@@ -484,7 +464,7 @@ int NetconData::receive(char *buf, int cnt, int timeo)
|
||||
if (timeo > 0) {
|
||||
int ret = select1(m_fd, timeo);
|
||||
if (ret == 0) {
|
||||
LOGDEB2(("NetconData::receive timed out\n"));
|
||||
LOGDEB2("NetconData::receive timed out\n" );
|
||||
m_didtimo = 1;
|
||||
return -1;
|
||||
}
|
||||
@@ -500,7 +480,7 @@ int NetconData::receive(char *buf, int cnt, int timeo)
|
||||
LOGSYSERR("NetconData::receive", "read", fdcbuf);
|
||||
return -1;
|
||||
}
|
||||
LOGDEB2(("NetconData::receive: normal return, cnt %d\n", cnt));
|
||||
LOGDEB2("NetconData::receive: normal return, cnt " << (cnt) << "\n" );
|
||||
return fromibuf + cnt;
|
||||
}
|
||||
|
||||
@@ -508,11 +488,11 @@ int NetconData::receive(char *buf, int cnt, int timeo)
|
||||
int NetconData::doreceive(char *buf, int cnt, int timeo)
|
||||
{
|
||||
int got, cur;
|
||||
LOGDEB2(("Netcon::doreceive: cnt %d, timeo %d\n", cnt, timeo));
|
||||
LOGDEB2("Netcon::doreceive: cnt " << (cnt) << ", timeo " << (timeo) << "\n" );
|
||||
cur = 0;
|
||||
while (cnt > cur) {
|
||||
got = receive(buf, cnt - cur, timeo);
|
||||
LOGDEB2(("Netcon::doreceive: got %d\n", got));
|
||||
LOGDEB2("Netcon::doreceive: got " << (got) << "\n" );
|
||||
if (got < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -536,7 +516,7 @@ int NetconData::doreceive(char *buf, int cnt, int timeo)
|
||||
static const int defbufsize = 200;
|
||||
int NetconData::getline(char *buf, int cnt, int timeo)
|
||||
{
|
||||
LOGDEB2(("NetconData::getline: cnt %d, timeo %d\n", cnt, timeo));
|
||||
LOGDEB2("NetconData::getline: cnt " << (cnt) << ", timeo " << (timeo) << "\n" );
|
||||
if (m_buf == 0) {
|
||||
if ((m_buf = (char *)malloc(defbufsize)) == 0) {
|
||||
LOGSYSERR("NetconData::getline: Out of mem", "malloc", "");
|
||||
@@ -553,8 +533,7 @@ int NetconData::getline(char *buf, int cnt, int timeo)
|
||||
// pointers consistant in all end cases
|
||||
int maxtransf = MIN(m_bufbytes, cnt - 1);
|
||||
int nn = maxtransf;
|
||||
LOGDEB2(("Before loop, bufbytes %d, maxtransf %d, nn: %d\n",
|
||||
m_bufbytes, maxtransf, nn));
|
||||
LOGDEB2("Before loop, bufbytes " << (m_bufbytes) << ", maxtransf " << (maxtransf) << ", nn: " << (nn) << "\n" );
|
||||
for (nn = maxtransf; nn > 0;) {
|
||||
// This is not pretty but we want nn to be decremented for
|
||||
// each byte copied (even newline), and not become -1 if
|
||||
@@ -568,8 +547,7 @@ int NetconData::getline(char *buf, int cnt, int timeo)
|
||||
maxtransf -= nn; // Actual count transferred
|
||||
m_bufbytes -= maxtransf;
|
||||
cnt -= maxtransf;
|
||||
LOGDEB2(("After transfer: actual transf %d cnt %d, m_bufbytes %d\n",
|
||||
maxtransf, cnt, m_bufbytes));
|
||||
LOGDEB2("After transfer: actual transf " << (maxtransf) << " cnt " << (cnt) << ", m_bufbytes " << (m_bufbytes) << "\n" );
|
||||
|
||||
// Finished ?
|
||||
if (cnt <= 1 || (cp > buf && cp[-1] == '\n')) {
|
||||
@@ -599,7 +577,7 @@ int NetconData::getline(char *buf, int cnt, int timeo)
|
||||
// and discard.
|
||||
int NetconData::cando(Netcon::Event reason)
|
||||
{
|
||||
LOGDEB2(("NetconData::cando\n"));
|
||||
LOGDEB2("NetconData::cando\n" );
|
||||
if (m_user) {
|
||||
return m_user->data(this, reason);
|
||||
}
|
||||
@@ -627,7 +605,7 @@ int NetconData::cando(Netcon::Event reason)
|
||||
int NetconCli::openconn(const char *host, unsigned int port, int timeo)
|
||||
{
|
||||
int ret = -1;
|
||||
LOGDEB2(("Netconcli::openconn: host %s, port %d\n", host, port));
|
||||
LOGDEB2("Netconcli::openconn: host " << (host) << ", port " << (port) << "\n" );
|
||||
|
||||
closeconn();
|
||||
|
||||
@@ -648,8 +626,7 @@ int NetconCli::openconn(const char *host, unsigned int port, int timeo)
|
||||
} else {
|
||||
struct hostent *hp;
|
||||
if ((hp = gethostbyname(host)) == 0) {
|
||||
LOGERR(("NetconCli::openconn: gethostbyname(%s) failed\n",
|
||||
host));
|
||||
LOGERR("NetconCli::openconn: gethostbyname(" << (host) << ") failed\n" );
|
||||
return -1;
|
||||
}
|
||||
memcpy(&ip_addr.sin_addr, hp->h_addr, hp->h_length);
|
||||
@@ -665,7 +642,7 @@ int NetconCli::openconn(const char *host, unsigned int port, int timeo)
|
||||
memset(&unix_addr, 0, sizeof(unix_addr));
|
||||
unix_addr.sun_family = AF_UNIX;
|
||||
if (strlen(host) > UNIX_PATH_MAX - 1) {
|
||||
LOGERR(("NetconCli::openconn: name too long: %s\n", host));
|
||||
LOGERR("NetconCli::openconn: name too long: " << (host) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
strcpy(unix_addr.sun_path, host);
|
||||
@@ -700,13 +677,13 @@ connectok:
|
||||
set_nonblock(0);
|
||||
}
|
||||
|
||||
LOGDEB2(("NetconCli::connect: setting keepalive\n"));
|
||||
LOGDEB2("NetconCli::connect: setting keepalive\n" );
|
||||
if (setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *)&one, sizeof(one)) < 0) {
|
||||
LOGSYSERR("NetconCli::connect", "setsockopt", "KEEPALIVE");
|
||||
}
|
||||
setpeer(host);
|
||||
LOGDEB2(("NetconCli::openconn: connection opened ok\n"));
|
||||
LOGDEB2("NetconCli::openconn: connection opened ok\n" );
|
||||
ret = 0;
|
||||
out:
|
||||
if (ret < 0) {
|
||||
@@ -718,12 +695,12 @@ out:
|
||||
// Same as previous, but get the port number from services
|
||||
int NetconCli::openconn(const char *host, const char *serv, int timeo)
|
||||
{
|
||||
LOGDEB2(("Netconcli::openconn: host %s, serv %s\n", host, serv));
|
||||
LOGDEB2("Netconcli::openconn: host " << (host) << ", serv " << (serv) << "\n" );
|
||||
|
||||
if (host[0] != '/') {
|
||||
struct servent *sp;
|
||||
if ((sp = getservbyname(serv, "tcp")) == 0) {
|
||||
LOGERR(("NetconCli::openconn: getservbyname failed for %s\n", serv));
|
||||
LOGERR("NetconCli::openconn: getservbyname failed for " << (serv) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
// Callee expects the port number in host byte order
|
||||
@@ -736,7 +713,7 @@ int NetconCli::openconn(const char *host, const char *serv, int timeo)
|
||||
|
||||
int NetconCli::setconn(int fd)
|
||||
{
|
||||
LOGDEB2(("Netconcli::setconn: fd %d\n", fd));
|
||||
LOGDEB2("Netconcli::setconn: fd " << (fd) << "\n" );
|
||||
closeconn();
|
||||
|
||||
m_fd = fd;
|
||||
@@ -776,10 +753,10 @@ int NetconServLis::openservice(const char *serv, int backlog)
|
||||
int port;
|
||||
struct servent *servp;
|
||||
if (!serv) {
|
||||
LOGERR(("NetconServLis::openservice: null serv??\n"));
|
||||
LOGERR("NetconServLis::openservice: null serv??\n" );
|
||||
return -1;
|
||||
}
|
||||
LOGDEB1(("NetconServLis::openservice: serv %s\n", serv));
|
||||
LOGDEB1("NetconServLis::openservice: serv " << (serv) << "\n" );
|
||||
#ifdef NETCON_ACCESSCONTROL
|
||||
if (initperms(serv) < 0) {
|
||||
return -1;
|
||||
@@ -789,16 +766,14 @@ int NetconServLis::openservice(const char *serv, int backlog)
|
||||
m_serv = serv;
|
||||
if (serv[0] != '/') {
|
||||
if ((servp = getservbyname(serv, "tcp")) == 0) {
|
||||
LOGERR(("NetconServLis::openservice: getservbyname failed for %s\n",
|
||||
serv));
|
||||
LOGERR("NetconServLis::openservice: getservbyname failed for " << (serv) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
port = (int)ntohs((short)servp->s_port);
|
||||
return openservice(port, backlog);
|
||||
} else {
|
||||
if (strlen(serv) > UNIX_PATH_MAX - 1) {
|
||||
LOGERR(("NetconServLis::openservice: too long for AF_UNIX: %s\n",
|
||||
serv));
|
||||
LOGERR("NetconServLis::openservice: too long for AF_UNIX: " << (serv) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
int ret = -1;
|
||||
@@ -820,7 +795,7 @@ int NetconServLis::openservice(const char *serv, int backlog)
|
||||
goto out;
|
||||
}
|
||||
|
||||
LOGDEB1(("NetconServLis::openservice: service opened ok\n"));
|
||||
LOGDEB1("NetconServLis::openservice: service opened ok\n" );
|
||||
ret = 0;
|
||||
out:
|
||||
if (ret < 0 && m_fd >= 0) {
|
||||
@@ -834,7 +809,7 @@ out:
|
||||
// Port is a natural host integer value
|
||||
int NetconServLis::openservice(int port, int backlog)
|
||||
{
|
||||
LOGDEB1(("NetconServLis::openservice: port %d\n", port));
|
||||
LOGDEB1("NetconServLis::openservice: port " << (port) << "\n" );
|
||||
#ifdef NETCON_ACCESSCONTROL
|
||||
if (initperms(port) < 0) {
|
||||
return -1;
|
||||
@@ -863,7 +838,7 @@ int NetconServLis::openservice(int port, int backlog)
|
||||
goto out;
|
||||
}
|
||||
|
||||
LOGDEB1(("NetconServLis::openservice: service opened ok\n"));
|
||||
LOGDEB1("NetconServLis::openservice: service opened ok\n" );
|
||||
ret = 0;
|
||||
out:
|
||||
if (ret < 0 && m_fd >= 0) {
|
||||
@@ -893,7 +868,7 @@ int NetconServLis::initperms(const char *serv)
|
||||
}
|
||||
|
||||
if (serv == 0 || *serv == 0 || strlen(serv) > 80) {
|
||||
LOGERR(("NetconServLis::initperms: bad service name %s\n", serv));
|
||||
LOGERR("NetconServLis::initperms: bad service name " << (serv) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -903,17 +878,17 @@ int NetconServLis::initperms(const char *serv)
|
||||
serv = "default";
|
||||
sprintf(keyname, "%s_okaddrs", serv);
|
||||
if (genparams->getparam(keyname, &okaddrs) < 0) {
|
||||
LOGERR(("NetconServLis::initperms: no okaddrs found in config file\n"));
|
||||
LOGERR("NetconServLis::initperms: no okaddrs found in config file\n" );
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
sprintf(keyname, "%s_okmasks", serv);
|
||||
if (genparams->getparam(keyname, &okmasks)) {
|
||||
LOGERR(("NetconServLis::initperms: okmasks not found\n"));
|
||||
LOGERR("NetconServLis::initperms: okmasks not found\n" );
|
||||
return -1;
|
||||
}
|
||||
if (okaddrs.len == 0 || okmasks.len == 0) {
|
||||
LOGERR(("NetconServLis::initperms: len 0 for okmasks or okaddrs\n"));
|
||||
LOGERR("NetconServLis::initperms: len 0 for okmasks or okaddrs\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -935,12 +910,12 @@ int NetconServLis::cando(Netcon::Event reason)
|
||||
NetconServCon *
|
||||
NetconServLis::accept(int timeo)
|
||||
{
|
||||
LOGDEB(("NetconServLis::accept\n"));
|
||||
LOGDEB("NetconServLis::accept\n" );
|
||||
|
||||
if (timeo > 0) {
|
||||
int ret = select1(m_fd, timeo);
|
||||
if (ret == 0) {
|
||||
LOGDEB2(("NetconServLis::accept timed out\n"));
|
||||
LOGDEB2("NetconServLis::accept timed out\n" );
|
||||
m_didtimo = 1;
|
||||
return 0;
|
||||
}
|
||||
@@ -976,7 +951,7 @@ NetconServLis::accept(int timeo)
|
||||
|
||||
con = new NetconServCon(newfd);
|
||||
if (con == 0) {
|
||||
LOGERR(("NetconServLis::accept: new NetconServCon failed\n"));
|
||||
LOGERR("NetconServLis::accept: new NetconServCon failed\n" );
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -985,8 +960,7 @@ NetconServLis::accept(int timeo)
|
||||
struct hostent *hp;
|
||||
if ((hp = gethostbyaddr((char *) & (who.sin_addr),
|
||||
sizeof(struct in_addr), AF_INET)) == 0) {
|
||||
LOGERR(("NetconServLis::accept: gethostbyaddr failed for addr 0x%lx\n",
|
||||
who.sin_addr.s_addr));
|
||||
LOGERR("NetconServLis::accept: gethostbyaddr failed for addr 0x" << (who.sin_addr.s_addr) << "\n" );
|
||||
con->setpeer(inet_ntoa(who.sin_addr));
|
||||
} else {
|
||||
con->setpeer(hp->h_name);
|
||||
@@ -995,12 +969,12 @@ NetconServLis::accept(int timeo)
|
||||
con->setpeer(m_serv.c_str());
|
||||
}
|
||||
|
||||
LOGDEB2(("NetconServLis::accept: setting keepalive\n"));
|
||||
LOGDEB2("NetconServLis::accept: setting keepalive\n" );
|
||||
if (setsockopt(newfd, SOL_SOCKET, SO_KEEPALIVE,
|
||||
(char *)&one, sizeof(one)) < 0) {
|
||||
LOGSYSERR("NetconServLis::accept", "setsockopt", "KEEPALIVE");
|
||||
}
|
||||
LOGDEB2(("NetconServLis::accept: got connect from %s\n", con->getpeer()));
|
||||
LOGDEB2("NetconServLis::accept: got connect from " << (con->getpeer()) << "\n" );
|
||||
|
||||
out:
|
||||
if (con == 0 && newfd >= 0) {
|
||||
@@ -1022,12 +996,12 @@ NetconServLis::checkperms(void *cl, int)
|
||||
unsigned long ip_addr;
|
||||
|
||||
if (addr->sa_family != AF_INET) {
|
||||
LOGERR(("NetconServLis::checkperms: connection from non-INET addr !\n"));
|
||||
LOGERR("NetconServLis::checkperms: connection from non-INET addr !\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
ip_addr = ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr);
|
||||
LOGDEB2(("checkperms: ip_addr: 0x%x\n", ip_addr));
|
||||
LOGDEB2("checkperms: ip_addr: 0x" << (ip_addr) << "\n" );
|
||||
for (int i = 0; i < okaddrs.len; i++) {
|
||||
unsigned int mask;
|
||||
if (i < okmasks.len) {
|
||||
@@ -1035,14 +1009,12 @@ NetconServLis::checkperms(void *cl, int)
|
||||
} else {
|
||||
mask = okmasks.intarray[okmasks.len - 1];
|
||||
}
|
||||
LOGDEB2(("checkperms: trying okaddr 0x%x, mask 0x%x\n",
|
||||
okaddrs.intarray[i], mask));
|
||||
LOGDEB2("checkperms: trying okaddr 0x" << (okaddrs.intarray[i]) << ", mask 0x" << (mask) << "\n" );
|
||||
if ((ip_addr & mask) == (okaddrs.intarray[i] & mask)) {
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
LOGERR(("NetconServLis::checkperm: connection from bad address 0x%x\n",
|
||||
ip_addr));
|
||||
LOGERR("NetconServLis::checkperm: connection from bad address 0x" << (ip_addr) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
#endif /* NETCON_ACCESSCONTROL */
|
||||
@@ -1059,7 +1031,8 @@ NetconServLis::checkperms(void *cl, int)
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
#include "netcon.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -1122,8 +1095,8 @@ int main(int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
DebugLog::setfilename("stderr");
|
||||
DebugLog::getdbl()->setloglevel(DEBDEB2);
|
||||
|
||||
Logger::getTheLog("")->setLogLevel(Logger::LLDEB2);
|
||||
|
||||
if (op_flags & OPT_c) {
|
||||
if (argc != 2) {
|
||||
@@ -1155,7 +1128,7 @@ class CliNetconWorker : public NetconWorker {
|
||||
public:
|
||||
CliNetconWorker() : m_count(0) {}
|
||||
int data(NetconData *con, Netcon::Event reason) {
|
||||
LOGDEB(("clientdata\n"));
|
||||
LOGDEB("clientdata\n" );
|
||||
if (reason & Netcon::NETCONPOLL_WRITE) {
|
||||
sprintf(fromcli, "Bonjour Bonjour client %d, count %d",
|
||||
getpid(), m_count);
|
||||
@@ -1257,7 +1230,7 @@ class ServNetconWorker : public NetconWorker {
|
||||
public:
|
||||
ServNetconWorker() : m_count(0) {}
|
||||
int data(NetconData *con, Netcon::Event reason) {
|
||||
LOGDEB(("serverdata\n"));
|
||||
LOGDEB("serverdata\n" );
|
||||
if (reason & Netcon::NETCONPOLL_WRITE) {
|
||||
con->setselevents(Netcon::NETCONPOLL_READ);
|
||||
char fromserv[200];
|
||||
@@ -1360,3 +1333,4 @@ int tryserv(char *serv)
|
||||
}
|
||||
|
||||
#endif /* TEST_NETCON */
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include "rclionice.h"
|
||||
#include "execmd.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -30,7 +30,7 @@ bool rclionice(const string& clss, const string& cdata)
|
||||
string ionicexe;
|
||||
if (!ExecCmd::which("ionice", ionicexe)) {
|
||||
// ionice not found, bail out
|
||||
LOGDEB0(("rclionice: ionice not found\n"));
|
||||
LOGDEB0("rclionice: ionice not found\n" );
|
||||
return false;
|
||||
}
|
||||
vector<string> args;
|
||||
@@ -51,8 +51,9 @@ bool rclionice(const string& clss, const string& cdata)
|
||||
int status = cmd.doexec(ionicexe, args);
|
||||
|
||||
if (status) {
|
||||
LOGERR(("rclionice: failed, status 0x%x\n", status));
|
||||
LOGERR("rclionice: failed, status 0x" << (status) << "\n" );
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include <string>
|
||||
|
||||
#include "cstr.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "pathut.h"
|
||||
#include "strmatcher.h"
|
||||
|
||||
@@ -37,16 +37,13 @@ using namespace std;
|
||||
|
||||
bool StrWildMatcher::match(const string& val) const
|
||||
{
|
||||
LOGDEB2(("StrWildMatcher::match: [%s] against [%s]\n",
|
||||
m_sexp.c_str(), val.c_str()));
|
||||
LOGDEB2("StrWildMatcher::match: [" << (m_sexp) << "] against [" << (val) << "]\n" );
|
||||
int ret = fnmatch(m_sexp.c_str(), val.c_str(), FNM_NOESCAPE);
|
||||
switch (ret) {
|
||||
case 0: return true;
|
||||
case FNM_NOMATCH: return false;
|
||||
default:
|
||||
LOGINFO(("StrWildMatcher::match:err: e [%s] s [%s] (%s) ret %d\n",
|
||||
m_sexp.c_str(), val.c_str(),
|
||||
url_encode(val).c_str(), ret));
|
||||
LOGINFO("StrWildMatcher::match:err: e [" << (m_sexp) << "] s [" << (val) << "] (" << (url_encode(val)) << ") ret " << (ret) << "\n" );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -130,3 +127,4 @@ bool StrRegexpMatcher::ok() const
|
||||
{
|
||||
return !m_errcode;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ using std::string;
|
||||
#include <iconv.h>
|
||||
|
||||
#include "transcode.h"
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "ptmutex.h"
|
||||
#ifdef RCL_ICONV_INBUF_CONST
|
||||
#define ICV_P2_TYPE const char**
|
||||
@@ -48,7 +48,7 @@ using std::string;
|
||||
bool transcode(const string &in, string &out, const string &icode,
|
||||
const string &ocode, int *ecnt)
|
||||
{
|
||||
LOGDEB2(("Transcode: %s -> %s\n", icode.c_str(), ocode.c_str()));
|
||||
LOGDEB2("Transcode: " << (icode) << " -> " << (ocode) << "\n" );
|
||||
#ifdef ICONV_CACHE_OPEN
|
||||
static iconv_t ic = (iconv_t)-1;
|
||||
static string cachedicode;
|
||||
@@ -106,9 +106,8 @@ bool transcode(const string &in, string &out, const string &icode,
|
||||
" : " + strerror(errno);
|
||||
#endif
|
||||
if (errno == EILSEQ) {
|
||||
LOGDEB1(("transcode:iconv: bad input seq.: shift, retry\n"));
|
||||
LOGDEB1((" Input consumed %d output produced %d\n",
|
||||
ip - in.c_str(), out.length() + OBSIZ - osiz));
|
||||
LOGDEB1("transcode:iconv: bad input seq.: shift, retry\n" );
|
||||
LOGDEB1(" Input consumed " << (ip - in) << " output produced " << (out.length() + OBSIZ - osiz) << "\n" );
|
||||
out.append(obuf, OBSIZ - osiz);
|
||||
out += "?";
|
||||
mecnt++;
|
||||
@@ -151,8 +150,7 @@ error:
|
||||
}
|
||||
|
||||
if (mecnt)
|
||||
LOGDEB(("transcode: [%s]->[%s] %d errors\n",
|
||||
icode.c_str(), ocode.c_str(), mecnt));
|
||||
LOGDEB("transcode: [" << (icode) << "]->[" << (ocode) << "] " << (mecnt) << " errors\n" );
|
||||
if (ecnt)
|
||||
*ecnt = mecnt;
|
||||
return ret;
|
||||
@@ -230,3 +228,4 @@ int main(int argc, char **argv)
|
||||
exit(0);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "cancelcheck.h"
|
||||
#include "execmd.h"
|
||||
#include "smallut.h"
|
||||
@@ -381,3 +381,4 @@ int main(int argc, char *argv[])
|
||||
return status >> 8;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "transcode.h"
|
||||
|
||||
#ifndef NO_NAMESPACES
|
||||
@@ -182,3 +182,4 @@ int main(int argc, char **argv)
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
+9
-10
@@ -29,7 +29,7 @@
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "pathut.h"
|
||||
#include "wipedir.h"
|
||||
|
||||
@@ -43,22 +43,22 @@ int wipedir(const string& dir, bool selfalso, bool recurse)
|
||||
|
||||
statret = lstat(dir.c_str(), &st);
|
||||
if (statret == -1) {
|
||||
LOGERR(("wipedir: cant stat %s, errno %d\n", dir.c_str(), errno));
|
||||
LOGERR("wipedir: cant stat " << (dir) << ", errno " << (errno) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
if (!S_ISDIR(st.st_mode)) {
|
||||
LOGERR(("wipedir: %s not a directory\n", dir.c_str()));
|
||||
LOGERR("wipedir: " << (dir) << " not a directory\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (access(dir.c_str(), R_OK|W_OK|X_OK) < 0) {
|
||||
LOGERR(("wipedir: no write access to %s\n", dir.c_str()));
|
||||
LOGERR("wipedir: no write access to " << (dir) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
|
||||
DIR *d = opendir(dir.c_str());
|
||||
if (d == 0) {
|
||||
LOGERR(("wipedir: cant opendir %s, errno %d\n", dir.c_str(), errno));
|
||||
LOGERR("wipedir: cant opendir " << (dir) << ", errno " << (errno) << "\n" );
|
||||
return -1;
|
||||
}
|
||||
int remaining = 0;
|
||||
@@ -72,7 +72,7 @@ int wipedir(const string& dir, bool selfalso, bool recurse)
|
||||
struct stat st;
|
||||
int statret = lstat(fn.c_str(), &st);
|
||||
if (statret == -1) {
|
||||
LOGERR(("wipedir: cant stat %s, errno %d\n", fn.c_str(), errno));
|
||||
LOGERR("wipedir: cant stat " << (fn) << ", errno " << (errno) << "\n" );
|
||||
goto out;
|
||||
}
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
@@ -87,8 +87,7 @@ int wipedir(const string& dir, bool selfalso, bool recurse)
|
||||
}
|
||||
} else {
|
||||
if (unlink(fn.c_str()) < 0) {
|
||||
LOGERR(("wipedir: cant unlink %s, errno %d\n",
|
||||
fn.c_str(), errno));
|
||||
LOGERR("wipedir: cant unlink " << (fn) << ", errno " << (errno) << "\n" );
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
@@ -97,8 +96,7 @@ int wipedir(const string& dir, bool selfalso, bool recurse)
|
||||
ret = remaining;
|
||||
if (selfalso && ret == 0) {
|
||||
if (rmdir(dir.c_str()) < 0) {
|
||||
LOGERR(("wipedir: rmdir(%s) failed, errno %d\n",
|
||||
dir.c_str(), errno));
|
||||
LOGERR("wipedir: rmdir(" << (dir) << ") failed, errno " << (errno) << "\n" );
|
||||
ret = -1;
|
||||
}
|
||||
}
|
||||
@@ -167,3 +165,4 @@ int main(int argc, const char **argv)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
+15
-24
@@ -24,7 +24,7 @@
|
||||
#include <queue>
|
||||
#include <list>
|
||||
|
||||
#include "debuglog.h"
|
||||
#include "log.h"
|
||||
#include "ptmutex.h"
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ public:
|
||||
|
||||
~WorkQueue()
|
||||
{
|
||||
LOGDEB2(("WorkQueue::~WorkQueue:%s\n", m_name.c_str()));
|
||||
LOGDEB2("WorkQueue::~WorkQueue:" << (m_name) << "\n" );
|
||||
if (!m_worker_threads.empty())
|
||||
setTerminateAndWait();
|
||||
}
|
||||
@@ -80,8 +80,7 @@ public:
|
||||
int err;
|
||||
pthread_t thr;
|
||||
if ((err = pthread_create(&thr, 0, start_routine, arg))) {
|
||||
LOGERR(("WorkQueue:%s: pthread_create failed, err %d\n",
|
||||
m_name.c_str(), err));
|
||||
LOGERR("WorkQueue:" << (m_name) << ": pthread_create failed, err " << (err) << "\n" );
|
||||
return false;
|
||||
}
|
||||
m_worker_threads.push_back(thr);
|
||||
@@ -97,8 +96,7 @@ public:
|
||||
{
|
||||
PTMutexLocker lock(m_mutex);
|
||||
if (!lock.ok() || !ok()) {
|
||||
LOGERR(("WorkQueue::put:%s: !ok or mutex_lock failed\n",
|
||||
m_name.c_str()));
|
||||
LOGERR("WorkQueue::put:" << (m_name) << ": !ok or mutex_lock failed\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -144,8 +142,7 @@ public:
|
||||
{
|
||||
PTMutexLocker lock(m_mutex);
|
||||
if (!lock.ok() || !ok()) {
|
||||
LOGERR(("WorkQueue::waitIdle:%s: not ok or can't lock\n",
|
||||
m_name.c_str()));
|
||||
LOGERR("WorkQueue::waitIdle:" << (m_name) << ": not ok or can't lock\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -157,8 +154,7 @@ public:
|
||||
if (pthread_cond_wait(&m_ccond, lock.getMutex())) {
|
||||
m_clients_waiting--;
|
||||
m_ok = false;
|
||||
LOGERR(("WorkQueue::waitIdle:%s: cond_wait failed\n",
|
||||
m_name.c_str()));
|
||||
LOGERR("WorkQueue::waitIdle:" << (m_name) << ": cond_wait failed\n" );
|
||||
return false;
|
||||
}
|
||||
m_clients_waiting--;
|
||||
@@ -176,7 +172,7 @@ public:
|
||||
void* setTerminateAndWait()
|
||||
{
|
||||
PTMutexLocker lock(m_mutex);
|
||||
LOGDEB(("setTerminateAndWait:%s\n", m_name.c_str()));
|
||||
LOGDEB("setTerminateAndWait:" << (m_name) << "\n" );
|
||||
|
||||
if (m_worker_threads.empty()) {
|
||||
// Already called ?
|
||||
@@ -189,17 +185,14 @@ public:
|
||||
pthread_cond_broadcast(&m_wcond);
|
||||
m_clients_waiting++;
|
||||
if (pthread_cond_wait(&m_ccond, lock.getMutex())) {
|
||||
LOGERR(("WorkQueue::setTerminate:%s: cond_wait failed\n",
|
||||
m_name.c_str()));
|
||||
LOGERR("WorkQueue::setTerminate:" << (m_name) << ": cond_wait failed\n" );
|
||||
m_clients_waiting--;
|
||||
return (void*)0;
|
||||
}
|
||||
m_clients_waiting--;
|
||||
}
|
||||
|
||||
LOGINFO(("%s: tasks %u nowakes %u wsleeps %u csleeps %u\n",
|
||||
m_name.c_str(), m_tottasks, m_nowake, m_workersleeps,
|
||||
m_clientsleeps));
|
||||
LOGINFO("" << (m_name) << ": tasks " << (m_tottasks) << " nowakes " << (m_nowake) << " wsleeps " << (m_workersleeps) << " csleeps " << (m_clientsleeps) << "\n" );
|
||||
// Perform the thread joins and compute overall status
|
||||
// Workers return (void*)1 if ok
|
||||
void *statusall = (void*)1;
|
||||
@@ -218,7 +211,7 @@ public:
|
||||
m_tottasks = m_nowake = m_workersleeps = m_clientsleeps = 0;
|
||||
m_ok = true;
|
||||
|
||||
LOGDEB(("setTerminateAndWait:%s done\n", m_name.c_str()));
|
||||
LOGDEB("setTerminateAndWait:" << (m_name) << " done\n" );
|
||||
return statusall;
|
||||
}
|
||||
|
||||
@@ -231,7 +224,7 @@ public:
|
||||
{
|
||||
PTMutexLocker lock(m_mutex);
|
||||
if (!lock.ok() || !ok()) {
|
||||
LOGDEB(("WorkQueue::take:%s: not ok\n", m_name.c_str()));
|
||||
LOGDEB("WorkQueue::take:" << (m_name) << ": not ok\n" );
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -243,8 +236,7 @@ public:
|
||||
if (pthread_cond_wait(&m_wcond, lock.getMutex()) || !ok()) {
|
||||
// !ok is a normal condition when shutting down
|
||||
if (ok())
|
||||
LOGERR(("WorkQueue::take:%s: cond_wait failed or !ok\n",
|
||||
m_name.c_str()));
|
||||
LOGERR("WorkQueue::take:" << (m_name) << ": cond_wait failed or !ok\n" );
|
||||
m_workers_waiting--;
|
||||
return false;
|
||||
}
|
||||
@@ -275,7 +267,7 @@ public:
|
||||
*/
|
||||
void workerExit()
|
||||
{
|
||||
LOGDEB(("workerExit:%s\n", m_name.c_str()));
|
||||
LOGDEB("workerExit:" << (m_name) << "\n" );
|
||||
PTMutexLocker lock(m_mutex);
|
||||
m_workers_exited++;
|
||||
m_ok = false;
|
||||
@@ -294,9 +286,7 @@ private:
|
||||
{
|
||||
bool isok = m_ok && m_workers_exited == 0 && !m_worker_threads.empty();
|
||||
if (!isok) {
|
||||
LOGDEB(("WorkQueue:ok:%s: not ok m_ok %d m_workers_exited %d "
|
||||
"m_worker_threads size %d\n", m_name.c_str(),
|
||||
m_ok, m_workers_exited, int(m_worker_threads.size())));
|
||||
LOGDEB("WorkQueue:ok:" << (m_name) << ": not ok m_ok " << (m_ok) << " m_workers_exited " << (m_workers_exited) << " m_worker_threads size " << (int(m_worker_threads.size())) << "\n" );
|
||||
}
|
||||
return isok;
|
||||
}
|
||||
@@ -339,3 +329,4 @@ private:
|
||||
};
|
||||
|
||||
#endif /* _WORKQUEUE_H_INCLUDED_ */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user