Talk:Run as a daemon or service: Difference between revisions

No edit summary
Line 81:
:: the part with not caring was supposed to refer to functions or libraries used within the daemon which constitute the useful part, not the daemonizing part. that is, it should be possible to take an existing program, and turn it into a daemon without having to replace all references of say <code>printf(...)</code> with <code>fprintf(somefile,...)</code>--[[User:EMBee|eMBee]] 09:10, 18 November 2011 (UTC)
::: And, of course, the shell script approach supports all of this. Redirect to /dev/null means those printf references do not have to be changed and, if stdout is redirected within the program, their output will be redirected appropriately. --[[User:Rdm|Rdm]] 18:56, 18 November 2011 (UTC)
 
== Strange stdout rule ==
 
For some strange reason, the current draft task wants to use "stdout which should be redirected to a file". This redirection of stdout has no purpose to the daemon, and is not better than simply opening a file. To redirect stdout, my C code calls dup2().
 
<lang c>fd = open(argv[1], O_WRONLY | O_APPEND | O_CREAT, 0666);
dup2(fd, STDOUT_FILENO);
fputs("string\n", stdout);</lang>
 
But if I forgot stdout, I would simplify the code by removing open() and dup2() and using a regular fopen().
 
<lang c>file = fopen(argv[1], "a");
fputs("string\n", file);</lang>
 
I suggest to remove the stdout rule from the draft task, and to permit each solution to write to a file without regard to whether it redirects stdout. --[[User:Kernigh|Kernigh]] 00:55, 19 November 2011 (UTC)
Anonymous user