#include "command_parse.h"
using irc::sockets::NonBlocking;
+using irc::sockets::Blocking;
using irc::sockets::insp_ntoa;
using irc::sockets::insp_inaddr;
using irc::sockets::insp_sockaddr;
void InspIRCd::SetSignals(bool SEGVHandler)
{
- signal (SIGALRM, SIG_IGN);
- signal (SIGHUP, InspIRCd::Rehash);
- signal (SIGPIPE, SIG_IGN);
- signal (SIGTERM, InspIRCd::Exit);
+ signal(SIGALRM, SIG_IGN);
+ signal(SIGHUP, InspIRCd::Rehash);
+ signal(SIGPIPE, SIG_IGN);
+ signal(SIGTERM, InspIRCd::Exit);
+ signal(SIGCHLD, SIG_IGN);
}
bool InspIRCd::DaemonSeed()
{
int childpid;
if ((childpid = fork ()) < 0)
- return (ERROR);
+ return false;
else if (childpid > 0)
{
/* We wait here for the child process to kill us,
* so that the shell prompt doesnt come back over
- * the output */
- while (1)
- sleep(600);
+ * the output.
+ * Sending a kill with a signal of 0 just checks
+ * if the child pid is still around. If theyre not,
+ * they threw an error and we should give up.
+ */
+ while (kill(childpid, 0) != -1)
+ sleep(1);
+ exit(ERROR);
}
setsid ();
umask (007);
this->Log(DEBUG,"%d listeners",stats->BoundPortCount);
for (unsigned long count = 0; count < stats->BoundPortCount; count++)
{
- this->Log(DEBUG,"Add listener: %d",Config->openSockfd[count]);
+ this->Log(DEBUG,"Add listener: %d",Config->openSockfd[count]->GetFd());
if (!SE->AddFd(Config->openSockfd[count]))
{
printf("\nEH? Could not add listener to socketengine. You screwed up, aborting.\n");
return TIME;
}
+bool FileLogger::Readable()
+{
+ return false;
+}
+
+void FileLogger::HandleEvent(EventType et)
+{
+ this->WriteLogLine("");
+ ServerInstance->SE->DelFd(this);
+}
+
+void FileLogger::WriteLogLine(const std::string &line)
+{
+ if (line.length())
+ buffer.append(line);
+
+ if (log)
+ {
+ int written = fprintf(log,"%s",buffer.c_str());
+ if ((written >= 0) && (written < (int)buffer.length()))
+ {
+ buffer.erase(0, buffer.length());
+ ServerInstance->SE->AddFd(this);
+ }
+ else if (written == -1)
+ {
+ if (errno == EAGAIN)
+ ServerInstance->SE->AddFd(this);
+ }
+ else
+ {
+ /* Wrote the whole buffer, and no need for write callback */
+ buffer = "";
+ }
+ }
+ if (writeops++ % 20)
+ {
+ fflush(log);
+ }
+}
+
+void FileLogger::Close()
+{
+ if (log)
+ {
+ int flags = fcntl(fileno(log), F_GETFL, 0);
+ fcntl(fileno(log), F_SETFL, flags ^ O_NONBLOCK);
+ if (buffer.size())
+ fprintf(log,"%s",buffer.c_str());
+ fflush(log);
+ fclose(log);
+ }
+ buffer = "";
+ ServerInstance->SE->DelFd(this);
+}
+
+FileLogger::FileLogger(InspIRCd* Instance, FILE* logfile) : ServerInstance(Instance), log(logfile), writeops(0)
+{
+ irc::sockets::NonBlocking(fileno(log));
+ this->SetFd(fileno(log));
+ buffer = "";
+}
+
+FileLogger::~FileLogger()
+{
+ this->Close();
+}
+