diff --git a/.gitignore b/.gitignore index a82e517..f858446 100644 --- a/.gitignore +++ b/.gitignore @@ -74,4 +74,7 @@ go.work modules.order Module.symvers Mkfile.old -dkms.conf \ No newline at end of file +dkms.conf + +### USER MODIFIED ### +c-daemon/bin/ \ No newline at end of file diff --git a/README.md b/README.md index b465797..9d27ac0 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,25 @@ This repo will be include two separate daemons. One of them is written with C la
+How to start c-daemon + go processes: +```bash +git clone https://git.aliberksandikci.com.tr/liderahenk/go-daemon +cd go-daemon/ +go build -o c-daemon/bin/ info +gcc -o c-daemon/bin/test c-daemon/daemon/test.c c-daemon/daemon/daem +on.c +./c-daemon/bin/test +``` + + + +
+ +--- + +
+ +
Notes ### Summary - [MakeUseOf](https://www.makeuseof.com/create-daemons-on-linux/) @@ -64,4 +83,6 @@ Now return to the terminal where you are running your application (./test) and p First of all, you can say that the new subprocess is running in the **background** since you do not see the **+** character in the **STAT** field. You can now see that the parent process of your process is the systemd process (or other init in use) -I'm too lazy to continue this readme(about c-daemon). just continue in [original website](https://www.makeuseof.com/create-daemons-on-linux/) or just review last versions of c files \ No newline at end of file +I'm too lazy to continue this readme(about c-daemon). just continue in [original website](https://www.makeuseof.com/create-daemons-on-linux/) or just review last versions of c files + + \ No newline at end of file diff --git a/c-daemon/daemon.c b/c-daemon/daemon.c deleted file mode 100644 index db509ab..0000000 --- a/c-daemon/daemon.c +++ /dev/null @@ -1,27 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -int _daemon(int nochdir, int noclose){ - pid_t pid; - // pid_t defined in sys/types.h - // pid_t is a signed int data type - - pid = fork(); // fork of the parent process - // fork() function defined in unistd.h - if (pid < 0){ - exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h - } - else if (pid > 0){ - exit(EXIT_SUCCESS); - } - if (setsid() == -1){ - return -1; - } - return 0; -} \ No newline at end of file diff --git a/c-daemon/daemon/daemon.c b/c-daemon/daemon/daemon.c new file mode 100644 index 0000000..095b6eb --- /dev/null +++ b/c-daemon/daemon/daemon.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#define NR_OPEN 1024 + +int _daemon(int nochdir, int noclose){ + pid_t pid, sid; + // pid_t defined in sys/types.h + // pid_t is a signed int data type + pid = fork(); // fork of the parent process + // fork() function defined in unistd.h + if (pid < 0){ + exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h + } + else if (pid > 0){ + exit(EXIT_SUCCESS); + } + // sid = setsid(); + // if (sid < 0) { + // exit(EXIT_FAILURE); + // } + // if ((chdir("/")) < 0) { + // exit(EXIT_FAILURE); + // } + // if (!noclose) { + // for (int i = 0; i < NR_OPEN; i++) + // close(i); + // open("/dev/null", O_RDWR); + // dup(0); + // dup(0); + // } + // close(STDOUT_FILENO); + // close(STDERR_FILENO); + while (1) { + int status = system("../go-files/info"); + // TODO SECURITY ISSUE + // LINK https://stackoverflow.com/questions/5237482/how-do-i-execute-an-external-program-within-c-code-in-linux-with-arguments# + + + sleep(1); + } + exit(EXIT_SUCCESS); +} \ No newline at end of file diff --git a/c-daemon/test.c b/c-daemon/daemon/test.c similarity index 63% rename from c-daemon/test.c rename to c-daemon/daemon/test.c index bfcefa3..07b860c 100644 --- a/c-daemon/test.c +++ b/c-daemon/daemon/test.c @@ -3,7 +3,10 @@ int _daemon (int, int); int main(){ + printf("START"); _daemon(0, 0); + printf("END"); getchar(); + printf("CLOSE"); return 0; } \ No newline at end of file diff --git a/info.go b/c-daemon/go-files/info.go similarity index 100% rename from info.go rename to c-daemon/go-files/info.go