News for hackers. Stuff that matters.
Re:fork() can fail by nuxi on Wednesday August 20, 2014 @05:44PM (#8204836)
There's a good reason you can't rely on CWD other than root - the directory can be on a different mountpoint and possibly even on a remote mountpoint. If the remote server goes down or the mountpoint is forcefully unmounted, what would your CWD point to then? Root is the only directory guaranteed to always exist, that's why you'd see a chdir('/') as one of the first steps in properly written unix daemons.
Re:fork() can fail by jjnoakes on Wednesday August 20, 2014 @05:50PM (#8204862)
Almost - the main reason for the chdir('/') is so that if you do happen to be in a mounted file system (locally or remotely), your daemon doesn't prevent the system administrator from gracefully unmounting that file system for whatever reason.