diff options
author | Rob Landley <rob@landley.net> | 2006-05-29 06:43:55 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-05-29 06:43:55 +0000 |
commit | a6e131dab39ee67522687a56b39ed815b9ae15ec (patch) | |
tree | 1ca2de8c070d79096f6db1a4a614d00a0ef7800d | |
parent | bba7f08d2788bc9bc30a7a60fdfd873a73fead9a (diff) | |
download | busybox-w32-a6e131dab39ee67522687a56b39ed815b9ae15ec.tar.gz busybox-w32-a6e131dab39ee67522687a56b39ed815b9ae15ec.tar.bz2 busybox-w32-a6e131dab39ee67522687a56b39ed815b9ae15ec.zip |
Size reductions, mostly switching things to use libbb functions.
-rw-r--r-- | miscutils/strings.c | 2 | ||||
-rw-r--r-- | networking/dnsd.c | 33 | ||||
-rw-r--r-- | networking/ifupdown.c | 69 | ||||
-rw-r--r-- | networking/interface.c | 4 | ||||
-rw-r--r-- | networking/libiproute/ll_map.c | 5 | ||||
-rw-r--r-- | networking/nameif.c | 4 |
6 files changed, 26 insertions, 91 deletions
diff --git a/miscutils/strings.c b/miscutils/strings.c index bd07f5d3e..7758907c7 100644 --- a/miscutils/strings.c +++ b/miscutils/strings.c | |||
@@ -41,7 +41,7 @@ int strings_main(int argc, char **argv) | |||
41 | argv += optind; | 41 | argv += optind; |
42 | 42 | ||
43 | n = bb_xgetlarg(n_arg, 10, 1, INT_MAX); | 43 | n = bb_xgetlarg(n_arg, 10, 1, INT_MAX); |
44 | string = xcalloc(n + 1, 1); | 44 | string = xzalloc(n + 1); |
45 | n--; | 45 | n--; |
46 | 46 | ||
47 | if (argc == 0) { | 47 | if (argc == 0) { |
diff --git a/networking/dnsd.c b/networking/dnsd.c index b9d022170..58a8fc1d2 100644 --- a/networking/dnsd.c +++ b/networking/dnsd.c | |||
@@ -82,8 +82,7 @@ static uint32_t ttl = DEFAULT_TTL; | |||
82 | /* | 82 | /* |
83 | * Convert host name from C-string to dns length/string. | 83 | * Convert host name from C-string to dns length/string. |
84 | */ | 84 | */ |
85 | static void | 85 | static void convname(char *a, uint8_t *q) |
86 | convname(char *a, uint8_t *q) | ||
87 | { | 86 | { |
88 | int i = (q[0] == '.') ? 0 : 1; | 87 | int i = (q[0] == '.') ? 0 : 1; |
89 | for(; i < MAX_HOST_LEN-1 && *q; i++, q++) | 88 | for(; i < MAX_HOST_LEN-1 && *q; i++, q++) |
@@ -95,8 +94,7 @@ convname(char *a, uint8_t *q) | |||
95 | /* | 94 | /* |
96 | * Insert length of substrings insetad of dots | 95 | * Insert length of substrings insetad of dots |
97 | */ | 96 | */ |
98 | static void | 97 | static void undot(uint8_t * rip) |
99 | undot(uint8_t * rip) | ||
100 | { | 98 | { |
101 | int i = 0, s = 0; | 99 | int i = 0, s = 0; |
102 | while(rip[i]) i++; | 100 | while(rip[i]) i++; |
@@ -111,8 +109,7 @@ undot(uint8_t * rip) | |||
111 | /* | 109 | /* |
112 | * Append message to log file | 110 | * Append message to log file |
113 | */ | 111 | */ |
114 | static void | 112 | static void log_message(char *filename, char *message) |
115 | log_message(char *filename, char *message) | ||
116 | { | 113 | { |
117 | FILE *logfile; | 114 | FILE *logfile; |
118 | if (!daemonmode) | 115 | if (!daemonmode) |
@@ -133,8 +130,7 @@ log_message(char *filename, char *message) | |||
133 | * converting to a length/string substring for that label. | 130 | * converting to a length/string substring for that label. |
134 | */ | 131 | */ |
135 | 132 | ||
136 | static int | 133 | static int getfileentry(FILE * fp, struct dns_entry *s, int verb) |
137 | getfileentry(FILE * fp, struct dns_entry *s, int verb) | ||
138 | { | 134 | { |
139 | unsigned int a,b,c,d; | 135 | unsigned int a,b,c,d; |
140 | char *r, *name; | 136 | char *r, *name; |
@@ -168,19 +164,16 @@ restart: | |||
168 | /* | 164 | /* |
169 | * Read hostname/IP records from file | 165 | * Read hostname/IP records from file |
170 | */ | 166 | */ |
171 | static void | 167 | static void dnsentryinit(int verb) |
172 | dnsentryinit(int verb) | ||
173 | { | 168 | { |
174 | FILE *fp; | 169 | FILE *fp; |
175 | struct dns_entry *m, *prev; | 170 | struct dns_entry *m, *prev; |
176 | prev = dnsentry = NULL; | 171 | prev = dnsentry = NULL; |
177 | 172 | ||
178 | if(!(fp = fopen(fileconf, "r"))) | 173 | fp = bb_xfopen(fileconf, "r"); |
179 | bb_perror_msg_and_die("open %s",fileconf); | ||
180 | 174 | ||
181 | while (1) { | 175 | while (1) { |
182 | if(!(m = (struct dns_entry *)malloc(sizeof(struct dns_entry)))) | 176 | m = xmalloc(sizeof(struct dns_entry)); |
183 | bb_perror_msg_and_die("malloc dns_entry"); | ||
184 | 177 | ||
185 | m->next = NULL; | 178 | m->next = NULL; |
186 | if (getfileentry(fp, m, verb)) | 179 | if (getfileentry(fp, m, verb)) |
@@ -199,8 +192,7 @@ dnsentryinit(int verb) | |||
199 | /* | 192 | /* |
200 | * Set up UDP socket | 193 | * Set up UDP socket |
201 | */ | 194 | */ |
202 | static int | 195 | static int listen_socket(char *iface_addr, int listen_port) |
203 | listen_socket(char *iface_addr, int listen_port) | ||
204 | { | 196 | { |
205 | struct sockaddr_in a; | 197 | struct sockaddr_in a; |
206 | char msg[100]; | 198 | char msg[100]; |
@@ -228,8 +220,7 @@ listen_socket(char *iface_addr, int listen_port) | |||
228 | * Look query up in dns records and return answer if found | 220 | * Look query up in dns records and return answer if found |
229 | * qs is the query string, first byte the string length | 221 | * qs is the query string, first byte the string length |
230 | */ | 222 | */ |
231 | static int | 223 | static int table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) |
232 | table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) | ||
233 | { | 224 | { |
234 | int i; | 225 | int i; |
235 | struct dns_entry *d=dnsentry; | 226 | struct dns_entry *d=dnsentry; |
@@ -269,8 +260,7 @@ table_lookup(uint16_t type, uint8_t * as, uint8_t * qs) | |||
269 | * Decode message and generate answer | 260 | * Decode message and generate answer |
270 | */ | 261 | */ |
271 | #define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0) | 262 | #define eret(s) do { fprintf (stderr, "%s\n", s); return -1; } while (0) |
272 | static int | 263 | static int process_packet(uint8_t * buf) |
273 | process_packet(uint8_t * buf) | ||
274 | { | 264 | { |
275 | struct dns_head *head; | 265 | struct dns_head *head; |
276 | struct dns_prop *qprop; | 266 | struct dns_prop *qprop; |
@@ -367,8 +357,7 @@ process_packet(uint8_t * buf) | |||
367 | /* | 357 | /* |
368 | * Exit on signal | 358 | * Exit on signal |
369 | */ | 359 | */ |
370 | static void | 360 | static void interrupt(int x) |
371 | interrupt(int x) | ||
372 | { | 361 | { |
373 | unlink(LOCK_FILE); | 362 | unlink(LOCK_FILE); |
374 | write(2, "interrupt exiting\n", 18); | 363 | write(2, "interrupt exiting\n", 18); |
diff --git a/networking/ifupdown.c b/networking/ifupdown.c index 038bb13bc..6a200bb26 100644 --- a/networking/ifupdown.c +++ b/networking/ifupdown.c | |||
@@ -629,10 +629,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
629 | 629 | ||
630 | enum { NONE, IFACE, MAPPING } currently_processing = NONE; | 630 | enum { NONE, IFACE, MAPPING } currently_processing = NONE; |
631 | 631 | ||
632 | defn = xmalloc(sizeof(struct interfaces_file_t)); | 632 | defn = xzalloc(sizeof(struct interfaces_file_t)); |
633 | defn->autointerfaces = NULL; | ||
634 | defn->mappings = NULL; | ||
635 | defn->ifaces = NULL; | ||
636 | 633 | ||
637 | f = bb_xfopen(filename, "r"); | 634 | f = bb_xfopen(filename, "r"); |
638 | 635 | ||
@@ -647,10 +644,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
647 | 644 | ||
648 | if (strcmp(firstword, "mapping") == 0) { | 645 | if (strcmp(firstword, "mapping") == 0) { |
649 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING | 646 | #ifdef CONFIG_FEATURE_IFUPDOWN_MAPPING |
650 | currmap = xmalloc(sizeof(struct mapping_defn_t)); | 647 | currmap = xzalloc(sizeof(struct mapping_defn_t)); |
651 | currmap->max_matches = 0; | ||
652 | currmap->n_matches = 0; | ||
653 | currmap->match = NULL; | ||
654 | 648 | ||
655 | while ((firstword = next_word(&buf_ptr)) != NULL) { | 649 | while ((firstword = next_word(&buf_ptr)) != NULL) { |
656 | if (currmap->max_matches == currmap->n_matches) { | 650 | if (currmap->max_matches == currmap->n_matches) { |
@@ -690,7 +684,7 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
690 | NULL | 684 | NULL |
691 | }; | 685 | }; |
692 | 686 | ||
693 | currif = xmalloc(sizeof(struct interface_defn_t)); | 687 | currif = xzalloc(sizeof(struct interface_defn_t)); |
694 | iface_name = next_word(&buf_ptr); | 688 | iface_name = next_word(&buf_ptr); |
695 | address_family_name = next_word(&buf_ptr); | 689 | address_family_name = next_word(&buf_ptr); |
696 | method_name = next_word(&buf_ptr); | 690 | method_name = next_word(&buf_ptr); |
@@ -724,9 +718,6 @@ static struct interfaces_file_t *read_interfaces(const char *filename) | |||
724 | return NULL; | 718 | return NULL; |
725 | } | 719 | } |
726 | 720 | ||
727 | currif->max_options = 0; | ||
728 | currif->n_options = 0; | ||
729 | currif->option = NULL; | ||
730 | 721 | ||
731 | { | 722 | { |
732 | llist_t *iface_list; | 723 | llist_t *iface_list; |
@@ -845,9 +836,7 @@ static char *setlocalenv(char *format, const char *name, const char *value) | |||
845 | char *here; | 836 | char *here; |
846 | char *there; | 837 | char *there; |
847 | 838 | ||
848 | result = xmalloc(strlen(format) + strlen(name) + strlen(value) + 1); | 839 | result = bb_xasprintf(format, name, value); |
849 | |||
850 | sprintf(result, format, name, value); | ||
851 | 840 | ||
852 | for (here = there = result; *there != '=' && *there; there++) { | 841 | for (here = there = result; *there != '=' && *there; there++) { |
853 | if (*there == '-') | 842 | if (*there == '-') |
@@ -878,11 +867,9 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
878 | *ppch = NULL; | 867 | *ppch = NULL; |
879 | } | 868 | } |
880 | free(__myenviron); | 869 | free(__myenviron); |
881 | __myenviron = NULL; | ||
882 | } | 870 | } |
883 | __myenviron = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ )); | 871 | __myenviron = xzalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ )); |
884 | environend = __myenviron; | 872 | environend = __myenviron; |
885 | *environend = NULL; | ||
886 | 873 | ||
887 | for (i = 0; i < iface->n_options; i++) { | 874 | for (i = 0; i < iface->n_options; i++) { |
888 | if (strcmp(iface->option[i].name, "up") == 0 | 875 | if (strcmp(iface->option[i].name, "up") == 0 |
@@ -892,19 +879,13 @@ static void set_environ(struct interface_defn_t *iface, const char *mode) | |||
892 | continue; | 879 | continue; |
893 | } | 880 | } |
894 | *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); | 881 | *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); |
895 | *environend = NULL; | ||
896 | } | 882 | } |
897 | 883 | ||
898 | *(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface); | 884 | *(environend++) = setlocalenv("%s=%s", "IFACE", iface->iface); |
899 | *environend = NULL; | ||
900 | *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); | 885 | *(environend++) = setlocalenv("%s=%s", "ADDRFAM", iface->address_family->name); |
901 | *environend = NULL; | ||
902 | *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); | 886 | *(environend++) = setlocalenv("%s=%s", "METHOD", iface->method->name); |
903 | *environend = NULL; | ||
904 | *(environend++) = setlocalenv("%s=%s", "MODE", mode); | 887 | *(environend++) = setlocalenv("%s=%s", "MODE", mode); |
905 | *environend = NULL; | ||
906 | *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"); | 888 | *(environend++) = setlocalenv("%s=%s", "PATH", "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"); |
907 | *environend = NULL; | ||
908 | } | 889 | } |
909 | 890 | ||
910 | static int doit(char *str) | 891 | static int doit(char *str) |
@@ -1069,7 +1050,7 @@ static char *run_mapping(char *physical, struct mapping_defn_t * map) | |||
1069 | free(logical); | 1050 | free(logical); |
1070 | logical = new_logical; | 1051 | logical = new_logical; |
1071 | } else { | 1052 | } else { |
1072 | /* If we are UNABLE to read a line of output, discard are | 1053 | /* If we are UNABLE to read a line of output, discard our |
1073 | * freshly allocated memory. */ | 1054 | * freshly allocated memory. */ |
1074 | free(new_logical); | 1055 | free(new_logical); |
1075 | } | 1056 | } |
@@ -1177,28 +1158,6 @@ int ifupdown_main(int argc, char **argv) | |||
1177 | if (cmds == iface_up) { | 1158 | if (cmds == iface_up) { |
1178 | target_list = defn->autointerfaces; | 1159 | target_list = defn->autointerfaces; |
1179 | } else { | 1160 | } else { |
1180 | #if 0 | ||
1181 | /* iface_down */ | ||
1182 | llist_t *new_item; | ||
1183 | const llist_t *list = state_list; | ||
1184 | while (list) { | ||
1185 | new_item = xmalloc(sizeof(llist_t)); | ||
1186 | new_item->data = bb_xstrdup(list->data); | ||
1187 | new_item->link = NULL; | ||
1188 | list = target_list; | ||
1189 | if (list == NULL) | ||
1190 | target_list = new_item; | ||
1191 | else { | ||
1192 | while (list->link) { | ||
1193 | list = list->link; | ||
1194 | } | ||
1195 | list = new_item; | ||
1196 | } | ||
1197 | list = list->link; | ||
1198 | } | ||
1199 | target_list = defn->autointerfaces; | ||
1200 | #else | ||
1201 | |||
1202 | /* iface_down */ | 1161 | /* iface_down */ |
1203 | const llist_t *list = state_list; | 1162 | const llist_t *list = state_list; |
1204 | while (list) { | 1163 | while (list) { |
@@ -1206,7 +1165,6 @@ int ifupdown_main(int argc, char **argv) | |||
1206 | list = list->link; | 1165 | list = list->link; |
1207 | } | 1166 | } |
1208 | target_list = defn->autointerfaces; | 1167 | target_list = defn->autointerfaces; |
1209 | #endif | ||
1210 | } | 1168 | } |
1211 | } else { | 1169 | } else { |
1212 | llist_add_to_end(&target_list, argv[optind]); | 1170 | llist_add_to_end(&target_list, argv[optind]); |
@@ -1308,8 +1266,7 @@ int ifupdown_main(int argc, char **argv) | |||
1308 | llist_t *iface_state = find_iface_state(state_list, iface); | 1266 | llist_t *iface_state = find_iface_state(state_list, iface); |
1309 | 1267 | ||
1310 | if (cmds == iface_up) { | 1268 | if (cmds == iface_up) { |
1311 | char *newiface = xmalloc(strlen(iface) + 1 + strlen(liface) + 1); | 1269 | char *newiface = bb_xasprintf("%s=%s", iface, liface); |
1312 | sprintf(newiface, "%s=%s", iface, liface); | ||
1313 | if (iface_state == NULL) { | 1270 | if (iface_state == NULL) { |
1314 | llist_add_to_end(&state_list, newiface); | 1271 | llist_add_to_end(&state_list, newiface); |
1315 | } else { | 1272 | } else { |
@@ -1318,17 +1275,7 @@ int ifupdown_main(int argc, char **argv) | |||
1318 | } | 1275 | } |
1319 | } else { | 1276 | } else { |
1320 | /* Remove an interface from the linked list */ | 1277 | /* Remove an interface from the linked list */ |
1321 | if (iface_state) { | 1278 | free(llist_pop(&iface_state)); |
1322 | llist_t *l = iface_state->link; | ||
1323 | free(iface_state->data); | ||
1324 | iface_state->data = NULL; | ||
1325 | iface_state->link = NULL; | ||
1326 | if (l) { | ||
1327 | iface_state->data = l->data; | ||
1328 | iface_state->link = l->link; | ||
1329 | } | ||
1330 | free(l); | ||
1331 | } | ||
1332 | } | 1279 | } |
1333 | } | 1280 | } |
1334 | } | 1281 | } |
diff --git a/networking/interface.c b/networking/interface.c index 3d399be71..260dac073 100644 --- a/networking/interface.c +++ b/networking/interface.c | |||
@@ -76,7 +76,6 @@ | |||
76 | 76 | ||
77 | #define _PATH_PROCNET_DEV "/proc/net/dev" | 77 | #define _PATH_PROCNET_DEV "/proc/net/dev" |
78 | #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" | 78 | #define _PATH_PROCNET_IFINET6 "/proc/net/if_inet6" |
79 | #define new(p) ((p) = xcalloc(1,sizeof(*(p)))) | ||
80 | 79 | ||
81 | #if HAVE_AFINET6 | 80 | #if HAVE_AFINET6 |
82 | 81 | ||
@@ -789,7 +788,8 @@ static struct interface *add_interface(char *name) | |||
789 | if (n < 0) | 788 | if (n < 0) |
790 | break; | 789 | break; |
791 | } | 790 | } |
792 | new(new); | 791 | |
792 | new = xzalloc(sizeof(*new)); | ||
793 | safe_strncpy(new->name, name, IFNAMSIZ); | 793 | safe_strncpy(new->name, name, IFNAMSIZ); |
794 | nextp = ife ? &ife->next : &int_list; | 794 | nextp = ife ? &ife->next : &int_list; |
795 | new->prev = ife; | 795 | new->prev = ife; |
diff --git a/networking/libiproute/ll_map.c b/networking/libiproute/ll_map.c index 46c873faa..24487eb3d 100644 --- a/networking/libiproute/ll_map.c +++ b/networking/libiproute/ll_map.c | |||
@@ -17,6 +17,7 @@ | |||
17 | 17 | ||
18 | #include "libnetlink.h" | 18 | #include "libnetlink.h" |
19 | #include "ll_map.h" | 19 | #include "ll_map.h" |
20 | #include "libbb.h" | ||
20 | 21 | ||
21 | struct idxmap | 22 | struct idxmap |
22 | { | 23 | { |
@@ -57,9 +58,7 @@ int ll_remember_index(struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) | |||
57 | break; | 58 | break; |
58 | 59 | ||
59 | if (im == NULL) { | 60 | if (im == NULL) { |
60 | im = malloc(sizeof(*im)); | 61 | im = xmalloc(sizeof(*im)); |
61 | if (im == NULL) | ||
62 | return 0; | ||
63 | im->next = *imp; | 62 | im->next = *imp; |
64 | im->index = ifi->ifi_index; | 63 | im->index = ifi->ifi_index; |
65 | *imp = im; | 64 | *imp = im; |
diff --git a/networking/nameif.c b/networking/nameif.c index 8590a98ad..7dc48ec16 100644 --- a/networking/nameif.c +++ b/networking/nameif.c | |||
@@ -105,7 +105,7 @@ int nameif_main(int argc, char **argv) | |||
105 | 105 | ||
106 | if (strlen(*a) > IF_NAMESIZE) | 106 | if (strlen(*a) > IF_NAMESIZE) |
107 | serror("interface name `%s' too long", *a); | 107 | serror("interface name `%s' too long", *a); |
108 | ch = xcalloc(1, sizeof(mactable_t)); | 108 | ch = xzalloc(sizeof(mactable_t)); |
109 | ch->ifname = bb_xstrdup(*a++); | 109 | ch->ifname = bb_xstrdup(*a++); |
110 | ch->mac = cc_macaddr(*a++); | 110 | ch->mac = cc_macaddr(*a++); |
111 | if (clist) | 111 | if (clist) |
@@ -126,7 +126,7 @@ int nameif_main(int argc, char **argv) | |||
126 | continue; | 126 | continue; |
127 | } | 127 | } |
128 | name_length = strcspn(line_ptr, " \t"); | 128 | name_length = strcspn(line_ptr, " \t"); |
129 | ch = xcalloc(1, sizeof(mactable_t)); | 129 | ch = xzalloc(sizeof(mactable_t)); |
130 | ch->ifname = bb_xstrndup(line_ptr, name_length); | 130 | ch->ifname = bb_xstrndup(line_ptr, name_length); |
131 | if (name_length > IF_NAMESIZE) | 131 | if (name_length > IF_NAMESIZE) |
132 | serror("interface name `%s' too long", ch->ifname); | 132 | serror("interface name `%s' too long", ch->ifname); |