X-Git-Url: http://git.maemo.org/git/?p=mnenc;a=blobdiff_plain;f=mnencd.cpp;fp=mnencd.cpp;h=ddc89e21590edebc3bddd3f9ff77b3c31612e72c;hp=2573b4702d0a30da8bd87edaff6cd5f055909d8e;hb=dd14c9c23b06bbd3e5c83fdf660844aab089c747;hpb=e4668695f0533b93ba8e58f16fe93c7d712309ba diff --git a/mnencd.cpp b/mnencd.cpp index 2573b47..ddc89e2 100644 --- a/mnencd.cpp +++ b/mnencd.cpp @@ -61,13 +61,6 @@ int main(int argc, char** argv) { umask(0); /* Open any logs here */ - - /* Create a new SID for the child process */ - sid = setsid(); - if (sid < 0) { - /* Log the failure */ - exit(EXIT_FAILURE); - } std::string name, dirname; name = getenv("USER"); dirname = "/home/" + name + "/.mnenc/"; @@ -76,10 +69,26 @@ int main(int argc, char** argv) { exit(EXIT_FAILURE); } } - + /*This is log stuff */ + std::string logname = "/home/" + name + "/.mnenc/log"; + std::ofstream log; //Log stream + log.open(logname.c_str(), ios::app); // open log + time_t rawtime; //Time stuff here + struct tm * timeinfo; + time ( &rawtime ); + timeinfo = localtime ( &rawtime ); + std::string current_time = asctime (timeinfo); //Holds current time + + /* Create a new SID for the child process */ + sid = setsid(); + if (sid < 0) { + log << current_time << ": Unable to create a new SID for the child process\n"; + exit(EXIT_FAILURE); + } + /* Change the current working directory */ if ((chdir("/tmp/")) < 0) { - /* Log the failure */ + log << current_time << ": Could not change to /tmp\n"; exit(EXIT_FAILURE); } @@ -89,10 +98,9 @@ int main(int argc, char** argv) { close(STDERR_FILENO); /* Daemon-specific initialization goes here */ - - mkfifo("./mnencdfifo", 0777); + mkfifo("./mnencdfifo", 0777); //This is the fifo for communications signal(SIGTERM, term); // register a SIGTERM handler - //raise(SIGTERM); // will cause term() to run + log.close(); //Closing log /* The Big Loop */ while (1) {