[LEDE-DEV] [PATCH 1/2] fstools: Replace strerror(errno) with %m format.

Rosen Penev rosenp at gmail.com
Sat Dec 9 20:54:41 PST 2017


Saves 1472 bytes under glibc. No other difference.

Signed-off-by: Rosen Penev <rosenp at gmail.com>
---
 block.c              | 32 ++++++++++++++++----------------
 jffs2reset.c         |  2 +-
 libfstools/find.c    |  2 +-
 libfstools/mount.c   |  7 +++----
 libfstools/mtd.c     |  4 ++--
 libfstools/overlay.c | 20 ++++++++++----------
 snapshot.c           |  2 +-
 7 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/block.c b/block.c
index d7a9c5f..ab130b9 100644
--- a/block.c
+++ b/block.c
@@ -1052,8 +1052,8 @@ static int mount_device(struct probe_info *pr, int type)
 
 		err = handle_mount(pr->dev, target, pr->type, m);
 		if (err)
-			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
-			         pr->dev, pr->type, target, errno, strerror(errno));
+			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %m\n",
+			         pr->dev, pr->type, target, errno);
 		else
 			handle_swapfiles(true);
 		return err;
@@ -1071,8 +1071,8 @@ static int mount_device(struct probe_info *pr, int type)
 
 		err = handle_mount(pr->dev, target, pr->type, NULL);
 		if (err)
-			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %s\n",
-			         pr->dev, pr->type, target, errno, strerror(errno));
+			ULOG_ERR("mounting %s (%s) as %s failed (%d) - %m\n",
+			         pr->dev, pr->type, target, errno);
 		else
 			handle_swapfiles(true);
 		return err;
@@ -1104,8 +1104,8 @@ static int umount_device(struct probe_info *pr)
 
 	err = umount2(mp, MNT_DETACH);
 	if (err)
-		ULOG_ERR("unmounting %s (%s)  failed (%d) - %s\n",
-		         pr->dev, mp, errno, strerror(errno));
+		ULOG_ERR("unmounting %s (%s)  failed (%d) - %m\n",
+		         pr->dev, mp, errno);
 	else
 		ULOG_INFO("unmounted %s (%s)\n",
 		          pr->dev, mp);
@@ -1134,8 +1134,8 @@ static int mount_action(char *action, char *device, int type)
 			err = umount2(mount_point, MNT_DETACH);
 
 		if (err)
-			ULOG_ERR("umount of %s failed (%d) - %s\n",
-			         mount_point, errno, strerror(errno));
+			ULOG_ERR("umount of %s failed (%d) - %m\n",
+			         mount_point, errno);
 
 		free(mount_point);
 		return 0;
@@ -1360,8 +1360,8 @@ static int check_extroot(char *path)
 			if (stat(tag, &s)) {
 				fp = fopen(tag, "w+");
 				if (!fp) {
-					ULOG_ERR("extroot: failed to write UUID to %s: %d (%s)\n",
-					         tag, errno, strerror(errno));
+					ULOG_ERR("extroot: failed to write UUID to %s: %d (%m)\n",
+					         tag, errno);
 					/* return 0 to continue boot regardless of error */
 					return 0;
 				}
@@ -1372,14 +1372,14 @@ static int check_extroot(char *path)
 
 			fp = fopen(tag, "r");
 			if (!fp) {
-				ULOG_ERR("extroot: failed to read UUID from %s: %d (%s)\n",
-				         tag, errno, strerror(errno));
+				ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n",
+				         tag, errno);
 				return -1;
 			}
 
 			if (!fgets(uuid, sizeof(uuid), fp))
-				ULOG_ERR("extroot: failed to read UUID from %s: %d (%s)\n",
-				         tag, errno, strerror(errno));
+				ULOG_ERR("extroot: failed to read UUID from %s: %d (%m)\n",
+				         tag, errno);
 			fclose(fp);
 
 			if (*uuid && !strcasecmp(uuid, pr->uuid))
@@ -1457,8 +1457,8 @@ static int mount_extroot(char *cfg)
 		            (m->options) ? (m->options) : (""));
 
 		if (err) {
-			ULOG_ERR("extroot: mounting %s (%s) on %s failed: %d (%s)\n",
-			         pr->dev, pr->type, path, errno, strerror(errno));
+			ULOG_ERR("extroot: mounting %s (%s) on %s failed: %d (%m)\n",
+			         pr->dev, pr->type, path, errno);
 		} else if (m->overlay) {
 			err = check_extroot(path);
 			if (err)
diff --git a/jffs2reset.c b/jffs2reset.c
index 9a31fdd..dbe0498 100644
--- a/jffs2reset.c
+++ b/jffs2reset.c
@@ -83,7 +83,7 @@ static int jffs2_mark(struct volume *v)
 	close(fd);
 
 	if (sz != 4) {
-		ULOG_ERR("writing %s failed: %s\n", v->blk, strerror(errno));
+		ULOG_ERR("writing %s failed: %m\n", v->blk);
 		return -1;
 	}
 
diff --git a/libfstools/find.c b/libfstools/find.c
index fcc47a7..b383f57 100644
--- a/libfstools/find.c
+++ b/libfstools/find.c
@@ -223,7 +223,7 @@ find_filesystem(char *fs)
 	int ret = -1;
 
 	if (!fp) {
-		ULOG_ERR("opening /proc/filesystems failed: %s\n", strerror(errno));
+		ULOG_ERR("opening /proc/filesystems failed: %m\n");
 		goto out;
 	}
 
diff --git a/libfstools/mount.c b/libfstools/mount.c
index 551f4e7..4dc6e3a 100644
--- a/libfstools/mount.c
+++ b/libfstools/mount.c
@@ -54,7 +54,7 @@ mount_move(char *oldroot, char *newroot, char *dir)
 	ret = mount(olddir, newdir, NULL, MS_NOATIME | MS_MOVE, NULL);
 
 /*	if (ret)
-		ULOG_ERR("failed %s %s: %s\n", olddir, newdir, strerror(errno));*/
+		ULOG_ERR("failed %s %s: %m\n", olddir, newdir);*/
 
 	return ret;
 }
@@ -73,7 +73,7 @@ pivot(char *new, char *old)
 	ret = pivot_root(new, pivotdir);
 
 	if (ret < 0) {
-		ULOG_ERR("pivot_root failed %s %s: %s\n", new, pivotdir, strerror(errno));
+		ULOG_ERR("pivot_root failed %s %s: %m\n", new, pivotdir);
 		return -1;
 	}
 
@@ -136,8 +136,7 @@ fopivot(char *rw_root, char *ro_root)
 		/* Mainlined overlayfs has been renamed to "overlay", try that first */
 		if (mount(overlay, "/mnt", "overlay", MS_NOATIME, mount_options)) {
 			if (mount(overlay, "/mnt", "overlayfs", MS_NOATIME, mount_options)) {
-				ULOG_ERR("mount failed: %s, options %s\n",
-				         strerror(errno), mount_options);
+				ULOG_ERR("mount failed: %s, options %m\n", mount_options);
 				return -1;
 			}
 		}
diff --git a/libfstools/mtd.c b/libfstools/mtd.c
index 2603a15..77c71ee 100644
--- a/libfstools/mtd.c
+++ b/libfstools/mtd.c
@@ -198,7 +198,7 @@ static int mtd_volume_identify(struct volume *v)
 	sz = read(p->fd, &deadc0de, sizeof(deadc0de));
 
 	if (sz != sizeof(deadc0de)) {
-		ULOG_ERR("reading %s failed: %s\n", v->name, strerror(errno));
+		ULOG_ERR("reading %s failed: %m\n", v->name);
 		return -1;
 	}
 
@@ -275,7 +275,7 @@ static int mtd_volume_init(struct volume *v)
 
 	ret = ioctl(p->fd, MEMGETINFO, &mtdinfo);
 	if (ret) {
-		ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %s\n", p->fd, strerror(errno));
+		ULOG_ERR("ioctl(%d, MEMGETINFO) failed: %m\n", p->fd);
 	} else {
 		struct erase_info_user mtdlock;
 
diff --git a/libfstools/overlay.c b/libfstools/overlay.c
index 5a49da2..7ada5ff 100644
--- a/libfstools/overlay.c
+++ b/libfstools/overlay.c
@@ -102,12 +102,12 @@ static int
 overlay_mount(struct volume *v, char *fs)
 {
 	if (mkdir("/tmp/overlay", 0755)) {
-		ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno));
+		ULOG_ERR("failed to mkdir /tmp/overlay: %m\n");
 		return -1;
 	}
 
 	if (mount(v->blk, "/tmp/overlay", fs, MS_NOATIME, NULL)) {
-		ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n", fs, v->blk, strerror(errno));
+		ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %m\n", fs, v->blk);
 		return -1;
 	}
 
@@ -129,27 +129,27 @@ switch2jffs(struct volume *v)
 	ret = mount(v->blk, "/rom/overlay", "jffs2", MS_NOATIME, NULL);
 	unlink("/tmp/.switch_jffs2");
 	if (ret) {
-		ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %s\n", v->blk, strerror(errno));
+		ULOG_ERR("failed - mount -t jffs2 %s /rom/overlay: %m\n", v->blk);
 		return -1;
 	}
 
 	if (mount("none", "/", NULL, MS_NOATIME | MS_REMOUNT, 0)) {
-		ULOG_ERR("failed - mount -o remount,ro none: %s\n", strerror(errno));
+		ULOG_ERR("failed - mount -o remount,ro none: %m\n");
 		return -1;
 	}
 
 	if (system("cp -a /tmp/root/* /rom/overlay")) {
-		ULOG_ERR("failed - cp -a /tmp/root/* /rom/overlay: %s\n", strerror(errno));
+		ULOG_ERR("failed - cp -a /tmp/root/* /rom/overlay: %m\n");
 		return -1;
 	}
 
 	if (pivot("/rom", "/mnt")) {
-		ULOG_ERR("failed - pivot /rom /mnt: %s\n", strerror(errno));
+		ULOG_ERR("failed - pivot /rom /mnt: %m\n");
 		return -1;
 	}
 
 	if (mount_move("/mnt", "/tmp/root", "")) {
-		ULOG_ERR("failed - mount -o move /mnt /tmp/root %s\n", strerror(errno));
+		ULOG_ERR("failed - mount -o move /mnt /tmp/root %m\n");
 		return -1;
 	}
 
@@ -267,13 +267,13 @@ static int overlay_mount_fs(struct volume *v)
 	char *fstype = overlay_fs_name(volume_identify(v));
 
 	if (mkdir("/tmp/overlay", 0755)) {
-		ULOG_ERR("failed to mkdir /tmp/overlay: %s\n", strerror(errno));
+		ULOG_ERR("failed to mkdir /tmp/overlay: %m\n");
 		return -1;
 	}
 
 	if (mount(v->blk, "/tmp/overlay", fstype, MS_NOATIME, NULL)) {
-		ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %s\n",
-		         fstype, v->blk, strerror(errno));
+		ULOG_ERR("failed to mount -t %s %s /tmp/overlay: %m\n",
+		         fstype, v->blk);
 		return -1;
 	}
 
diff --git a/snapshot.c b/snapshot.c
index bb44cd3..df555e2 100644
--- a/snapshot.c
+++ b/snapshot.c
@@ -136,7 +136,7 @@ snapshot_mark(int argc, char **argv)
 	close(fd);
 
 	if (sz != 1) {
-		ULOG_ERR("writing %s failed: %s\n", v->blk, strerror(errno));
+		ULOG_ERR("writing %s failed: %m\n", v->blk);
 		return -1;
 	}
 
-- 
2.7.4




More information about the Lede-dev mailing list