@@ -27,7 +27,7 @@ static uev_t period_watcher;
27
27
static uev_t timeout_watcher ;
28
28
static struct watchdog_info info ;
29
29
30
- /* Actual reset reason as read at boot, reported by supervisor API */
30
+ /* Watchdogd reset reason as read at boot */
31
31
wdog_reason_t reset_reason ;
32
32
wdog_code_t reset_code = WDOG_SYSTEM_OK ;
33
33
unsigned int reset_counter = 0 ;
@@ -38,10 +38,9 @@ unsigned int reset_counter = 0;
38
38
int wdt_open (const char * dev )
39
39
{
40
40
static int once = 0 ;
41
- static int cause = 0 ;
42
41
43
42
if (fd >= 0 )
44
- return cause ;
43
+ return 0 ;
45
44
46
45
if (dev ) {
47
46
if (!strncmp (dev , "/dev" , 4 ))
@@ -93,8 +92,7 @@ int wdt_open(const char *dev)
93
92
if (!wdt_capability (WDIOF_POWERUNDER ))
94
93
WARN ("WDT does not support PWR fail condition, treating as card reset." );
95
94
96
- /* Read boot cause from watchdog ... */
97
- return cause = wdt_get_bootstatus ();
95
+ return 0 ;
98
96
}
99
97
100
98
static void period_cb (uev_t * w , void * arg , int event )
@@ -108,13 +106,13 @@ static void period_cb(uev_t *w, void *arg, int event)
108
106
*/
109
107
int wdt_init (uev_ctx_t * ctx , const char * dev )
110
108
{
111
- int T , cause ;
109
+ int T , err ;
112
110
113
111
if (wdt_testmode ())
114
112
return 0 ;
115
113
116
- cause = wdt_open (dev );
117
- if (cause < 0 )
114
+ err = wdt_open (dev );
115
+ if (err )
118
116
return 1 ;
119
117
120
118
/* Set requested WDT timeout right before we enter the event loop. */
@@ -145,7 +143,7 @@ int wdt_init(uev_ctx_t *ctx, const char *dev)
145
143
return 0 ;
146
144
147
145
/* Save/update /run/watchdogd.status */
148
- wdt_set_bootstatus (cause , timeout , period );
146
+ wdt_set_bootstatus (timeout , period );
149
147
150
148
/* Calculate period (T) in milliseconds for libuEv */
151
149
T = period * 1000 ;
@@ -246,13 +244,13 @@ int wdt_fload_reason(FILE *fp, wdog_reason_t *r, pid_t *pid)
246
244
pid = & dummy ;
247
245
248
246
while ((ptr = fgets (buf , sizeof (buf ), fp ))) {
249
- if (sscanf (buf , WDT_REASON_CNT ": %u\n" , & r -> counter ) == 1 )
247
+ if (sscanf (buf , WDT_RESETCOUNT ": %u\n" , & r -> counter ) == 1 )
250
248
continue ;
251
249
if (sscanf (buf , WDT_REASON_PID ": %d\n" , pid ) == 1 )
252
250
continue ;
253
251
if (sscanf (buf , WDT_REASON_WID ": %d\n" , & r -> wid ) == 1 )
254
252
continue ;
255
- if (sscanf (buf , WDT_REASON_CSE ": %d\n" , (int * )& r -> code ) == 1 )
253
+ if (sscanf (buf , WDT_REASON_STR ": %d\n" , (int * )& r -> code ) == 1 )
256
254
continue ;
257
255
258
256
if (string_match (buf , WDT_REASON_LBL ": " )) {
@@ -261,8 +259,8 @@ int wdt_fload_reason(FILE *fp, wdog_reason_t *r, pid_t *pid)
261
259
continue ;
262
260
}
263
261
264
- if (string_match (buf , WDT_REASON_TME ": " )) {
265
- ptr += strlen (WDT_REASON_TME ) + 2 ;
262
+ if (string_match (buf , WDT_RESET_DATE ": " )) {
263
+ ptr += strlen (WDT_RESET_DATE ) + 2 ;
266
264
strptime (chomp (ptr ), "%FT%TZ" , & r -> date );
267
265
continue ;
268
266
}
@@ -275,19 +273,27 @@ int wdt_fstore_reason(FILE *fp, wdog_reason_t *r, pid_t pid)
275
273
{
276
274
time_t now ;
277
275
278
- fprintf (fp , WDT_REASON_CNT ": %u\n" , r -> counter );
276
+ fprintf (fp , WDT_RESETCOUNT ": %u\n" , r -> counter );
279
277
now = time (NULL );
280
278
if (now != (time_t )- 1 ) {
281
279
char buf [25 ];
282
280
283
281
strftime (buf , sizeof buf , "%FT%TZ" , gmtime (& now ));
284
- fprintf (fp , WDT_REASON_TME ": %s\n" , buf );
282
+ fprintf (fp , WDT_RESET_DATE ": %s\n" , buf );
283
+ }
284
+ fprintf (fp , WDT_REASON_STR ": %d - %s\n" , r -> code , wdog_reset_reason_str (r ));
285
+ switch (r -> code ) {
286
+ case WDOG_FAILED_SUBSCRIPTION :
287
+ case WDOG_FAILED_KICK :
288
+ case WDOG_FAILED_UNSUBSCRIPTION :
289
+ case WDOG_FAILED_TO_MEET_DEADLINE :
290
+ fprintf (fp , WDT_REASON_PID ": %d\n" , pid );
291
+ fprintf (fp , WDT_REASON_WID ": %d\n" , r -> wid );
292
+ fprintf (fp , WDT_REASON_LBL ": %s\n" , r -> label );
293
+ break ;
294
+ default :
295
+ break ;
285
296
}
286
- fprintf (fp , WDT_REASON_PID ": %d\n" , pid );
287
- fprintf (fp , WDT_REASON_WID ": %d\n" , r -> wid );
288
- fprintf (fp , WDT_REASON_LBL ": %s\n" , r -> label );
289
- fprintf (fp , WDT_REASON_CSE ": %d\n" , r -> code );
290
- fprintf (fp , WDT_REASON_STR ": %s\n" , wdog_reset_reason_str (r ));
291
297
292
298
return fclose (fp );
293
299
}
@@ -326,6 +332,31 @@ static int compat_supervisor(wdog_reason_t *r)
326
332
#define compat_supervisor (r ) 0
327
333
#endif /* COMPAT_SUPERVISOR */
328
334
335
+ const char * bootstatus_string (int cause )
336
+ {
337
+ const char * str = NULL ;
338
+
339
+ if (cause & WDIOF_CARDRESET )
340
+ str = "WDIOF_CARDRESET" ;
341
+ if (cause & WDIOF_EXTERN1 )
342
+ str = "WDIOF_EXTERN1" ;
343
+ if (cause & WDIOF_EXTERN2 )
344
+ str = "WDIOF_EXTERN2" ;
345
+ if (cause & WDIOF_POWERUNDER )
346
+ str = "WDIOF_POWERUNDER" ;
347
+ if (cause & WDIOF_POWEROVER )
348
+ str = "WDIOF_POWEROVER" ;
349
+ if (cause & WDIOF_FANFAULT )
350
+ str = "WDIOF_FANFAULT" ;
351
+ if (cause & WDIOF_OVERHEAT )
352
+ str = "WDIOF_OVERHEAT" ;
353
+
354
+ if (!str )
355
+ str = "WDIOF_UNKNOWN" ;
356
+
357
+ return str ;
358
+ }
359
+
329
360
static int create_bootstatus (char * fn , wdog_reason_t * r , int cause , int timeout , int interval , pid_t pid )
330
361
{
331
362
FILE * fp ;
@@ -336,24 +367,29 @@ static int create_bootstatus(char *fn, wdog_reason_t *r, int cause, int timeout,
336
367
return -1 ;
337
368
}
338
369
339
- fprintf (fp , WDT_REASON_WDT ": 0x%04x\n" , cause >= 0 ? cause : 0 );
340
- fprintf (fp , WDT_REASON_TMO ": %d\n" , timeout );
341
- fprintf (fp , WDT_REASON_INT ": %d\n" , interval );
370
+ fprintf (fp , WDT_TMOSEC_OPT ": %d\n" , timeout );
371
+ fprintf (fp , WDT_INTSEC_OPT ": %d\n" , interval );
372
+ fprintf (fp , WDT_BOOTSTATUS ": 0x%04x\n" , cause >= 0 ? cause : 0 );
373
+ fprintf (fp , WDT_RESETCAUSE ": %s\n" , bootstatus_string (cause ));
342
374
343
375
return wdt_fstore_reason (fp , r , pid );
344
376
}
345
377
346
- int wdt_set_bootstatus (int cause , int timeout , int interval )
378
+ int wdt_set_bootstatus (int timeout , int interval )
347
379
{
380
+ wdog_reason_t reason ;
348
381
pid_t pid = 0 ;
349
382
char * status ;
350
- wdog_reason_t reason ;
383
+ int cause ;
351
384
352
385
if (wdt_testmode ())
353
386
status = WDOG_STATUS_TEST ;
354
387
else
355
388
status = WDOG_STATUS ;
356
389
390
+ cause = wdt_get_bootstatus ();
391
+ LOG ("Reset cause: 0x%04x - %s" , cause , bootstatus_string (cause ));
392
+
357
393
/*
358
394
* In case we're restarted at runtime this prevents us from
359
395
* recreating the status file(s).
@@ -403,32 +439,22 @@ int wdt_set_bootstatus(int cause, int timeout, int interval)
403
439
404
440
int wdt_get_bootstatus (void )
405
441
{
406
- int status = 0 ;
442
+ int cause ;
407
443
int err ;
408
444
409
445
if (wdt_testmode ())
410
- return status ;
446
+ return 0 ;
411
447
412
448
if (fd == -1 ) {
413
449
DEBUG ("Cannot get boot status, currently disabled." );
414
450
return 0 ;
415
451
}
416
452
417
- if ((err = ioctl (fd , WDIOC_GETBOOTSTATUS , & status )))
418
- status += err ;
419
-
420
- if (!err && status ) {
421
- if (status & WDIOF_POWERUNDER )
422
- LOG ("Reset cause: POWER-ON" );
423
- if (status & WDIOF_FANFAULT )
424
- LOG ("Reset cause: FAN-FAULT" );
425
- if (status & WDIOF_OVERHEAT )
426
- LOG ("Reset cause: CPU-OVERHEAT" );
427
- if (status & WDIOF_CARDRESET )
428
- LOG ("Reset cause: WATCHDOG" );
429
- }
453
+ err = ioctl (fd , WDIOC_GETBOOTSTATUS , & cause );
454
+ if (err )
455
+ return err ;
430
456
431
- return status ;
457
+ return cause ;
432
458
}
433
459
434
460
int wdt_enable (int enable )
0 commit comments