@@ -409,6 +409,7 @@ int win_system(const char * command)
409409 si .cb = sizeof (si );
410410 memset (& pi , 0 , sizeof (pi ));
411411
412+ upsdebugx (4 , "%s: calling CreateProcess: %s" , __func__ , NUT_STRARG (command ));
412413 res = CreateProcess (NULL , (char * )command , NULL , NULL , FALSE, 0 , NULL , NULL , & si , & pi );
413414
414415 if (res != 0 ) {
@@ -478,6 +479,7 @@ void syslog(int priority, const char *fmt, ...)
478479 /* then comes the message */
479480 memcpy (buf1 + sizeof (DWORD ), buf2 , sizeof (buf2 ));
480481
482+ upsdebugx (6 , "%s: posting to event log NAMED_PIPE: '%s'" , __func__ , pipe_full_name );
481483 pipe = CreateFile (
482484 pipe_full_name , /* pipe name */
483485 GENERIC_WRITE ,
@@ -496,6 +498,7 @@ void syslog(int priority, const char *fmt, ...)
496498 /* testing result is useless. If we have an error and try to report it,
497499 * this will probably lead to a call to this function and an infinite
498500 * loop */
501+ upsdebugx (6 , "%s: closing event log NAMED_PIPE" , __func__ );
499502 CloseHandle (pipe );
500503}
501504
@@ -530,6 +533,7 @@ void pipe_create(const char * pipe_name)
530533 CloseHandle (pipe_connection_overlapped .hEvent );
531534 }
532535 memset (& pipe_connection_overlapped , 0 , sizeof (pipe_connection_overlapped ));
536+ upsdebugx (2 , "%s: creating NAMED_PIPE (listener): '%s'" , __func__ , pipe_full_name );
533537 pipe_connection_handle = CreateNamedPipe (
534538 pipe_full_name ,
535539 PIPE_ACCESS_INBOUND /* to server only */
@@ -573,6 +577,12 @@ void pipe_connect()
573577 /* We have detected a connection on the opened pipe. So we start by saving its handle and create a new pipe for future connections */
574578 pipe_conn_t * conn ;
575579
580+ /* TOTHINK: Here we seem to have assumptions about a general connection
581+ * via overlapped I/O being the signal to daemon (via named_pipe_name)...
582+ * might this conflict with other I/Os (driver/server sockets, dummy-ups
583+ * files, etc.)?
584+ */
585+ upsdebugx (3 , "%s: handle incoming connection on NAMED PIPE" , __func__ );
576586 conn = xcalloc (1 , sizeof (* conn ));
577587 conn -> handle = pipe_connection_handle ;
578588
@@ -609,17 +619,22 @@ void pipe_connect()
609619
610620void pipe_disconnect (pipe_conn_t * conn )
611621{
622+ upsdebugx (3 , "%s: starting" , __func__ );
623+
612624 if (conn -> overlapped .hEvent != INVALID_HANDLE_VALUE ) {
625+ upsdebugx (4 , "%s: calling CloseHandle() for conn->overlapped.hEvent" , __func__ );
613626 CloseHandle (conn -> overlapped .hEvent );
614627 conn -> overlapped .hEvent = INVALID_HANDLE_VALUE ;
615628 }
616629
617630 if (conn -> handle != INVALID_HANDLE_VALUE ) {
631+ upsdebugx (4 , "%s: calling DisconnectNamedPipe() for not-yet-invalid conn->handle" , __func__ );
618632 if (DisconnectNamedPipe (conn -> handle ) == 0 ) {
619633 upslogx (LOG_ERR ,
620634 "DisconnectNamedPipe error : %d" ,
621635 (int )GetLastError ());
622636 }
637+ upsdebugx (4 , "%s: calling CloseHandle() for conn->handle" , __func__ );
623638 CloseHandle (conn -> handle );
624639 conn -> handle = INVALID_HANDLE_VALUE ;
625640 }
@@ -665,6 +680,7 @@ int send_to_named_pipe(const char * pipe_name, const char * data)
665680
666681 snprintf (pipe_full_name , sizeof (pipe_full_name ), "\\\\.\\pipe\\%s" , pipe_name );
667682
683+ upsdebugx (6 , "%s: posting to NAMED_PIPE: '%s'" , __func__ , pipe_full_name );
668684 pipe = CreateFile (
669685 pipe_full_name ,
670686 GENERIC_WRITE ,
@@ -686,6 +702,7 @@ int send_to_named_pipe(const char * pipe_name, const char * data)
686702 return 1 ;
687703 }
688704
705+ upsdebugx (6 , "%s: closing event log NAMED_PIPE" , __func__ );
689706 CloseHandle (pipe );
690707 return 0 ;
691708}
0 commit comments