@@ -352,7 +352,7 @@ bool copy_file(const gchar* src, const gchar* dest) {
352
352
goto fail1 ;
353
353
}
354
354
355
- fd_dest = open (dest , O_WRONLY |O_CREAT |O_TRUNC , st . st_mode );
355
+ fd_dest = open (dest , O_WRONLY |O_CREAT |O_TRUNC , S_IWUSR );
356
356
if (-1 == fd_dest ) {
357
357
LOG (MOD "Unable to open destination file '%s'\n" , dest );
358
358
goto fail1 ;
@@ -364,6 +364,11 @@ bool copy_file(const gchar* src, const gchar* dest) {
364
364
goto fail2 ;
365
365
}
366
366
367
+ if (chmod (dest , st .st_mode ) != 0 ) {
368
+ LOG (MOD "Unable to chmod '%d' '%s'\n" , st .st_mode , dest );
369
+ goto fail2 ;
370
+ }
371
+
367
372
result = true;
368
373
369
374
fail2 :
@@ -561,15 +566,24 @@ bool is_first_boot(void) {
561
566
bool firstboot = false;
562
567
gchar * boot_id ;
563
568
gchar * first_boot_id ;
569
+ GString * boot_id_str ;
564
570
565
571
G_LOCK (first_boot_id_file );
566
572
567
573
if (stat (FIRST_BOOT_ID_FILE , & st ) != 0 ) {
568
574
firstboot = true;
569
- if (!copy_file (KERNEL_BOOT_ID_FILE , FIRST_BOOT_ID_FILE )) {
570
- LOG (MOD "Copy file '%s' failed\n" , KERNEL_BOOT_ID_FILE );
571
- return false;
575
+ if (!g_file_get_contents (KERNEL_BOOT_ID_FILE , & boot_id , NULL , NULL )) {
576
+ LOG (MOD "Unable to read file '%s'\n" , KERNEL_BOOT_ID_FILE );
572
577
}
578
+ boot_id_str = g_string_new (boot_id );
579
+ g_free (boot_id );
580
+ if (!write_file (boot_id_str , FIRST_BOOT_ID_FILE , O_CREAT |O_TRUNC |O_WRONLY , S_IRUSR |S_IWUSR )) {
581
+ LOG (MOD "Unable to save boot id\n" );
582
+ g_string_free (boot_id_str , true);
583
+ goto exit ;
584
+ }
585
+ g_string_free (boot_id_str , true);
586
+
573
587
} else {
574
588
if (!g_file_get_contents (KERNEL_BOOT_ID_FILE , & boot_id , NULL , NULL )) {
575
589
LOG (MOD "Unable to read file '%s'\n" , KERNEL_BOOT_ID_FILE );
@@ -588,6 +602,7 @@ bool is_first_boot(void) {
588
602
}
589
603
590
604
exit :
605
+ LOG (MOD "First boot: %s\n" , (firstboot ? "True" : "False" ));
591
606
G_UNLOCK (first_boot_id_file );
592
607
return firstboot ;
593
608
}
0 commit comments