aboutsummaryrefslogtreecommitdiff
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)
downloadbusybox-w32-5415c856eaccd1bc5d064022770a288f43b2e94f.tar.gz
busybox-w32-5415c856eaccd1bc5d064022770a288f43b2e94f.tar.bz2
busybox-w32-5415c856eaccd1bc5d064022770a288f43b2e94f.zip
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)
382 } 382 }
383 host = xstrdup(ap->sprint(&sa, 1)); 383 host = xstrdup(ap->sprint(&sa, 1));
384 } 384 }
385 fp = xfopen("/proc/net/arp", "r"); 385 fp = xfopen_for_read("/proc/net/arp");
386 /* Bypass header -- read one line */ 386 /* Bypass header -- read one line */
387 fgets(line, sizeof(line), fp); 387 fgets(line, sizeof(line), fp);
388 388
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)
113 parser = config_open(fileconf); 113 parser = config_open(fileconf);
114 if (parser) { 114 if (parser) {
115 char *token[2]; 115 char *token[2];
116 while (config_read(parser, token, 2, 0, "# \t", 0)) { 116 while (config_read(parser, token, 2, 2, "# \t", 0)) {
117 unsigned int a,b,c,d; 117 unsigned int a,b,c,d;
118 /* 118 /*
119 * Assumes all host names are lower case only 119 * Assumes all host names are lower case only
@@ -121,7 +121,8 @@ static void dnsentryinit(void)
121 * Presently the dot is copied into name without 121 * Presently the dot is copied into name without
122 * converting to a length/string substring for that label. 122 * converting to a length/string substring for that label.
123 */ 123 */
124 if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4) 124// if (!token[1] || sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4)
125 if (sscanf(token[1], ".%u.%u.%u.%u"+1, &a, &b, &c, &d) != 4)
125 continue; 126 continue;
126 127
127 m = xzalloc(sizeof(*m)); 128 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 @@
16 16
17static void do_sethostname(char *s, int isfile) 17static void do_sethostname(char *s, int isfile)
18{ 18{
19 FILE *f;
20
21 if (!s) 19 if (!s)
22 return; 20 return;
23 if (!isfile) { 21 if (isfile) {
24 if (sethostname(s, strlen(s)) < 0) { 22 parser_t *parser = config_open2(s, xfopen_for_read);
25 if (errno == EPERM) 23 while (config_read(parser, &s, 1, 1, "# \t", 0)) {
26 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root); 24 do_sethostname(s, 0);
27 bb_perror_msg_and_die("sethostname");
28 }
29 } else {
30 f = xfopen(s, "r");
31#define strbuf bb_common_bufsiz1
32 while (fgets(strbuf, sizeof(strbuf), f) != NULL) {
33 if (strbuf[0] == '#') {
34 continue;
35 }
36 chomp(strbuf);
37 do_sethostname(strbuf, 0);
38 } 25 }
39 if (ENABLE_FEATURE_CLEAN_UP) 26 if (ENABLE_FEATURE_CLEAN_UP)
40 fclose(f); 27 config_close(parser);
28 } else if (sethostname(s, strlen(s)) < 0) {
29 if (errno == EPERM)
30 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
31 bb_perror_msg_and_die("sethostname");
41 } 32 }
42} 33}
43 34
@@ -98,5 +89,5 @@ int hostname_main(int argc, char **argv)
98 } 89 }
99 if (ENABLE_FEATURE_CLEAN_UP) 90 if (ENABLE_FEATURE_CLEAN_UP)
100 free(buf); 91 free(buf);
101 return 0; 92 return EXIT_SUCCESS;
102} 93}
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)
518 sprintf((char *)filename, "%s/%s", path, httpd_conf); 518 sprintf((char *)filename, "%s/%s", path, httpd_conf);
519 } 519 }
520 520
521 while ((f = fopen(filename, "r")) == NULL) { 521 while ((f = fopen_for_read(filename)) == NULL) {
522 if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) { 522 if (flag == SUBDIR_PARSE || flag == FIND_FROM_HTTPD_ROOT) {
523 /* config file not found, no changes to config */ 523 /* config file not found, no changes to config */
524 return; 524 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)
692 enum { NONE, IFACE, MAPPING } currently_processing = NONE; 692 enum { NONE, IFACE, MAPPING } currently_processing = NONE;
693 693
694 defn = xzalloc(sizeof(*defn)); 694 defn = xzalloc(sizeof(*defn));
695 f = xfopen(filename, "r"); 695 f = xfopen_for_read(filename);
696 696
697 while ((buf = xmalloc_fgetline(f)) != NULL) { 697 while ((buf = xmalloc_fgetline(f)) != NULL) {
698#if ENABLE_DESKTOP 698#if ENABLE_DESKTOP
@@ -1090,7 +1090,7 @@ static llist_t *find_iface_state(llist_t *state_list, const char *iface)
1090static llist_t *read_iface_state(void) 1090static llist_t *read_iface_state(void)
1091{ 1091{
1092 llist_t *state_list = NULL; 1092 llist_t *state_list = NULL;
1093 FILE *state_fp = fopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "r"); 1093 FILE *state_fp = fopen_for_read(CONFIG_IFUPDOWN_IFSTATE_PATH);
1094 1094
1095 if (state_fp) { 1095 if (state_fp) {
1096 char *start, *end_ptr; 1096 char *start, *end_ptr;
@@ -1256,7 +1256,7 @@ int ifupdown_main(int argc, char **argv)
1256 } 1256 }
1257 1257
1258 /* Actually write the new state */ 1258 /* Actually write the new state */
1259 state_fp = xfopen(CONFIG_IFUPDOWN_IFSTATE_PATH, "w"); 1259 state_fp = xfopen_for_write(CONFIG_IFUPDOWN_IFSTATE_PATH);
1260 state = state_list; 1260 state = state_list;
1261 while (state) { 1261 while (state) {
1262 if (state->data) { 1262 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)
990#define IPV6_ADDR_MAPPED 0x1000U 990#define IPV6_ADDR_MAPPED 0x1000U
991#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */ 991#define IPV6_ADDR_RESERVED 0x2000U /* reserved address space */
992 992
993 f = fopen(_PATH_PROCNET_IFINET6, "r"); 993 f = fopen_for_read(_PATH_PROCNET_IFINET6);
994 if (f != NULL) { 994 if (f != NULL) {
995 while (fscanf 995 while (fscanf
996 (f, "%4s%4s%4s%4s%4s%4s%4s%4s %08x %02x %02x %02x %20s\n", 996 (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)
64 if (hz_internal) 64 if (hz_internal)
65 return hz_internal; 65 return hz_internal;
66 66
67 fp = fopen("/proc/net/psched", "r"); 67 fp = fopen_for_read("/proc/net/psched");
68 if (fp) { 68 if (fp) {
69 unsigned nom, denom; 69 unsigned nom, denom;
70 70
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)
18 char buf[512]; 18 char buf[512];
19 FILE *fp; 19 FILE *fp;
20 20
21 fp = fopen(file, "r"); 21 fp = fopen_for_read(file);
22 if (!fp) 22 if (!fp)
23 return; 23 return;
24 while (fgets(buf, sizeof(buf), fp)) { 24 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)
170 } 170 }
171 171
172 ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0); 172 ctl_sk = xsocket(PF_INET, SOCK_DGRAM, 0);
173 ifh = xfopen("/proc/net/dev", "r"); 173 ifh = xfopen_for_read("/proc/net/dev");
174 174
175 linenum = 0; 175 linenum = 0;
176 while (clist) { 176 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 *)
466 FILE *procinfo; 466 FILE *procinfo;
467 char *buffer; 467 char *buffer;
468 468
469 procinfo = fopen(file, "r"); 469 procinfo = fopen_for_read(file);
470 if (procinfo == NULL) { 470 if (procinfo == NULL) {
471 if (errno != ENOENT) { 471 if (errno != ENOENT) {
472 bb_simple_perror_msg(file); 472 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)
484 struct sockaddr_in s_addr; 484 struct sockaddr_in s_addr;
485 struct in_addr mask; 485 struct in_addr mask;
486 486
487 FILE *fp = xfopen("/proc/net/route", "r"); 487 FILE *fp = xfopen_for_read("/proc/net/route");
488 488
489 printf("Kernel IP routing table\n" 489 printf("Kernel IP routing table\n"
490 "Destination Gateway Genmask Flags %s Iface\n", 490 "Destination Gateway Genmask Flags %s Iface\n",
@@ -552,7 +552,7 @@ static void INET6_displayroutes(void)
552 int iflags, metric, refcnt, use, prefix_len, slen; 552 int iflags, metric, refcnt, use, prefix_len, slen;
553 struct sockaddr_in6 snaddr6; 553 struct sockaddr_in6 snaddr6;
554 554
555 FILE *fp = xfopen("/proc/net/ipv6_route", "r"); 555 FILE *fp = xfopen_for_read("/proc/net/ipv6_route");
556 556
557 printf("Kernel IPv6 routing table\n%-44s%-40s" 557 printf("Kernel IPv6 routing table\n%-44s%-40s"
558 "Flags Metric Ref Use Iface\n", 558 "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)
508 struct IFADDRLIST *al; 508 struct IFADDRLIST *al;
509 char buf[256], tdevice[256], device[256]; 509 char buf[256], tdevice[256], device[256];
510 510
511 f = xfopen("/proc/net/route", "r"); 511 f = xfopen_for_read("/proc/net/route");
512 512
513 /* Find the appropriate interface */ 513 /* Find the appropriate interface */
514 n = 0; 514 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)
321 if (!parser) 321 if (!parser)
322 return; 322 return;
323 323
324 while (config_read(parser, token, 2, 0, "# \t", PARSE_LAST_IS_GREEDY)) { 324 while (config_read(parser, token, 2, 2, "# \t", PARSE_LAST_IS_GREEDY)) {
325 if (!token[1])
326 continue;
327 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { 325 for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
328 if (!strcasecmp(token[0], k->keyword)) { 326 if (!strcasecmp(token[0], k->keyword)) {
329 if (!k->handler(token[1], k->var)) { 327 if (!k->handler(token[1], k->var)) {