@@ -71,7 +71,7 @@ static conn_t *connhead = NULL;
7171static char * cmdscript = NULL , * pipefn = NULL , * lockfn = NULL ;
7272
7373/* ups name and notify type (string) as received from upsmon */
74- static const char * upsname , * notify_type ;
74+ static const char * upsname , * notify_type , * prog = NULL ;
7575
7676#ifdef WIN32
7777static OVERLAPPED connect_overlapped ;
@@ -873,6 +873,7 @@ static void start_daemon(TYPE_FD lockfd)
873873# endif /* not HAVE_DUP */
874874# endif /* not HAVE_DUP2 */
875875
876+ /* Still in child, non-WIN32 - work as timer daemon (infinite loop) */
876877 pipefd = open_sock ();
877878
878879 if (nut_debug_level )
@@ -884,6 +885,13 @@ static void start_daemon(TYPE_FD lockfd)
884885 /* drop the lock now that the background is running */
885886 unlink (lockfn );
886887 close (lockfd );
888+ writepid (prog );
889+
890+ /* Whatever upsmon envvars were set when this daemon started, would be
891+ * irrelevant and only confusing at the moment a particular timer causes
892+ * CMDSCRIPT to run */
893+ unsetenv ("NOTIFYTYPE" );
894+ unsetenv ("UPSNAME" );
887895
888896 /* now watch for activity */
889897 upsdebugx (2 , "Timer daemon waiting for connections on pipefd %d" ,
@@ -988,6 +996,13 @@ static void start_daemon(TYPE_FD lockfd)
988996 /* drop the lock now that the background is running */
989997 CloseHandle (lockfd );
990998 DeleteFile (lockfn );
999+ writepid (prog );
1000+
1001+ /* Whatever upsmon envvars were set when this daemon started, would be
1002+ * irrelevant and only confusing at the moment a particular timer causes
1003+ * CMDSCRIPT to run */
1004+ unsetenv ("NOTIFYTYPE" );
1005+ unsetenv ("UPSNAME" );
9911006
9921007 /* now watch for activity */
9931008
@@ -1513,9 +1528,13 @@ static void help(const char *arg_progname)
15131528
15141529int main (int argc , char * * argv )
15151530{
1516- const char * prog = xbasename (argv [0 ]);
15171531 int i ;
15181532
1533+ if (argc > 0 )
1534+ prog = xbasename (argv [0 ]);
1535+ if (!prog )
1536+ prog = "upssched" ;
1537+
15191538 while ((i = getopt (argc , argv , "+DVh" )) != -1 ) {
15201539 switch (i ) {
15211540 case 'D' :
0 commit comments