X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=mnencd.cpp;h=2573b4702d0a30da8bd87edaff6cd5f055909d8e;hb=cd87e77c1952c0b831c3eee5f3556ccd3797bb70;hp=68be9a5dac5b07ece3aa2c3e81395d4e0aeabc0c;hpb=6a648ab17c5def963cedae232102f72e3a2f70ee;p=mnenc diff --git a/mnencd.cpp b/mnencd.cpp index 68be9a5..2573b47 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 @@ -68,9 +68,17 @@ int main(int argc, char** argv) { /* Log the failure */ exit(EXIT_FAILURE); } - + 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); + } + } + /* Change the current working directory */ - if ((chdir("/home/micke/.fifo")) < 0) { + if ((chdir("/tmp/")) < 0) { /* Log the failure */ exit(EXIT_FAILURE); } @@ -81,9 +89,11 @@ int main(int argc, char** argv) { close(STDERR_FILENO); /* Daemon-specific initialization goes here */ - - mkfifo("./fife", 0777); + mkfifo("./mnencdfifo", 0777); + signal(SIGTERM, term); // register a SIGTERM handler + //raise(SIGTERM); // will cause term() to run + /* The Big Loop */ while (1) { std::string request = m_read(); @@ -91,6 +101,5 @@ int main(int argc, char** argv) { m_send(reply); sleep(1); /* wait 1 second*/ } - unlink("fife"); exit(EXIT_SUCCESS); }