--- smsdaemon/Spooler.cpp 2008/12/07 00:59:05 132 +++ smsdaemon/Spooler.cpp 2008/12/08 21:49:49 158 @@ -15,7 +15,7 @@ #include #include -#include "util.h" +#include "Util.h" #include "Exceptions.h" @@ -38,7 +38,7 @@ { bool error = false; lock(); - std::string file = getSpoolFilename(); + std::string file = findSpoolFilename(); std::ofstream out(file.c_str()); if (out) { out << recipient << "\n" << message; @@ -50,6 +50,7 @@ if (error) throw std::runtime_error("Could not create spoolfile"); + this->filename = file; } std::string Spooler::dequeue() @@ -86,13 +87,15 @@ unlock(); + this->filename = file; + if (file != "") return message; else throw filenotfoundexception(); } -std::string Spooler::getSpoolFilename() +std::string Spooler::findSpoolFilename() { std::string file; std::stringstream ss; @@ -113,9 +116,12 @@ ::close(fd); return file; } + int err = errno; + ::close(fd); - if (errno == EEXIST) + if (err == EEXIST) { continue; + } if (retrycount > 20) throw std::runtime_error("to many retry attempt at creating spool file"); @@ -127,13 +133,13 @@ void Spooler::lock() { - fd = open(spooldir.c_str() , O_RDONLY); + lockfd = open(spooldir.c_str() , O_RDONLY); - if (fd == -1) { + if (lockfd == -1) { errnoException("Couldn open lockfile"); } - int status = flock(fd, LOCK_EX); + int status = flock(lockfd, LOCK_EX); if (status == -1) { errnoException(); @@ -142,5 +148,11 @@ void Spooler::unlock() { - flock(fd, LOCK_UN); + flock(lockfd, LOCK_UN); + close(lockfd); +} + +string Spooler::getFilename() +{ + return filename; }