diff options
author | James Byrne | 2019-07-02 11:35:03 +0200 |
---|---|---|
committer | Denys Vlasenko | 2019-07-02 11:35:03 +0200 |
commit | 6937487be73cd4563b876413277a295a5fe2f32c (patch) | |
tree | f16cc9999a7c827891e6ec8d99c699fc791008ee /util-linux/mount.c | |
parent | caecfdc20d450686cd1f7e9b5f650322f894b3c2 (diff) | |
download | busybox-6937487be73cd4563b876413277a295a5fe2f32c.zip busybox-6937487be73cd4563b876413277a295a5fe2f32c.tar.gz |
libbb: reduce the overhead of single parameter bb_error_msg() calls
Back in 2007, commit 0c97c9d43707 ("'simple' error message functions by
Loic Grenie") introduced bb_simple_perror_msg() to allow for a lower
overhead call to bb_perror_msg() when only a string was being printed
with no parameters. This saves space for some CPU architectures because
it avoids the overhead of a call to a variadic function. However there
has never been a simple version of bb_error_msg(), and since 2007 many
new calls to bb_perror_msg() have been added that only take a single
parameter and so could have been using bb_simple_perror_message().
This changeset introduces 'simple' versions of bb_info_msg(),
bb_error_msg(), bb_error_msg_and_die(), bb_herror_msg() and
bb_herror_msg_and_die(), and replaces all calls that only take a
single parameter, or use something like ("%s", arg), with calls to the
corresponding 'simple' version.
Since it is likely that single parameter calls to the variadic functions
may be accidentally reintroduced in the future a new debugging config
option WARN_SIMPLE_MSG has been introduced. This uses some macro magic
which will cause any such calls to generate a warning, but this is
turned off by default to avoid use of the unpleasant macros in normal
circumstances.
This is a large changeset due to the number of calls that have been
replaced. The only files that contain changes other than simple
substitution of function calls are libbb.h, libbb/herror_msg.c,
libbb/verror_msg.c and libbb/xfuncs_printf.c. In miscutils/devfsd.c,
networking/udhcp/common.h and util-linux/mdev.c additonal macros have
been added for logging so that single parameter and multiple parameter
logging variants exist.
The amount of space saved varies considerably by architecture, and was
found to be as follows (for 'defconfig' using GCC 7.4):
Arm: -92 bytes
MIPS: -52 bytes
PPC: -1836 bytes
x86_64: -938 bytes
Note that for the MIPS architecture only an exception had to be made
disabling the 'simple' calls for 'udhcp' (in networking/udhcp/common.h)
because it made these files larger on MIPS.
Signed-off-by: James Byrne <james.byrne@origamienergy.com>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util-linux/mount.c')
-rw-r--r-- | util-linux/mount.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/util-linux/mount.c b/util-linux/mount.c index e6bad7c..84c85c0 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -483,7 +483,7 @@ static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp) mountTable = setmntent(bb_path_mtab_file, "r"); if (!mountTable) { - bb_perror_msg(bb_path_mtab_file); + bb_simple_perror_msg(bb_path_mtab_file); return; } @@ -511,7 +511,7 @@ static void FAST_FUNC update_mtab_entry_on_move(const struct mntent *mp) } endmntent(mountTable); } else if (errno != EROFS) - bb_perror_msg(bb_path_mtab_file); + bb_simple_perror_msg(bb_path_mtab_file); if (ENABLE_FEATURE_CLEAN_UP) { for (i = 0; i < count; i++) { @@ -739,7 +739,7 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero // Abort entirely if permission denied. if (rc && errno == EPERM) - bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); + bb_simple_error_msg_and_die(bb_msg_perm_denied_are_you_root); // If the mount was successful, and we're maintaining an old-style // mtab file by hand, add the new entry to it now. @@ -751,7 +751,7 @@ static int mount_it_now(struct mntent *mp, unsigned long vfsflags, char *filtero int i; if (!mountTable) { - bb_perror_msg(bb_path_mtab_file); + bb_simple_perror_msg(bb_path_mtab_file); goto ret; } @@ -1288,18 +1288,18 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi s = strchr(hostname, ','); if (s) { *s = '\0'; - bb_error_msg("warning: multiple hostnames not supported"); + bb_simple_error_msg("warning: multiple hostnames not supported"); } server_addr.sin_family = AF_INET; if (!inet_aton(hostname, &server_addr.sin_addr)) { hp = gethostbyname(hostname); if (hp == NULL) { - bb_herror_msg("%s", hostname); + bb_simple_herror_msg(hostname); goto fail; } if (hp->h_length != (int)sizeof(struct in_addr)) { - bb_error_msg_and_die("only IPv4 is supported"); + bb_simple_error_msg_and_die("only IPv4 is supported"); } memcpy(&server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); } @@ -1389,7 +1389,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi else if (is_prefixed_with(opteq, "udp")) tcp = 0; else - bb_error_msg("warning: unrecognized proto= option"); + bb_simple_error_msg("warning: unrecognized proto= option"); continue; case 20: // "addr" - ignore continue; @@ -1522,7 +1522,7 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi if (nfs_mount_version >= 3) nolock = !val; else - bb_error_msg("warning: option nolock is not supported"); + bb_simple_error_msg("warning: option nolock is not supported"); break; case 11: //rdirplus nordirplus = !val; @@ -1590,11 +1590,11 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi } else { hp = gethostbyname(mounthost); if (hp == NULL) { - bb_herror_msg("%s", mounthost); + bb_simple_herror_msg(mounthost); goto fail; } if (hp->h_length != (int)sizeof(struct in_addr)) { - bb_error_msg_and_die("only IPv4 is supported"); + bb_simple_error_msg_and_die("only IPv4 is supported"); } mount_server_addr.sin_family = AF_INET; memcpy(&mount_server_addr.sin_addr, hp->h_addr_list[0], sizeof(struct in_addr)); @@ -1767,18 +1767,18 @@ static NOINLINE int nfsmount(struct mntent *mp, unsigned long vfsflags, char *fi /* Create nfs socket for kernel */ if (tcp) { if (nfs_mount_version < 3) { - bb_error_msg("NFS over TCP is not supported"); + bb_simple_error_msg("NFS over TCP is not supported"); goto fail; } fsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); } else fsock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fsock < 0) { - bb_perror_msg("nfs socket"); + bb_simple_perror_msg("nfs socket"); goto fail; } if (bindresvport(fsock, 0) < 0) { - bb_perror_msg("nfs bindresvport"); + bb_simple_perror_msg("nfs bindresvport"); goto fail; } if (port == 0) { @@ -2047,9 +2047,9 @@ static int singlemount(struct mntent *mp, int ignore_busy) ); if (loopfd < 0) { if (errno == EPERM || errno == EACCES) - bb_error_msg(bb_msg_perm_denied_are_you_root); + bb_simple_error_msg(bb_msg_perm_denied_are_you_root); else - bb_perror_msg("can't setup loop device"); + bb_simple_perror_msg("can't setup loop device"); return errno; } @@ -2255,7 +2255,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // argument when we get it. if (argv[1]) { if (nonroot) - bb_error_msg_and_die(bb_msg_you_must_be_root); + bb_simple_error_msg_and_die(bb_msg_you_must_be_root); mtpair->mnt_fsname = argv[0]; mtpair->mnt_dir = argv[1]; mtpair->mnt_type = fstype; @@ -2272,7 +2272,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) cmdopt_flags = parse_mount_options(cmdopts, NULL); if (nonroot && (cmdopt_flags & ~MS_SILENT)) // Non-root users cannot specify flags - bb_error_msg_and_die(bb_msg_you_must_be_root); + bb_simple_error_msg_and_die(bb_msg_you_must_be_root); // If we have a shared subtree flag, don't worry about fstab or mtab. if (ENABLE_FEATURE_MOUNT_FLAGS @@ -2337,7 +2337,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // No, mount -a won't mount anything, // even user mounts, for mere humans if (nonroot) - bb_error_msg_and_die(bb_msg_you_must_be_root); + bb_simple_error_msg_and_die(bb_msg_you_must_be_root); // Does type match? (NULL matches always) if (!fstype_matches(mtcur->mnt_type, fstype)) @@ -2417,7 +2417,7 @@ int mount_main(int argc UNUSED_PARAM, char **argv) // fstab must have "users" or "user" l = parse_mount_options(mtcur->mnt_opts, NULL); if (!(l & MOUNT_USERS)) - bb_error_msg_and_die(bb_msg_you_must_be_root); + bb_simple_error_msg_and_die(bb_msg_you_must_be_root); } //util-linux-2.12 does not do this check. |