- 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.
This commit is contained in:
Bernhard Reutner-Fischer 2006-04-12 17:55:51 +00:00
parent 79865bc507
commit dac7ff15b7
22 changed files with 99 additions and 218 deletions

View File

@ -1228,8 +1228,8 @@ int gzip_main(int argc, char **argv)
inFileNum = STDIN_FILENO; inFileNum = STDIN_FILENO;
outFileNum = STDOUT_FILENO; outFileNum = STDOUT_FILENO;
} else { } else {
inFileNum = open(argv[i], O_RDONLY); inFileNum = bb_xopen(argv[i], O_RDONLY);
if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0) if (fstat(inFileNum, &statBuf) < 0)
bb_perror_msg_and_die("%s", argv[i]); bb_perror_msg_and_die("%s", argv[i]);
time_stamp = statBuf.st_ctime; time_stamp = statBuf.st_ctime;
ifile_size = statBuf.st_size; ifile_size = statBuf.st_size;

View File

@ -28,21 +28,7 @@ For a new applet mu, here is the code that would go in mu.c:
* *
* Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL> * Copyright (C) [YEAR] by [YOUR NAME] <YOUR EMAIL>
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
* 02111-1307 USA
*
*/ */
#include "busybox.h" #include "busybox.h"
@ -52,8 +38,7 @@ int mu_main(int argc, char **argv)
int fd; int fd;
char mu; char mu;
if ((fd = open("/dev/random", O_RDONLY)) < 0) fd = bb_xopen("/dev/random", O_RDONLY);
bb_perror_msg_and_die("/dev/random");
if ((n = safe_read(fd, &mu, 1)) < 1) if ((n = safe_read(fd, &mu, 1)) < 1)
bb_perror_msg_and_die("/dev/random"); bb_perror_msg_and_die("/dev/random");

View File

@ -145,6 +145,7 @@ extern int bb_fclose_nonstdin(FILE *f);
extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN; extern void bb_fflush_stdout_and_exit(int retval) ATTRIBUTE_NORETURN;
extern void xstat(const char *filename, struct stat *buf); extern void xstat(const char *filename, struct stat *buf);
extern int bb_xsocket(int domain, int type, int protocol);
#define BB_GETOPT_ERROR 0x80000000UL #define BB_GETOPT_ERROR 0x80000000UL
extern const char *bb_opt_complementally; extern const char *bb_opt_complementally;

View File

@ -30,6 +30,7 @@ LIBBB-y:= \
trim.c u_signal_names.c vdprintf.c verror_msg.c \ trim.c u_signal_names.c vdprintf.c verror_msg.c \
vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \ vherror_msg.c vperror_msg.c wfopen.c xconnect.c xgetcwd.c xstat.c \
xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \ xgethostbyname.c xgethostbyname2.c xreadlink.c xregcomp.c xgetlarg.c \
bb_xsocket.c \
get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \ get_terminal_width_height.c fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \ getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \ perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \

18
libbb/bb_xsocket.c Normal file
View File

@ -0,0 +1,18 @@
/* vi: set sw=4 ts=4: */
/*
* bb_xsocket.c - a socket() which dies on failure with error message
*
* Copyright (C) 2006 Denis Vlasenko
*
* Licensed under LGPL, see file docs/lesser.txt in this tarball for details.
*/
#include <sys/socket.h>
#include "libbb.h"
int bb_xsocket(int domain, int type, int protocol)
{
int r = socket(domain, type, protocol);
if (r < 0)
bb_perror_msg_and_die("socket");
return r;
}

View File

@ -61,7 +61,7 @@ void bb_lookup_host(struct sockaddr_in *s_in, const char *host)
int xconnect(struct sockaddr_in *s_addr) int xconnect(struct sockaddr_in *s_addr)
{ {
int s = socket(AF_INET, SOCK_STREAM, 0); int s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0) if (connect(s, (struct sockaddr *)s_addr, sizeof(struct sockaddr_in)) < 0)
{ {
if (ENABLE_FEATURE_CLEAN_UP) close(s); if (ENABLE_FEATURE_CLEAN_UP) close(s);

View File

@ -1,4 +1,4 @@
/* vi:set ts=4:*/ /* vi: set sw=4 ts=4: */
/* /*
* arping.c - Ping hosts by ARP requests/replies * arping.c - Ping hosts by ARP requests/replies
* *
@ -358,7 +358,7 @@ int arping_main(int argc, char **argv)
if (!(cfg&dad) || src.s_addr) { if (!(cfg&dad) || src.s_addr) {
struct sockaddr_in saddr; struct sockaddr_in saddr;
int probe_fd = socket(AF_INET, SOCK_DGRAM, 0); int probe_fd = socket(AF_INET, SOCK_DGRAM, 0); /* maybe use bb_xsocket? */
if (probe_fd < 0) { if (probe_fd < 0) {
bb_error_msg_and_die("socket"); bb_error_msg_and_die("socket");

View File

@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* /*
* Mini DNS server implementation for busybox * Mini DNS server implementation for busybox
* *
@ -204,8 +205,7 @@ listen_socket(char *iface_addr, int listen_port)
char msg[100]; char msg[100];
int s; int s;
int yes = 1; int yes = 1;
if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) s = bb_xsocket(PF_INET, SOCK_DGRAM, 0);
bb_perror_msg_and_die("socket() failed");
#ifdef SO_REUSEADDR #ifdef SO_REUSEADDR
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0) if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&yes, sizeof(yes)) < 0)
bb_perror_msg_and_die("setsockopt() failed"); bb_perror_msg_and_die("setsockopt() failed");

View File

@ -1,10 +1,8 @@
/* vi: set sw=4 ts=4: */
/* /*
* ether-wake.c - Send a magic packet to wake up sleeping machines. * ether-wake.c - Send a magic packet to wake up sleeping machines.
* *
* This program is free software; you can redistribute it and/or * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
* *
* Author: Donald Becker, http://www.scyld.com/"; http://www.scyld.com/wakeonlan.html * Author: Donald Becker, http://www.scyld.com/"; http://www.scyld.com/wakeonlan.html
* Busybox port: Christian Volkmann <haveaniceday@online.de> * Busybox port: Christian Volkmann <haveaniceday@online.de>
@ -95,10 +93,10 @@
*/ */
#ifdef PF_PACKET #ifdef PF_PACKET
# define whereto_t sockaddr_ll # define whereto_t sockaddr_ll
# define make_socket() socket(PF_PACKET, SOCK_RAW, 0) # define make_socket() bb_xsocket(PF_PACKET, SOCK_RAW, 0)
#else #else
# define whereto_t sockaddr # define whereto_t sockaddr
# define make_socket() socket(AF_INET, SOCK_PACKET, SOCK_PACKET) # define make_socket() bb_xsocket(AF_INET, SOCK_PACKET, SOCK_PACKET)
#endif #endif
#ifdef DEBUG #ifdef DEBUG
@ -145,8 +143,6 @@ int etherwake_main(int argc, char *argv[])
/* create the raw socket */ /* create the raw socket */
s = make_socket(); s = make_socket();
if (s < 0)
bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
/* now that we have a raw socket we can drop root */ /* now that we have a raw socket we can drop root */
setuid(getuid()); setuid(getuid());

View File

@ -6,20 +6,7 @@
* Original Author: Tomi Ollila <too@iki.fi> * Original Author: Tomi Ollila <too@iki.fi>
* http://www.guru-group.fi/~too/sw/ * http://www.guru-group.fi/~too/sw/
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/ */
#include <unistd.h> #include <unistd.h>
@ -117,8 +104,7 @@ static void inetbind(void)
else else
port = se->s_port; port = se->s_port;
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) s = bb_xsocket(AF_INET, SOCK_STREAM, 0);
bb_perror_msg_and_die("Cannot create server socket");
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));

View File

@ -6,19 +6,7 @@
* *
* simplify patch stolen from libbb without using strdup * simplify patch stolen from libbb without using strdup
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
***************************************************************************** *****************************************************************************
* *
@ -959,25 +947,21 @@ static int openServer(void)
memset(&lsocket, 0, sizeof(lsocket)); memset(&lsocket, 0, sizeof(lsocket));
lsocket.sin_family = AF_INET; lsocket.sin_family = AF_INET;
lsocket.sin_addr.s_addr = INADDR_ANY; lsocket.sin_addr.s_addr = INADDR_ANY;
lsocket.sin_port = htons(config->port) ; lsocket.sin_port = htons(config->port);
fd = socket(AF_INET, SOCK_STREAM, 0); fd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
if (fd >= 0) { /* tell the OS it's OK to reuse a previous address even though */
/* tell the OS it's OK to reuse a previous address even though */ /* it may still be in a close down state. Allows bind to succeed. */
/* it may still be in a close down state. Allows bind to succeed. */ int on = 1;
int on = 1;
#ifdef SO_REUSEPORT #ifdef SO_REUSEPORT
setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) ; setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)) ;
#else #else
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ; setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)) ;
#endif #endif
if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) { if (bind(fd, (struct sockaddr *)&lsocket, sizeof(lsocket)) == 0) {
listen(fd, 9); listen(fd, 9);
signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */ signal(SIGCHLD, SIG_IGN); /* prevent zombie (defunct) processes */
} else {
bb_perror_msg_and_die("bind");
}
} else { } else {
bb_perror_msg_and_die("create socket"); bb_perror_msg_and_die("bind");
} }
return fd; return fd;
} }

View File

@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* ifconfig /* ifconfig
* *
* Similar to the standard Unix ifconfig, but with only the necessary * Similar to the standard Unix ifconfig, but with only the necessary
@ -9,14 +10,7 @@
* Authors of the original ifconfig was: * Authors of the original ifconfig was:
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* *
* This program is free software; you can redistribute it * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* $Id: ifconfig.c,v 1.30 2004/03/31 11:30:08 andersen Exp $
*
*/ */
/* /*
@ -335,9 +329,7 @@ int ifconfig_main(int argc, char **argv)
} }
/* Create a channel to the NET kernel. */ /* Create a channel to the NET kernel. */
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { sockfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
bb_perror_msg_and_die("socket");
}
/* get interface name */ /* get interface name */
safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ); safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);

View File

@ -10,19 +10,7 @@
19990512 Uses Select. Charles P. Wright 19990512 Uses Select. Charles P. Wright
19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright 19990513 Fixes stdin stupidity and uses buffers. Charles P. Wright
This program is free software; you can redistribute it and/or modify Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/ */
#include <stdio.h> #include <stdio.h>
@ -87,8 +75,7 @@ int nc_main(int argc, char **argv)
if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc)) if ((do_listen && optind != argc) || (!do_listen && optind + 2 != argc))
bb_show_usage(); bb_show_usage();
if ((sfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) sfd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
bb_perror_msg_and_die("socket");
x = 1; x = 1;
if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1) if (setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof (x)) == -1)
bb_perror_msg_and_die("reuseaddr"); bb_perror_msg_and_die("reuseaddr");

View File

@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* route /* route
* *
* Similar to the standard Unix route, but with only the necessary * Similar to the standard Unix route, but with only the necessary
@ -9,11 +10,7 @@
* Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org> * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
* (derived from FvK's 'route.c 1.70 01/04/94') * (derived from FvK's 'route.c 1.70 01/04/94')
* *
* This program is free software; you can redistribute it * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* and/or modify it under the terms of the GNU General
* Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at
* your option) any later version.
* *
* $Id: route.c,v 1.26 2004/03/19 23:27:08 mjn3 Exp $ * $Id: route.c,v 1.26 2004/03/19 23:27:08 mjn3 Exp $
* *
@ -338,9 +335,7 @@ static void INET_setroute(int action, char **args)
} }
/* Create a socket to the INET kernel. */ /* Create a socket to the INET kernel. */
if ((skfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { skfd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
bb_perror_msg_and_die("socket");
}
if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) { if (ioctl(skfd, ((action==RTACTION_ADD) ? SIOCADDRT : SIOCDELRT), &rt)<0) {
bb_perror_msg_and_die("SIOC[ADD|DEL]RT"); bb_perror_msg_and_die("SIOC[ADD|DEL]RT");
@ -434,9 +429,7 @@ static void INET6_setroute(int action, char **args)
} }
/* Create a socket to the INET6 kernel. */ /* Create a socket to the INET6 kernel. */
if ((skfd = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) { skfd = bb_xsocket(AF_INET6, SOCK_DGRAM, 0);
bb_perror_msg_and_die("socket");
}
rt.rtmsg_ifindex = 0; rt.rtmsg_ifindex = 0;

View File

@ -1,10 +1,9 @@
/* $Id: telnetd.c,v 1.13 2004/09/14 17:24:58 bug1 Exp $ /* vi:set ts=4:*/
* /*
* Simple telnet server * Simple telnet server
* Bjorn Wesen, Axis Communications AB (bjornw@axis.com) * Bjorn Wesen, Axis Communications AB (bjornw@axis.com)
* *
* This file is distributed under the Gnu Public License (GPL), * Licensed under GPL, see file LICENSE in this tarball for details.
* please see the file LICENSE for further information.
* *
* --------------------------------------------------------------------------- * ---------------------------------------------------------------------------
* (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN * (C) Copyright 2000, Axis Communications AB, LUND, SWEDEN
@ -446,10 +445,7 @@ telnetd_main(int argc, char **argv)
/* Grab a TCP socket. */ /* Grab a TCP socket. */
master_fd = socket(SOCKET_TYPE, SOCK_STREAM, 0); master_fd = bb_xsocket(SOCKET_TYPE, SOCK_STREAM, 0);
if (master_fd < 0) {
bb_perror_msg_and_die("socket");
}
(void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)); (void)setsockopt(master_fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on));
/* Set it to listen to specified port. */ /* Set it to listen to specified port. */

View File

@ -1,35 +1,23 @@
/* ------------------------------------------------------------------------- */ /* vi: set sw=4 ts=4: */
/* tftp.c */ /* -------------------------------------------------------------------------
/* */ * tftp.c
/* A simple tftp client for busybox. */ *
/* Tries to follow RFC1350. */ * A simple tftp client for busybox.
/* Only "octet" mode supported. */ * Tries to follow RFC1350.
/* Optional blocksize negotiation (RFC2347 + RFC2348) */ * Only "octet" mode supported.
/* */ * Optional blocksize negotiation (RFC2347 + RFC2348)
/* Copyright (C) 2001 Magnus Damm <damm@opensource.se> */ *
/* */ * Copyright (C) 2001 Magnus Damm <damm@opensource.se>
/* Parts of the code based on: */ *
/* */ * Parts of the code based on:
/* atftp: Copyright (C) 2000 Jean-Pierre Lefebvre <helix@step.polymtl.ca> */ *
/* and Remi Lefebvre <remi@debian.org> */ * atftp: Copyright (C) 2000 Jean-Pierre Lefebvre <helix@step.polymtl.ca>
/* */ * and Remi Lefebvre <remi@debian.org>
/* utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de> */ *
/* */ * utftp: Copyright (C) 1999 Uwe Ohse <uwe@ohse.de>
/* This program is free software; you can redistribute it and/or modify */ *
/* it under the terms of the GNU General Public License as published by */ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
/* the Free Software Foundation; either version 2 of the License, or */ * ------------------------------------------------------------------------- */
/* (at your option) any later version. */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
/* General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program; if not, write to the Free Software */
/* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
/* */
/* ------------------------------------------------------------------------- */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -177,7 +165,7 @@ static inline int tftp(const int cmd, const struct hostent *host,
tftp_bufsize += 4; tftp_bufsize += 4;
if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { if ((socketfd = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { /* bb_xsocket? */
bb_perror_msg("socket"); bb_perror_msg("socket");
return EXIT_FAILURE; return EXIT_FAILURE;
} }

View File

@ -1,3 +1,4 @@
/* vi: set sw=4 ts=4: */
/* /*
* Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000 * Copyright (c) 1988, 1989, 1991, 1994, 1995, 1996, 1997, 1998, 1999, 2000
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
@ -359,9 +360,7 @@ ifaddrlist(struct IFADDRLIST **ipaddrp)
struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr; struct ifreq ibuf[(32 * 1024) / sizeof(struct ifreq)], ifr;
struct IFADDRLIST *st_ifaddrlist; struct IFADDRLIST *st_ifaddrlist;
fd = socket(AF_INET, SOCK_DGRAM, 0); fd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
if (fd < 0)
bb_perror_msg_and_die("socket");
ifc.ifc_len = sizeof(ibuf); ifc.ifc_len = sizeof(ibuf);
ifc.ifc_buf = (caddr_t)ibuf; ifc.ifc_buf = (caddr_t)ibuf;
@ -1091,8 +1090,7 @@ traceroute_main(int argc, char *argv[])
if (n > 2) if (n > 2)
close(n); close(n);
if ((s = socket(AF_INET, SOCK_RAW, pe->p_proto)) < 0) s = bb_xsocket(AF_INET, SOCK_RAW, pe->p_proto);
bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
#ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG #ifdef CONFIG_FEATURE_TRACEROUTE_SO_DEBUG
if (op & USAGE_OP_DEBUG) if (op & USAGE_OP_DEBUG)
@ -1103,9 +1101,7 @@ traceroute_main(int argc, char *argv[])
(void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on, (void)setsockopt(s, SOL_SOCKET, SO_DONTROUTE, (char *)&on,
sizeof(on)); sizeof(on));
sndsock = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); sndsock = bb_xsocket(AF_INET, SOCK_RAW, IPPROTO_RAW);
if (sndsock < 0)
bb_perror_msg_and_die(bb_msg_can_not_create_raw_socket);
#ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE #ifdef CONFIG_FEATURE_TRACEROUTE_SOURCE_ROUTE
#if defined(IP_OPTIONS) #if defined(IP_OPTIONS)

View File

@ -4,20 +4,7 @@
* *
* Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org> * Copyright (C) 2001 Manuel Novoa III <mjn3@codepoet.org>
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/ */
/* BB_AUDIT SUSv3 N/A */ /* BB_AUDIT SUSv3 N/A */
@ -136,9 +123,7 @@ int vconfig_main(int argc, char **argv)
} }
/* Don't bother closing the filedes. It will be closed on cleanup. */ /* Don't bother closing the filedes. It will be closed on cleanup. */
if (open(conf_file_name, O_RDONLY) < 0) { /* Is 802.1q is present? */ bb_xopen(conf_file_name, O_RDONLY); /* Will die if 802.1q is not present */
bb_perror_msg_and_die("open %s", conf_file_name);
}
memset(&ifr, 0, sizeof(struct vlan_ioctl_args)); memset(&ifr, 0, sizeof(struct vlan_ioctl_args));
@ -173,10 +158,9 @@ int vconfig_main(int argc, char **argv)
} }
} }
if (((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) fd = bb_xsocket(AF_INET, SOCK_STREAM, 0);
|| (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) if (ioctl(fd, SIOCSIFVLAN, &ifr) < 0) {
) { bb_perror_msg_and_die("ioctl error for %s", *argv);
bb_perror_msg_and_die("socket or ioctl error for %s", *argv);
} }
return 0; return 0;

View File

@ -369,12 +369,7 @@ static void message(char *fmt, ...)
static void init_RemoteLog(void) static void init_RemoteLog(void)
{ {
memset(&remoteaddr, 0, sizeof(remoteaddr)); memset(&remoteaddr, 0, sizeof(remoteaddr));
remotefd = socket(AF_INET, SOCK_DGRAM, 0); remotefd = bb_xsocket(AF_INET, SOCK_DGRAM, 0);
if (remotefd < 0) {
bb_error_msg("cannot create socket");
}
remoteaddr.sin_family = AF_INET; remoteaddr.sin_family = AF_INET;
remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list; remoteaddr.sin_addr = *(struct in_addr *) *(xgethostbyname(RemoteHost))->h_addr_list;
remoteaddr.sin_port = htons(RemotePort); remoteaddr.sin_port = htons(RemotePort);
@ -543,11 +538,7 @@ static void doSyslogd(void)
memset(&sunx, 0, sizeof(sunx)); memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX; sunx.sun_family = AF_UNIX;
strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path)); strncpy(sunx.sun_path, lfile, sizeof(sunx.sun_path));
if ((sock_fd = socket(AF_UNIX, SOCK_DGRAM, 0)) < 0) { sock_fd = bb_xsocket(AF_UNIX, SOCK_DGRAM, 0);
bb_perror_msg_and_die("Couldn't get file descriptor for socket "
_PATH_LOG);
}
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path); addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) { if (bind(sock_fd, (struct sockaddr *) &sunx, addrLength) < 0) {
bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG); bb_perror_msg_and_die("Could not connect to socket " _PATH_LOG);

View File

@ -4,19 +4,7 @@
* *
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org> * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
* *
* This program is free software; you can redistribute it and/or modify * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* *
* This is a from-scratch implementation of fbset; but the de facto fbset * This is a from-scratch implementation of fbset; but the de facto fbset
* implementation was a good reference. fbset (original) is released under * implementation was a good reference. fbset (original) is released under
@ -408,8 +396,7 @@ int fbset_main(int argc, char **argv)
} }
} }
if ((fh = open(fbdev, O_RDONLY)) < 0) fh = bb_xopen(fbdev, O_RDONLY);
bb_perror_msg_and_die("fbset(open)");
if (ioctl(fh, FBIOGET_VSCREENINFO, &var)) if (ioctl(fh, FBIOGET_VSCREENINFO, &var))
bb_perror_msg_and_die("fbset(ioctl)"); bb_perror_msg_and_die("fbset(ioctl)");
if (g_options & OPT_READMODE) { if (g_options & OPT_READMODE) {

View File

@ -307,8 +307,7 @@ static inline int get_size(const char *file)
int fd; int fd;
long size; long size;
if ((fd = open(file, O_RDWR)) < 0) fd = bb_xopen(file, O_RDWR);
bb_perror_msg_and_die("%s", file);
if (ioctl(fd, BLKGETSIZE, &size) >= 0) { if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
close(fd); close(fd);
return (size * 512); return (size * 512);
@ -821,9 +820,7 @@ goodbye:
tmp += dirsize; tmp += dirsize;
*(short *) tmp = 2; *(short *) tmp = 2;
strcpy(tmp + 2, ".badblocks"); strcpy(tmp + 2, ".badblocks");
DEV = open(device_name, O_RDWR); DEV = bb_xopen(device_name, O_RDWR);
if (DEV < 0)
bb_error_msg_and_die("unable to open %s", device_name);
if (fstat(DEV, &statbuf) < 0) if (fstat(DEV, &statbuf) < 0)
bb_error_msg_and_die("unable to stat %s", device_name); bb_error_msg_and_die("unable to stat %s", device_name);
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))

View File

@ -258,8 +258,7 @@ static inline long get_size(const char *file)
int fd; int fd;
long size; long size;
if ((fd = open(file, O_RDONLY)) < 0) /* TODO: bb_xopen3 */ fd = bb_xopen(file, O_RDONLY);
bb_perror_msg_and_die("%s", file);
if (ioctl(fd, BLKGETSIZE, &size) >= 0) { if (ioctl(fd, BLKGETSIZE, &size) >= 0) {
size /= pagesize / 512; size /= pagesize / 512;
} else { } else {
@ -342,8 +341,8 @@ int mkswap_main(int argc, char **argv)
PAGES * goodpages); PAGES * goodpages);
} }
DEV = open(device_name, O_RDWR); DEV = bb_xopen(device_name, O_RDWR);
if (DEV < 0 || fstat(DEV, &statbuf) < 0) if (fstat(DEV, &statbuf) < 0)
bb_perror_msg_and_die("%s", device_name); bb_perror_msg_and_die("%s", device_name);
if (!S_ISBLK(statbuf.st_mode)) if (!S_ISBLK(statbuf.st_mode))
check = 0; check = 0;