Skip to content

Commit 9cf9d1e

Browse files
author
Julio Montes
committed
fix copy kernel boot id
fix copy_file function to set mode after sendfile
1 parent 448b906 commit 9cf9d1e

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/lib.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ bool copy_file(const gchar* src, const gchar* dest) {
352352
goto fail1;
353353
}
354354

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);
356356
if (-1 == fd_dest) {
357357
LOG(MOD "Unable to open destination file '%s'\n", dest);
358358
goto fail1;
@@ -364,6 +364,11 @@ bool copy_file(const gchar* src, const gchar* dest) {
364364
goto fail2;
365365
}
366366

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+
367372
result = true;
368373

369374
fail2:
@@ -561,15 +566,24 @@ bool is_first_boot(void) {
561566
bool firstboot = false;
562567
gchar* boot_id;
563568
gchar* first_boot_id;
569+
GString* boot_id_str;
564570

565571
G_LOCK(first_boot_id_file);
566572

567573
if (stat(FIRST_BOOT_ID_FILE, &st) != 0) {
568574
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);
572577
}
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+
573587
} else {
574588
if (!g_file_get_contents(KERNEL_BOOT_ID_FILE, &boot_id, NULL, NULL)) {
575589
LOG(MOD "Unable to read file '%s'\n", KERNEL_BOOT_ID_FILE);
@@ -588,6 +602,7 @@ bool is_first_boot(void) {
588602
}
589603

590604
exit:
605+
LOG(MOD "First boot: %s\n", (firstboot ? "True" : "False" ));
591606
G_UNLOCK(first_boot_id_file);
592607
return firstboot;
593608
}

0 commit comments

Comments
 (0)