Skip to content

Commit 1c69ee9

Browse files
committed
Clean up logging
Do not use "." or "!" at the end of a log message. Log the error code if one is available.
1 parent 6bd3523 commit 1c69ee9

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

initramfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const char *mount_boot()
7070
return NULL;
7171
}
7272
} else {
73-
ERROR("'boot' parameter not found.\n");
73+
ERROR("'boot' parameter not found\n");
7474
return NULL;
7575
}
7676

loop.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ int logetfree()
1313
{
1414
int fd = open("/dev/loop-control", O_RDWR);
1515
if (fd < 0) {
16-
WARNING("Failed to open /dev/loop-control.\n");
16+
WARNING("Failed to open '/dev/loop-control': %d\n", fd);
1717
return -1;
1818
}
1919

2020
int devnr = ioctl(fd, LOOP_CTL_GET_FREE);
2121
if (devnr < 0) {
22-
WARNING("Failed to acquire free loop device.\n");
22+
WARNING("Failed to acquire free loop device: %d\n", devnr);
2323
} else {
24-
DEBUG("Got free loop device: %d.\n", devnr);
24+
DEBUG("Got free loop device: %d\n", devnr);
2525
}
2626

2727
close(fd);
@@ -30,24 +30,24 @@ int logetfree()
3030

3131
int losetup(const char *loop, const char *file)
3232
{
33-
DEBUG("Setting up loop: '%s' via '%s'.\n", file, loop);
33+
DEBUG("Setting up loop: '%s' via '%s'\n", file, loop);
3434

3535
int filefd = open(file, O_RDONLY);
3636
if (filefd < 0) {
37-
ERROR("losetup: cannot open '%s'.\n", file);
37+
ERROR("losetup: cannot open '%s': %d\n", file, filefd);
3838
return -1;
3939
}
4040

4141
int loopfd = open(loop, O_RDONLY);
4242
if (loopfd < 0) {
43-
ERROR("losetup: cannot open '%s'.\n", loop);
43+
ERROR("losetup: cannot open '%s': %d\n", loop, loopfd);
4444
close(filefd);
4545
return -1;
4646
}
4747

4848
int res = ioctl(loopfd, LOOP_SET_FD, filefd);
4949
if (res < 0) {
50-
ERROR("Cannot setup loop device '%s'.\n", loop);
50+
ERROR("Cannot setup loop device '%s': %d\n", loop, res);
5151
}
5252

5353
close(loopfd);

mininit.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ int create_mount_point(const char *path)
4242

4343
void perform_updates(const char *boot_mount, bool is_backup)
4444
{
45-
if (chdir(boot_mount) < 0) {
46-
ERROR("Unable to change to '%s' directory.\n", boot_mount);
45+
if (chdir(boot_mount)) {
46+
ERROR("Unable to change to '%s' directory: %d\n", boot_mount, errno);
4747
return;
4848
}
4949

@@ -53,20 +53,20 @@ void perform_updates(const char *boot_mount, bool is_backup)
5353

5454
DEBUG("Remounting '%s' read-write\n", boot_mount);
5555
if (mount(NULL, boot_mount, NULL, MS_REMOUNT | MS_NOATIME, NULL)) {
56-
ERROR("Unable to remount '%s' read-write.\n", boot_mount);
56+
ERROR("Unable to remount '%s' read-write: %d\n", boot_mount, errno);
5757
return;
5858
}
5959

6060
if (update_modules) {
61-
DEBUG("Modules update found!\n");
61+
DEBUG("Modules update found\n");
6262
rename("modules.squashfs", "modules.squashfs.bak");
6363
rename("modules.squashfs.sha1", "modules.squashfs.bak.sha1");
6464
rename("update_m.bin", "modules.squashfs");
6565
rename("update_m.bin.sha1", "modules.squashfs.sha1");
6666
}
6767

6868
if (update_rootfs) {
69-
DEBUG("RootFS update found!\n");
69+
DEBUG("RootFS update found\n");
7070

7171
/* If rootfs_bak was not passed, or the backup is not available,
7272
* make a backup of the current rootfs before the update */
@@ -83,7 +83,7 @@ void perform_updates(const char *boot_mount, bool is_backup)
8383

8484
DEBUG("Remounting '%s' read-only\n", boot_mount);
8585
if (mount(NULL, boot_mount, NULL, MS_REMOUNT | MS_RDONLY, NULL)) {
86-
ERROR("Unable to remount '%s' read-only.\n", boot_mount);
86+
ERROR("Unable to remount '%s' read-only: %d\n", boot_mount, errno);
8787
}
8888
}
8989

@@ -140,7 +140,7 @@ int main(int argc, char **argv, char **envp)
140140

141141
/* Mount the loop device that was just set up. */
142142
if (mount(loop_dev, "/root", ROOTFS_TYPE, MS_RDONLY, NULL)) {
143-
ERROR("Failed to mount the rootfs image.\n");
143+
ERROR("Failed to mount the rootfs image: %d\n", errno);
144144
return -1;
145145
}
146146

@@ -153,18 +153,18 @@ int main(int argc, char **argv, char **envp)
153153
/* Move the devtmpfs mount to inside the rootfs tree. */
154154
DEBUG("Moving '/dev' mount\n");
155155
if (mount("/dev", "dev", NULL, MS_MOVE, NULL)) {
156-
ERROR("Unable to move the '/dev' mount.\n");
156+
ERROR("Unable to move the '/dev' mount: %d\n", errno);
157157
return -1;
158158
}
159159

160160
/* Re-open the console device at the new location. */
161161
int fd = open("dev/console", O_RDWR, 0);
162162
if (fd < 0) {
163-
ERROR("Unable to re-open console.\n");
163+
ERROR("Unable to re-open console: %d\n", fd);
164164
return -1;
165165
}
166166
if (dup2(fd, 0) != 0 || dup2(fd, 1) != 1 || dup2(fd, 2) != 2) {
167-
ERROR("Unable to duplicate console handles.\n");
167+
ERROR("Unable to duplicate console handles\n");
168168
return -1;
169169
}
170170
if (fd > 2) close(fd);
@@ -227,7 +227,7 @@ int main(int argc, char **argv, char **envp)
227227
};
228228
for (int i = 0; ; i++) {
229229
if (!inits[i]) {
230-
ERROR("Unable to find the 'init' executable.\n");
230+
ERROR("Unable to find the 'init' executable\n");
231231
return -1;
232232
}
233233
if (!access(inits[i], X_OK)) {
@@ -239,6 +239,6 @@ int main(int argc, char **argv, char **envp)
239239

240240
/* Execute the 'init' executable */
241241
execvpe(argv[0], argv, envp);
242-
ERROR("exec or init failed.\n");
242+
ERROR("Exec of 'init' failed: %d\n", errno);
243243
return 0;
244244
}

0 commit comments

Comments
 (0)