Hi,
this series of 7 patches is a first attempt to add an ioctl api to libbb
and to use it in all applets where:
if ( ioctl() < 0 [!= 0])
bb_perror_msg{and_die}();
or similar code is used.
The new libbb functions are:
int ioctl_or_vperror(int fd, int request, void *argp, const char *fmt,...);
void ioctl_or_vperror_and_die(int fd, int request, void *argp, const char
*fmt,...);
These two functions can be called directly.
#if ENABLE_IOCTL_HEX2STR_ERROR
int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
void bb_ioctl_or_die(int fd, int request, void *argp, const char *ioctl_name);
#define ioctl_or_warn(fd,request,argp)
bb_ioctl_or_warn(fd,request,argp,#request)
#define ioctl_or_die(fd,request,argp) bb_ioctl_or_die(fd,request,argp,#request)
#else
int bb_ioctl_or_warn(int fd, int request, void *argp);
void bb_ioctl_or_die(int fd, int request, void *argp);
#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
#define ioctl_or_die(fd,request,argp) bb_ioctl_or_die(fd,request,argp)
#endif
These functions should not be called directly, instead:
ioctl_or_warn(fd,request,argp);
ioctl_or_die(fd,request,argp);
should be used, thus allowing to change the number of args passed
to them by enabling/disabling the CONFIG_IOCTL_HEX2STR_ERROR option.
This option is located in:
Busybox Settings ---> Busybox Library Tuning ---> [*] Use ioctl names
rather than hex values in error messages
This option by default is enabled so that busybox's behaviour is unchaged and
the same as the current,
For example error messages like this are displayed:
deallocvt: VT_DISALLOCATE: Device or resource busy
By disabling it the error message format will change to:
deallocvt: ioctl 0x5608 failed: Device or resource busy
After applying all the patches even with this config option enabled there will
be a size reduction:
scripts/bloat-o-meter busybox_old busybox_unstripped
function old new delta
process_dev 5283 5498 +215
ioctl_or_vperror - 54 +54
ioctl_or_vperror_and_die - 51 +51
bb_ioctl_or_warn - 47 +47
bb_ioctl_or_die - 39 +39
print_value_on_off - 33 +33
arp_main 2184 2198 +14
fdformat_main 575 585 +10
collect_int 114 123 +9
xsocket_type 124 129 +5
readcmd 1283 1288 +5
xselect 1501 1505 +4
mkfs_minix_main 3035 3038 +3
varunset 58 60 +2
process0_stdin 220 222 +2
changepath 178 180 +2
arping_main 2019 2020 +1
zcip_main 1714 1713 -1
flush_buffer_cache 78 77 -1
make_human_readable_str 220 218 -2
fsck_main 1911 1909 -2
xstrtoul_range_sfx 229 226 -3
xstrtoull_range_sfx 295 291 -4
telnet_main 1699 1695 -4
evalcommand 1132 1127 -5
setconsole_main 120 114 -6
ipaddr_list_or_flush 2665 2659 -6
if_readconf 179 173 -6
eject_main 146 140 -6
hwclock_main 504 497 -7
freeramdisk_main 86 79 -7
collect_fork 119 112 -7
collect_blk 474 467 -7
print_tunnel 749 741 -8
mt_main 295 287 -8
deallocvt_main 82 74 -8
vlock_main 634 625 -9
vconfig_main 351 342 -9
raidautorun_main 59 50 -9
nameif_main 670 661 -9
chvt_main 90 81 -9
setlogcons_main 92 82 -10
read_rtc 186 176 -10
dumpkmap_main 284 274 -10
do_get_ioctl 115 105 -10
do_del_ioctl 125 115 -10
do_add_ioctl 134 124 -10
setkeycodes_main 165 154 -11
ifconfig_main 1303 1292 -11
write_table 244 232 -12
getty_main 2514 2502 -12
catv_main 342 330 -12
ifaddrlist 394 381 -13
do_show 793 778 -15
do_iplink 1171 1156 -15
loadfont_main 495 479 -16
do_loadfont 191 174 -17
route_main 2220 2202 -18
ether_wake_main 747 728 -19
set_address 75 53 -22
fbset_main 2066 2043 -23
do_time 593 570 -23
xioctl 25 - -25
parse_args 1508 1482 -26
udhcp_read_interface 316 282 -34
bb_ioctl 45 - -45
bb_ioctl_alt 70 - -70
bb_ioctl_on_off 80 - -80
.rodata 123143 122791 -352
------------------------------------------------------------------------------
(add/remove: 5/4 grow/shrink: 12/48 up/down: 496/-1074) Total: -578 bytes
By disabling this option the size reduction is far bigger:
[EMAIL PROTECTED]:~/Desktop/busybox.orig# scripts/bloat-o-meter busybox_old
busybox_unstripped
function old new delta
ioctl_or_vperror - 54 +54
ioctl_or_vperror_and_die - 51 +51
bb_ioctl_or_warn - 47 +47
bb_ioctl_or_die - 39 +39
print_value_on_off - 33 +33
collect_int 114 123 +9
arp_main 2184 2193 +9
readcmd 1283 1288 +5
xselect 1501 1505 +4
mkfs_minix_main 3035 3038 +3
process0_stdin 220 222 +2
fsck_main 1911 1909 -2
xstrtoul_range_sfx 229 226 -3
xstrtoull_range_sfx 295 291 -4
telnet_main 1699 1695 -4
arping_main 2019 2015 -4
evalcommand 1132 1127 -5
zcip_main 1714 1708 -6
eject_main 146 140 -6
process_dev 5283 5276 -7
freeramdisk_main 86 79 -7
mt_main 295 287 -8
vconfig_main 351 342 -9
nameif_main 670 661 -9
dumpkmap_main 284 274 -10
setkeycodes_main 165 154 -11
setconsole_main 120 109 -11
ipaddr_list_or_flush 2665 2654 -11
if_readconf 179 168 -11
write_table 244 232 -12
hwclock_main 504 492 -12
getty_main 2514 2502 -12
print_tunnel 749 736 -13
ifaddrlist 394 381 -13
deallocvt_main 82 69 -13
vlock_main 634 620 -14
raidautorun_main 59 45 -14
setlogcons_main 92 77 -15
read_rtc 186 171 -15
fdformat_main 575 560 -15
do_get_ioctl 115 100 -15
do_del_ioctl 125 110 -15
do_add_ioctl 134 119 -15
chvt_main 90 71 -19
do_show 793 773 -20
ether_wake_main 747 723 -24
xioctl 25 - -25
loadfont_main 495 469 -26
set_address 75 48 -27
do_loadfont 191 164 -27
do_time 593 565 -28
parse_args 1508 1477 -31
route_main 2220 2187 -33
fbset_main 2066 2033 -33
ifconfig_main 1303 1267 -36
do_iplink 1171 1131 -40
udhcp_read_interface 316 272 -44
bb_ioctl 45 - -45
bb_ioctl_alt 70 - -70
bb_ioctl_on_off 80 - -80
.rodata 123143 121863 -1280
------------------------------------------------------------------------------
(add/remove: 5/4 grow/shrink: 6/46 up/down: 256/-2209) Total: -1953 bytes
So the difference between enabling/disabling it is about: 1375 bytes.
After applying patch n.1 the remaining patches could be applied in whatever
order.
The hdparm applet has a separate patch as it was the one with the greatest
number
of changes so that it needs more love and testing than the others.
This patches are mostly only compiled tested.
Critics, hints and help from the list is as always welcome.
Ciao,
Tito
--- busybox.orig/include/libbb.h 2007-07-05 08:20:25.000000000 +0200
+++ busybox/include/libbb.h 2007-07-09 21:27:21.000000000 +0200
@@ -780,6 +780,20 @@
int get_terminal_width_height(const int fd, int *width, int *height);
+int ioctl_or_vperror(int fd, int request, void *argp, const char *fmt,...)__attribute__ ((format (printf, 4, 5)));
+void ioctl_or_vperror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
+#if ENABLE_IOCTL_HEX2STR_ERROR
+int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
+void bb_ioctl_or_die(int fd, int request, void *argp, const char *ioctl_name);
+#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
+#define ioctl_or_die(fd,request,argp) bb_ioctl_or_die(fd,request,argp,#request)
+#else
+int bb_ioctl_or_warn(int fd, int request, void *argp);
+void bb_ioctl_or_die(int fd, int request, void *argp);
+#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
+#define ioctl_or_die(fd,request,argp) bb_ioctl_or_die(fd,request,argp)
+#endif
+
char *is_in_ino_dev_hashtable(const struct stat *statbuf);
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
void reset_ino_dev_hashtable(void);
--- busybox.orig/libbb/Config.in 2007-06-19 22:39:56.000000000 +0200
+++ busybox/libbb/Config.in 2007-07-09 21:34:17.000000000 +0200
@@ -120,4 +120,11 @@
will be used instead (which gives wrong results if date/time
is reset).
+config IOCTL_HEX2STR_ERROR
+ bool "Use ioctl names rather than hex values in error messages"
+ default y
+ help
+ Use ioctl names rather than hex values in error messages
+ (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this
+ saves about 1375 bytes.
endmenu
--- busybox.orig/libbb/xfuncs.c 2007-05-26 23:23:50.000000000 +0200
+++ busybox/libbb/xfuncs.c 2007-07-09 21:30:18.000000000 +0200
@@ -639,3 +639,62 @@
return ret;
}
+
+void ioctl_or_vperror_and_die(int fd, int request, void *argp, const char *fmt,...)
+{
+ va_list p;
+
+ if (ioctl(fd, request, argp) != 0) {
+ va_start(p, fmt);
+ bb_vperror_msg(fmt, p);
+ xfunc_die();
+ /*va_end(p);*/
+ }
+}
+
+int ioctl_or_vperror(int fd, int request, void *argp, const char *fmt,...)
+{
+ va_list p;
+ int ret = ioctl(fd, request, argp);
+
+ if ( ret != 0) {
+ va_start(p, fmt);
+ bb_vperror_msg(fmt, p);
+ va_end(p);
+ }
+ return ret;
+}
+
+#if ENABLE_IOCTL_HEX2STR_ERROR
+int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
+{
+ int ret;
+
+ ret = ioctl(fd, request, argp);
+ if (ret != 0)
+ bb_perror_msg("%s", ioctl_name);
+ return ret;
+}
+
+void bb_ioctl_or_die(int fd, int request, void *argp, const char *ioctl_name)
+{
+ if (ioctl(fd, request, argp) != 0)
+ bb_perror_msg_and_die("%s", ioctl_name);
+}
+#else
+int bb_ioctl_or_warn(int fd, int request, void *argp)
+{
+ int ret;
+
+ ret = ioctl(fd, request, argp);
+ if (ret != 0)
+ bb_perror_msg("ioctl %#x failed", request);
+ return ret;
+}
+
+void bb_ioctl_or_die(int fd, int request, void *argp)
+{
+ if (ioctl(fd, request, argp) != 0)
+ bb_perror_msg_and_die("ioctl %#x failed", request);
+}
+#endif
--- busybox.orig/scripts/defconfig 2007-06-19 13:39:41.000000000 +0200
+++ busybox/scripts/defconfig 2007-07-09 21:32:52.000000000 +0200
@@ -77,6 +77,7 @@
# CONFIG_FEATURE_USERNAME_COMPLETION is not set
# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
# CONFIG_MONOTONIC_SYSCALL is not set
+CONFIG_IOCTL_HEX2STR_ERROR=y
#
# Applets
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox