summaryrefslogtreecommitdiffhomepage
path: root/networking
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-07-21 23:05:26 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-07-21 23:05:26 +0000
commit5415c856eaccd1bc5d064022770a288f43b2e94f (patch)
tree5973db4e6f81b5e311e8944700ded5db1083d440 /networking
parentb74a2dba571d1c5a6127c683fb50923336d9c59f (diff)
libbb: [x]fopen_for_{read,write} introduced and used.
(by Valdimir) function old new delta config_open2 - 41 +41 config_read 507 542 +35 find_pair 169 187 +18 fopen_for_write - 14 +14 fopen_for_read - 14 +14 find_main 406 418 +12 xfopen_for_write - 10 +10 xfopen_for_read - 10 +10 popstring 134 140 +6 parse_inittab 396 401 +5 next_token 923 928 +5 pack_gzip 1659 1661 +2 bb__parsespent 117 119 +2 fallbackSort 1719 1717 -2 evalvar 1376 1374 -2 qrealloc 36 33 -3 ... ... ... ... singlemount 4579 4569 -10 process_stdin 443 433 -10 patch_main 1111 1101 -10 ifupdown_main 2175 2165 -10 file_action_grep 90 80 -10 uuidcache_init 649 637 -12 hush_main 797 785 -12 read_config 230 217 -13 dpkg_main 3835 3820 -15 read_line_input 3134 3110 -24 sysctl_main 232 203 -29 config_open 40 10 -30 WARN_BAD_LINE 44 - -44 login_main 1714 1575 -139 ------------------------------------------------------------------------------ (add/remove: 5/1 grow/shrink: 8/74 up/down: 174/-737) Total: -563 bytes
Diffstat (limited to 'networking')
-rw-r--r--networking/arp.c2
-rw-r--r--networking/dnsd.c5
-rw-r--r--networking/hostname.c29
-rw-r--r--networking/httpd.c2
-rw-r--r--networking/ifupdown.c6
-rw-r--r--networking/interface.c2
-rw-r--r--networking/libiproute/iproute.c2
-rw-r--r--networking/libiproute/rt_names.c2
-rw-r--r--networking/nameif.c2
-rw-r--r--networking/netstat.c2
-rw-r--r--networking/route.c4
-rw-r--r--networking/traceroute.c2
-rw-r--r--networking/udhcp/files.c4
13 files changed, 27 insertions, 37 deletions
diff --git a/networking/arp.c b/networking/arp.c
index ac8c870f8..620f7c00f 100644
--- a/networking/arp.c
+++ b/networking/arp.c
@@ -382,7 +382,7 @@ static int arp_show(char *name)
}
host = xstrdup(ap->sprint(&sa, 1));
}
- fp = xfopen("/proc/net/arp", "r");
+ fp = xfopen_for_read("/proc/net/arp");
/* Bypass header -- read one line */
fgets(line, sizeof(line), fp);
diff --git a/networking/dnsd.c b/networking/dnsd.c
index 0047a8445..efb5cfba7 100644
--- a/networking/dnsd.c
+++ b/networking/dnsd.c
@@ -113,7 +113,7 @@ static void dnsentryinit(void)
parser = config_open(fileconf);
if (parser) {
char *token[2];
- while (config_read(parser, token, 2, 0, "# \t", 0)) {
+ while (config_read(parser, token, 2, 2, "# \t", 0)) {
unsigned int a,b,c,d;
/*
* Assumes all host names are lower case only
@@ -121,7 +121,8 @@ static void dnsentryinit(void)
* Presently the dot is copied into name without
* converting to a length/string substring for that label.
*/
- if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4)
+// if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4)
+ if (sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4)
continue;
m = xzalloc(sizeof(*m));
diff --git a/networking/hostname.c b/networking/hostname.c
index 93cbc961f..dd2a20689 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -16,28 +16,19 @@
static void do_sethostname(char *s, int isfile)
{
- FILE *f;
-
if (!s)
return;
- if (!isfile) {
- if (sethostname(s, strlen(s)) < 0) {
- if (errno == EPERM)
- bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
- bb_perror_msg_and_die("sethostname");
- }
- } else {
- f = xfopen(s, "r");
-#define strbuf bb_common_bufsiz1
- while (fgets(strbuf, sizeof(strbuf), f) != NULL) {
- if (strbuf[0] == '#') {
- continue;
- }
- chomp(strbuf);
- do_sethostname(strbuf, 0);
+ if (isfile) {
+ parser_t *parser = config_open2(s, xfopen_for_read);
+ while (config_read(parser, &s, 1, 1, "# \t", 0)) {
+ do_sethostname(s, 0);
}
if (ENABLE_FEATURE_CLEAN_UP)
- fclose(f);
+ config_close(parser);
+ } else if (sethostname(s, strlen(s)) < 0) {
+ if (errno == EPERM)
+ bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
+ bb_perror_msg_and_die("sethostname");
}
}
@@ -98,5 +89,5 @@ int hostname_main(int argc, char **argv)
}
if (ENABLE_FEATURE_CLEAN_UP)
free(buf);
- return 0;
+ return EXIT_SUCCESS;
}
diff --git a/networking/httpd.c b/networking/httpd.c
index 8c4242e44..82891f121 100644
--- a/networking/httpd.c
+++ b/networking/httpd.c
@@ -518,7 +518,7 @@ static void parse_conf(const char *path, int flag)
sprintf((char *)filename, "%s/%s", path, httpd_conf);
}
- while ((f = fopen(filename, "r")) == NULL) {
+ while ((f = fopen_for_read(filename)) == NULL) {
if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
/* config file not found, no changes to config */
return;
diff --git a/networking/ifupdown.c b/networking/ifupdown.c
index cb937cac4..c0e9e812e 100644
--- a/networking/ifupdown.c
+++ b/networking/ifupdown.c
@@ -692,7 +692,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename)
enum { NONE, IFACE, MAPPING } currently_processing = NONE;
defn = xzalloc(sizeof(*defn));
- f = xfopen(filename, "r");
+ f = xfopen_for_read(filename);
while ((buf = xmalloc_fgetline(f)) != NULL) {
#if ENABLE_DESKTOP
@@ -1090,7 +1090,7 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface)
static llist_t *read_iface_state(void)
{
llist_t *state_list = NULL;
- FILE *state_fp = fopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "r");
+ FILE *state_fp = fopen_for_read(CONFIG_IFUPDOWN_IFSTATE_PATH);
if (state_fp) {
char *start, *end_ptr;
@@ -1256,7 +1256,7 @@ int ifupdown_main(int argc, char **argv)
}
/* Actually write the new state */
- state_fp = xfopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "w");
+ state_fp = xfopen_for_write(CONFIG_IFUPDOWN_IFSTATE_PATH);
state = state_list;
while (state) {
if (state->data) {
diff --git a/networking/interface.c b/networking/interface.c
index 83b24f1d6..065b4baeb 100644
--- a/networking/interface.c
+++ b/networking/interface.c
@@ -990,7 +990,7 @@ static void ife_print(struct interface *ptr)
#define IPV6_ADDR_MAPPED 0x1000U
#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
- f = fopen(_PATH_PROCNET_IFINET6, "r");
+ f = fopen_for_read(_PATH_PROCNET_IFINET6);
if (f != NULL) {
while (fscanf
(f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n",
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 17af41f9c..bdccad69d 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -64,7 +64,7 @@ static unsigned get_hz(void)
if (hz_internal)
return hz_internal;
- fp = fopen("/proc/net/psched", "r");
+ fp = fopen_for_read("/proc/net/psched");
if (fp) {
unsigned nom, denom;
diff --git a/networking/libiproute/rt_names.c b/networking/libiproute/rt_names.c
index 797c83b4e..b22df9cb7 100644
--- a/networking/libiproute/rt_names.c
+++ b/networking/libiproute/rt_names.c
@@ -18,7 +18,7 @@ static void rtnl_tab_initialize(const char *file, const char **tab, int size)
char buf[512];
FILE *fp;
- fp = fopen(file, "r");
+ fp = fopen_for_read(file);
if (!fp)
return;
while (fgets(buf, sizeof(buf), fp)) {
diff --git a/networking/nameif.c b/networking/nameif.c
index 76a8cb7df..5a3bd606f 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -170,7 +170,7 @@ int nameif_main(int argc, char **argv)
}
ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0);
- ifh = xfopen("/proc/net/dev", "r");
+ ifh = xfopen_for_read("/proc/net/dev");
linenum = 0;
while (clist) {
diff --git a/networking/netstat.c b/networking/netstat.c
index 24b26545e..46510acc1 100644
--- a/networking/netstat.c
+++ b/networking/netstat.c
@@ -466,7 +466,7 @@ static void do_info(const char *file, const char *name, int (*proc)(int, char *)
FILE *procinfo;
char *buffer;
- procinfo = fopen(file, "r");
+ procinfo = fopen_for_read(file);
if (procinfo == NULL) {
if (errno != ENOENT) {
bb_simple_perror_msg(file);
diff --git a/networking/route.c b/networking/route.c
index 7b6d4f45f..2bc2f9210 100644
--- a/networking/route.c
+++ b/networking/route.c
@@ -484,7 +484,7 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt)
struct sockaddr_in s_addr;
struct in_addr mask;
- FILE *fp = xfopen("/proc/net/route", "r");
+ FILE *fp = xfopen_for_read("/proc/net/route");
printf("Kernel IP routing table\n"
"Destination Gateway Genmask Flags %s Iface\n",
@@ -552,7 +552,7 @@ static void INET6_displayroutes(void)
int iflags, metric, refcnt, use, prefix_len, slen;
struct sockaddr_in6 snaddr6;
- FILE *fp = xfopen("/proc/net/ipv6_route", "r");
+ FILE *fp = xfopen_for_read("/proc/net/ipv6_route");
printf("Kernel IPv6 routing table\n%-44s%-40s"
"Flags Metric Ref Use Iface\n",
diff --git a/networking/traceroute.c b/networking/traceroute.c
index f16fc792f..4e6ca2d9b 100644
--- a/networking/traceroute.c
+++ b/networking/traceroute.c
@@ -508,7 +508,7 @@ findsaddr(const struct sockaddr_in *to, struct sockaddr_in *from)
struct IFADDRLIST *al;
char buf[256], tdevice[256], device[256];
- f = xfopen("/proc/net/route", "r");
+ f = xfopen_for_read("/proc/net/route");
/* Find the appropriate interface */
n = 0;
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c
index fe6bff4ba..264a98899 100644
--- a/networking/udhcp/files.c
+++ b/networking/udhcp/files.c
@@ -321,9 +321,7 @@ void read_config(const char *file)
if (!parser)
return;
- while (config_read(parser, token, 2, 0, "# \t", PARSE_LAST_IS_GREEDY)) {
- if (!token[1])
- continue;
+ while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) {
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
if (!strcasecmp(token[0], k->keyword)) {
if (!k->handler(token[1], k->var)) {