--- smsdaemon/Spooler.cpp 2008/12/08 21:49:49 158 +++ smsdaemon/Spooler.cpp 2008/12/18 06:53:29 196 @@ -40,14 +40,17 @@ lock(); std::string file = findSpoolFilename(); std::ofstream out(file.c_str()); - if (out) { + if (out) + { out << recipient << "\n" << message; out.close(); - } else { + } + else + { error = true; } unlock(); - + if (error) throw std::runtime_error("Could not create spoolfile"); this->filename = file; @@ -62,11 +65,11 @@ errnoException(); string file; - string message; + string message; dirent* entry; - while ( (entry = readdir(dir)) != 0) + while ( (entry = readdir(dir)) != 0) { - if (entry->d_name[0] == '.' ) + if (entry->d_name[0] == '.' ) { continue; } @@ -80,7 +83,8 @@ closedir(dir); - if (file != "") { + if (file != "") + { message = Util::readfile(file); ::unlink(file.c_str()); } @@ -102,7 +106,8 @@ int retrycount = 0; - while(1) { + while (1) + { ss.str(std::string()); //clear ss << std::setw(8) << std::setfill('0') << std::uppercase << std::hex << rand(); @@ -112,21 +117,23 @@ int fd = ::open(file.c_str(), O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR | S_IRGRP| S_IROTH); retrycount ++; - if (fd != -1) { + if (fd != -1) + { ::close(fd); return file; } int err = errno; ::close(fd); - if (err == EEXIST) { + if (err == EEXIST) + { continue; } if (retrycount > 20) throw std::runtime_error("to many retry attempt at creating spool file"); - throw std::runtime_error("no access to spool directory"); + throw std::runtime_error("no access to spool directory"); } } @@ -135,13 +142,15 @@ { lockfd = open(spooldir.c_str() , O_RDONLY); - if (lockfd == -1) { + if (lockfd == -1) + { errnoException("Couldn open lockfile"); } int status = flock(lockfd, LOCK_EX); - if (status == -1) { + if (status == -1) + { errnoException(); } }