c-daemon not linked to tty
This commit is contained in:
parent
7198d71d38
commit
c9c795fe4e
3 changed files with 38 additions and 8 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -77,4 +77,4 @@ Mkfile.old
|
||||||
dkms.conf
|
dkms.conf
|
||||||
|
|
||||||
### USER MODIFIED ###
|
### USER MODIFIED ###
|
||||||
# c-daemon/bin/
|
c-daemon/bin/
|
|
@ -15,6 +15,7 @@ git clone https://git.aliberksandikci.com.tr/liderahenk/go-daemon
|
||||||
cd go-daemon/
|
cd go-daemon/
|
||||||
go build -o c-daemon/bin/ c-daemon/go-files/info.go
|
go build -o c-daemon/bin/ c-daemon/go-files/info.go
|
||||||
gcc -o c-daemon/bin/test c-daemon/daemon/test.c c-daemon/daemon/daemon.c
|
gcc -o c-daemon/bin/test c-daemon/daemon/test.c c-daemon/daemon/daemon.c
|
||||||
|
sudo ln -sv "$(pwd)"/c-daemon/bin/info /info
|
||||||
```
|
```
|
||||||
|
|
||||||
How to **start** c-daemon + go processes:
|
How to **start** c-daemon + go processes:
|
||||||
|
|
|
@ -8,35 +8,63 @@
|
||||||
#include <linux/limits.h>
|
#include <linux/limits.h>
|
||||||
#define NR_OPEN 1024
|
#define NR_OPEN 1024
|
||||||
|
|
||||||
|
void logg(int num){
|
||||||
|
printf("You are in: %d\n",num);
|
||||||
|
}
|
||||||
|
|
||||||
int _daemon(int nochdir, int noclose){
|
int _daemon(int nochdir, int noclose){
|
||||||
pid_t pid, sid;
|
pid_t pid, sid;
|
||||||
// pid_t defined in sys/types.h
|
// pid_t defined in sys/types.h
|
||||||
// pid_t is a signed int data type
|
// pid_t is a signed int data type
|
||||||
|
|
||||||
|
logg(1);
|
||||||
pid = fork(); // fork of the parent process
|
pid = fork(); // fork of the parent process
|
||||||
// fork() function defined in unistd.h
|
// fork() function defined in unistd.h
|
||||||
|
|
||||||
|
logg(2);
|
||||||
|
|
||||||
if (pid < 0){
|
if (pid < 0){
|
||||||
|
logg(3);
|
||||||
exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h
|
exit(EXIT_FAILURE); // exit and EXIT_FAILURE defined in stdlib.h
|
||||||
}
|
}
|
||||||
else if (pid > 0){
|
else if (pid > 0){
|
||||||
|
logg(4);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
// sid = setsid();
|
|
||||||
// if (sid < 0) {
|
logg(5);
|
||||||
// exit(EXIT_FAILURE);
|
sid = setsid();
|
||||||
// }
|
logg(8);
|
||||||
// if ((chdir("/")) < 0) {
|
|
||||||
// exit(EXIT_FAILURE);
|
if (sid < 0) {
|
||||||
// }
|
logg(9);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
logg(10);
|
||||||
|
|
||||||
|
if ((chdir("/")) < 0) {
|
||||||
|
logg(11);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// logg(11);
|
||||||
// if (!noclose) {
|
// if (!noclose) {
|
||||||
|
// logg(12);
|
||||||
// for (int i = 0; i < NR_OPEN; i++)
|
// for (int i = 0; i < NR_OPEN; i++)
|
||||||
// close(i);
|
// close(i);
|
||||||
|
// logg(13);
|
||||||
// open("/dev/null", O_RDWR);
|
// open("/dev/null", O_RDWR);
|
||||||
|
// logg(14);
|
||||||
// dup(0);
|
// dup(0);
|
||||||
|
// logg(15);
|
||||||
// dup(0);
|
// dup(0);
|
||||||
|
// logg(16);
|
||||||
// }
|
// }
|
||||||
// close(STDOUT_FILENO);
|
// close(STDOUT_FILENO);
|
||||||
// close(STDERR_FILENO);
|
// close(STDERR_FILENO);
|
||||||
while (1) {
|
while (1) {
|
||||||
|
logg(6);
|
||||||
int status = system("./info");
|
int status = system("./info");
|
||||||
// TODO SECURITY ISSUE
|
// TODO SECURITY ISSUE
|
||||||
// LINK https://stackoverflow.com/questions/5237482/how-do-i-execute-an-external-program-within-c-code-in-linux-with-arguments#
|
// LINK https://stackoverflow.com/questions/5237482/how-do-i-execute-an-external-program-within-c-code-in-linux-with-arguments#
|
||||||
|
@ -44,5 +72,6 @@ int _daemon(int nochdir, int noclose){
|
||||||
|
|
||||||
sleep(1);
|
sleep(1);
|
||||||
}
|
}
|
||||||
|
logg(7);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
Loading…
Reference in a new issue