aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-14 22:07:14 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-14 22:07:14 +0000
commitfb79a2e2cfe33002398f1898c26d8e4f341db006 (patch)
treef5b3ee27db5bc8c9b181fbec171f8fa430a75ba5
parentfcfaf2e18aba06dd90b16958ecfbfcfbf59ceb02 (diff)
downloadbusybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.tar.gz
busybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.tar.bz2
busybox-w32-fb79a2e2cfe33002398f1898c26d8e4f341db006.zip
xioctl and friends by Tito <farmatito@tiscali.it>
function old new delta do_iptunnel 203 977 +774 process_dev 5328 5494 +166 ioctl_or_perror - 54 +54 ioctl_or_perror_and_die - 51 +51 ioctl_alt_func - 49 +49 bb_ioctl_or_warn - 47 +47 do_add_ioctl 102 145 +43 bb_xioctl - 39 +39 print_value_on_off - 31 +31 get_lcm 105 123 +18 arp_main 2155 2167 +12 .................. zcip_main 1576 1566 -10 setlogcons_main 92 82 -10 dumpkmap_main 263 253 -10 do_get_ioctl 85 75 -10 setkeycodes_main 165 154 -11 write_table 244 232 -12 vconfig_main 318 306 -12 do_del_ioctl 93 81 -12 set_address 75 62 -13 maybe_set_utc 30 16 -14 loadfont_main 495 479 -16 slattach_main 712 695 -17 do_loadfont 191 174 -17 do_iplink 1155 1136 -19 getty_main 2583 2562 -21 fbset_main 2058 2035 -23 do_time 588 565 -23 xioctl 25 - -25 read_rtc 186 160 -26 parse_conf 1299 1270 -29 udhcp_read_interface 269 239 -30 bb_ioctl 45 - -45 bb_ioctl_alt 70 - -70 bb_ioctl_on_off 78 - -78 .rodata 129370 129018 -352 do_show 799 - -799 ------------------------------------------------------------------------------ (add/remove: 6/5 grow/shrink: 13/49 up/down: 1316/-1864) Total: -548 bytes text data bss dec hex filename 675352 2740 13968 692060 a8f5c busybox_old 674804 2740 13968 691512 a8d38 busybox_unstripped
-rw-r--r--console-tools/chvt.c6
-rw-r--r--console-tools/deallocvt.c4
-rw-r--r--console-tools/dumpkmap.c8
-rw-r--r--console-tools/loadfont.c20
-rw-r--r--console-tools/setconsole.c4
-rw-r--r--console-tools/setkeycodes.c6
-rw-r--r--console-tools/setlogcons.c3
-rw-r--r--coreutils/date.c8
-rw-r--r--e2fsprogs/old_e2fsprogs/mke2fs.c6
-rw-r--r--include/libbb.h14
-rw-r--r--libbb/Config.in7
-rw-r--r--libbb/xfuncs.c58
-rw-r--r--loginutils/getty.c6
-rw-r--r--loginutils/vlock.c4
-rw-r--r--miscutils/devfsd.c16
-rw-r--r--miscutils/eject.c5
-rw-r--r--miscutils/hdparm.c158
-rw-r--r--miscutils/mt.c6
-rw-r--r--miscutils/raidautorun.c4
-rw-r--r--networking/arp.c9
-rw-r--r--networking/arping.c9
-rw-r--r--networking/ether-wake.c6
-rw-r--r--networking/ifconfig.c18
-rw-r--r--networking/interface.c3
-rw-r--r--networking/libiproute/ipaddress.c3
-rw-r--r--networking/libiproute/iplink.c32
-rw-r--r--networking/libiproute/iptunnel.c80
-rw-r--r--networking/nameif.c6
-rw-r--r--networking/route.c19
-rw-r--r--networking/slattach.c12
-rw-r--r--networking/traceroute.c4
-rw-r--r--networking/udhcp/socket.c12
-rw-r--r--networking/vconfig.c5
-rw-r--r--networking/zcip.c4
-rw-r--r--scripts/defconfig1
-rw-r--r--util-linux/fbset.c6
-rw-r--r--util-linux/fdformat.c17
-rw-r--r--util-linux/fdisk.c18
-rw-r--r--util-linux/freeramdisk.c6
-rw-r--r--util-linux/hwclock.c13
40 files changed, 295 insertions, 331 deletions
diff --git a/console-tools/chvt.c b/console-tools/chvt.c
index e8761d523..86d3f2ddb 100644
--- a/console-tools/chvt.c
+++ b/console-tools/chvt.c
@@ -26,9 +26,7 @@ int chvt_main(int argc, char **argv)
26 26
27 fd = get_console_fd(); 27 fd = get_console_fd();
28 num = xatoul_range(argv[1], 1, 63); 28 num = xatoul_range(argv[1], 1, 63);
29 if ((-1 == ioctl(fd, VT_ACTIVATE, num)) 29 xioctl(fd, VT_ACTIVATE, (void *)num);
30 || (-1 == ioctl(fd, VT_WAITACTIVE, num))) { 30 xioctl(fd, VT_WAITACTIVE, (void *)num);
31 bb_perror_msg_and_die("ioctl");
32 }
33 return EXIT_SUCCESS; 31 return EXIT_SUCCESS;
34} 32}
diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c
index db52747ad..a69026664 100644
--- a/console-tools/deallocvt.c
+++ b/console-tools/deallocvt.c
@@ -31,8 +31,6 @@ int deallocvt_main(int argc, char **argv)
31 bb_show_usage(); 31 bb_show_usage();
32 } 32 }
33 33
34 if (-1 == ioctl(get_console_fd(), VT_DISALLOCATE, num)) { 34 xioctl(get_console_fd(), VT_DISALLOCATE, (void *)num);
35 bb_perror_msg_and_die("VT_DISALLOCATE");
36 }
37 return EXIT_SUCCESS; 35 return EXIT_SUCCESS;
38} 36}
diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c
index f61795cf0..a606d568e 100644
--- a/console-tools/dumpkmap.c
+++ b/console-tools/dumpkmap.c
@@ -50,12 +50,12 @@ int dumpkmap_main(int argc, char **argv)
50 for (j = 0; j < NR_KEYS; j++) { 50 for (j = 0; j < NR_KEYS; j++) {
51 ke.kb_index = j; 51 ke.kb_index = j;
52 ke.kb_table = i; 52 ke.kb_table = i;
53 if (ioctl(fd, KDGKBENT, &ke) < 0) { 53 if (!ioctl_or_perror(fd, KDGKBENT, &ke,
54 bb_perror_msg("ioctl failed with %s, %s, %p", 54 "ioctl failed with %s, %s, %p",
55 (char *)&ke.kb_index, 55 (char *)&ke.kb_index,
56 (char *)&ke.kb_table, 56 (char *)&ke.kb_table,
57 &ke.kb_value); 57 &ke.kb_value)
58 } else { 58 ) {
59 write(1, (void*)&ke.kb_value, 2); 59 write(1, (void*)&ke.kb_value, 2);
60 } 60 }
61 } 61 }
diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c
index b046d40e3..6b4dcb475 100644
--- a/console-tools/loadfont.c
+++ b/console-tools/loadfont.c
@@ -49,13 +49,11 @@ static void do_loadfont(int fd, unsigned char *inbuf, int unit, int fontsize)
49 cfd.charheight = unit; 49 cfd.charheight = unit;
50 cfd.chardata = buf; 50 cfd.chardata = buf;
51 51
52 if (ioctl(fd, PIO_FONTX, &cfd) == 0) 52 if (!ioctl_or_perror(fd, PIO_FONTX, &cfd, "PIO_FONTX ioctl failed (will try PIO_FONT)"))
53 goto ret; /* success */ 53 goto ret; /* success */
54 bb_perror_msg("PIO_FONTX ioctl (will try PIO_FONT)");
55 } 54 }
56#endif 55#endif
57 if (ioctl(fd, PIO_FONT, buf)) 56 xioctl(fd, PIO_FONT, buf);
58 bb_perror_msg_and_die("PIO_FONT ioctl");
59 ret: 57 ret:
60 free(buf); 58 free(buf);
61} 59}
@@ -92,20 +90,10 @@ do_loadtable(int fd, unsigned char *inbuf, int tailsz, int fontsize)
92 advice.advised_hashsize = 0; 90 advice.advised_hashsize = 0;
93 advice.advised_hashstep = 0; 91 advice.advised_hashstep = 0;
94 advice.advised_hashlevel = 0; 92 advice.advised_hashlevel = 0;
95 if (ioctl(fd, PIO_UNIMAPCLR, &advice)) { 93 xioctl(fd, PIO_UNIMAPCLR, &advice);
96#ifdef ENOIOCTLCMD
97 if (errno == ENOIOCTLCMD) {
98 bb_error_msg("it seems this kernel is older than 1.1.92");
99 bb_error_msg_and_die("no Unicode mapping table loaded");
100 } else
101#endif
102 bb_perror_msg_and_die("PIO_UNIMAPCLR");
103 }
104 ud.entry_ct = ct; 94 ud.entry_ct = ct;
105 ud.entries = up; 95 ud.entries = up;
106 if (ioctl(fd, PIO_UNIMAP, &ud)) { 96 xioctl(fd, PIO_UNIMAP, &ud);
107 bb_perror_msg_and_die("PIO_UNIMAP");
108 }
109} 97}
110 98
111static void loadnewfont(int fd) 99static void loadnewfont(int fd)
diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c
index f437415db..8745b3be2 100644
--- a/console-tools/setconsole.c
+++ b/console-tools/setconsole.c
@@ -42,8 +42,6 @@ int setconsole_main(int argc, char **argv)
42 device = DEV_CONSOLE; 42 device = DEV_CONSOLE;
43 } 43 }
44 44
45 if (-1 == ioctl(xopen(device, O_RDONLY), TIOCCONS)) { 45 xioctl(xopen(device, O_RDONLY), TIOCCONS, NULL);
46 bb_perror_msg_and_die("TIOCCONS");
47 }
48 return EXIT_SUCCESS; 46 return EXIT_SUCCESS;
49} 47}
diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c
index 0911ede50..3de5f9856 100644
--- a/console-tools/setkeycodes.c
+++ b/console-tools/setkeycodes.c
@@ -39,9 +39,9 @@ int setkeycodes_main(int argc, char** argv)
39 a.scancode -= 0xe000; 39 a.scancode -= 0xe000;
40 a.scancode += 128; 40 a.scancode += 128;
41 } 41 }
42 if (ioctl(fd, KDSETKEYCODE, &a)) { 42 ioctl_or_perror_and_die(fd, KDSETKEYCODE, &a,
43 bb_perror_msg_and_die("failed to set SCANCODE %x to KEYCODE %d", sc, a.keycode); 43 "failed to set SCANCODE %x to KEYCODE %d",
44 } 44 sc, a.keycode);
45 argc -= 2; 45 argc -= 2;
46 argv += 2; 46 argv += 2;
47 } 47 }
diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c
index f95a65390..2e2a5a471 100644
--- a/console-tools/setlogcons.c
+++ b/console-tools/setlogcons.c
@@ -25,8 +25,7 @@ int setlogcons_main(int argc, char **argv)
25 if (argc == 2) 25 if (argc == 2)
26 arg.subarg = xatoul_range(argv[1], 0, 63); 26 arg.subarg = xatoul_range(argv[1], 0, 63);
27 27
28 if (ioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg)) 28 xioctl(xopen(VC_1, O_RDONLY), TIOCLINUX, &arg);
29 bb_perror_msg_and_die("TIOCLINUX");
30 29
31 return 0; 30 return 0;
32} 31}
diff --git a/coreutils/date.c b/coreutils/date.c
index cec8854ff..1b20cd443 100644
--- a/coreutils/date.c
+++ b/coreutils/date.c
@@ -32,16 +32,10 @@
32#define DATE_OPT_TIMESPEC 0x20 32#define DATE_OPT_TIMESPEC 0x20
33#define DATE_OPT_HINT 0x40 33#define DATE_OPT_HINT 0x40
34 34
35static void xputenv(char *s)
36{
37 if (putenv(s) != 0)
38 bb_error_msg_and_die(bb_msg_memory_exhausted);
39}
40
41static void maybe_set_utc(int opt) 35static void maybe_set_utc(int opt)
42{ 36{
43 if (opt & DATE_OPT_UTC) 37 if (opt & DATE_OPT_UTC)
44 xputenv((char*)"TZ=UTC0"); 38 putenv((char*)"TZ=UTC0");
45} 39}
46 40
47int date_main(int argc, char **argv); 41int date_main(int argc, char **argv);
diff --git a/e2fsprogs/old_e2fsprogs/mke2fs.c b/e2fsprogs/old_e2fsprogs/mke2fs.c
index 4d5cce307..9ea5d5c92 100644
--- a/e2fsprogs/old_e2fsprogs/mke2fs.c
+++ b/e2fsprogs/old_e2fsprogs/mke2fs.c
@@ -169,7 +169,7 @@ static void invalid_block(ext2_filsys fs EXT2FS_ATTR((unused)), blk_t blk)
169/* 169/*
170 * Busybox stuff 170 * Busybox stuff
171 */ 171 */
172static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...)__attribute__ ((format (printf, 2, 3))); 172static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
173static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...) 173static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...)
174{ 174{
175 va_list ap; 175 va_list ap;
@@ -184,7 +184,7 @@ static void mke2fs_error_msg_and_die(int retval, const char *fmt, ...)
184 } 184 }
185} 185}
186 186
187static void mke2fs_verbose(const char *fmt, ...)__attribute__ ((format (printf, 1, 2))); 187static void mke2fs_verbose(const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
188static void mke2fs_verbose(const char *fmt, ...) 188static void mke2fs_verbose(const char *fmt, ...)
189{ 189{
190 va_list ap; 190 va_list ap;
@@ -202,7 +202,7 @@ static void mke2fs_verbose_done(void)
202 mke2fs_verbose("done\n"); 202 mke2fs_verbose("done\n");
203} 203}
204 204
205static void mke2fs_warning_msg(int retval, char *fmt, ... )__attribute__ ((format (printf, 2, 3))); 205static void mke2fs_warning_msg(int retval, char *fmt, ... ) __attribute__ ((format (printf, 2, 3)));
206static void mke2fs_warning_msg(int retval, char *fmt, ... ) 206static void mke2fs_warning_msg(int retval, char *fmt, ... )
207{ 207{
208 va_list ap; 208 va_list ap;
diff --git a/include/libbb.h b/include/libbb.h
index bf6ae923d..46860c614 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -780,6 +780,20 @@ extern void crypt_make_salt(char *p, int cnt);
780 780
781int get_terminal_width_height(const int fd, int *width, int *height); 781int get_terminal_width_height(const int fd, int *width, int *height);
782 782
783int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
784void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
785#if ENABLE_IOCTL_HEX2STR_ERROR
786int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
787void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name);
788#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
789#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp,#request)
790#else
791int bb_ioctl_or_warn(int fd, int request, void *argp);
792void bb_xioctl(int fd, int request, void *argp);
793#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
794#define xioctl(fd,request,argp) bb_xioctl(fd,request,argp)
795#endif
796
783char *is_in_ino_dev_hashtable(const struct stat *statbuf); 797char *is_in_ino_dev_hashtable(const struct stat *statbuf);
784void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name); 798void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
785void reset_ino_dev_hashtable(void); 799void reset_ino_dev_hashtable(void);
diff --git a/libbb/Config.in b/libbb/Config.in
index f82a2b1ce..5055015cf 100644
--- a/libbb/Config.in
+++ b/libbb/Config.in
@@ -120,4 +120,11 @@ config MONOTONIC_SYSCALL
120 will be used instead (which gives wrong results if date/time 120 will be used instead (which gives wrong results if date/time
121 is reset). 121 is reset).
122 122
123config IOCTL_HEX2STR_ERROR
124 bool "Use ioctl names rather than hex values in error messages"
125 default y
126 help
127 Use ioctl names rather than hex values in error messages
128 (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this
129 saves about 1400 bytes.
123endmenu 130endmenu
diff --git a/libbb/xfuncs.c b/libbb/xfuncs.c
index d02ef9c77..fad111aa9 100644
--- a/libbb/xfuncs.c
+++ b/libbb/xfuncs.c
@@ -639,3 +639,61 @@ int get_terminal_width_height(const int fd, int *width, int *height)
639 639
640 return ret; 640 return ret;
641} 641}
642
643void ioctl_or_perror_and_die(int fd, int request, void *argp, const char *fmt,...)
644{
645 va_list p;
646
647 if (ioctl(fd, request, argp) < 0) {
648 va_start(p, fmt);
649 bb_vperror_msg(fmt, p);
650 /* xfunc_die can actually longjmp, so be nice */
651 va_end(p);
652 xfunc_die();
653 }
654}
655
656int ioctl_or_perror(int fd, int request, void *argp, const char *fmt,...)
657{
658 va_list p;
659 int ret = ioctl(fd, request, argp);
660
661 if (ret < 0) {
662 va_start(p, fmt);
663 bb_vperror_msg(fmt, p);
664 va_end(p);
665 }
666 return ret;
667}
668
669#if ENABLE_IOCTL_HEX2STR_ERROR
670int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
671{
672 int ret;
673
674 ret = ioctl(fd, request, argp);
675 if (ret < 0)
676 bb_perror_msg("%s", ioctl_name);
677 return ret;
678}
679void bb_xioctl(int fd, int request, void *argp, const char *ioctl_name)
680{
681 if (ioctl(fd, request, argp) < 0)
682 bb_perror_msg_and_die("%s", ioctl_name);
683}
684#else
685int bb_ioctl_or_warn(int fd, int request, void *argp)
686{
687 int ret;
688
689 ret = ioctl(fd, request, argp);
690 if (ret < 0)
691 bb_perror_msg("ioctl %#x failed", request);
692 return ret;
693}
694void bb_xioctl(int fd, int request, void *argp)
695{
696 if (ioctl(fd, request, argp) < 0)
697 bb_perror_msg_and_die("ioctl %#x failed", request);
698}
699#endif
diff --git a/loginutils/getty.c b/loginutils/getty.c
index f969124c1..2fcb0d902 100644
--- a/loginutils/getty.c
+++ b/loginutils/getty.c
@@ -281,8 +281,7 @@ static void open_tty(const char *tty, struct termios *tp, int local)
281 * 5 seconds seems to be a good value. 281 * 5 seconds seems to be a good value.
282 */ 282 */
283 283
284 if (ioctl(0, TCGETS, tp) < 0) 284 ioctl_or_perror_and_die(0, TCGETS, tp, "%s: TCGETS", tty);
285 bb_perror_msg_and_die("%s: ioctl(TCGETS)", tty);
286 285
287 /* 286 /*
288 * It seems to be a terminal. Set proper protections and ownership. Mode 287 * It seems to be a terminal. Set proper protections and ownership. Mode
@@ -647,8 +646,7 @@ static void termios_final(struct options *op, struct termios *tp, struct chardat
647 646
648 /* Finally, make the new settings effective */ 647 /* Finally, make the new settings effective */
649 648
650 if (ioctl(0, TCSETS, tp) < 0) 649 ioctl_or_perror_and_die(0, TCSETS, tp, "%s: TCSETS", op->tty);
651 bb_perror_msg_and_die("%s: ioctl(TCSETS)", op->tty);
652} 650}
653 651
654 652
diff --git a/loginutils/vlock.c b/loginutils/vlock.c
index 7f614fca1..665ebd83a 100644
--- a/loginutils/vlock.c
+++ b/loginutils/vlock.c
@@ -62,9 +62,7 @@ int vlock_main(int argc, char **argv)
62 62
63 vfd = xopen(CURRENT_TTY, O_RDWR); 63 vfd = xopen(CURRENT_TTY, O_RDWR);
64 64
65 if (ioctl(vfd, VT_GETMODE, &vtm) < 0) { 65 xioctl(vfd, VT_GETMODE, &vtm);
66 bb_perror_msg_and_die("VT_GETMODE");
67 }
68 66
69 /* mask a bunch of signals */ 67 /* mask a bunch of signals */
70 sigprocmask(SIG_SETMASK, NULL, &sig); 68 sigprocmask(SIG_SETMASK, NULL, &sig);
diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c
index 814fbd686..1dfbadf83 100644
--- a/miscutils/devfsd.c
+++ b/miscutils/devfsd.c
@@ -234,7 +234,6 @@ static char get_old_ide_name(unsigned , unsigned);
234static char *write_old_sd_name(char *, unsigned, unsigned, const char *); 234static char *write_old_sd_name(char *, unsigned, unsigned, const char *);
235 235
236/* busybox functions */ 236/* busybox functions */
237static void do_ioctl_or_die(int fd, int request, unsigned long event_mask_flag);
238static int get_uid_gid(int flag, const char *string); 237static int get_uid_gid(int flag, const char *string);
239static void safe_memcpy(char * dest, const char * src, int len); 238static void safe_memcpy(char * dest, const char * src, int len);
240static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, const char *ptr); 239static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, const char *ptr);
@@ -298,12 +297,6 @@ static const char * const bb_msg_variable_not_found = "variable: %s not found";
298#define error_logger_and_die(p, fmt, args...) exit(1) 297#define error_logger_and_die(p, fmt, args...) exit(1)
299#endif 298#endif
300 299
301static void do_ioctl_or_die(int fd, int request, unsigned long event_mask_flag)
302{
303 if (ioctl(fd, request, event_mask_flag) == -1)
304 msg_logger_and_die(LOG_ERR, "ioctl");
305}
306
307static void safe_memcpy(char *dest, const char *src, int len) 300static void safe_memcpy(char *dest, const char *src, int len)
308{ 301{
309 memcpy(dest , src, len); 302 memcpy(dest , src, len);
@@ -386,8 +379,7 @@ int devfsd_main(int argc, char **argv)
386 if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) 379 if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0)
387 bb_perror_msg_and_die("FD_CLOEXEC"); 380 bb_perror_msg_and_die("FD_CLOEXEC");
388 381
389 if (ioctl(fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev) == -1) 382 xioctl(fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev);
390 bb_perror_msg_and_die("ioctl");
391 383
392 /*setup initial entries */ 384 /*setup initial entries */
393 for (curr = initial_symlinks; curr->dest != NULL; ++curr) 385 for (curr = initial_symlinks; curr->dest != NULL; ++curr)
@@ -404,7 +396,7 @@ int devfsd_main(int argc, char **argv)
404 exit(EXIT_SUCCESS); /* -v */ 396 exit(EXIT_SUCCESS); /* -v */
405 } 397 }
406 /* Tell kernel we are special(i.e. we get to see hidden entries) */ 398 /* Tell kernel we are special(i.e. we get to see hidden entries) */
407 do_ioctl_or_die(fd, DEVFSDIOC_SET_EVENT_MASK, 0); 399 xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, 0);
408 400
409 sigemptyset(&new_action.sa_mask); 401 sigemptyset(&new_action.sa_mask);
410 new_action.sa_flags = 0; 402 new_action.sa_flags = 0;
@@ -435,7 +427,7 @@ int devfsd_main(int argc, char **argv)
435 427
436 if (do_daemon) { 428 if (do_daemon) {
437 /* Release so that the child can grab it */ 429 /* Release so that the child can grab it */
438 do_ioctl_or_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); 430 xioctl(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0);
439 bb_daemonize_or_rexec(0, argv); 431 bb_daemonize_or_rexec(0, argv);
440 } else if (ENABLE_DEVFSD_FG_NP) { 432 } else if (ENABLE_DEVFSD_FG_NP) {
441 setpgid(0, 0); /* Become process group leader */ 433 setpgid(0, 0); /* Become process group leader */
@@ -661,7 +653,7 @@ static int do_servicing(int fd, unsigned long event_mask)
661 653
662 /* Tell devfs what events we care about */ 654 /* Tell devfs what events we care about */
663 tmp_event_mask = event_mask; 655 tmp_event_mask = event_mask;
664 do_ioctl_or_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); 656 xioctl(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask);
665 while (!caught_signal) { 657 while (!caught_signal) {
666 errno = 0; 658 errno = 0;
667 bytes = read(fd,(char *) &info, sizeof info); 659 bytes = read(fd,(char *) &info, sizeof info);
diff --git a/miscutils/eject.c b/miscutils/eject.c
index 631a344a1..ba7da5c65 100644
--- a/miscutils/eject.c
+++ b/miscutils/eject.c
@@ -50,9 +50,8 @@ int eject_main(int argc, char **argv)
50 if (flags & FLAG_CLOSE 50 if (flags & FLAG_CLOSE
51 || (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN)) 51 || (flags & FLAG_SMART && ioctl(dev, CDROM_DRIVE_STATUS) == CDS_TRAY_OPEN))
52 cmd = CDROMCLOSETRAY; 52 cmd = CDROMCLOSETRAY;
53 if (ioctl(dev, cmd)) { 53
54 bb_perror_msg_and_die("%s", device); 54 ioctl_or_perror_and_die(dev, cmd, NULL, "%s", device);
55 }
56 55
57 if (ENABLE_FEATURE_CLEAN_UP) 56 if (ENABLE_FEATURE_CLEAN_UP)
58 close(dev); 57 close(dev);
diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c
index fe4c67a9a..5c7d1f60c 100644
--- a/miscutils/hdparm.c
+++ b/miscutils/hdparm.c
@@ -200,8 +200,7 @@ static const char * const ata1_cfg_str[] = { /* word 0 in ATA-1 mode */
200#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */ 200#define MULTIPLE_SETTING_VALID 0x0100 /* 1=multiple sector setting is valid */
201 201
202/* word 49: capabilities 0 */ 202/* word 49: capabilities 0 */
203#define STD_STBY 0x2000 /* 1=standard values supported (ATA); 203#define STD_STBY 0x2000 /* 1=standard values supported (ATA); 0=vendor specific values */
204 0=vendor specific values */
205#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */ 204#define IORDY_SUP 0x0800 /* 1=support; 0=may be supported */
206#define IORDY_OFF 0x0400 /* 1=may be disabled */ 205#define IORDY_OFF 0x0400 /* 1=may be disabled */
207#define LBA_SUP 0x0200 /* 1=Logical Block Address support */ 206#define LBA_SUP 0x0200 /* 1=Logical Block Address support */
@@ -442,25 +441,29 @@ static const char * const secu_str[] = {
442#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */ 441#undef DO_FLUSHCACHE /* under construction: force cache flush on -W0 */
443 442
444/* Busybox messages and functions */ 443/* Busybox messages and functions */
445static int bb_ioctl(int fd, int request, void *argp, const char *string) 444#if ENABLE_IOCTL_HEX2STR_ERROR
445static int ioctl_alt_func(int fd, int cmd, unsigned char *args, int alt, const char *string)
446{ 446{
447 int e = ioctl(fd, request, argp); 447 if (!ioctl(fd, cmd, args))
448 if (e && string) 448 return 0;
449 bb_perror_msg(" %s", string); 449 args[0] = alt;
450 return e; 450 return bb_ioctl_or_warn(fd, cmd, args, string);
451} 451}
452 452#define ioctl_alt_or_warn(fd,cmd,args,alt) ioctl_alt_func(fd,cmd,args,alt,#cmd)
453static int bb_ioctl_alt(int fd, int cmd, unsigned char *args, int alt, const char *string) 453#else
454static int ioctl_alt_func(int fd, int cmd, unsigned char *args, int alt)
454{ 455{
455 if (!ioctl(fd, cmd, args)) 456 if (!ioctl(fd, cmd, args))
456 return 0; 457 return 0;
457 args[0] = alt; 458 args[0] = alt;
458 return bb_ioctl(fd, cmd, args, string); 459 return bb_ioctl_or_warn(fd, cmd, args);
459} 460}
461#define ioctl_alt_or_warn(fd,cmd,args,alt) ioctl_alt_func(fd,cmd,args,alt)
462#endif
460 463
461static void on_off(int value) 464static void on_off(int value)
462{ 465{
463 printf(value ? " (on)\n" : " (off)\n"); 466 puts(value ? " (on)" : " (off)");
464} 467}
465 468
466static void print_flag_on_off(int get_arg, const char *s, unsigned long arg) 469static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
@@ -471,15 +474,10 @@ static void print_flag_on_off(int get_arg, const char *s, unsigned long arg)
471 } 474 }
472} 475}
473 476
474static void bb_ioctl_on_off(int fd, int request, void *argp, const char *string, 477static void print_value_on_off(const char *str, unsigned long argp)
475 const char * str)
476{ 478{
477 if (ioctl(fd, request, &argp) != 0) 479 printf(" %s\t= %2ld", str, argp);
478 bb_perror_msg(" %s", string); 480 on_off(argp != 0);
479 else {
480 printf(" %s\t= %2ld", str, (unsigned long) argp);
481 on_off(((unsigned long) argp) != 0);
482 }
483} 481}
484 482
485#if ENABLE_FEATURE_HDPARM_GET_IDENTITY 483#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
@@ -1245,11 +1243,15 @@ static void dump_identity(const struct hd_driveid *id)
1245static void flush_buffer_cache(int fd) 1243static void flush_buffer_cache(int fd)
1246{ 1244{
1247 fsync(fd); /* flush buffers */ 1245 fsync(fd); /* flush buffers */
1248 bb_ioctl(fd, BLKFLSBUF, NULL, "BLKFLSBUF"); /* do it again, big time */ 1246 ioctl_or_warn(fd, BLKFLSBUF, NULL); /* do it again, big time */
1249#ifdef HDIO_DRIVE_CMD 1247#ifdef HDIO_DRIVE_CMD
1250 sleep(1); 1248 sleep(1);
1251 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) /* await completion */ 1249 if (ioctl(fd, HDIO_DRIVE_CMD, NULL) && errno != EINVAL) { /* await completion */
1252 bb_perror_msg("HDIO_DRIVE_CMD"); 1250 if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
1251 bb_perror_msg("HDIO_DRIVE_CMD");
1252 else
1253 bb_perror_msg("ioctl %#x failed", HDIO_DRIVE_CMD);
1254 }
1253#endif 1255#endif
1254} 1256}
1255 1257
@@ -1284,9 +1286,7 @@ static int do_blkgetsize(int fd, unsigned long long *blksize64)
1284 *blksize64 /= 512; 1286 *blksize64 /= 512;
1285 return 0; 1287 return 0;
1286 } 1288 }
1287 rc = ioctl(fd, BLKGETSIZE, &blksize32); // returns sectors 1289 rc = ioctl_or_warn(fd, BLKGETSIZE, &blksize32); // returns sectors
1288 if (rc)
1289 bb_perror_msg("BLKGETSIZE");
1290 *blksize64 = blksize32; 1290 *blksize64 = blksize32;
1291 return rc; 1291 return rc;
1292} 1292}
@@ -1516,12 +1516,12 @@ static void process_dev(char *devname)
1516 1516
1517 if (set_readahead) { 1517 if (set_readahead) {
1518 print_flag(get_readahead, "fs readahead", Xreadahead); 1518 print_flag(get_readahead, "fs readahead", Xreadahead);
1519 bb_ioctl(fd, BLKRASET, (int *)Xreadahead, "BLKRASET"); 1519 ioctl_or_warn(fd, BLKRASET, (int *)Xreadahead);
1520 } 1520 }
1521#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF 1521#if ENABLE_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF
1522 if (unregister_hwif) { 1522 if (unregister_hwif) {
1523 printf(" attempting to unregister hwif#%lu\n", hwif); 1523 printf(" attempting to unregister hwif#%lu\n", hwif);
1524 bb_ioctl(fd, HDIO_UNREGISTER_HWIF, (int *)(unsigned long)hwif, "HDIO_UNREGISTER_HWIF"); 1524 ioctl_or_warn(fd, HDIO_UNREGISTER_HWIF, (int *)(unsigned long)hwif);
1525 } 1525 }
1526#endif 1526#endif
1527#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF 1527#if ENABLE_FEATURE_HDPARM_HDIO_SCAN_HWIF
@@ -1530,7 +1530,7 @@ static void process_dev(char *devname)
1530 args[0] = hwif_data; 1530 args[0] = hwif_data;
1531 args[1] = hwif_ctrl; 1531 args[1] = hwif_ctrl;
1532 args[2] = hwif_irq; 1532 args[2] = hwif_irq;
1533 bb_ioctl(fd, HDIO_SCAN_HWIF, args, "HDIO_SCAN_HWIF"); 1533 ioctl_or_warn(fd, HDIO_SCAN_HWIF, args);
1534 args[0] = WIN_SETFEATURES; 1534 args[0] = WIN_SETFEATURES;
1535 args[1] = 0; 1535 args[1] = 0;
1536 } 1536 }
@@ -1547,70 +1547,70 @@ static void process_dev(char *devname)
1547 else 1547 else
1548 printf("set UDMA mode to %d\n", (piomode-200)); 1548 printf("set UDMA mode to %d\n", (piomode-200));
1549 } 1549 }
1550 bb_ioctl(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode, "HDIO_SET_PIO_MODE"); 1550 ioctl_or_warn(fd, HDIO_SET_PIO_MODE, (int *)(unsigned long)piomode);
1551 } 1551 }
1552 if (set_io32bit) { 1552 if (set_io32bit) {
1553 print_flag(get_io32bit, "32-bit IO_support flag", io32bit); 1553 print_flag(get_io32bit, "32-bit IO_support flag", io32bit);
1554 bb_ioctl(fd, HDIO_SET_32BIT, (int *)io32bit, "HDIO_SET_32BIT"); 1554 ioctl_or_warn(fd, HDIO_SET_32BIT, (int *)io32bit);
1555 } 1555 }
1556 if (set_mult) { 1556 if (set_mult) {
1557 print_flag(get_mult, "multcount", mult); 1557 print_flag(get_mult, "multcount", mult);
1558#ifdef HDIO_DRIVE_CMD 1558#ifdef HDIO_DRIVE_CMD
1559 bb_ioctl(fd, HDIO_SET_MULTCOUNT, (void *)mult, "HDIO_SET_MULTCOUNT"); 1559 ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult);
1560#else 1560#else
1561 force_operation |= (!bb_ioctl(fd, HDIO_SET_MULTCOUNT, (void *)mult, "HDIO_SET_MULTCOUNT")); 1561 force_operation |= (!ioctl_or_warn(fd, HDIO_SET_MULTCOUNT, (void *)mult));
1562#endif 1562#endif
1563 } 1563 }
1564 if (set_readonly) { 1564 if (set_readonly) {
1565 print_flag_on_off(get_readonly, "readonly", readonly); 1565 print_flag_on_off(get_readonly, "readonly", readonly);
1566 bb_ioctl(fd, BLKROSET, &readonly, "BLKROSET"); 1566 ioctl_or_warn(fd, BLKROSET, &readonly);
1567 } 1567 }
1568 if (set_unmask) { 1568 if (set_unmask) {
1569 print_flag_on_off(get_unmask, "unmaskirq", unmask); 1569 print_flag_on_off(get_unmask, "unmaskirq", unmask);
1570 bb_ioctl(fd, HDIO_SET_UNMASKINTR, (int *)unmask, "HDIO_SET_UNMASKINTR"); 1570 ioctl_or_warn(fd, HDIO_SET_UNMASKINTR, (int *)unmask);
1571 } 1571 }
1572#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA 1572#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
1573 if (set_dma) { 1573 if (set_dma) {
1574 print_flag_on_off(get_dma, "using_dma", dma); 1574 print_flag_on_off(get_dma, "using_dma", dma);
1575 bb_ioctl(fd, HDIO_SET_DMA, (int *)dma, "HDIO_SET_DMA"); 1575 ioctl_or_warn(fd, HDIO_SET_DMA, (int *)dma);
1576 } 1576 }
1577#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */ 1577#endif /* FEATURE_HDPARM_HDIO_GETSET_DMA */
1578 if (set_dma_q) { 1578 if (set_dma_q) {
1579 print_flag_on_off(get_dma_q, "DMA queue_depth", dma_q); 1579 print_flag_on_off(get_dma_q, "DMA queue_depth", dma_q);
1580 bb_ioctl(fd, HDIO_SET_QDMA, (int *)dma_q, "HDIO_SET_QDMA"); 1580 ioctl_or_warn(fd, HDIO_SET_QDMA, (int *)dma_q);
1581 } 1581 }
1582 if (set_nowerr) { 1582 if (set_nowerr) {
1583 print_flag_on_off(get_nowerr, "nowerr", nowerr); 1583 print_flag_on_off(get_nowerr, "nowerr", nowerr);
1584 bb_ioctl(fd, HDIO_SET_NOWERR, (int *)nowerr, "HDIO_SET_NOWERR"); 1584 ioctl_or_warn(fd, HDIO_SET_NOWERR, (int *)nowerr);
1585 } 1585 }
1586 if (set_keep) { 1586 if (set_keep) {
1587 print_flag_on_off(get_keep, "keep_settings", keep); 1587 print_flag_on_off(get_keep, "keep_settings", keep);
1588 bb_ioctl(fd, HDIO_SET_KEEPSETTINGS, (int *)keep, "HDIO_SET_KEEPSETTINGS"); 1588 ioctl_or_warn(fd, HDIO_SET_KEEPSETTINGS, (int *)keep);
1589 } 1589 }
1590#ifdef HDIO_DRIVE_CMD 1590#ifdef HDIO_DRIVE_CMD
1591 if (set_doorlock) { 1591 if (set_doorlock) {
1592 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK; 1592 args[0] = doorlock ? WIN_DOORLOCK : WIN_DOORUNLOCK;
1593 args[2] = 0; 1593 args[2] = 0;
1594 print_flag_on_off(get_doorlock, "drive doorlock", doorlock); 1594 print_flag_on_off(get_doorlock, "drive doorlock", doorlock);
1595 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(doorlock)"); 1595 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1596 args[0] = WIN_SETFEATURES; 1596 args[0] = WIN_SETFEATURES;
1597 } 1597 }
1598 if (set_dkeep) { 1598 if (set_dkeep) {
1599 /* lock/unlock the drive's "feature" settings */ 1599 /* lock/unlock the drive's "feature" settings */
1600 print_flag_on_off(get_dkeep, "drive keep features", dkeep); 1600 print_flag_on_off(get_dkeep, "drive keep features", dkeep);
1601 args[2] = dkeep ? 0x66 : 0xcc; 1601 args[2] = dkeep ? 0x66 : 0xcc;
1602 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(keepsettings)"); 1602 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1603 } 1603 }
1604 if (set_defects) { 1604 if (set_defects) {
1605 args[2] = defects ? 0x04 : 0x84; 1605 args[2] = defects ? 0x04 : 0x84;
1606 print_flag(get_defects, "drive defect-mgmt", defects); 1606 print_flag(get_defects, "drive defect-mgmt", defects);
1607 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(defectmgmt)"); 1607 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1608 } 1608 }
1609 if (set_prefetch) { 1609 if (set_prefetch) {
1610 args[1] = prefetch; 1610 args[1] = prefetch;
1611 args[2] = 0xab; 1611 args[2] = 0xab;
1612 print_flag(get_prefetch, "drive prefetch", prefetch); 1612 print_flag(get_prefetch, "drive prefetch", prefetch);
1613 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setprefetch)"); 1613 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1614 args[1] = 0; 1614 args[1] = 0;
1615 } 1615 }
1616 if (set_xfermode) { 1616 if (set_xfermode) {
@@ -1620,20 +1620,20 @@ static void process_dev(char *devname)
1620 print_flag(1, "xfermode", xfermode_requested); 1620 print_flag(1, "xfermode", xfermode_requested);
1621 interpret_xfermode(xfermode_requested); 1621 interpret_xfermode(xfermode_requested);
1622 } 1622 }
1623 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setxfermode)"); 1623 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1624 args[1] = 0; 1624 args[1] = 0;
1625 } 1625 }
1626 if (set_lookahead) { 1626 if (set_lookahead) {
1627 args[2] = lookahead ? 0xaa : 0x55; 1627 args[2] = lookahead ? 0xaa : 0x55;
1628 print_flag_on_off(get_lookahead, "drive read-lookahead", lookahead); 1628 print_flag_on_off(get_lookahead, "drive read-lookahead", lookahead);
1629 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setreadahead)"); 1629 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1630 } 1630 }
1631 if (set_apmmode) { 1631 if (set_apmmode) {
1632 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */ 1632 args[2] = (apmmode == 255) ? 0x85 /* disable */ : 0x05 /* set */; /* feature register */
1633 args[1] = apmmode; /* sector count register 1-255 */ 1633 args[1] = apmmode; /* sector count register 1-255 */
1634 if (get_apmmode) 1634 if (get_apmmode)
1635 printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode); 1635 printf(" setting APM level to %s 0x%02lX (%ld)\n", (apmmode == 255) ? "disabled" : "", apmmode, apmmode);
1636 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD"); 1636 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1637 args[1] = 0; 1637 args[1] = 0;
1638 } 1638 }
1639 if (set_wcache) { 1639 if (set_wcache) {
@@ -1647,12 +1647,12 @@ static void process_dev(char *devname)
1647 print_flag_on_off(get_wcache, "drive write-caching", wcache); 1647 print_flag_on_off(get_wcache, "drive write-caching", wcache);
1648#ifdef DO_FLUSHCACHE 1648#ifdef DO_FLUSHCACHE
1649 if (!wcache) 1649 if (!wcache)
1650 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); 1650 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
1651#endif /* DO_FLUSHCACHE */ 1651#endif /* DO_FLUSHCACHE */
1652 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setcache)"); 1652 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1653#ifdef DO_FLUSHCACHE 1653#ifdef DO_FLUSHCACHE
1654 if (!wcache) 1654 if (!wcache)
1655 bb_ioctl(fd, HDIO_DRIVE_CMD, &flushcache, "HDIO_DRIVE_CMD(flushcache)"); 1655 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &flushcache);
1656#endif /* DO_FLUSHCACHE */ 1656#endif /* DO_FLUSHCACHE */
1657 } 1657 }
1658 1658
@@ -1669,7 +1669,7 @@ static void process_dev(char *devname)
1669#endif 1669#endif
1670 if (get_standbynow) printf(" issuing standby command\n"); 1670 if (get_standbynow) printf(" issuing standby command\n");
1671 args[0] = WIN_STANDBYNOW1; 1671 args[0] = WIN_STANDBYNOW1;
1672 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2, "HDIO_DRIVE_CMD(standby)"); 1672 ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_STANDBYNOW2);
1673 } 1673 }
1674 if (set_sleepnow) { 1674 if (set_sleepnow) {
1675#ifndef WIN_SLEEPNOW1 1675#ifndef WIN_SLEEPNOW1
@@ -1680,12 +1680,12 @@ static void process_dev(char *devname)
1680#endif 1680#endif
1681 if (get_sleepnow) printf(" issuing sleep command\n"); 1681 if (get_sleepnow) printf(" issuing sleep command\n");
1682 args[0] = WIN_SLEEPNOW1; 1682 args[0] = WIN_SLEEPNOW1;
1683 bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2, "HDIO_DRIVE_CMD(sleep)"); 1683 ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_SLEEPNOW2);
1684 } 1684 }
1685 if (set_seagate) { 1685 if (set_seagate) {
1686 args[0] = 0xfb; 1686 args[0] = 0xfb;
1687 if (get_seagate) printf(" disabling Seagate auto powersaving mode\n"); 1687 if (get_seagate) printf(" disabling Seagate auto powersaving mode\n");
1688 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(seagatepwrsave)"); 1688 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1689 } 1689 }
1690 if (set_standby) { 1690 if (set_standby) {
1691 args[0] = WIN_SETIDLE1; 1691 args[0] = WIN_SETIDLE1;
@@ -1694,7 +1694,7 @@ static void process_dev(char *devname)
1694 print_flag(1, "standby", standby_requested); 1694 print_flag(1, "standby", standby_requested);
1695 interpret_standby(standby_requested); 1695 interpret_standby(standby_requested);
1696 } 1696 }
1697 bb_ioctl(fd, HDIO_DRIVE_CMD, &args, "HDIO_DRIVE_CMD(setidle1)"); 1697 ioctl_or_warn(fd, HDIO_DRIVE_CMD, &args);
1698 args[1] = 0; 1698 args[1] = 0;
1699 } 1699 }
1700#else /* HDIO_DRIVE_CMD */ 1700#else /* HDIO_DRIVE_CMD */
@@ -1709,15 +1709,17 @@ static void process_dev(char *devname)
1709 if (get_mult || get_identity) { 1709 if (get_mult || get_identity) {
1710 multcount = -1; 1710 multcount = -1;
1711 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) { 1711 if (ioctl(fd, HDIO_GET_MULTCOUNT, &multcount)) {
1712 if (get_mult) 1712 if (get_mult && ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn. */
1713 bb_perror_msg("HDIO_GET_MULTCOUNT"); 1713 bb_perror_msg("HDIO_GET_MULTCOUNT");
1714 else
1715 bb_perror_msg("ioctl %#x failed", HDIO_GET_MULTCOUNT);
1714 } else if (get_mult) { 1716 } else if (get_mult) {
1715 printf(fmt, "multcount", multcount); 1717 printf(fmt, "multcount", multcount);
1716 on_off(multcount != 0); 1718 on_off(multcount != 0);
1717 } 1719 }
1718 } 1720 }
1719 if (get_io32bit) { 1721 if (get_io32bit) {
1720 if (!bb_ioctl(fd, HDIO_GET_32BIT, &parm, "HDIO_GET_32BIT")) { 1722 if (!ioctl_or_warn(fd, HDIO_GET_32BIT, &parm)) {
1721 printf(" IO_support\t=%3ld (", parm); 1723 printf(" IO_support\t=%3ld (", parm);
1722 if (parm == 0) 1724 if (parm == 0)
1723 printf("default 16-bit)\n"); 1725 printf("default 16-bit)\n");
@@ -1734,14 +1736,14 @@ static void process_dev(char *devname)
1734 } 1736 }
1735 } 1737 }
1736 if (get_unmask) { 1738 if (get_unmask) {
1737 bb_ioctl_on_off(fd, HDIO_GET_UNMASKINTR, (unsigned long *)parm, 1739 if(!ioctl_or_warn(fd, HDIO_GET_UNMASKINTR, (unsigned long *)parm))
1738 "HDIO_GET_UNMASKINTR", "unmaskirq"); 1740 print_value_on_off("unmaskirq", parm);
1739 } 1741 }
1740 1742
1741 1743
1742#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA 1744#if ENABLE_FEATURE_HDPARM_HDIO_GETSET_DMA
1743 if (get_dma) { 1745 if (get_dma) {
1744 if (!bb_ioctl(fd, HDIO_GET_DMA, &parm, "HDIO_GET_DMA")) { 1746 if (!ioctl_or_warn(fd, HDIO_GET_DMA, &parm)) {
1745 printf(fmt, "using_dma", parm); 1747 printf(fmt, "using_dma", parm);
1746 if (parm == 8) 1748 if (parm == 8)
1747 printf(" (DMA-Assisted-PIO)\n"); 1749 printf(" (DMA-Assisted-PIO)\n");
@@ -1751,31 +1753,31 @@ static void process_dev(char *devname)
1751 } 1753 }
1752#endif 1754#endif
1753 if (get_dma_q) { 1755 if (get_dma_q) {
1754 bb_ioctl_on_off(fd, HDIO_GET_QDMA, (unsigned long *)parm, 1756 if(!ioctl_or_warn(fd, HDIO_GET_QDMA, (unsigned long *)parm))
1755 "HDIO_GET_QDMA", "queue_depth"); 1757 print_value_on_off("queue_depth", parm);
1756 } 1758 }
1757 if (get_keep) { 1759 if (get_keep) {
1758 bb_ioctl_on_off(fd, HDIO_GET_KEEPSETTINGS, (unsigned long *)parm, 1760 if(!ioctl_or_warn(fd, HDIO_GET_KEEPSETTINGS, (unsigned long *)parm))
1759 "HDIO_GET_KEEPSETTINGS", "keepsettings"); 1761 print_value_on_off("keepsettings", parm);
1760 } 1762 }
1761 1763
1762 if (get_nowerr) { 1764 if (get_nowerr) {
1763 bb_ioctl_on_off(fd, HDIO_GET_NOWERR, (unsigned long *)&parm, 1765 if(!ioctl_or_warn(fd, HDIO_GET_NOWERR, (unsigned long *)parm))
1764 "HDIO_GET_NOWERR", "nowerr"); 1766 print_value_on_off("nowerr", parm);
1765 } 1767 }
1766 if (get_readonly) { 1768 if (get_readonly) {
1767 bb_ioctl_on_off(fd, BLKROGET, (unsigned long *)parm, 1769 if(!ioctl_or_warn(fd, BLKROGET, (unsigned long *)parm))
1768 "BLKROGET", "readonly"); 1770 print_value_on_off("readonly", parm);
1769 } 1771 }
1770 if (get_readahead) { 1772 if (get_readahead) {
1771 bb_ioctl_on_off(fd, BLKRAGET, (unsigned long *) parm, 1773 if(!ioctl_or_warn(fd, BLKRAGET, (unsigned long *)parm))
1772 "BLKRAGET", "readahead"); 1774 print_value_on_off("readahead", parm);
1773 } 1775 }
1774 if (get_geom) { 1776 if (get_geom) {
1775 if (!bb_ioctl(fd, BLKGETSIZE, &parm, "BLKGETSIZE")) { 1777 if (!ioctl_or_warn(fd, BLKGETSIZE, &parm)) {
1776 struct hd_geometry g; 1778 struct hd_geometry g;
1777 1779
1778 if (!bb_ioctl(fd, HDIO_GETGEO, &g, "HDIO_GETGEO")) 1780 if (!ioctl_or_warn(fd, HDIO_GETGEO, &g))
1779 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n", 1781 printf(" geometry\t= %u/%u/%u, sectors = %ld, start = %ld\n",
1780 g.cylinders, g.heads, g.sectors, parm, g.start); 1782 g.cylinders, g.heads, g.sectors, parm, g.start);
1781 } 1783 }
@@ -1791,7 +1793,7 @@ static void process_dev(char *devname)
1791 const char *state; 1793 const char *state;
1792 1794
1793 args[0] = WIN_CHECKPOWERMODE1; 1795 args[0] = WIN_CHECKPOWERMODE1;
1794 if (bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2, 0)) { 1796 if (ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args, WIN_CHECKPOWERMODE2)) {
1795 if (errno != EIO || args[0] != 0 || args[1] != 0) 1797 if (errno != EIO || args[0] != 0 || args[1] != 0)
1796 state = "unknown"; 1798 state = "unknown";
1797 else 1799 else
@@ -1805,14 +1807,14 @@ static void process_dev(char *devname)
1805#endif 1807#endif
1806#if ENABLE_FEATURE_HDPARM_HDIO_DRIVE_RESET 1808#if ENABLE_FEATURE_HDPARM_HDIO_DRIVE_RESET
1807 if (perform_reset) { 1809 if (perform_reset) {
1808 bb_ioctl(fd, HDIO_DRIVE_RESET, NULL, "HDIO_DRIVE_RESET"); 1810 ioctl_or_warn(fd, HDIO_DRIVE_RESET, NULL);
1809 } 1811 }
1810#endif /* FEATURE_HDPARM_HDIO_DRIVE_RESET */ 1812#endif /* FEATURE_HDPARM_HDIO_DRIVE_RESET */
1811#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF 1813#if ENABLE_FEATURE_HDPARM_HDIO_TRISTATE_HWIF
1812 if (perform_tristate) { 1814 if (perform_tristate) {
1813 args[0] = 0; 1815 args[0] = 0;
1814 args[1] = tristate; 1816 args[1] = tristate;
1815 bb_ioctl(fd, HDIO_TRISTATE_HWIF, &args, "HDIO_TRISTATE_HWIF"); 1817 ioctl_or_warn(fd, HDIO_TRISTATE_HWIF, &args);
1816 } 1818 }
1817#endif /* FEATURE_HDPARM_HDIO_TRISTATE_HWIF */ 1819#endif /* FEATURE_HDPARM_HDIO_TRISTATE_HWIF */
1818#if ENABLE_FEATURE_HDPARM_GET_IDENTITY 1820#if ENABLE_FEATURE_HDPARM_GET_IDENTITY
@@ -1828,8 +1830,10 @@ static void process_dev(char *devname)
1828 dump_identity(&id); 1830 dump_identity(&id);
1829 } else if (errno == -ENOMSG) 1831 } else if (errno == -ENOMSG)
1830 printf(" no identification info available\n"); 1832 printf(" no identification info available\n");
1833 else if (ENABLE_IOCTL_HEX2STR_ERROR) /* To be coherent with ioctl_or_warn */
1834 bb_perror_msg("HDIO_GET_IDENTITY");
1831 else 1835 else
1832 bb_perror_msg("HDIO_GET_IDENTITY"); 1836 bb_perror_msg("ioctl %#x failed", HDIO_GET_IDENTITY);
1833 } 1837 }
1834 1838
1835 if (get_IDentity) { 1839 if (get_IDentity) {
@@ -1838,7 +1842,7 @@ static void process_dev(char *devname)
1838 memset(args1, 0, sizeof(args1)); 1842 memset(args1, 0, sizeof(args1));
1839 args1[0] = WIN_IDENTIFY; 1843 args1[0] = WIN_IDENTIFY;
1840 args1[3] = 1; 1844 args1[3] = 1;
1841 if (!bb_ioctl_alt(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY, "HDIO_DRIVE_CMD(identify)")) 1845 if (!ioctl_alt_or_warn(fd, HDIO_DRIVE_CMD, args1, WIN_PIDENTIFY))
1842 identify((void *)(args1 + 4)); 1846 identify((void *)(args1 + 4));
1843 } 1847 }
1844#endif 1848#endif
@@ -1848,17 +1852,17 @@ static void process_dev(char *devname)
1848 print_flag(1, "bus state", busstate); 1852 print_flag(1, "bus state", busstate);
1849 bus_state_value(busstate); 1853 bus_state_value(busstate);
1850 } 1854 }
1851 bb_ioctl(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate, "HDIO_SET_BUSSTATE"); 1855 ioctl_or_warn(fd, HDIO_SET_BUSSTATE, (int *)(unsigned long)busstate);
1852 } 1856 }
1853 if (get_busstate) { 1857 if (get_busstate) {
1854 if (!bb_ioctl(fd, HDIO_GET_BUSSTATE, &parm, "HDIO_GET_BUSSTATE")) { 1858 if (!ioctl_or_warn(fd, HDIO_GET_BUSSTATE, &parm)) {
1855 printf(fmt, "bus state", parm); 1859 printf(fmt, "bus state", parm);
1856 bus_state_value(parm); 1860 bus_state_value(parm);
1857 } 1861 }
1858 } 1862 }
1859#endif 1863#endif
1860 if (reread_partn) 1864 if (reread_partn)
1861 bb_ioctl(fd, BLKRRPART, NULL, "BLKRRPART"); 1865 ioctl_or_warn(fd, BLKRRPART, NULL);
1862 1866
1863 if (do_ctimings) 1867 if (do_ctimings)
1864 do_time(0, fd); /* time cache */ 1868 do_time(0, fd); /* time cache */
diff --git a/miscutils/mt.c b/miscutils/mt.c
index 2971421ef..b9bc2a11b 100644
--- a/miscutils/mt.c
+++ b/miscutils/mt.c
@@ -106,14 +106,12 @@ int mt_main(int argc, char **argv)
106 106
107 switch (code->value) { 107 switch (code->value) {
108 case MTTELL: 108 case MTTELL:
109 if (ioctl(fd, MTIOCPOS, &position) < 0) 109 ioctl_or_perror_and_die(fd, MTIOCPOS, &position, "%s", file);
110 bb_perror_msg_and_die("%s", file);
111 printf("At block %d.\n", (int) position.mt_blkno); 110 printf("At block %d.\n", (int) position.mt_blkno);
112 break; 111 break;
113 112
114 default: 113 default:
115 if (ioctl(fd, MTIOCTOP, &op) != 0) 114 ioctl_or_perror_and_die(fd, MTIOCTOP, &op, "%s", file);
116 bb_perror_msg_and_die("%s", file);
117 break; 115 break;
118 } 116 }
119 117
diff --git a/miscutils/raidautorun.c b/miscutils/raidautorun.c
index 2b65d39bc..edcb6d66d 100644
--- a/miscutils/raidautorun.c
+++ b/miscutils/raidautorun.c
@@ -19,9 +19,7 @@ int raidautorun_main(int argc, char **argv)
19 if (argc != 2) 19 if (argc != 2)
20 bb_show_usage(); 20 bb_show_usage();
21 21
22 if (ioctl(xopen(argv[1], O_RDONLY), RAID_AUTORUN, NULL) != 0) { 22 xioctl(xopen(argv[1], O_RDONLY), RAID_AUTORUN, NULL);
23 bb_perror_msg_and_die("ioctl");
24 }
25 23
26 return EXIT_SUCCESS; 24 return EXIT_SUCCESS;
27} 25}
diff --git a/networking/arp.c b/networking/arp.c
index 6a7c862b8..e529257a8 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -188,9 +188,8 @@ static void arp_getdevhw(char *ifname, struct sockaddr *sa,
188 const struct hwtype *xhw; 188 const struct hwtype *xhw;
189 189
190 strcpy(ifr.ifr_name, ifname); 190 strcpy(ifr.ifr_name, ifname);
191 if (ioctl(sockfd, SIOCGIFHWADDR, &ifr) < 0) { 191 ioctl_or_perror_and_die(sockfd, SIOCGIFHWADDR, &ifr,
192 bb_perror_msg_and_die("cant get HW-Address for '%s'", ifname); 192 "cant get HW-Address for '%s'", ifname);
193 }
194 if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) { 193 if (hwt && (ifr.ifr_hwaddr.sa_family != hw->type)) {
195 bb_error_msg_and_die("protocol type mismatch"); 194 bb_error_msg_and_die("protocol type mismatch");
196 } 195 }
@@ -306,9 +305,7 @@ static int arp_set(char **args)
306 /* Call the kernel. */ 305 /* Call the kernel. */
307 if (option_mask32 & ARP_OPT_v) 306 if (option_mask32 & ARP_OPT_v)
308 bb_error_msg("SIOCSARP()"); 307 bb_error_msg("SIOCSARP()");
309 if (ioctl(sockfd, SIOCSARP, &req) < 0) { 308 xioctl(sockfd, SIOCSARP, &req);
310 bb_perror_msg_and_die("SIOCSARP");
311 }
312 return 0; 309 return 0;
313} 310}
314 311
diff --git a/networking/arping.c b/networking/arping.c
index 7a9fbc2f4..8e457b13a 100644
--- a/networking/arping.c
+++ b/networking/arping.c
@@ -273,14 +273,11 @@ int arping_main(int argc, char **argv)
273 273
274 memset(&ifr, 0, sizeof(ifr)); 274 memset(&ifr, 0, sizeof(ifr));
275 strncpy(ifr.ifr_name, device, IFNAMSIZ - 1); 275 strncpy(ifr.ifr_name, device, IFNAMSIZ - 1);
276 if (ioctl(sock, SIOCGIFINDEX, &ifr) < 0) { 276 ioctl_or_perror_and_die(sock, SIOCGIFINDEX, &ifr, "interface %s not found", device);
277 bb_error_msg_and_die("interface %s not found", device);
278 }
279 ifindex = ifr.ifr_ifindex; 277 ifindex = ifr.ifr_ifindex;
280 278
281 if (ioctl(sock, SIOCGIFFLAGS, (char *) &ifr)) { 279 xioctl(sock, SIOCGIFFLAGS, (char *) &ifr);
282 bb_error_msg_and_die("SIOCGIFFLAGS"); 280
283 }
284 if (!(ifr.ifr_flags & IFF_UP)) { 281 if (!(ifr.ifr_flags & IFF_UP)) {
285 bb_error_msg_and_die("interface %s is down", device); 282 bb_error_msg_and_die("interface %s is down", device);
286 } 283 }
diff --git a/networking/ether-wake.c b/networking/ether-wake.c
index 9de0d489b..b67e1b5d8 100644
--- a/networking/ether-wake.c
+++ b/networking/ether-wake.c
@@ -220,8 +220,7 @@ int ether_wake_main(int argc, char **argv)
220 struct ifreq if_hwaddr; 220 struct ifreq if_hwaddr;
221 221
222 strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name)); 222 strncpy(if_hwaddr.ifr_name, ifname, sizeof(if_hwaddr.ifr_name));
223 if (ioctl(s, SIOCGIFHWADDR, &if_hwaddr) != 0) 223 ioctl_or_perror_and_die(s, SIOCGIFHWADDR, &if_hwaddr, "SIOCGIFHWADDR on %s failed", ifname);
224 bb_perror_msg_and_die("SIOCGIFHWADDR on %s failed", ifname);
225 224
226 memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6); 225 memcpy(outpack+6, if_hwaddr.ifr_hwaddr.sa_data, 6);
227 226
@@ -257,8 +256,7 @@ int ether_wake_main(int argc, char **argv)
257 { 256 {
258 struct ifreq ifr; 257 struct ifreq ifr;
259 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); 258 strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
260 if (ioctl(s, SIOCGIFINDEX, &ifr) != 0) 259 xioctl(s, SIOCGIFINDEX, &ifr);
261 bb_perror_msg_and_die("SIOCGIFINDEX");
262 memset(&whereto, 0, sizeof(whereto)); 260 memset(&whereto, 0, sizeof(whereto));
263 whereto.sll_family = AF_PACKET; 261 whereto.sll_family = AF_PACKET;
264 whereto.sll_ifindex = ifr.ifr_ifindex; 262 whereto.sll_ifindex = ifr.ifr_ifindex;
diff --git a/networking/ifconfig.c b/networking/ifconfig.c
index 5e11b2b7c..0d53676cd 100644
--- a/networking/ifconfig.c
+++ b/networking/ifconfig.c
@@ -402,12 +402,10 @@ int ifconfig_main(int argc, char **argv)
402 402
403 /* Create a channel to the NET kernel. */ 403 /* Create a channel to the NET kernel. */
404 sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0); 404 sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
405 if (ioctl(sockfd6, SIOGIFINDEX, &ifr) < 0) 405 xioctl(sockfd6, SIOGIFINDEX, &ifr);
406 bb_perror_msg_and_die("SIOGIFINDEX");
407 ifr6.ifr6_ifindex = ifr.ifr_ifindex; 406 ifr6.ifr6_ifindex = ifr.ifr_ifindex;
408 ifr6.ifr6_prefixlen = prefix_len; 407 ifr6.ifr6_prefixlen = prefix_len;
409 if (ioctl(sockfd6, a1op->selector, &ifr6) < 0) 408 ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "%s", a1op->name);
410 bb_perror_msg_and_die(a1op->name);
411 if (ENABLE_FEATURE_CLEAN_UP) 409 if (ENABLE_FEATURE_CLEAN_UP)
412 free(lsa); 410 free(lsa);
413 continue; 411 continue;
@@ -444,8 +442,7 @@ int ifconfig_main(int argc, char **argv)
444 p = ((char *)&ifr) + a1op->ifr_offset; 442 p = ((char *)&ifr) + a1op->ifr_offset;
445#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ 443#if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
446 if (mask & A_MAP_TYPE) { 444 if (mask & A_MAP_TYPE) {
447 if (ioctl(sockfd, SIOCGIFMAP, &ifr) < 0) 445 xioctl(sockfd, SIOCGIFMAP, &ifr);
448 bb_perror_msg_and_die("SIOCGIFMAP");
449 if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR) 446 if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR)
450 *((unsigned char *) p) = i; 447 *((unsigned char *) p) = i;
451 else if (mask & A_MAP_USHORT) 448 else if (mask & A_MAP_USHORT)
@@ -460,8 +457,7 @@ int ifconfig_main(int argc, char **argv)
460 *((int *) p) = i; 457 *((int *) p) = i;
461 } 458 }
462 459
463 if (ioctl(sockfd, a1op->selector, &ifr) < 0) 460 ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "%s", a1op->name);
464 bb_perror_msg_and_die(a1op->name);
465#ifdef QUESTIONABLE_ALIAS_CASE 461#ifdef QUESTIONABLE_ALIAS_CASE
466 if (mask & A_COLON_CHK) { 462 if (mask & A_COLON_CHK) {
467 /* 463 /*
@@ -486,15 +482,13 @@ int ifconfig_main(int argc, char **argv)
486 mask = N_SET; 482 mask = N_SET;
487 } 483 }
488 484
489 if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) 485 xioctl(sockfd, SIOCGIFFLAGS, &ifr);
490 bb_perror_msg_and_die("SIOCGIFFLAGS");
491 selector = op->selector; 486 selector = op->selector;
492 if (mask & SET_MASK) 487 if (mask & SET_MASK)
493 ifr.ifr_flags |= selector; 488 ifr.ifr_flags |= selector;
494 else 489 else
495 ifr.ifr_flags &= ~selector; 490 ifr.ifr_flags &= ~selector;
496 if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) 491 xioctl(sockfd, SIOCSIFFLAGS, &ifr);
497 bb_perror_msg_and_die("SIOCSIFFLAGS");
498 } /* while () */ 492 } /* while () */
499 493
500 if (ENABLE_FEATURE_CLEAN_UP) 494 if (ENABLE_FEATURE_CLEAN_UP)
diff --git a/networking/interface.c b/networking/interface.c
index 204febf7d..ea02f4cc9 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -521,8 +521,7 @@ static int if_readconf(void)
521 ifc.ifc_len = sizeof(struct ifreq) * numreqs; 521 ifc.ifc_len = sizeof(struct ifreq) * numreqs;
522 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len); 522 ifc.ifc_buf = xrealloc(ifc.ifc_buf, ifc.ifc_len);
523 523
524 if (ioctl(skfd, SIOCGIFCONF, &ifc) < 0) { 524 if (ioctl_or_warn(skfd, SIOCGIFCONF, &ifc) < 0) {
525 bb_perror_msg("SIOCGIFCONF");
526 goto out; 525 goto out;
527 } 526 }
528 if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) { 527 if (ifc.ifc_len == sizeof(struct ifreq) * numreqs) {
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index a4add6a47..fc10ba37c 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -84,8 +84,7 @@ static void print_queuelen(char *name)
84 84
85 memset(&ifr, 0, sizeof(ifr)); 85 memset(&ifr, 0, sizeof(ifr));
86 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); 86 strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
87 if (ioctl(s, SIOCGIFTXQLEN, &ifr) < 0) { 87 if (ioctl_or_warn(s, SIOCGIFTXQLEN, &ifr) < 0) {
88 bb_perror_msg("SIOCGIFXQLEN");
89 close(s); 88 close(s);
90 return; 89 return;
91 } 90 }
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index 7db4d7e15..3d3ea2a23 100644
--- a/networking/libiproute/iplink.c
+++ b/networking/libiproute/iplink.c
@@ -49,14 +49,11 @@ static void do_chflags(char *dev, uint32_t flags, uint32_t mask)
49 49
50 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 50 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
51 fd = get_ctl_fd(); 51 fd = get_ctl_fd();
52 if (ioctl(fd, SIOCGIFFLAGS, &ifr)) { 52 xioctl(fd, SIOCGIFFLAGS, &ifr);
53 bb_perror_msg_and_die("SIOCGIFFLAGS");
54 }
55 if ((ifr.ifr_flags ^ flags) & mask) { 53 if ((ifr.ifr_flags ^ flags) & mask) {
56 ifr.ifr_flags &= ~mask; 54 ifr.ifr_flags &= ~mask;
57 ifr.ifr_flags |= mask & flags; 55 ifr.ifr_flags |= mask & flags;
58 if (ioctl(fd, SIOCSIFFLAGS, &ifr)) 56 xioctl(fd, SIOCSIFFLAGS, &ifr);
59 bb_perror_msg_and_die("SIOCSIFFLAGS");
60 } 57 }
61 close(fd); 58 close(fd);
62} 59}
@@ -66,15 +63,11 @@ static void do_changename(char *dev, char *newdev)
66{ 63{
67 struct ifreq ifr; 64 struct ifreq ifr;
68 int fd; 65 int fd;
69 int err;
70 66
71 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 67 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
72 strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname)); 68 strncpy(ifr.ifr_newname, newdev, sizeof(ifr.ifr_newname));
73 fd = get_ctl_fd(); 69 fd = get_ctl_fd();
74 err = ioctl(fd, SIOCSIFNAME, &ifr); 70 xioctl(fd, SIOCSIFNAME, &ifr);
75 if (err) {
76 bb_perror_msg_and_die("SIOCSIFNAME");
77 }
78 close(fd); 71 close(fd);
79} 72}
80 73
@@ -88,9 +81,7 @@ static void set_qlen(char *dev, int qlen)
88 memset(&ifr, 0, sizeof(ifr)); 81 memset(&ifr, 0, sizeof(ifr));
89 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 82 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
90 ifr.ifr_qlen = qlen; 83 ifr.ifr_qlen = qlen;
91 if (ioctl(s, SIOCSIFTXQLEN, &ifr) < 0) { 84 xioctl(s, SIOCSIFTXQLEN, &ifr);
92 bb_perror_msg_and_die("SIOCSIFXQLEN");
93 }
94 close(s); 85 close(s);
95} 86}
96 87
@@ -104,9 +95,7 @@ static void set_mtu(char *dev, int mtu)
104 memset(&ifr, 0, sizeof(ifr)); 95 memset(&ifr, 0, sizeof(ifr));
105 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 96 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
106 ifr.ifr_mtu = mtu; 97 ifr.ifr_mtu = mtu;
107 if (ioctl(s, SIOCSIFMTU, &ifr) < 0) { 98 xioctl(s, SIOCSIFMTU, &ifr);
108 bb_perror_msg_and_die("SIOCSIFMTU");
109 }
110 close(s); 99 close(s);
111} 100}
112 101
@@ -122,9 +111,7 @@ static int get_address(char *dev, int *htype)
122 111
123 memset(&ifr, 0, sizeof(ifr)); 112 memset(&ifr, 0, sizeof(ifr));
124 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 113 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
125 if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) { 114 xioctl(s, SIOCGIFINDEX, &ifr);
126 bb_perror_msg_and_die("SIOCGIFINDEX");
127 }
128 115
129 memset(&me, 0, sizeof(me)); 116 memset(&me, 0, sizeof(me));
130 me.sll_family = AF_PACKET; 117 me.sll_family = AF_PACKET;
@@ -163,9 +150,10 @@ static void set_address(struct ifreq *ifr, int brd)
163 int s; 150 int s;
164 151
165 s = get_ctl_fd(); 152 s = get_ctl_fd();
166 if (ioctl(s, brd ? SIOCSIFHWBROADCAST :SIOCSIFHWADDR, ifr) < 0) { 153 if (brd)
167 bb_perror_msg_and_die(brd ? "SIOCSIFHWBROADCAST" : "SIOCSIFHWADDR"); 154 xioctl(s, SIOCSIFHWBROADCAST, ifr);
168 } 155 else
156 xioctl(s, SIOCSIFHWADDR, ifr);
169 close(s); 157 close(s);
170} 158}
171 159
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index b12bceb45..90d0e1186 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -14,8 +14,6 @@
14 * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag 14 * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag
15 */ 15 */
16 16
17//#include <sys/socket.h>
18//#include <sys/ioctl.h>
19#include <netinet/ip.h> 17#include <netinet/ip.h>
20#include <net/if.h> 18#include <net/if.h>
21#include <net/if_arp.h> 19#include <net/if_arp.h>
@@ -38,9 +36,7 @@ static int do_ioctl_get_ifindex(char *dev)
38 36
39 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 37 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
40 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 38 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
41 if (ioctl(fd, SIOCGIFINDEX, &ifr)) { 39 xioctl(fd, SIOCGIFINDEX, &ifr);
42 bb_perror_msg_and_die("SIOCGIFINDEX");
43 }
44 close(fd); 40 close(fd);
45 return ifr.ifr_ifindex; 41 return ifr.ifr_ifindex;
46} 42}
@@ -49,30 +45,26 @@ static int do_ioctl_get_iftype(char *dev)
49{ 45{
50 struct ifreq ifr; 46 struct ifreq ifr;
51 int fd; 47 int fd;
48 int err;
52 49
53 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name)); 50 strncpy(ifr.ifr_name, dev, sizeof(ifr.ifr_name));
54 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 51 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
55 if (ioctl(fd, SIOCGIFHWADDR, &ifr)) { 52 err = ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr);
56 bb_perror_msg("SIOCGIFHWADDR");
57 return -1;
58 }
59 close(fd); 53 close(fd);
60 return ifr.ifr_addr.sa_family; 54 return err ? -1 : ifr.ifr_addr.sa_family;
61} 55}
62 56
63static char *do_ioctl_get_ifname(int idx) 57static char *do_ioctl_get_ifname(int idx)
64{ 58{
65 struct ifreq ifr; 59 struct ifreq ifr;
66 int fd; 60 int fd;
61 int err;
67 62
68 ifr.ifr_ifindex = idx; 63 ifr.ifr_ifindex = idx;
69 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 64 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
70 if (ioctl(fd, SIOCGIFNAME, &ifr)) { 65 err = ioctl_or_warn(fd, SIOCGIFNAME, &ifr);
71 bb_perror_msg("SIOCGIFNAME");
72 return NULL;
73 }
74 close(fd); 66 close(fd);
75 return xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name)); 67 return err ? NULL : xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name));
76} 68}
77 69
78static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p) 70static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
@@ -84,10 +76,7 @@ static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
84 strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name)); 76 strncpy(ifr.ifr_name, basedev, sizeof(ifr.ifr_name));
85 ifr.ifr_ifru.ifru_data = (void*)p; 77 ifr.ifr_ifru.ifru_data = (void*)p;
86 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 78 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
87 err = ioctl(fd, SIOCGETTUNNEL, &ifr); 79 err = ioctl_or_warn(fd, SIOCGETTUNNEL, &ifr);
88 if (err) {
89 bb_perror_msg("SIOCGETTUNNEL");
90 }
91 close(fd); 80 close(fd);
92 return err; 81 return err;
93} 82}
@@ -105,9 +94,15 @@ static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
105 } 94 }
106 ifr.ifr_ifru.ifru_data = (void*)p; 95 ifr.ifr_ifru.ifru_data = (void*)p;
107 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 96 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
108 if (ioctl(fd, cmd, &ifr)) { 97#if ENABLE_IOCTL_HEX2STR_ERROR
109 bb_perror_msg_and_die("ioctl"); 98 /* #define magic will turn ioctl# into string */
110 } 99 if (cmd == SIOCCHGTUNNEL)
100 xioctl(fd, SIOCCHGTUNNEL, &ifr);
101 else
102 xioctl(fd, SIOCADDTUNNEL, &ifr);
103#else
104 xioctl(fd, cmd, &ifr);
105#endif
111 close(fd); 106 close(fd);
112 return 0; 107 return 0;
113} 108}
@@ -125,9 +120,7 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
125 } 120 }
126 ifr.ifr_ifru.ifru_data = (void*)p; 121 ifr.ifr_ifru.ifru_data = (void*)p;
127 fd = xsocket(AF_INET, SOCK_DGRAM, 0); 122 fd = xsocket(AF_INET, SOCK_DGRAM, 0);
128 if (ioctl(fd, SIOCDELTUNNEL, &ifr)) { 123 xioctl(fd, SIOCDELTUNNEL, &ifr);
129 bb_perror_msg_and_die("SIOCDELTUNNEL");
130 }
131 close(fd); 124 close(fd);
132 return 0; 125 return 0;
133} 126}
@@ -526,29 +519,24 @@ static int do_show(int argc, char **argv)
526/* Return value becomes exitcode. It's okay to not return at all */ 519/* Return value becomes exitcode. It's okay to not return at all */
527int do_iptunnel(int argc, char **argv) 520int do_iptunnel(int argc, char **argv)
528{ 521{
529 static const char * const keywords[] = { 522 static const char *const keywords[] = {
530 "add", "change", "delete", "show", "list", "lst", NULL 523 "add", "change", "delete", "show", "list", "lst", NULL
531 }; 524 };
532 enum {ARG_add = 1, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst}; 525 enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
533 smalluint key = 4; /* show */ 526 int key;
534 if (argc > 0) { 527
535 key = index_in_substr_array(keywords, *argv) +1; 528 if (argc) {
529 key = index_in_substr_array(keywords, *argv);
530 if (key < 0)
531 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
536 --argc; 532 --argc;
537 ++argv; 533 ++argv;
538 } else 534 if (key == ARG_add)
539 return do_show(0, NULL); 535 return do_add(SIOCADDTUNNEL, argc, argv);
540 if (key < ARG_add) 536 if (key == ARG_change)
541 bail: 537 return do_add(SIOCCHGTUNNEL, argc, argv);
542 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); 538 if (key == ARG_del)
543 539 return do_del(argc, argv);
544 if (key == ARG_add) 540 }
545 return do_add(SIOCADDTUNNEL, argc, argv); 541 return do_show(argc, argv);
546 if (key == ARG_change)
547 return do_add(SIOCCHGTUNNEL, argc, argv);
548 if (key == ARG_del)
549 return do_del(argc, argv);
550 if (key == ARG_show || key == ARG_list || key == ARG_lst)
551 return do_show(argc, argv);
552 /* be gentle to gcc; avoid warning about non returning */
553 goto bail; /* never reached */
554} 542}
diff --git a/networking/nameif.c b/networking/nameif.c
index a65f30819..fd081fd63 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -148,9 +148,9 @@ int nameif_main(int argc, char **argv)
148 continue; 148 continue;
149 149
150 strcpy(ifr.ifr_newname, ch->ifname); 150 strcpy(ifr.ifr_newname, ch->ifname);
151 if (ioctl(ctl_sk, SIOCSIFNAME, &ifr) < 0) 151 ioctl_or_perror_and_die(ctl_sk, SIOCSIFNAME, &ifr,
152 bb_perror_msg_and_die("cannot change ifname %s to %s", 152 "cannot change ifname %s to %s",
153 ifr.ifr_name, ch->ifname); 153 ifr.ifr_name, ch->ifname);
154 154
155 /* Remove list entry of renamed interface */ 155 /* Remove list entry of renamed interface */
156 if (ch->prev != NULL) { 156 if (ch->prev != NULL) {
diff --git a/networking/route.c b/networking/route.c
index b5490ddd8..530c51b10 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -327,9 +327,10 @@ static void INET_setroute(int action, char **args)
327 /* Create a socket to the INET kernel. */ 327 /* Create a socket to the INET kernel. */
328 skfd = xsocket(AF_INET, SOCK_DGRAM, 0); 328 skfd = xsocket(AF_INET, SOCK_DGRAM, 0);
329 329
330 if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { 330 if (action == RTACTION_ADD)
331 bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); 331 xioctl(skfd, SIOCADDRT, &rt);
332 } 332 else
333 xioctl(skfd, SIOCDELRT, &rt);
333 334
334 if (ENABLE_FEATURE_CLEAN_UP) close(skfd); 335 if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
335} 336}
@@ -423,17 +424,15 @@ static void INET6_setroute(int action, char **args)
423 struct ifreq ifr; 424 struct ifreq ifr;
424 memset(&ifr, 0, sizeof(ifr)); 425 memset(&ifr, 0, sizeof(ifr));
425 strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name)); 426 strncpy(ifr.ifr_name, devname, sizeof(ifr.ifr_name));
426 427 xioctl(skfd, SIOGIFINDEX, &ifr);
427 if (ioctl(skfd, SIOGIFINDEX, &ifr) < 0) {
428 bb_perror_msg_and_die("SIOGIFINDEX");
429 }
430 rt.rtmsg_ifindex = ifr.ifr_ifindex; 428 rt.rtmsg_ifindex = ifr.ifr_ifindex;
431 } 429 }
432 430
433 /* Tell the kernel to accept this route. */ 431 /* Tell the kernel to accept this route. */
434 if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { 432 if (action == RTACTION_ADD)
435 bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); 433 xioctl(skfd, SIOCADDRT, &rt);
436 } 434 else
435 xioctl(skfd, SIOCDELRT, &rt);
437 436
438 if (ENABLE_FEATURE_CLEAN_UP) close(skfd); 437 if (ENABLE_FEATURE_CLEAN_UP) close(skfd);
439} 438}
diff --git a/networking/slattach.c b/networking/slattach.c
index 3495df598..1a4423b72 100644
--- a/networking/slattach.c
+++ b/networking/slattach.c
@@ -50,8 +50,7 @@ static void save_state(void)
50 bb_perror_msg_and_die("get state"); 50 bb_perror_msg_and_die("get state");
51 51
52 /* Save line discipline */ 52 /* Save line discipline */
53 if (ioctl(handle, TIOCGETD, &saved_disc) < 0) 53 xioctl(handle, TIOCGETD, &saved_disc);
54 bb_perror_msg_and_die("get discipline");
55} 54}
56 55
57static int set_termios_state_and_warn(struct termios *state) 56static int set_termios_state_and_warn(struct termios *state)
@@ -81,8 +80,7 @@ static void restore_state_and_exit(int exitcode)
81 struct termios state; 80 struct termios state;
82 81
83 /* Restore line discipline */ 82 /* Restore line discipline */
84 if (ioctl(handle, TIOCSETD, &saved_disc) < 0) { 83 if (ioctl_or_warn(handle, TIOCSETD, &saved_disc) < 0) {
85 bb_perror_msg("set discipline");
86 exitcode = 1; 84 exitcode = 1;
87 } 85 }
88 86
@@ -115,14 +113,12 @@ static void set_state(struct termios *state, int encap)
115 goto bad; 113 goto bad;
116 /* Set line discliple (N_SLIP always) */ 114 /* Set line discliple (N_SLIP always) */
117 disc = N_SLIP; 115 disc = N_SLIP;
118 if (ioctl(handle, TIOCSETD, &disc) < 0) { 116 if (ioctl_or_warn(handle, TIOCSETD, &disc) < 0) {
119 bb_perror_msg("set discipline");
120 goto bad; 117 goto bad;
121 } 118 }
122 119
123 /* Set encapsulation (SLIP, CSLIP, etc) */ 120 /* Set encapsulation (SLIP, CSLIP, etc) */
124 if (ioctl(handle, SIOCSIFENCAP, &encap) < 0) { 121 if (ioctl_or_warn(handle, SIOCSIFENCAP, &encap) < 0) {
125 bb_perror_msg("set encapsulation");
126 bad: 122 bad:
127 restore_state_and_exit(1); 123 restore_state_and_exit(1);
128 } 124 }
diff --git a/networking/traceroute.c b/networking/traceroute.c
index ad3ec4eda..c87f7ffc5 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -445,8 +445,8 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
445 if (strchr(al->device, ':') != NULL) 445 if (strchr(al->device, ':') != NULL)
446 continue; 446 continue;
447#endif 447#endif
448 if (ioctl(fd, SIOCGIFADDR, (char *)&ifr) < 0) 448 ioctl_or_perror_and_die(fd, SIOCGIFADDR, (char *)&ifr,
449 bb_perror_msg_and_die("SIOCGIFADDR: %s", al->device); 449 "SIOCGIFADDR: %s", al->device);
450 450
451 addr_sin = (struct sockaddr_in *)&ifr.ifr_addr; 451 addr_sin = (struct sockaddr_in *)&ifr.ifr_addr;
452 al->addr = addr_sin->sin_addr.s_addr; 452 al->addr = addr_sin->sin_addr.s_addr;
diff --git a/networking/udhcp/socket.c b/networking/udhcp/socket.c
index be5985f88..21a058545 100644
--- a/networking/udhcp/socket.c
+++ b/networking/udhcp/socket.c
@@ -53,9 +53,9 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
53 ifr.ifr_addr.sa_family = AF_INET; 53 ifr.ifr_addr.sa_family = AF_INET;
54 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); 54 strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name));
55 if (addr) { 55 if (addr) {
56 if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) { 56 if (ioctl_or_perror(fd, SIOCGIFADDR, &ifr,
57 bb_perror_msg("SIOCGIFADDR failed (is interface %s " 57 "is interface %s up and configured?", interface)
58 "up and configured?)", interface); 58 ) {
59 close(fd); 59 close(fd);
60 return -1; 60 return -1;
61 } 61 }
@@ -65,8 +65,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
65 } 65 }
66 66
67 if (ifindex) { 67 if (ifindex) {
68 if (ioctl(fd, SIOCGIFINDEX, &ifr) != 0) { 68 if (ioctl_or_warn(fd, SIOCGIFINDEX, &ifr) != 0) {
69 bb_perror_msg("SIOCGIFINDEX failed");
70 close(fd); 69 close(fd);
71 return -1; 70 return -1;
72 } 71 }
@@ -75,8 +74,7 @@ int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t
75 } 74 }
76 75
77 if (arp) { 76 if (arp) {
78 if (ioctl(fd, SIOCGIFHWADDR, &ifr) != 0) { 77 if (ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr) != 0) {
79 bb_perror_msg("SIOCGIFHWADDR failed");
80 close(fd); 78 close(fd);
81 return -1; 79 return -1;
82 } 80 }
diff --git a/networking/vconfig.c b/networking/vconfig.c
index e063d0a49..4776e1324 100644
--- a/networking/vconfig.c
+++ b/networking/vconfig.c
@@ -157,9 +157,8 @@ int vconfig_main(int argc, char **argv)
157 } 157 }
158 158
159 fd = xsocket(AF_INET, SOCK_STREAM, 0); 159 fd = xsocket(AF_INET, SOCK_STREAM, 0);
160 if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) { 160 ioctl_or_perror_and_die(fd, SIOCSIFVLAN, &ifr,
161 bb_perror_msg_and_die("ioctl error for %s", *argv); 161 "ioctl error for %s", *argv);
162 }
163 162
164 return 0; 163 return 0;
165} 164}
diff --git a/networking/zcip.c b/networking/zcip.c
index de4ee0b1a..281f551d7 100644
--- a/networking/zcip.c
+++ b/networking/zcip.c
@@ -247,9 +247,7 @@ int zcip_main(int argc, char **argv)
247 // get the interface's ethernet address 247 // get the interface's ethernet address
248 //memset(&ifr, 0, sizeof(ifr)); 248 //memset(&ifr, 0, sizeof(ifr));
249 strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name)); 249 strncpy(ifr.ifr_name, intf, sizeof(ifr.ifr_name));
250 if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { 250 xioctl(fd, SIOCGIFHWADDR, &ifr);
251 bb_perror_msg_and_die("get ethernet address");
252 }
253 memcpy(&eth_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); 251 memcpy(&eth_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN);
254 252
255 // start with some stable ip address, either a function of 253 // start with some stable ip address, either a function of
diff --git a/scripts/defconfig b/scripts/defconfig
index 522b1ca25..4d12f8ec5 100644
--- a/scripts/defconfig
+++ b/scripts/defconfig
@@ -77,6 +77,7 @@ CONFIG_FEATURE_EDITING_HISTORY=15
77# CONFIG_FEATURE_USERNAME_COMPLETION is not set 77# CONFIG_FEATURE_USERNAME_COMPLETION is not set
78# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set 78# CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
79# CONFIG_MONOTONIC_SYSCALL is not set 79# CONFIG_MONOTONIC_SYSCALL is not set
80CONFIG_IOCTL_HEX2STR_ERROR=y
80 81
81# 82#
82# Applets 83# Applets
diff --git a/util-linux/fbset.c b/util-linux/fbset.c
index f963040bd..69986df25 100644
--- a/util-linux/fbset.c
+++ b/util-linux/fbset.c
@@ -385,8 +385,7 @@ int fbset_main(int argc, char **argv)
385 } 385 }
386 386
387 fh = xopen(fbdev, O_RDONLY); 387 fh = xopen(fbdev, O_RDONLY);
388 if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) 388 xioctl(fh, FBIOGET_VSCREENINFO, &var);
389 bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "GE");
390 if (g_options & OPT_READMODE) { 389 if (g_options & OPT_READMODE) {
391 if (!readmode(&var, modefile, mode)) { 390 if (!readmode(&var, modefile, mode)) {
392 bb_error_msg_and_die("unknown video mode '%s'", mode); 391 bb_error_msg_and_die("unknown video mode '%s'", mode);
@@ -397,8 +396,7 @@ int fbset_main(int argc, char **argv)
397 if (g_options & OPT_CHANGE) { 396 if (g_options & OPT_CHANGE) {
398 if (g_options & OPT_ALL) 397 if (g_options & OPT_ALL)
399 var.activate = FB_ACTIVATE_ALL; 398 var.activate = FB_ACTIVATE_ALL;
400 if (ioctl(fh, FBIOPUT_VSCREENINFO, &var)) 399 xioctl(fh, FBIOPUT_VSCREENINFO, &var);
401 bb_perror_msg_and_die("ioctl(%sT_VSCREENINFO)", "PU");
402 } 400 }
403 showmode(&var); 401 showmode(&var);
404 /* Don't close the file, as exiting will take care of that */ 402 /* Don't close the file, as exiting will take care of that */
diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c
index e9fbeee7b..5e253efa8 100644
--- a/util-linux/fdformat.c
+++ b/util-linux/fdformat.c
@@ -45,13 +45,6 @@ struct format_descr {
45#define FDGETPRM _IOR(2, 0x04, struct floppy_struct) 45#define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
46#define FD_FILL_BYTE 0xF6 /* format fill byte. */ 46#define FD_FILL_BYTE 0xF6 /* format fill byte. */
47 47
48static void xioctl(int fd, int request, void *argp, const char *string)
49{
50 if (ioctl(fd, request, argp) < 0) {
51 bb_perror_msg_and_die(string);
52 }
53}
54
55int fdformat_main(int argc,char **argv); 48int fdformat_main(int argc,char **argv);
56int fdformat_main(int argc,char **argv) 49int fdformat_main(int argc,char **argv)
57{ 50{
@@ -77,7 +70,7 @@ int fdformat_main(int argc,char **argv)
77 fd = xopen(*argv, O_RDWR); 70 fd = xopen(*argv, O_RDWR);
78 71
79 /* original message was: "Could not determine current format type" */ 72 /* original message was: "Could not determine current format type" */
80 xioctl(fd, FDGETPRM, &param, "FDGETPRM"); 73 xioctl(fd, FDGETPRM, &param);
81 74
82 printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n", 75 printf("%s-sided, %d tracks, %d sec/track. Total capacity %d kB\n",
83 (param.head == 2) ? "Double" : "Single", 76 (param.head == 2) ? "Double" : "Single",
@@ -85,21 +78,21 @@ int fdformat_main(int argc,char **argv)
85 78
86 /* FORMAT */ 79 /* FORMAT */
87 printf("Formatting... "); 80 printf("Formatting... ");
88 xioctl(fd, FDFMTBEG, NULL, "FDFMTBEG"); 81 xioctl(fd, FDFMTBEG, NULL);
89 82
90 /* n == track */ 83 /* n == track */
91 for (n = 0; n < param.track; n++) { 84 for (n = 0; n < param.track; n++) {
92 descr.head = 0; 85 descr.head = 0;
93 descr.track = n; 86 descr.track = n;
94 xioctl(fd, FDFMTTRK, &descr, "FDFMTTRK"); 87 xioctl(fd, FDFMTTRK, &descr);
95 printf("%3d\b\b\b", n); 88 printf("%3d\b\b\b", n);
96 if (param.head == 2) { 89 if (param.head == 2) {
97 descr.head = 1; 90 descr.head = 1;
98 xioctl(fd, FDFMTTRK, &descr, "FDFMTTRK"); 91 xioctl(fd, FDFMTTRK, &descr);
99 } 92 }
100 } 93 }
101 94
102 xioctl(fd, FDFMTEND, NULL, "FDFMTEND"); 95 xioctl(fd, FDFMTEND, NULL);
103 printf("done\n"); 96 printf("done\n");
104 97
105 /* VERIFY */ 98 /* VERIFY */
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 870789112..3b9892fa8 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -2434,23 +2434,9 @@ reread_partition_table(int leave)
2434 printf("Calling ioctl() to re-read partition table\n"); 2434 printf("Calling ioctl() to re-read partition table\n");
2435 sync(); 2435 sync();
2436 /* sleep(2); Huh? */ 2436 /* sleep(2); Huh? */
2437 i = ioctl(fd, BLKRRPART); 2437 i = ioctl_or_perror(fd, BLKRRPART, NULL,
2438#if 0 2438 "WARNING: rereading partition table "
2439 else {
2440 /* some kernel versions (1.2.x) seem to have trouble
2441 rereading the partition table, but if asked to do it
2442 twice, the second time works. - biro@yggdrasil.com */
2443 sync();
2444 sleep(2);
2445 i = ioctl(fd, BLKRRPART);
2446 }
2447#endif
2448
2449 if (i) {
2450 bb_perror_msg("WARNING: rereading partition table "
2451 "failed, kernel still uses old table"); 2439 "failed, kernel still uses old table");
2452 }
2453
2454#if 0 2440#if 0
2455 if (dos_changed) 2441 if (dos_changed)
2456 printf( 2442 printf(
diff --git a/util-linux/freeramdisk.c b/util-linux/freeramdisk.c
index a1f2c56cf..4bd93781b 100644
--- a/util-linux/freeramdisk.c
+++ b/util-linux/freeramdisk.c
@@ -17,7 +17,6 @@
17int freeramdisk_main(int argc, char **argv); 17int freeramdisk_main(int argc, char **argv);
18int freeramdisk_main(int argc, char **argv) 18int freeramdisk_main(int argc, char **argv)
19{ 19{
20 int result;
21 int fd; 20 int fd;
22 21
23 if (argc != 2) bb_show_usage(); 22 if (argc != 2) bb_show_usage();
@@ -25,11 +24,10 @@ int freeramdisk_main(int argc, char **argv)
25 fd = xopen(argv[1], O_RDWR); 24 fd = xopen(argv[1], O_RDWR);
26 25
27 // Act like freeramdisk, fdflush, or both depending on configuration. 26 // Act like freeramdisk, fdflush, or both depending on configuration.
28 result = ioctl(fd, (ENABLE_FREERAMDISK && applet_name[1]=='r') 27 ioctl_or_perror_and_die(fd, (ENABLE_FREERAMDISK && applet_name[1]=='r')
29 || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH); 28 || !ENABLE_FDFLUSH ? BLKFLSBUF : FDFLUSH, NULL, "%s", argv[1]);
30 29
31 if (ENABLE_FEATURE_CLEAN_UP) close(fd); 30 if (ENABLE_FEATURE_CLEAN_UP) close(fd);
32 31
33 if (result) bb_perror_msg_and_die("%s", argv[1]);
34 return EXIT_SUCCESS; 32 return EXIT_SUCCESS;
35} 33}
diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c
index 204a103c3..8b65df6a6 100644
--- a/util-linux/hwclock.c
+++ b/util-linux/hwclock.c
@@ -59,25 +59,23 @@ static time_t read_rtc(int utc)
59 int rtc = xopen_rtc(O_RDONLY); 59 int rtc = xopen_rtc(O_RDONLY);
60 60
61 memset(&tm, 0, sizeof(struct tm)); 61 memset(&tm, 0, sizeof(struct tm));
62 if (ioctl(rtc, RTC_RD_TIME, &tm) < 0) 62 xioctl(rtc, RTC_RD_TIME, &tm);
63 bb_perror_msg_and_die("cannot read time from RTC");
64 tm.tm_isdst = -1; /* not known */ 63 tm.tm_isdst = -1; /* not known */
65 64
66 close(rtc); 65 close(rtc);
67 66
68 if (utc) { 67 if (utc) {
69 oldtz = getenv("TZ"); 68 oldtz = getenv("TZ");
70 setenv("TZ", "UTC 0", 1); 69 putenv((char*)"TZ=UTC0");
71 tzset(); 70 tzset();
72 } 71 }
73 72
74 t = mktime(&tm); 73 t = mktime(&tm);
75 74
76 if (utc) { 75 if (utc) {
76 unsetenv("TZ");
77 if (oldtz) 77 if (oldtz)
78 setenv("TZ", oldtz, 1); 78 putenv(oldtz - 3);
79 else
80 unsetenv("TZ");
81 tzset(); 79 tzset();
82 } 80 }
83 return t; 81 return t;
@@ -91,8 +89,7 @@ static void write_rtc(time_t t, int utc)
91 tm = *(utc ? gmtime(&t) : localtime(&t)); 89 tm = *(utc ? gmtime(&t) : localtime(&t));
92 tm.tm_isdst = 0; 90 tm.tm_isdst = 0;
93 91
94 if (ioctl(rtc, RTC_SET_TIME, &tm) < 0) 92 xioctl(rtc, RTC_SET_TIME, &tm);
95 bb_perror_msg_and_die("cannot set the RTC time");
96 93
97 close(rtc); 94 close(rtc);
98} 95}