remove logs

This commit is contained in:
Aliberk Sandıkçı 2023-07-26 15:58:21 +03:00
parent 30bda9ac00
commit 24324dcadb
Signed by: asandikci
GPG key ID: 25C67A03B5666BC1
3 changed files with 4 additions and 26 deletions

Binary file not shown.

View file

@ -17,61 +17,42 @@ int _daemon(int nochdir, int noclose){
// 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);
} }
logg(5);
sid = setsid(); sid = setsid();
logg(8);
if (sid < 0) { if (sid < 0) {
logg(9);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
logg(10);
if ((chdir("/")) < 0) { if ((chdir("/")) < 0) {
logg(17);
exit(EXIT_FAILURE); 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); // close(STDOUT_FILENO); => close(1);
open("/dev/null", O_RDWR); // close(STDERR_FILENO); => close(2);
logg(14); }
dup(0); open("/dev/null", O_RDWR);
logg(15); dup(0);
dup(0); dup(0);
logg(16);
} }
// close(STDOUT_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#
sleep(1); sleep(1);
} }
logg(7);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }

View file

@ -3,10 +3,7 @@
int _daemon (int, int); int _daemon (int, int);
int main(){ int main(){
printf("START");
_daemon(0, 0); _daemon(0, 0);
printf("END");
getchar(); getchar();
printf("CLOSE");
return 0; return 0;
} }