@@ -170,35 +170,44 @@ static void file_save(void *arg)
170170static  void  file_restore (void  * arg )
171171{
172172	struct  tm  tm  =  { 0  };
173- 	int  rc  =  1 ;
173+ 	int  rc  =  0 ;
174174	FILE  * fp ;
175+ 	char  msg [120 ];
175176
176177	if  (!rtc_file ) {
177- 		logit (LOG_NOTICE , "System has no RTC (missing driver?), skipping restore." );
178+ 		snprintf (msg , sizeof (msg ), "Resetting system clock to kernel default, %s." , rtc_timestamp );
179+ 		print_desc (NULL , msg );
180+ 		rc  =  time_set (NULL );
181+ 		print (rc , NULL );
178182		return ;
179183	}
180184
181- 	print_desc (NULL , "Restoring system clock from backup" );
182- 
183185	fp  =  fopen (rtc_file , "r" );
184186	if  (fp ) {
185187		char  buf [32 ];
186188
187189		if  (fgets (buf , sizeof (buf ), fp )) {
188190			chomp (buf );
189191			strptime (buf , RTC_FMT , & tm );
190- 			rc  =  time_set (& tm );
192+ 			if  (!strptime (buf , RTC_FMT , & tm ))
193+ 				rc  =  1 ;
191194		}
192195		fclose (fp );
193- 	}  else 
194- 		logit ( LOG_WARNING ,  "Missing %s" ,  rtc_file ) ;
196+ 	}
197+ 		rc   =   1 ;
195198
196199	if  (rc ) {
197- 		time_set (NULL );
198- 		rc  =  2 ;
200+ 		print_desc (NULL , "Failed to restore system clock from restore file" );
201+ 		print (2 , NULL );
202+ 		snprintf (msg , sizeof (msg ), "Resetting system clock to kernel default, %s." , rtc_timestamp );
203+ 		print_desc (NULL , msg );
204+ 		rc  =  time_set (NULL );
205+ 		print (rc , NULL );
206+ 	} else  {
207+ 		print_desc (NULL , "Restoring system clock from restore file" );
208+ 		rc  =  time_set (& tm );
209+ 		print (rc , NULL );
199210	}
200- 
201- 	print (rc , NULL );
202211}
203212
204213static  int  rtc_open (void )
@@ -292,8 +301,7 @@ static void rtc_restore(void *arg)
292301		print (2 , NULL );
293302
294303		/* Try restoring from last save game */ 
295- 		if  (rtc_file )
296- 			file_restore (arg );
304+ 		file_restore (arg );
297305	} else 
298306		print (0 , NULL );
299307
0 commit comments