@@ -477,7 +477,7 @@ static ssize_t apc_read_i(char *buf, size_t buflen, int flags, const char *fn, u
477477 fatalx (EXIT_FAILURE , "Error: apc_read_i called with buflen too large" );
478478 }
479479
480- if (INVALID_FD (upsfd ))
480+ if (INVALID_FD_SER (upsfd ))
481481 return 0 ;
482482
483483 if (flags & SER_D0 ) {
@@ -605,7 +605,7 @@ static ssize_t apc_write_i(unsigned char code, const char *fn, unsigned int ln)
605605 ssize_t ret ;
606606 errno = 0 ;
607607
608- if (INVALID_FD (upsfd ))
608+ if (INVALID_FD_SER (upsfd ))
609609 return 0 ;
610610
611611 ret = ser_send_char (upsfd , code );
@@ -2301,6 +2301,13 @@ void upsdrv_initups(void)
23012301 }
23022302
23032303 upsfd = extrafd = ser_open (device_path );
2304+
2305+ if (INVALID_FD_SER (upsfd )) {
2306+ upslogx (LOG_WARNING , "%s: failed to open %s" ,
2307+ __func__ , device_path );
2308+ /* \todo: Deal with the failure */
2309+ }
2310+
23042311 apc_ser_set ();
23052312
23062313 /* fill length values */
@@ -2312,14 +2319,15 @@ void upsdrv_cleanup(void)
23122319{
23132320 char temp [APC_LBUF ];
23142321
2315- if (INVALID_FD (upsfd ))
2322+ if (INVALID_FD_SER (upsfd ))
23162323 return ;
23172324
23182325 apc_flush (0 );
23192326 /* try to bring the UPS out of smart mode */
23202327 apc_write (APC_GODUMB );
23212328 apc_read (temp , sizeof (temp ), SER_TO );
23222329 ser_close (upsfd , device_path );
2330+ upsfd = ERROR_FD_SER ;
23232331}
23242332
23252333void upsdrv_initinfo (void )
@@ -2412,6 +2420,12 @@ void upsdrv_updateinfo(void)
24122420 /* dstate_setinfo("driver.state", "init.info"); */
24132421 upsdrv_initinfo ();
24142422
2423+ if (INVALID_FD_SER (upsfd )) {
2424+ upsdebugx (1 , "%s: upsfd remains invalid" , __func__ );
2425+ dstate_datastale ();
2426+ return ;
2427+ }
2428+
24152429 reconnect_trying (RECONNECT_UPDATEINFO );
24162430 upsdebugx (1 , "%s: call upsdrv_updateinfo" , __func__ );
24172431 /* dstate_setinfo("driver.state", "init.updateinfo"); */
0 commit comments