diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 17:55:51 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2006-04-12 17:55:51 +0000 |
commit | dac7ff15b7d32deeeef3d9665744fc5774c21d70 (patch) | |
tree | 0e4c34863628d79fdad0c6217f4deb0ca0a91c33 | |
parent | 79865bc5077cf6d17b27e9599921d4c85b1575fd (diff) | |
download | busybox-w32-dac7ff15b7d32deeeef3d9665744fc5774c21d70.tar.gz busybox-w32-dac7ff15b7d32deeeef3d9665744fc5774c21d70.tar.bz2 busybox-w32-dac7ff15b7d32deeeef3d9665744fc5774c21d70.zip |
- patch from Denis Vlasenko to add and use bb_xsocket() and to use
bb_xopen some more while at it.
Also use shorter boilerplate while at it.
-rw-r--r-- | archival/gzip.c | 4 | ||||
-rw-r--r-- | docs/new-applet-HOWTO.txt | 19 | ||||
-rw-r--r-- | include/libbb.h | 1 | ||||
-rw-r--r-- | libbb/Makefile.in | 1 | ||||
-rw-r--r-- | libbb/bb_xsocket.c | 18 | ||||
-rw-r--r-- | libbb/xconnect.c | 2 | ||||
-rw-r--r-- | networking/arping.c | 4 | ||||
-rw-r--r-- | networking/dnsd.c | 4 | ||||
-rw-r--r-- | networking/ether-wake.c | 12 | ||||
-rw-r--r-- | networking/fakeidentd.c | 18 | ||||
-rw-r--r-- | networking/httpd.c | 40 | ||||
-rw-r--r-- | networking/ifconfig.c | 14 | ||||
-rw-r--r-- | networking/nc.c | 17 | ||||
-rw-r--r-- | networking/route.c | 15 | ||||
-rw-r--r-- | networking/telnetd.c | 12 | ||||
-rw-r--r-- | networking/tftp.c | 54 | ||||
-rw-r--r-- | networking/traceroute.c | 12 | ||||
-rw-r--r-- | networking/vconfig.c | 26 | ||||
-rw-r--r-- | sysklogd/syslogd.c | 13 | ||||
-rw-r--r-- | util-linux/fbset.c | 17 | ||||
-rw-r--r-- | util-linux/mkfs_minix.c | 7 | ||||
-rw-r--r-- | util-linux/mkswap.c | 7 |
22 files changed, 99 insertions, 218 deletions
diff --git a/archival/gzip.c b/archival/gzip.c index 41ed3a2c7..5fb118706 100644 --- a/archival/gzip.c +++ b/archival/gzip.c | |||
@@ -1228,8 +1228,8 @@ int gzip_main(int argc, char **argv) | |||
1228 | inFileNum = STDIN_FILENO; | 1228 | inFileNum = STDIN_FILENO; |
1229 | outFileNum = STDOUT_FILENO; | 1229 | outFileNum = STDOUT_FILENO; |
1230 | } else { | 1230 | } else { |
1231 | inFileNum = open(argv[i], O_RDONLY); | 1231 | inFileNum = bb_xopen(argv[i], O_RDONLY); |
1232 | if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0) | 1232 | if (fstat(inFileNum, &statBuf) < 0) |
1233 | bb_perror_msg_and_die("%s", argv[i]); | 1233 | bb_perror_msg_and_die("%s", argv[i]); |
1234 | time_stamp = statBuf.st_ctime; | 1234 | time_stamp = statBuf.st_ctime; |
1235 | ifile_size = statBuf.st_size; | 1235 | ifile_size = statBuf.st_size; |
diff --git a/docs/new-applet-HOWTO.txt b/docs/new-applet-HOWTO.txt index 24bc1d824..2f5702bd6 100644 --- a/docs/new-applet-HOWTO.txt +++ b/docs/new-applet-HOWTO.txt | |||
@@ -28,21 +28,7 @@ For a new applet mu, here is the code that would go in mu.c: | |||
28 | * | 28 | * |
29 | * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL> | 29 | * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL> |
30 | * | 30 | * |
31 | * This program is free software; you can redistribute it and/or modify | 31 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
32 | * it under the terms of the GNU General Public License as published by | ||
33 | * the Free Software Foundation; either version 2 of the License, or | ||
34 | * (at your option) any later version. | ||
35 | * | ||
36 | * This program is distributed in the hope that it will be useful, | ||
37 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
38 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
39 | * General Public License for more details. | ||
40 | * | ||
41 | * You should have received a copy of the GNU General Public License | ||
42 | * along with this program; if not, write to the Free Software | ||
43 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
44 | * 02111-1307 USA | ||
45 | * | ||
46 | */ | 32 | */ |
47 | 33 | ||
48 | #include "busybox.h" | 34 | #include "busybox.h" |
@@ -52,8 +38,7 @@ int mu_main(int argc, char **argv) | |||
52 | int fd; | 38 | int fd; |
53 | char mu; | 39 | char mu; |
54 | 40 | ||
55 | if ((fd = open("/dev/random", O_RDONLY)) < 0) | 41 | fd = bb_xopen("/dev/random", O_RDONLY); |
56 | bb_perror_msg_and_die("/dev/random"); | ||
57 | 42 | ||
58 | if ((n = safe_read(fd, &mu, 1)) < 1) | 43 | if ((n = safe_read(fd, &mu, 1)) < 1) |
59 | bb_perror_msg_and_die("/dev/random"); | 44 | bb_perror_msg_and_die("/dev/random"); |
diff --git a/include/libbb.h b/include/libbb.h index d3634f95d..c031f2841 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -145,6 +145,7 @@ extern int bb_fclose_nonstdin(FILE *f); | |||
145 | extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; | 145 | extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; |
146 | 146 | ||
147 | extern void xstat(const char *filename, struct stat *buf); | 147 | extern void xstat(const char *filename, struct stat *buf); |
148 | extern int bb_xsocket(int domain, int type, int protocol); | ||
148 | 149 | ||
149 | #define BB_GETOPT_ERROR 0x80000000UL | 150 | #define BB_GETOPT_ERROR 0x80000000UL |
150 | extern const char *bb_opt_complementally; | 151 | extern const char *bb_opt_complementally; |
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index de511fc9b..c69978370 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -30,6 +30,7 @@ LIBBB-y:= \ | |||
30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ | 30 | trim.c u_signal_names.c vdprintf.c verror_msg.c \ |
31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ | 31 | vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ |
32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ | 32 | xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ |
33 | bb_xsocket.c \ | ||
33 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ | 34 | get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ |
34 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ | 35 | getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ |
35 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ | 36 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ |
diff --git a/libbb/bb_xsocket.c b/libbb/bb_xsocket.c new file mode 100644 index 000000000..839309ae1 --- /dev/null +++ b/libbb/bb_xsocket.c | |||
@@ -0,0 +1,18 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * bb_xsocket.c - a socket() which dies on failure with error message | ||
4 | * | ||
5 | * Copyright (C) 2006 Denis Vlasenko | ||
6 | * | ||
7 | * Licensed under LGPL, see file docs/lesser.txt in this tarball for details. | ||
8 | */ | ||
9 | #include <sys/socket.h> | ||
10 | #include "libbb.h" | ||
11 | |||
12 | int bb_xsocket(int domain, int type, int protocol) | ||
13 | { | ||
14 | int r = socket(domain, type, protocol); | ||
15 | if (r < 0) | ||
16 | bb_perror_msg_and_die("socket"); | ||
17 | return r; | ||
18 | } | ||
diff --git a/libbb/xconnect.c b/libbb/xconnect.c index ec99c5882..39052b87b 100644 --- a/libbb/xconnect.c +++ b/libbb/xconnect.c | |||
@@ -61,7 +61,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host) | |||
61 | 61 | ||
62 | int xconnect(struct sockaddr_in *s_addr) | 62 | int xconnect(struct sockaddr_in *s_addr) |
63 | { | 63 | { |
64 | int s = socket(AF_INET, SOCK_STREAM, 0); | 64 | int s = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
65 | if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) | 65 | if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) |
66 | { | 66 | { |
67 | if (ENABLE_FEATURE_CLEAN_UP) close(s); | 67 | if (ENABLE_FEATURE_CLEAN_UP) close(s); |
diff --git a/networking/arping.c b/networking/arping.c index 48c14f15c..721368273 100644 --- a/networking/arping.c +++ b/networking/arping.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* vi:set ts=4:*/ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* | 2 | /* |
3 | * arping.c - Ping hosts by ARP requests/replies | 3 | * arping.c - Ping hosts by ARP requests/replies |
4 | * | 4 | * |
@@ -358,7 +358,7 @@ int arping_main(int argc, char **argv) | |||
358 | 358 | ||
359 | if (!(cfg&dad) || src.s_addr) { | 359 | if (!(cfg&dad) || src.s_addr) { |
360 | struct sockaddr_in saddr; | 360 | struct sockaddr_in saddr; |
361 | int probe_fd = socket(AF_INET, SOCK_DGRAM, 0); | 361 | int probe_fd = socket(AF_INET, SOCK_DGRAM, 0); /* maybe use bb_xsocket? */ |
362 | 362 | ||
363 | if (probe_fd < 0) { | 363 | if (probe_fd < 0) { |
364 | bb_error_msg_and_die("socket"); | 364 | bb_error_msg_and_die("socket"); |
diff --git a/networking/dnsd.c b/networking/dnsd.c index a815860ab..9c5193820 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Mini DNS server implementation for busybox | 3 | * Mini DNS server implementation for busybox |
3 | * | 4 | * |
@@ -204,8 +205,7 @@ listen_socket(char *iface_addr, int listen_port) | |||
204 | char msg[100]; | 205 | char msg[100]; |
205 | int s; | 206 | int s; |
206 | int yes = 1; | 207 | int yes = 1; |
207 | if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) | 208 | s = bb_xsocket(PF_INET, SOCK_DGRAM, 0); |
208 | bb_perror_msg_and_die("socket() failed"); | ||
209 | #ifdef SO_REUSEADDR | 209 | #ifdef SO_REUSEADDR |
210 | if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) | 210 | if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) |
211 | bb_perror_msg_and_die("setsockopt() failed"); | 211 | bb_perror_msg_and_die("setsockopt() failed"); |
diff --git a/networking/ether-wake.c b/networking/ether-wake.c index 7d5f79b6a..b4fb0c2d1 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c | |||
@@ -1,10 +1,8 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * ether-wake.c - Send a magic packet to wake up sleeping machines. | 3 | * ether-wake.c - Send a magic packet to wake up sleeping machines. |
3 | * | 4 | * |
4 | * This program is free software; you can redistribute it and/or | 5 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
5 | * modify it under the terms of the GNU General Public License | ||
6 | * as published by the Free Software Foundation; either version | ||
7 | * 2 of the License, or (at your option) any later version. | ||
8 | * | 6 | * |
9 | * Author: Donald Becker, http://www.scyld.com/"; http://www.scyld.com/wakeonlan.html | 7 | * Author: Donald Becker, http://www.scyld.com/"; http://www.scyld.com/wakeonlan.html |
10 | * Busybox port: Christian Volkmann <haveaniceday@online.de> | 8 | * Busybox port: Christian Volkmann <haveaniceday@online.de> |
@@ -95,10 +93,10 @@ | |||
95 | */ | 93 | */ |
96 | #ifdef PF_PACKET | 94 | #ifdef PF_PACKET |
97 | # define whereto_t sockaddr_ll | 95 | # define whereto_t sockaddr_ll |
98 | # define make_socket() socket(PF_PACKET, SOCK_RAW, 0) | 96 | # define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0) |
99 | #else | 97 | #else |
100 | # define whereto_t sockaddr | 98 | # define whereto_t sockaddr |
101 | # define make_socket() socket(AF_INET, SOCK_PACKET, SOCK_PACKET) | 99 | # define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET) |
102 | #endif | 100 | #endif |
103 | 101 | ||
104 | #ifdef DEBUG | 102 | #ifdef DEBUG |
@@ -145,8 +143,6 @@ int etherwake_main(int argc, char *argv[]) | |||
145 | 143 | ||
146 | /* create the raw socket */ | 144 | /* create the raw socket */ |
147 | s = make_socket(); | 145 | s = make_socket(); |
148 | if (s < 0) | ||
149 | bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); | ||
150 | 146 | ||
151 | /* now that we have a raw socket we can drop root */ | 147 | /* now that we have a raw socket we can drop root */ |
152 | setuid(getuid()); | 148 | setuid(getuid()); |
diff --git a/networking/fakeidentd.c b/networking/fakeidentd.c index 5442c22c2..26efdcb34 100644 --- a/networking/fakeidentd.c +++ b/networking/fakeidentd.c | |||
@@ -6,20 +6,7 @@ | |||
6 | * Original Author: Tomi Ollila <too@iki.fi> | 6 | * Original Author: Tomi Ollila <too@iki.fi> |
7 | * http://www.guru-group.fi/~too/sw/ | 7 | * http://www.guru-group.fi/~too/sw/ |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | ||
23 | */ | 10 | */ |
24 | 11 | ||
25 | #include <unistd.h> | 12 | #include <unistd.h> |
@@ -117,8 +104,7 @@ static void inetbind(void) | |||
117 | else | 104 | else |
118 | port = se->s_port; | 105 | port = se->s_port; |
119 | 106 | ||
120 | if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) | 107 | s = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
121 | bb_perror_msg_and_die("Cannot create server socket"); | ||
122 | 108 | ||
123 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); | 109 | setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); |
124 | 110 | ||
diff --git a/networking/httpd.c b/networking/httpd.c index c89073a2a..fde8ae4bd 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -6,19 +6,7 @@ | |||
6 | * | 6 | * |
7 | * simplify patch stolen from libbb without using strdup | 7 | * simplify patch stolen from libbb without using strdup |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
10 | * it under the terms of the GNU General Public License as published by | ||
11 | * the Free Software Foundation; either version 2 of the License, or | ||
12 | * (at your option) any later version. | ||
13 | * | ||
14 | * This program is distributed in the hope that it will be useful, | ||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
17 | * General Public License for more details. | ||
18 | * | ||
19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program; if not, write to the Free Software | ||
21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
22 | * | 10 | * |
23 | ***************************************************************************** | 11 | ***************************************************************************** |
24 | * | 12 | * |
@@ -959,25 +947,21 @@ static int openServer(void) | |||
959 | memset(&lsocket, 0, sizeof(lsocket)); | 947 | memset(&lsocket, 0, sizeof(lsocket)); |
960 | lsocket.sin_family = AF_INET; | 948 | lsocket.sin_family = AF_INET; |
961 | lsocket.sin_addr.s_addr = INADDR_ANY; | 949 | lsocket.sin_addr.s_addr = INADDR_ANY; |
962 | lsocket.sin_port = htons(config->port) ; | 950 | lsocket.sin_port = htons(config->port); |
963 | fd = socket(AF_INET, SOCK_STREAM, 0); | 951 | fd = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
964 | if (fd >= 0) { | 952 | /* tell the OS it's OK to reuse a previous address even though */ |
965 | /* tell the OS it's OK to reuse a previous address even though */ | 953 | /* it may still be in a close down state. Allows bind to succeed. */ |
966 | /* it may still be in a close down state. Allows bind to succeed. */ | 954 | int on = 1; |
967 | int on = 1; | ||
968 | #ifdef SO_REUSEPORT | 955 | #ifdef SO_REUSEPORT |
969 | setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) ; | 956 | setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) ; |
970 | #else | 957 | #else |
971 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ; | 958 | setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ; |
972 | #endif | 959 | #endif |
973 | if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) { | 960 | if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) { |
974 | listen(fd, 9); | 961 | listen(fd, 9); |
975 | signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */ | 962 | signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */ |
976 | } else { | ||
977 | bb_perror_msg_and_die("bind"); | ||
978 | } | ||
979 | } else { | 963 | } else { |
980 | bb_perror_msg_and_die("create socket"); | 964 | bb_perror_msg_and_die("bind"); |
981 | } | 965 | } |
982 | return fd; | 966 | return fd; |
983 | } | 967 | } |
diff --git a/networking/ifconfig.c b/networking/ifconfig.c index 1e1bd83ee..7b358c43f 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* ifconfig | 2 | /* ifconfig |
2 | * | 3 | * |
3 | * Similar to the standard Unix ifconfig, but with only the necessary | 4 | * Similar to the standard Unix ifconfig, but with only the necessary |
@@ -9,14 +10,7 @@ | |||
9 | * Authors of the original ifconfig was: | 10 | * Authors of the original ifconfig was: |
10 | * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> | 11 | * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
11 | * | 12 | * |
12 | * This program is free software; you can redistribute it | 13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
13 | * and/or modify it under the terms of the GNU General | ||
14 | * Public License as published by the Free Software | ||
15 | * Foundation; either version 2 of the License, or (at | ||
16 | * your option) any later version. | ||
17 | * | ||
18 | * $Id: ifconfig.c,v 1.30 2004/03/31 11:30:08 andersen Exp $ | ||
19 | * | ||
20 | */ | 14 | */ |
21 | 15 | ||
22 | /* | 16 | /* |
@@ -335,9 +329,7 @@ int ifconfig_main(int argc, char **argv) | |||
335 | } | 329 | } |
336 | 330 | ||
337 | /* Create a channel to the NET kernel. */ | 331 | /* Create a channel to the NET kernel. */ |
338 | if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | 332 | sockfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); |
339 | bb_perror_msg_and_die("socket"); | ||
340 | } | ||
341 | 333 | ||
342 | /* get interface name */ | 334 | /* get interface name */ |
343 | safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ); | 335 | safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ); |
diff --git a/networking/nc.c b/networking/nc.c index 85148c4a7..86f0b99df 100644 --- a/networking/nc.c +++ b/networking/nc.c | |||
@@ -10,19 +10,7 @@ | |||
10 | 19990512 Uses Select. Charles P. Wright | 10 | 19990512 Uses Select. Charles P. Wright |
11 | 19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright | 11 | 19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright |
12 | 12 | ||
13 | This program is free software; you can redistribute it and/or modify | 13 | Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
14 | it under the terms of the GNU General Public License as published by | ||
15 | the Free Software Foundation; either version 2 of the License, or | ||
16 | (at your option) any later version. | ||
17 | |||
18 | This program is distributed in the hope that it will be useful, | ||
19 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
21 | GNU General Public License for more details. | ||
22 | |||
23 | You should have received a copy of the GNU General Public License | ||
24 | along with this program; if not, write to the Free Software | ||
25 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
26 | */ | 14 | */ |
27 | 15 | ||
28 | #include <stdio.h> | 16 | #include <stdio.h> |
@@ -87,8 +75,7 @@ int nc_main(int argc, char **argv) | |||
87 | if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc)) | 75 | if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc)) |
88 | bb_show_usage(); | 76 | bb_show_usage(); |
89 | 77 | ||
90 | if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) | 78 | sfd = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
91 | bb_perror_msg_and_die("socket"); | ||
92 | x = 1; | 79 | x = 1; |
93 | if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1) | 80 | if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1) |
94 | bb_perror_msg_and_die("reuseaddr"); | 81 | bb_perror_msg_and_die("reuseaddr"); |
diff --git a/networking/route.c b/networking/route.c index 8ae0da182..e7e8f1c02 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* route | 2 | /* route |
2 | * | 3 | * |
3 | * Similar to the standard Unix route, but with only the necessary | 4 | * Similar to the standard Unix route, but with only the necessary |
@@ -9,11 +10,7 @@ | |||
9 | * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> | 10 | * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> |
10 | * (derived from FvK's 'route.c 1.70 01/04/94') | 11 | * (derived from FvK's 'route.c 1.70 01/04/94') |
11 | * | 12 | * |
12 | * This program is free software; you can redistribute it | 13 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
13 | * and/or modify it under the terms of the GNU General | ||
14 | * Public License as published by the Free Software | ||
15 | * Foundation; either version 2 of the License, or (at | ||
16 | * your option) any later version. | ||
17 | * | 14 | * |
18 | * $Id: route.c,v 1.26 2004/03/19 23:27:08 mjn3 Exp $ | 15 | * $Id: route.c,v 1.26 2004/03/19 23:27:08 mjn3 Exp $ |
19 | * | 16 | * |
@@ -338,9 +335,7 @@ static void INET_setroute(int action, char **args) | |||
338 | } | 335 | } |
339 | 336 | ||
340 | /* Create a socket to the INET kernel. */ | 337 | /* Create a socket to the INET kernel. */ |
341 | if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { | 338 | skfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); |
342 | bb_perror_msg_and_die("socket"); | ||
343 | } | ||
344 | 339 | ||
345 | if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { | 340 | if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { |
346 | bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); | 341 | bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); |
@@ -434,9 +429,7 @@ static void INET6_setroute(int action, char **args) | |||
434 | } | 429 | } |
435 | 430 | ||
436 | /* Create a socket to the INET6 kernel. */ | 431 | /* Create a socket to the INET6 kernel. */ |
437 | if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { | 432 | skfd = bb_xsocket(AF_INET6, SOCK_DGRAM, 0); |
438 | bb_perror_msg_and_die("socket"); | ||
439 | } | ||
440 | 433 | ||
441 | rt.rtmsg_ifindex = 0; | 434 | rt.rtmsg_ifindex = 0; |
442 | 435 | ||
diff --git a/networking/telnetd.c b/networking/telnetd.c index 8943b2e3b..3e4b42cfa 100644 --- a/networking/telnetd.c +++ b/networking/telnetd.c | |||
@@ -1,10 +1,9 @@ | |||
1 | /* $Id: telnetd.c,v 1.13 2004/09/14 17:24:58 bug1 Exp $ | 1 | /* vi:set ts=4:*/ |
2 | * | 2 | /* |
3 | * Simple telnet server | 3 | * Simple telnet server |
4 | * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) | 4 | * Bjorn Wesen, Axis Communications AB (bjornw@axis.com) |
5 | * | 5 | * |
6 | * This file is distributed under the Gnu Public License (GPL), | 6 | * Licensed under GPL, see file LICENSE in this tarball for details. |
7 | * please see the file LICENSE for further information. | ||
8 | * | 7 | * |
9 | * --------------------------------------------------------------------------- | 8 | * --------------------------------------------------------------------------- |
10 | * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN | 9 | * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN |
@@ -446,10 +445,7 @@ telnetd_main(int argc, char **argv) | |||
446 | 445 | ||
447 | /* Grab a TCP socket. */ | 446 | /* Grab a TCP socket. */ |
448 | 447 | ||
449 | master_fd = socket(SOCKET_TYPE, SOCK_STREAM, 0); | 448 | master_fd = bb_xsocket(SOCKET_TYPE, SOCK_STREAM, 0); |
450 | if (master_fd < 0) { | ||
451 | bb_perror_msg_and_die("socket"); | ||
452 | } | ||
453 | (void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); | 449 | (void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); |
454 | 450 | ||
455 | /* Set it to listen to specified port. */ | 451 | /* Set it to listen to specified port. */ |
diff --git a/networking/tftp.c b/networking/tftp.c index ddcb5225f..b830f18a5 100644 --- a/networking/tftp.c +++ b/networking/tftp.c | |||
@@ -1,35 +1,23 @@ | |||
1 | /* ------------------------------------------------------------------------- */ | 1 | /* vi: set sw=4 ts=4: */ |
2 | /* tftp.c */ | 2 | /* ------------------------------------------------------------------------- |
3 | /* */ | 3 | * tftp.c |
4 | /* A simple tftp client for busybox. */ | 4 | * |
5 | /* Tries to follow RFC1350. */ | 5 | * A simple tftp client for busybox. |
6 | /* Only "octet" mode supported. */ | 6 | * Tries to follow RFC1350. |
7 | /* Optional blocksize negotiation (RFC2347 + RFC2348) */ | 7 | * Only "octet" mode supported. |
8 | /* */ | 8 | * Optional blocksize negotiation (RFC2347 + RFC2348) |
9 | /* Copyright (C) 2001 Magnus Damm <damm@opensource.se> */ | 9 | * |
10 | /* */ | 10 | * Copyright (C) 2001 Magnus Damm <damm@opensource.se> |
11 | /* Parts of the code based on: */ | 11 | * |
12 | /* */ | 12 | * Parts of the code based on: |
13 | /* atftp: Copyright (C) 2000 Jean-Pierre Lefebvre <helix@step.polymtl.ca> */ | 13 | * |
14 | /* and Remi Lefebvre <remi@debian.org> */ | 14 | * atftp: Copyright (C) 2000 Jean-Pierre Lefebvre <helix@step.polymtl.ca> |
15 | /* */ | 15 | * and Remi Lefebvre <remi@debian.org> |
16 | /* utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de> */ | 16 | * |
17 | /* */ | 17 | * utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de> |
18 | /* This program is free software; you can redistribute it and/or modify */ | 18 | * |
19 | /* it under the terms of the GNU General Public License as published by */ | 19 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
20 | /* the Free Software Foundation; either version 2 of the License, or */ | 20 | * ------------------------------------------------------------------------- */ |
21 | /* (at your option) any later version. */ | ||
22 | /* */ | ||
23 | /* This program is distributed in the hope that it will be useful, */ | ||
24 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ | ||
25 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ | ||
26 | /* General Public License for more details. */ | ||
27 | /* */ | ||
28 | /* You should have received a copy of the GNU General Public License */ | ||
29 | /* along with this program; if not, write to the Free Software */ | ||
30 | /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ | ||
31 | /* */ | ||
32 | /* ------------------------------------------------------------------------- */ | ||
33 | 21 | ||
34 | #include <stdio.h> | 22 | #include <stdio.h> |
35 | #include <stdlib.h> | 23 | #include <stdlib.h> |
@@ -177,7 +165,7 @@ static inline int tftp(const int cmd, const struct hostent *host, | |||
177 | 165 | ||
178 | tftp_bufsize += 4; | 166 | tftp_bufsize += 4; |
179 | 167 | ||
180 | if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { | 168 | if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { /* bb_xsocket? */ |
181 | bb_perror_msg("socket"); | 169 | bb_perror_msg("socket"); |
182 | return EXIT_FAILURE; | 170 | return EXIT_FAILURE; |
183 | } | 171 | } |
diff --git a/networking/traceroute.c b/networking/traceroute.c index 22d27f240..0abd9047d 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c | |||
@@ -1,3 +1,4 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
1 | /* | 2 | /* |
2 | * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 | 3 | * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 |
3 | * The Regents of the University of California. All rights reserved. | 4 | * The Regents of the University of California. All rights reserved. |
@@ -359,9 +360,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp) | |||
359 | struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr; | 360 | struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr; |
360 | struct IFADDRLIST *st_ifaddrlist; | 361 | struct IFADDRLIST *st_ifaddrlist; |
361 | 362 | ||
362 | fd = socket(AF_INET, SOCK_DGRAM, 0); | 363 | fd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); |
363 | if (fd < 0) | ||
364 | bb_perror_msg_and_die("socket"); | ||
365 | 364 | ||
366 | ifc.ifc_len = sizeof(ibuf); | 365 | ifc.ifc_len = sizeof(ibuf); |
367 | ifc.ifc_buf = (caddr_t)ibuf; | 366 | ifc.ifc_buf = (caddr_t)ibuf; |
@@ -1091,8 +1090,7 @@ traceroute_main(int argc, char *argv[]) | |||
1091 | if (n > 2) | 1090 | if (n > 2) |
1092 | close(n); | 1091 | close(n); |
1093 | 1092 | ||
1094 | if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) | 1093 | s = bb_xsocket(AF_INET, SOCK_RAW, pe->p_proto); |
1095 | bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); | ||
1096 | 1094 | ||
1097 | #ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG | 1095 | #ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG |
1098 | if (op & USAGE_OP_DEBUG) | 1096 | if (op & USAGE_OP_DEBUG) |
@@ -1103,9 +1101,7 @@ traceroute_main(int argc, char *argv[]) | |||
1103 | (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, | 1101 | (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, |
1104 | sizeof(on)); | 1102 | sizeof(on)); |
1105 | 1103 | ||
1106 | sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); | 1104 | sndsock = bb_xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW); |
1107 | if (sndsock < 0) | ||
1108 | bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket); | ||
1109 | 1105 | ||
1110 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE | 1106 | #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE |
1111 | #if defined(IP_OPTIONS) | 1107 | #if defined(IP_OPTIONS) |
diff --git a/networking/vconfig.c b/networking/vconfig.c index 36458f784..72729c7ed 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c | |||
@@ -4,20 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> | 5 | * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | 8 | */ |
22 | 9 | ||
23 | /* BB_AUDIT SUSv3 N/A */ | 10 | /* BB_AUDIT SUSv3 N/A */ |
@@ -136,9 +123,7 @@ int vconfig_main(int argc, char **argv) | |||
136 | } | 123 | } |
137 | 124 | ||
138 | /* Don't bother closing the filedes. It will be closed on cleanup. */ | 125 | /* Don't bother closing the filedes. It will be closed on cleanup. */ |
139 | if (open(conf_file_name, O_RDONLY) < 0) { /* Is 802.1q is present? */ | 126 | bb_xopen(conf_file_name, O_RDONLY); /* Will die if 802.1q is not present */ |
140 | bb_perror_msg_and_die("open %s", conf_file_name); | ||
141 | } | ||
142 | 127 | ||
143 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); | 128 | memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); |
144 | 129 | ||
@@ -173,10 +158,9 @@ int vconfig_main(int argc, char **argv) | |||
173 | } | 158 | } |
174 | } | 159 | } |
175 | 160 | ||
176 | if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) | 161 | fd = bb_xsocket(AF_INET, SOCK_STREAM, 0); |
177 | || (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) | 162 | if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) { |
178 | ) { | 163 | bb_perror_msg_and_die("ioctl error for %s", *argv); |
179 | bb_perror_msg_and_die("socket or ioctl error for %s", *argv); | ||
180 | } | 164 | } |
181 | 165 | ||
182 | return 0; | 166 | return 0; |
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index bb8ba1b82..b43c72d66 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c | |||
@@ -369,12 +369,7 @@ static void message(char *fmt, ...) | |||
369 | static void init_RemoteLog(void) | 369 | static void init_RemoteLog(void) |
370 | { | 370 | { |
371 | memset(&remoteaddr, 0, sizeof(remoteaddr)); | 371 | memset(&remoteaddr, 0, sizeof(remoteaddr)); |
372 | remotefd = socket(AF_INET, SOCK_DGRAM, 0); | 372 | remotefd = bb_xsocket(AF_INET, SOCK_DGRAM, 0); |
373 | |||
374 | if (remotefd < 0) { | ||
375 | bb_error_msg("cannot create socket"); | ||
376 | } | ||
377 | |||
378 | remoteaddr.sin_family = AF_INET; | 373 | remoteaddr.sin_family = AF_INET; |
379 | remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; | 374 | remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; |
380 | remoteaddr.sin_port = htons(RemotePort); | 375 | remoteaddr.sin_port = htons(RemotePort); |
@@ -543,11 +538,7 @@ static void doSyslogd(void) | |||
543 | memset(&sunx, 0, sizeof(sunx)); | 538 | memset(&sunx, 0, sizeof(sunx)); |
544 | sunx.sun_family = AF_UNIX; | 539 | sunx.sun_family = AF_UNIX; |
545 | strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); | 540 | strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); |
546 | if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { | 541 | sock_fd = bb_xsocket(AF_UNIX, SOCK_DGRAM, 0); |
547 | bb_perror_msg_and_die("Couldn't get file descriptor for socket " | ||
548 | _PATH_LOG); | ||
549 | } | ||
550 | |||
551 | addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); | 542 | addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); |
552 | if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { | 543 | if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { |
553 | bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); | 544 | bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); |
diff --git a/util-linux/fbset.c b/util-linux/fbset.c index d2667cf84..7d3cae251 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c | |||
@@ -4,19 +4,7 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | 8 | * |
21 | * This is a from-scratch implementation of fbset; but the de facto fbset | 9 | * This is a from-scratch implementation of fbset; but the de facto fbset |
22 | * implementation was a good reference. fbset (original) is released under | 10 | * implementation was a good reference. fbset (original) is released under |
@@ -408,8 +396,7 @@ int fbset_main(int argc, char **argv) | |||
408 | } | 396 | } |
409 | } | 397 | } |
410 | 398 | ||
411 | if ((fh = open(fbdev, O_RDONLY)) < 0) | 399 | fh = bb_xopen(fbdev, O_RDONLY); |
412 | bb_perror_msg_and_die("fbset(open)"); | ||
413 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) | 400 | if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) |
414 | bb_perror_msg_and_die("fbset(ioctl)"); | 401 | bb_perror_msg_and_die("fbset(ioctl)"); |
415 | if (g_options & OPT_READMODE) { | 402 | if (g_options & OPT_READMODE) { |
diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 904a58ee3..30bc9f12d 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c | |||
@@ -307,8 +307,7 @@ static inline int get_size(const char *file) | |||
307 | int fd; | 307 | int fd; |
308 | long size; | 308 | long size; |
309 | 309 | ||
310 | if ((fd = open(file, O_RDWR)) < 0) | 310 | fd = bb_xopen(file, O_RDWR); |
311 | bb_perror_msg_and_die("%s", file); | ||
312 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 311 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
313 | close(fd); | 312 | close(fd); |
314 | return (size * 512); | 313 | return (size * 512); |
@@ -821,9 +820,7 @@ goodbye: | |||
821 | tmp += dirsize; | 820 | tmp += dirsize; |
822 | *(short *) tmp = 2; | 821 | *(short *) tmp = 2; |
823 | strcpy(tmp + 2, ".badblocks"); | 822 | strcpy(tmp + 2, ".badblocks"); |
824 | DEV = open(device_name, O_RDWR); | 823 | DEV = bb_xopen(device_name, O_RDWR); |
825 | if (DEV < 0) | ||
826 | bb_error_msg_and_die("unable to open %s", device_name); | ||
827 | if (fstat(DEV, &statbuf) < 0) | 824 | if (fstat(DEV, &statbuf) < 0) |
828 | bb_error_msg_and_die("unable to stat %s", device_name); | 825 | bb_error_msg_and_die("unable to stat %s", device_name); |
829 | if (!S_ISBLK(statbuf.st_mode)) | 826 | if (!S_ISBLK(statbuf.st_mode)) |
diff --git a/util-linux/mkswap.c b/util-linux/mkswap.c index ce123e502..32021fe08 100644 --- a/util-linux/mkswap.c +++ b/util-linux/mkswap.c | |||
@@ -258,8 +258,7 @@ static inline long get_size(const char *file) | |||
258 | int fd; | 258 | int fd; |
259 | long size; | 259 | long size; |
260 | 260 | ||
261 | if ((fd = open(file, O_RDONLY)) < 0) /* TODO: bb_xopen3 */ | 261 | fd = bb_xopen(file, O_RDONLY); |
262 | bb_perror_msg_and_die("%s", file); | ||
263 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { | 262 | if (ioctl(fd, BLKGETSIZE, &size) >= 0) { |
264 | size /= pagesize / 512; | 263 | size /= pagesize / 512; |
265 | } else { | 264 | } else { |
@@ -342,8 +341,8 @@ int mkswap_main(int argc, char **argv) | |||
342 | PAGES * goodpages); | 341 | PAGES * goodpages); |
343 | } | 342 | } |
344 | 343 | ||
345 | DEV = open(device_name, O_RDWR); | 344 | DEV = bb_xopen(device_name, O_RDWR); |
346 | if (DEV < 0 || fstat(DEV, &statbuf) < 0) | 345 | if (fstat(DEV, &statbuf) < 0) |
347 | bb_perror_msg_and_die("%s", device_name); | 346 | bb_perror_msg_and_die("%s", device_name); |
348 | if (!S_ISBLK(statbuf.st_mode)) | 347 | if (!S_ISBLK(statbuf.st_mode)) |
349 | check = 0; | 348 | check = 0; |