@@ -71,7 +71,7 @@ static conn_t *connhead = NULL;
71
71
static char * cmdscript = NULL , * pipefn = NULL , * lockfn = NULL ;
72
72
73
73
/* 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 ;
75
75
76
76
#ifdef WIN32
77
77
static OVERLAPPED connect_overlapped ;
@@ -873,6 +873,7 @@ static void start_daemon(TYPE_FD lockfd)
873
873
# endif /* not HAVE_DUP */
874
874
# endif /* not HAVE_DUP2 */
875
875
876
+ /* Still in child, non-WIN32 - work as timer daemon (infinite loop) */
876
877
pipefd = open_sock ();
877
878
878
879
if (nut_debug_level )
@@ -884,6 +885,13 @@ static void start_daemon(TYPE_FD lockfd)
884
885
/* drop the lock now that the background is running */
885
886
unlink (lockfn );
886
887
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" );
887
895
888
896
/* now watch for activity */
889
897
upsdebugx (2 , "Timer daemon waiting for connections on pipefd %d" ,
@@ -988,6 +996,13 @@ static void start_daemon(TYPE_FD lockfd)
988
996
/* drop the lock now that the background is running */
989
997
CloseHandle (lockfd );
990
998
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" );
991
1006
992
1007
/* now watch for activity */
993
1008
@@ -1513,9 +1528,13 @@ static void help(const char *arg_progname)
1513
1528
1514
1529
int main (int argc , char * * argv )
1515
1530
{
1516
- const char * prog = xbasename (argv [0 ]);
1517
1531
int i ;
1518
1532
1533
+ if (argc > 0 )
1534
+ prog = xbasename (argv [0 ]);
1535
+ if (!prog )
1536
+ prog = "upssched" ;
1537
+
1519
1538
while ((i = getopt (argc , argv , "+DVh" )) != -1 ) {
1520
1539
switch (i ) {
1521
1540
case 'D' :
0 commit comments