X-Git-Url: http://git.maemo.org/git/?p=mnenc;a=blobdiff_plain;f=mnencd.cpp;h=ddc89e21590edebc3bddd3f9ff77b3c31612e72c;hp=68be9a5dac5b07ece3aa2c3e81395d4e0aeabc0c;hb=29a4076ab4f859e49ed17f0a2a804e67606550b9;hpb=c6bc8721b6091a5a7e130ffb0837a21bede85b4f diff --git a/mnencd.cpp b/mnencd.cpp index 68be9a5..ddc89e2 100644 --- a/mnencd.cpp +++ b/mnencd.cpp @@ -26,7 +26,7 @@ ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * */ - +#include #include #include #include @@ -61,17 +61,34 @@ int main(int argc, char** argv) { umask(0); /* Open any logs here */ - + std::string name, dirname; + name = getenv("USER"); + dirname = "/home/" + name + "/.mnenc/"; + if(mkdir(dirname.c_str(), S_IRWXU | S_IRWXG | S_IRWXO ) < 0) { + if(errno != EEXIST) { + 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 the failure */ + log << current_time << ": Unable to create a new SID for the child process\n"; exit(EXIT_FAILURE); } /* Change the current working directory */ - if ((chdir("/home/micke/.fifo")) < 0) { - /* Log the failure */ + if ((chdir("/tmp/")) < 0) { + log << current_time << ": Could not change to /tmp\n"; exit(EXIT_FAILURE); } @@ -81,9 +98,10 @@ int main(int argc, char** argv) { close(STDERR_FILENO); /* Daemon-specific initialization goes here */ + mkfifo("./mnencdfifo", 0777); //This is the fifo for communications + signal(SIGTERM, term); // register a SIGTERM handler + log.close(); //Closing log - mkfifo("./fife", 0777); - /* The Big Loop */ while (1) { std::string request = m_read(); @@ -91,6 +109,5 @@ int main(int argc, char** argv) { m_send(reply); sleep(1); /* wait 1 second*/ } - unlink("fife"); exit(EXIT_SUCCESS); }