On Fri, Jan 31, 2020 at 06:39:04PM +0000, Moisés Simón wrote:
> Sorry to hijack,
>
> Do you know of any basic guide for this?
>
> I have done a syslog normalizer daemon which calls pledge(), unveil() and redirects std{out,err} and forks to search and normalize the logs.
>
> I'm not professional programmer so I'm doing my best and want to learn as much as I can.
>
> Thank you
I guess the best guide is the code itself :) You can have a look at
/usr/src/lib/libc/gen/daemon.c, where the libc function daemon(3) is
defined. You can also see a simple and complete example in the code of
something like tftpd at /usr/src/usr.sbin/tftpd/tftpd.c
that code uses a local clone of daemon(3) (that is called rdaemon),
but the logic is exactly the same, and it's a full working example
with chdir(2) (or chroot(2)), privilege drop, fork(2), setsid(2),
close stdin/stdout/stderr, and pledge(2) before the daemon starts to
do its things.
Ingo has already provided pointers to excellent resources about the
general concepts and the typical organisation and implementation of
processes in Unix.
HTH
No comments:
Post a Comment