Not completely unrelated: Rely on the system environment to put your program into daemon mode, don't attempt to re-invent the wheel for the millonth time. Daemontools can make a daemon from almost any program. Reliable logging is also handled by daemontools, just write to STDERR. See also The DJB Way.
From the viewpoint of a library user, I would prefer the principle of the least surprise:
- A function should return a false value on error (preferably even in list context) and a true value on success, for the good old my $foo=function() or die "Can't function: $!";. Assigning to $! should do no harm, even if it is just a string.
- A function that knows that some fatal error has occured (memory exhausted, internal structures damaged, unrecoverable system call errors) should better die(). If I (as a library user) really know better, I can always wrap the function call in an eval { BLOCK }.
- A function returning a string should not add unexpected behaviour to that string. If you want to return an error string, behave like system and evaluate to false on SUCCESS, so a user can write error handling à la C: my $err=function(); if ($err) { die $err }. I don't like that style very much, because it requires manual error checking (remember: we have die and eval { BLOCK }) and blocks the return value for better uses.
Alexander
--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)