diff options
| author | bloodstalker <thabogre@gmail.com> | 2017-02-28 14:56:32 +0000 | 
|---|---|---|
| committer | bloodstalker <thabogre@gmail.com> | 2017-02-28 14:56:32 +0000 | 
| commit | 4a9f121b23ce3ebd7390391e61a9b0c6c0e7d5ea (patch) | |
| tree | 7ebd7fcd3070aea7b714057daa13a51648595d02 | |
| parent | the daemon makefile (diff) | |
| download | mutator-4a9f121b23ce3ebd7390391e61a9b0c6c0e7d5ea.tar.gz mutator-4a9f121b23ce3ebd7390391e61a9b0c6c0e7d5ea.zip | |
daemon sourcefile
| -rw-r--r-- | daemon/mutatord.c | 83 | 
1 files changed, 83 insertions, 0 deletions
| 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 <sys/types.h> +#include <sys/stat.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <errno.h> +#include <unistd.h> +#include <syslog.h> +#include <string.h> +/**********************************************************************************************************************/ +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*/ + | 
