From cba04afc91bfd3c4b77880e10f4e1cd5a41adaa2 Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 3 May 2005 12:51:05 +0000 Subject: Fixed to always write log to bin directory git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1291 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/inspircd.cpp | 38 +++++++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index a9e0e316f..fa4605227 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2339,7 +2339,7 @@ void Error(int status) } -int main(int argc, char **argv) +int main(int argc, char** argv) { Start(); srand(time(NULL)); @@ -2367,7 +2367,7 @@ int main(int argc, char **argv) } strlcpy(MyExecutable,argv[0],MAXBUF); - if (InspIRCd() == ERROR) + if (InspIRCd(argv,argc) == ERROR) { log(DEFAULT,"main: daemon function bailed"); printf("ERROR: could not initialise. Shutting down.\n"); @@ -3776,6 +3776,32 @@ bool DirValid(char* dirandfile) else return false; } +std::string GetFullProgDir(char** argv, int argc) +{ + char work[MAXBUF]; + strlcpy(work,argv[0],MAXBUF); + int p = strlen(work); + // we just want the dir + while (strlen(work)) + { + if (work[p] == '/') + { + work[p] = '\0'; + break; + } + work[p--] = '\0'; + } + char buffer[MAXBUF], otherdir[MAXBUF]; + // Get the current working directory + if( getcwd( buffer, MAXBUF ) == NULL ) + return ""; + chdir(work); + if( getcwd( otherdir, MAXBUF ) == NULL ) + return ""; + chdir(buffer); + return otherdir; +} + bool LoadModule(const char* filename) { char modfile[MAXBUF]; @@ -3832,7 +3858,7 @@ bool LoadModule(const char* filename) return true; } -int InspIRCd(void) +int InspIRCd(char** argv, int argc) { struct sockaddr_in client,server; char addrs[MAXBUF][255]; @@ -3844,12 +3870,14 @@ int InspIRCd(void) fd_set selectFds; timeval tv; - log_file = fopen("ircd.log","a+"); + std::string logpath = GetFullProgDir(argv,argc) + "/ircd.log"; + log_file = fopen(logpath.c_str(),"a+"); if (!log_file) { - printf("ERROR: Could not write to logfile ircd.log, bailing!\n\n"); + printf("ERROR: Could not write to logfile %s, bailing!\n\n",logpath.c_str()); Exit(ERROR); } + printf("Logging to %s...\n",logpath.c_str()); log(DEFAULT,"$Id$"); if (geteuid() == 0) -- cgit v1.2.3