summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-03 12:51:05 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2005-05-03 12:51:05 +0000
commitcba04afc91bfd3c4b77880e10f4e1cd5a41adaa2 (patch)
tree92f0d103b99cde402984cceceaaf0550d63dc401
parentf9055253d2e8a7612fced65c3f96a6f940111148 (diff)
Fixed to always write log to bin directory
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@1291 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r--src/inspircd.cpp38
1 files changed, 33 insertions, 5 deletions
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)