@@ -817,30 +817,25 @@ void open_syslog(const char *progname)
817817#endif /* WIN32 */
818818}
819819
820- /* close ttys and become a daemon */
821- void background (void )
820+ int background_fork (void )
822821{
823- /* Normally we enable SYSLOG and disable STDERR,
824- * unless NUT_DEBUG_SYSLOG envvar interferes as
825- * interpreted in syslog_is_disabled() method: */
826- int syslog_disabled = syslog_is_disabled (),
827- stderr_disabled = (syslog_disabled == 0 || syslog_disabled == 2 );
822+ int pid = 0 ;
828823
829824#ifndef WIN32
830- int pid ;
831-
832825 if ((pid = fork ()) < 0 )
833826 fatal_with_errno (EXIT_FAILURE , "Unable to enter background" );
834827#endif /* !WIN32 */
835828
836- if (!syslog_disabled )
837- /* not disabled: NUT_DEBUG_SYSLOG is unset or invalid */
838- xbit_set (& upslog_flags , UPSLOG_SYSLOG );
839- if (stderr_disabled )
840- /* NUT_DEBUG_SYSLOG="none" or unset/invalid */
841- xbit_clear (& upslog_flags , UPSLOG_STDERR );
829+ return pid ;
830+ }
842831
832+ /* close ttys and become a daemon */
833+ void background (void )
834+ {
843835#ifndef WIN32
836+ int pid ;
837+
838+ pid = background_fork ();
844839 if (pid != 0 ) {
845840 /* parent */
846841 /* these are typically fds 0-2: */
@@ -849,9 +844,28 @@ void background(void)
849844 close (STDERR_FILENO );
850845 _exit (EXIT_SUCCESS );
851846 }
847+ #else /* WIN32 */
848+ NUT_WIN32_INCOMPLETE_MAYBE_NOT_APPLICABLE ();
849+ #endif /* WIN32 */
850+ background_child ();
851+ }
852+
853+ void background_child (void )
854+ {
855+ /* Normally we enable SYSLOG and disable STDERR,
856+ * unless NUT_DEBUG_SYSLOG envvar interferes as
857+ * interpreted in syslog_is_disabled() method: */
858+ int syslog_disabled = syslog_is_disabled (),
859+ stderr_disabled = (syslog_disabled == 0 || syslog_disabled == 2 );
852860
853- /* child */
861+ if (!syslog_disabled )
862+ /* not disabled: NUT_DEBUG_SYSLOG is unset or invalid */
863+ xbit_set (& upslog_flags , UPSLOG_SYSLOG );
864+ if (stderr_disabled )
865+ /* NUT_DEBUG_SYSLOG="none" or unset/invalid */
866+ xbit_clear (& upslog_flags , UPSLOG_STDERR );
854867
868+ #ifndef WIN32
855869 /* make fds 0-2 (typically) point somewhere defined */
856870# ifdef HAVE_DUP2
857871 /* system can close (if needed) and (re-)open a specific FD number */
0 commit comments