Skip to content

Commit 6aada97

Browse files
committed
Use relative paths to boot mount point
This reduces the amount of string formatting. It also avoids the awkward "//rootfs.squashfs" string when running from a system partition (where boot_mount is "/").
1 parent 1c69ee9 commit 6aada97

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

mininit.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,15 @@ int create_mount_point(const char *path)
4040
return 0;
4141
}
4242

43-
void perform_updates(const char *boot_mount, bool is_backup)
43+
void perform_updates(bool is_backup)
4444
{
45-
if (chdir(boot_mount)) {
46-
ERROR("Unable to change to '%s' directory: %d\n", boot_mount, errno);
47-
return;
48-
}
49-
5045
bool update_modules = !access("update_m.bin", R_OK);
5146
bool update_rootfs = !access("update_r.bin", R_OK);
5247
if (!update_modules && !update_rootfs) return;
5348

54-
DEBUG("Remounting '%s' read-write\n", boot_mount);
55-
if (mount(NULL, boot_mount, NULL, MS_REMOUNT | MS_NOATIME, NULL)) {
56-
ERROR("Unable to remount '%s' read-write: %d\n", boot_mount, errno);
49+
DEBUG("Remounting boot device read-write\n");
50+
if (mount(NULL, ".", NULL, MS_REMOUNT | MS_NOATIME, NULL)) {
51+
ERROR("Unable to remount boot device read-write: %d\n", errno);
5752
return;
5853
}
5954

@@ -81,9 +76,9 @@ void perform_updates(const char *boot_mount, bool is_backup)
8176

8277
sync();
8378

84-
DEBUG("Remounting '%s' read-only\n", boot_mount);
85-
if (mount(NULL, boot_mount, NULL, MS_REMOUNT | MS_RDONLY, NULL)) {
86-
ERROR("Unable to remount '%s' read-only: %d\n", boot_mount, errno);
79+
DEBUG("Remounting boot device read-only\n");
80+
if (mount(NULL, ".", NULL, MS_REMOUNT | MS_RDONLY, NULL)) {
81+
ERROR("Unable to remount boot device read-only: %d\n", errno);
8782
}
8883
}
8984

@@ -117,7 +112,12 @@ int main(int argc, char **argv, char **envp)
117112
return -1;
118113
}
119114

120-
perform_updates(boot_mount, is_backup);
115+
if (chdir(boot_mount)) {
116+
ERROR("Unable to change to '%s' directory: %d\n", boot_mount, errno);
117+
return -1;
118+
}
119+
120+
perform_updates(is_backup);
121121

122122
/* Get free loop device. */
123123
int devnr = logetfree();
@@ -134,9 +134,7 @@ int main(int argc, char **argv, char **envp)
134134
is_backup && !access(ROOTFS_BACKUP, F_OK)
135135
? ROOTFS_BACKUP
136136
: ROOTFS_CURRENT;
137-
char rootfs_path[strlen(boot_mount) + 1 + strlen(rootfs_img) + 1];
138-
sprintf(rootfs_path, "%s/%s", boot_mount, rootfs_img);
139-
losetup(loop_dev, rootfs_path);
137+
losetup(loop_dev, rootfs_img);
140138

141139
/* Mount the loop device that was just set up. */
142140
if (mount(loop_dev, "/root", ROOTFS_TYPE, MS_RDONLY, NULL)) {

0 commit comments

Comments
 (0)