From 4a9f121b23ce3ebd7390391e61a9b0c6c0e7d5ea Mon Sep 17 00:00:00 2001 From: bloodstalker Date: Tue, 28 Feb 2017 18:26:32 +0330 Subject: daemon sourcefile --- daemon/mutatord.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 daemon/mutatord.c (limited to 'daemon/mutatord.c') diff --git a/daemon/mutatord.c b/daemon/mutatord.c new file mode 100644 index 0000000..400d695 --- /dev/null +++ b/daemon/mutatord.c @@ -0,0 +1,83 @@ + +/***************************************************Project Mutator****************************************************/ +/*first line intentionally left blank.*/ +/*the source code for the static checks(Misra-C,...)*/ +/*Copyright (C) 2017 Farzad Sadeghi +This source file contains mutator's daemon. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.*/ +/**********************************************************************************************************************/ +/*inclusion directives*/ +#include "mutatord.h" +/*library headers*/ +#include +#include +#include +#include +#include +#include +#include +#include +#include +/**********************************************************************************************************************/ +int main(void) +{ + /*getting a process ID*/ + pid_t pid; + /*getting a session ID*/ + pid_t sid; + + /*fork off the parent process*/ + pid = fork(); + + if (pid < 0) + { + exit(EXIT_FAILURE); + } + + if (pid > 0) + { + exit(EXIT_SUCCESS); + } + + umask(0); + + /*create a new session ID for the child process*/ + sid = setsid(); + if (sid < 0) + { + exit(EXIT_FAILURE); + } + + /*change the current working directory*/ + if (chdir("/") < 0) + { + exit(EXIT_FAILURE); + } + + /*close the standard file descriptors*/ + close(STDIN_FILENO) ; + close(STDOUT_FILENO); + close(STDERR_FILENO); + + /*deamon loop*/ + while(1) + { + sleep(30); + } + +} +/*last line intentionally left blank*/ + -- cgit v1.2.3