From vda at busybox.net Sun Jul 1 07:53:08 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 07:53:08 -0700 (PDT) Subject: svn commit: trunk/busybox/procps Message-ID: <20070701145308.59D1EA605F@busybox.net> Author: vda Date: 2007-07-01 07:53:06 -0700 (Sun, 01 Jul 2007) New Revision: 18981 Log: ps: fix "unused variable" warning; fix integer variable declared as char. Modified: trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2007-06-30 17:12:14 UTC (rev 18980) +++ trunk/busybox/procps/ps.c 2007-07-01 14:53:06 UTC (rev 18981) @@ -340,8 +340,9 @@ int ps_main(int argc, char **argv) { procps_status_t *p = NULL; - int i, len; + int len; SKIP_SELINUX(const) int use_selinux = 0; + USE_SELINUX(int i;) #if !ENABLE_FEATURE_PS_WIDE enum { terminal_width = 79 }; #else @@ -367,7 +368,7 @@ i = getopt32(argc, argv, "Z"); #endif #if ENABLE_SELINUX - if ((i & 1) && is_selinux_enabled()) + if (i && is_selinux_enabled()) use_selinux = PSSCAN_CONTEXT; #endif #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ @@ -404,7 +405,7 @@ } { - char sz = terminal_width - len; + int sz = terminal_width - len; char buf[sz + 1]; read_cmdline(buf, sz, p->pid, p->comm); puts(buf); From vda at busybox.net Sun Jul 1 10:05:58 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 10:05:58 -0700 (PDT) Subject: svn commit: trunk/busybox: include networking/udhcp Message-ID: <20070701170558.B4373A65A6@busybox.net> Author: vda Date: 2007-07-01 10:05:57 -0700 (Sun, 01 Jul 2007) New Revision: 18982 Log: udhcp: new config option "Rewrite the lease file at every new acknowledge" (Mats Erik Andersson (Blue2Net AB)) udhcp: consistently treat server_config.start/end IPs as host-order fix IP parsing for 64bit machines fix unsafe hton macro usage in read_opt() do not chdir("/") when daemonizing fix help text Modified: trunk/busybox/include/usage.h trunk/busybox/networking/udhcp/Config.in trunk/busybox/networking/udhcp/dhcpc.c trunk/busybox/networking/udhcp/dhcpc.h trunk/busybox/networking/udhcp/dhcpd.c trunk/busybox/networking/udhcp/dhcpd.h trunk/busybox/networking/udhcp/files.c trunk/busybox/networking/udhcp/leases.c trunk/busybox/networking/udhcp/serverpacket.c trunk/busybox/networking/udhcp/socket.c Changeset: Modified: trunk/busybox/include/usage.h =================================================================== --- trunk/busybox/include/usage.h 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/include/usage.h 2007-07-01 17:05:57 UTC (rev 18982) @@ -3575,7 +3575,8 @@ "Adjust filesystem options on ext[23] filesystems" #define udhcpc_trivial_usage \ - "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]" + "[-Cfbnqtv] [-c CID] [-V VCLS] [-H HOSTNAME] [-i INTERFACE]\n" \ + " [-p pidfile] [-r IP] [-s script]" #define udhcpc_full_usage \ " -V,--vendorclass=CLASSID Set vendor class identifier\n" \ " -i,--interface=INTERFACE Interface to use (default: eth0)\n" \ @@ -3594,7 +3595,7 @@ " -v,--version Display version" \ #define udhcpd_trivial_usage \ - "[configfile]\n" \ + "[configfile]" \ #define udhcpd_full_usage \ "" Modified: trunk/busybox/networking/udhcp/Config.in =================================================================== --- trunk/busybox/networking/udhcp/Config.in 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/Config.in 2007-07-01 17:05:57 UTC (rev 18982) @@ -32,6 +32,16 @@ See http://udhcp.busybox.net for further details. +config FEATURE_UDHCPD_WRITE_LEASES_EARLY + bool "Rewrite the lease file at every new acknowledge" + default n + depends on APP_UDHCPD + help + If selected, udhcpd will write a new file with leases every + time a new lease has been accepted, thus eleminating the need + to send SIGUSR1 for the initial writing, or updating. Any timed + rewriting remains undisturbed + config APP_UDHCPC bool "udhcp Client (udhcpc)" default n Modified: trunk/busybox/networking/udhcp/dhcpc.c =================================================================== --- trunk/busybox/networking/udhcp/dhcpc.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/dhcpc.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -114,8 +114,7 @@ * If that will be properly disabled for NOMMU, client_background() * will work on NOMMU too */ #else -// chdir(/) is problematic. Imagine that e.g. pidfile name is RELATIVE! what will unlink do then, eh? - bb_daemonize(DAEMON_CHDIR_ROOT); + bb_daemonize(0); /* rewrite pidfile, as our pid is different now */ if (client_config.pidfile) write_pidfile(client_config.pidfile); Modified: trunk/busybox/networking/udhcp/dhcpc.h =================================================================== --- trunk/busybox/networking/udhcp/dhcpc.h 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/dhcpc.h 2007-07-01 17:05:57 UTC (rev 18982) @@ -17,12 +17,12 @@ /* (can be set directly to the result of getopt32) */ char foreground; /* Do not fork */ char quit_after_lease; /* Quit after obtaining lease */ - char release_on_quit; /* perform release on quit */ + char release_on_quit; /* Perform release on quit */ char abort_if_no_lease; /* Abort if no lease */ char background_if_no_lease; /* Fork to background if no lease */ - const char *interface; /* The name of the interface to use */ + const char *interface; /* The name of the interface to use */ char *pidfile; /* Optionally store the process ID */ - const char *script; /* User script to run at dhcp events */ + const char *script; /* User script to run at dhcp events */ uint8_t *clientid; /* Optional client id to use */ uint8_t *vendorclass; /* Optional vendor class-id to use */ uint8_t *hostname; /* Optional hostname to use */ Modified: trunk/busybox/networking/udhcp/dhcpd.c =================================================================== --- trunk/busybox/networking/udhcp/dhcpd.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/dhcpd.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -37,7 +37,7 @@ //Huh, dhcpd don't have --foreground, --syslog options?? TODO if (!ENABLE_FEATURE_UDHCP_DEBUG) { - bb_daemonize_or_rexec(DAEMON_CHDIR_ROOT, argv); + bb_daemonize_or_rexec(0, argv); logmode &= ~LOGMODE_STDIO; } @@ -60,15 +60,15 @@ } /* Sanity check */ - num_ips = ntohl(server_config.end) - ntohl(server_config.start) + 1; + num_ips = server_config.end_ip - server_config.start_ip + 1; if (server_config.max_leases > num_ips) { - bb_error_msg("max_leases value (%lu) not sane, " - "setting to %lu instead", + bb_error_msg("max_leases=%lu is too big, " + "setting to %lu", server_config.max_leases, num_ips); server_config.max_leases = num_ips; } - leases = xzalloc(server_config.max_leases * sizeof(struct dhcpOfferedAddr)); + leases = xzalloc(server_config.max_leases * sizeof(*leases)); read_leases(server_config.lease_file); if (read_interface(server_config.interface, &server_config.ifindex, @@ -207,10 +207,13 @@ /* make some contention for this address */ } else sendNAK(&packet); - } else if (requested_align < server_config.start - || requested_align > server_config.end - ) { - sendNAK(&packet); + } else { + uint32_t r = ntohl(requested_align); + if (r < server_config.start_ip + || r > server_config.end_ip + ) { + sendNAK(&packet); + } } /* else remain silent */ } else { Modified: trunk/busybox/networking/udhcp/dhcpd.h =================================================================== --- trunk/busybox/networking/udhcp/dhcpd.h 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/dhcpd.h 2007-07-01 17:05:57 UTC (rev 18982) @@ -27,23 +27,24 @@ struct server_config_t { uint32_t server; /* Our IP, in network order */ - uint32_t start; /* Start address of leases, network order */ - uint32_t end; /* End of leases, network order */ + /* start,end are in host order: we need to compare start <= ip <= end */ + uint32_t start_ip; /* Start address of leases, in host order */ + uint32_t end_ip; /* End of leases, in host order */ struct option_set *options; /* List of DHCP options loaded from the config file */ char *interface; /* The name of the interface to use */ int ifindex; /* Index number of the interface to use */ uint8_t arp[6]; /* Our arp address */ - unsigned long lease; /* lease time in seconds (host order) */ - unsigned long max_leases; /* maximum number of leases (including reserved address) */ char remaining; /* should the lease file be interpreted as lease time remaining, or * as the time the lease expires */ + unsigned long lease; /* lease time in seconds (host order) */ + unsigned long max_leases; /* maximum number of leases (including reserved address) */ unsigned long auto_time; /* how long should udhcpd wait before writing a config file. * if this is zero, it will only write one on SIGUSR1 */ unsigned long decline_time; /* how long an address is reserved if a client returns a * decline message */ unsigned long conflict_time; /* how long an arp conflict offender is leased for */ unsigned long offer_time; /* how long an offered address is reserved */ - unsigned long min_lease; /* minimum lease a client can request*/ + unsigned long min_lease; /* minimum lease a client can request */ char *lease_file; char *pidfile; char *notify_file; /* What to run whenever leases are written */ @@ -95,13 +96,6 @@ /*** files.h ***/ -struct config_keyword { - const char *keyword; - int (* const handler)(const char *line, void *var); - void *var; - const char *def; -}; - int read_config(const char *file); void write_leases(void); void read_leases(const char *file); Modified: trunk/busybox/networking/udhcp/files.c =================================================================== --- trunk/busybox/networking/udhcp/files.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/files.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -11,42 +11,30 @@ #include "options.h" -/* - * Domain names may have 254 chars, and string options can be 254 - * chars long. However, 80 bytes will be enough for most, and won't - * hog up memory. If you have a special application, change it - */ -#define READ_CONFIG_BUF_SIZE 80 - -/* on these functions, make sure you datatype matches */ +/* on these functions, make sure your datatype matches */ static int read_ip(const char *line, void *arg) { len_and_sockaddr *lsa; - int retval = 0; lsa = host_and_af2sockaddr(line, 0, AF_INET); if (lsa) { - *(struct in_addr*)arg = lsa->sin.sin_addr; + *(uint32_t*)arg = lsa->sin.sin_addr.s_addr; free(lsa); - retval = 1; + return 1; } - return retval; + return 0; } static int read_mac(const char *line, void *arg) { uint8_t *mac_bytes = arg; struct ether_addr *temp_ether_addr; - int retval = 1; temp_ether_addr = ether_aton(line); - if (temp_ether_addr == NULL) - retval = 0; - else - memcpy(mac_bytes, temp_ether_addr, 6); - - return retval; + return 0; + memcpy(mac_bytes, temp_ether_addr, 6); + return 1; } @@ -56,14 +44,13 @@ free(*dest); *dest = xstrdup(line); - return 1; } static int read_u32(const char *line, void *arg) { - *((uint32_t*)arg) = bb_strtou32(line, NULL, 10); + *(uint32_t*)arg = bb_strtou32(line, NULL, 10); return errno == 0; } @@ -71,15 +58,16 @@ static int read_yn(const char *line, void *arg) { char *dest = arg; - int retval = 1; - if (!strcasecmp("yes", line)) + if (!strcasecmp("yes", line)) { *dest = 1; - else if (!strcasecmp("no", line)) + return 1; + } + if (!strcasecmp("no", line)) { *dest = 0; - else retval = 0; - - return retval; + return 1; + } + return 0; } @@ -89,8 +77,9 @@ while (opt_list && opt_list->data[OPT_CODE] < code) opt_list = opt_list->next; - if (opt_list && opt_list->data[OPT_CODE] == code) return opt_list; - else return NULL; + if (opt_list && opt_list->data[OPT_CODE] == code) + return opt_list; + return NULL; } @@ -111,7 +100,7 @@ #endif /* make a new option */ - new = xmalloc(sizeof(struct option_set)); + new = xmalloc(sizeof(*new)); new->data = xmalloc(length + 2); new->data[OPT_CODE] = option->code; new->data[OPT_LEN] = length; @@ -184,7 +173,7 @@ return 0; if (!strcasecmp(option->name, opt)) break; - option++; + option++; } do { @@ -199,8 +188,11 @@ break; case OPTION_IP_PAIR: retval = read_ip(val, buffer); - if (!(val = strtok(NULL, ", \t/-"))) retval = 0; - if (retval) retval = read_ip(val, buffer + 4); + val = strtok(NULL, ", \t/-"); + if (!val) + retval = 0; + if (retval) + retval = read_ip(val, buffer + 4); break; case OPTION_STRING: #if ENABLE_FEATURE_RFC3397 @@ -220,22 +212,33 @@ buffer[0] = strtoul(val, &endptr, 0); retval = (endptr[0] == '\0'); break; - case OPTION_U16: - *result_u16 = htons(strtoul(val, &endptr, 0)); - retval = (endptr[0] == '\0'); + /* htonX are macros in older libc's, using temp var + * in code below for safety */ + /* TODO: use bb_strtoX? */ + case OPTION_U16: { + unsigned long tmp = strtoul(val, &endptr, 0); + *result_u16 = htons(tmp); + retval = (endptr[0] == '\0' /*&& tmp < 0x10000*/); break; - case OPTION_S16: - *result_u16 = htons(strtol(val, &endptr, 0)); + } + case OPTION_S16: { + long tmp = strtol(val, &endptr, 0); + *result_u16 = htons(tmp); retval = (endptr[0] == '\0'); break; - case OPTION_U32: - *result_u32 = htonl(strtoul(val, &endptr, 0)); + } + case OPTION_U32: { + unsigned long tmp = strtoul(val, &endptr, 0); + *result_u32 = htonl(tmp); retval = (endptr[0] == '\0'); break; - case OPTION_S32: - *result_u32 = htonl(strtol(val, &endptr, 0)); + } + case OPTION_S32: { + long tmp = strtol(val, &endptr, 0); + *result_u32 = htonl(tmp); retval = (endptr[0] == '\0'); break; + } default: break; } @@ -253,7 +256,6 @@ uint8_t *mac_bytes; uint32_t *ip; - /* Allocate memory for addresses */ mac_bytes = xmalloc(sizeof(unsigned char) * 8); ip = xmalloc(sizeof(uint32_t)); @@ -275,39 +277,54 @@ } +struct config_keyword { + const char *keyword; + int (*handler)(const char *line, void *var); + void *var; + const char *def; +}; + static const struct config_keyword keywords[] = { - /* keyword handler variable address default */ - {"start", read_ip, &(server_config.start), "192.168.0.20"}, - {"end", read_ip, &(server_config.end), "192.168.0.254"}, - {"interface", read_str, &(server_config.interface), "eth0"}, - {"option", read_opt, &(server_config.options), ""}, - {"opt", read_opt, &(server_config.options), ""}, - {"max_leases", read_u32, &(server_config.max_leases), "254"}, - {"remaining", read_yn, &(server_config.remaining), "yes"}, - {"auto_time", read_u32, &(server_config.auto_time), "7200"}, - {"decline_time",read_u32, &(server_config.decline_time),"3600"}, - {"conflict_time",read_u32,&(server_config.conflict_time),"3600"}, - {"offer_time", read_u32, &(server_config.offer_time), "60"}, - {"min_lease", read_u32, &(server_config.min_lease), "60"}, - {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE}, - {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"}, - {"notify_file", read_str, &(server_config.notify_file), ""}, - {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"}, - {"sname", read_str, &(server_config.sname), ""}, - {"boot_file", read_str, &(server_config.boot_file), ""}, - {"static_lease",read_staticlease, &(server_config.static_leases), ""}, - /*ADDME: static lease */ - {"", NULL, NULL, ""} + /* keyword handler variable address default */ + {"start", read_ip, &(server_config.start_ip), "192.168.0.20"}, + {"end", read_ip, &(server_config.end_ip), "192.168.0.254"}, + {"interface", read_str, &(server_config.interface), "eth0"}, + {"option", read_opt, &(server_config.options), ""}, + {"opt", read_opt, &(server_config.options), ""}, + /* Avoid "max_leases value not sane" warning by setting default + * to default_end_ip - default_start_ip + 1: */ + {"max_leases", read_u32, &(server_config.max_leases), "235"}, + {"remaining", read_yn, &(server_config.remaining), "yes"}, + {"auto_time", read_u32, &(server_config.auto_time), "7200"}, + {"decline_time", read_u32, &(server_config.decline_time), "3600"}, + {"conflict_time",read_u32, &(server_config.conflict_time),"3600"}, + {"offer_time", read_u32, &(server_config.offer_time), "60"}, + {"min_lease", read_u32, &(server_config.min_lease), "60"}, + {"lease_file", read_str, &(server_config.lease_file), LEASES_FILE}, + {"pidfile", read_str, &(server_config.pidfile), "/var/run/udhcpd.pid"}, + {"notify_file", read_str, &(server_config.notify_file), ""}, + {"siaddr", read_ip, &(server_config.siaddr), "0.0.0.0"}, + {"sname", read_str, &(server_config.sname), ""}, + {"boot_file", read_str, &(server_config.boot_file), ""}, + {"static_lease", read_staticlease, &(server_config.static_leases), ""}, + /* ADDME: static lease */ }; +/* + * Domain names may have 254 chars, and string options can be 254 + * chars long. However, 80 bytes will be enough for most, and won't + * hog up memory. If you have a special application, change it + */ +#define READ_CONFIG_BUF_SIZE 80 + int read_config(const char *file) { FILE *in; char buffer[READ_CONFIG_BUF_SIZE], *token, *line; int i, lm = 0; - for (i = 0; keywords[i].keyword[0]; i++) + for (i = 0; i < ARRAY_SIZE(keywords); i++) if (keywords[i].def[0]) keywords[i].handler(keywords[i].def, keywords[i].var); @@ -337,7 +354,7 @@ while (i >= 0 && isspace(line[i])) line[i--] = '\0'; - for (i = 0; keywords[i].keyword[0]; i++) + for (i = 0; i < ARRAY_SIZE(keywords); i++) if (!strcasecmp(token, keywords[i].keyword)) if (!keywords[i].handler(line, keywords[i].var)) { bb_error_msg("cannot parse line %d of %s", lm, file); @@ -348,6 +365,10 @@ } } fclose(in); + + server_config.start_ip = ntohl(server_config.start_ip); + server_config.end_ip = ntohl(server_config.end_ip); + return 1; } @@ -408,9 +429,11 @@ && full_read(fp, &lease, sizeof(lease)) == sizeof(lease) ) { /* ADDME: is it a static lease */ - if (lease.yiaddr >= server_config.start && lease.yiaddr <= server_config.end) { + uint32_t y = ntohl(lease.yiaddr); + if (y >= server_config.start_ip && y <= server_config.end_ip) { lease.expires = ntohl(lease.expires); - if (!server_config.remaining) lease.expires -= time(0); + if (!server_config.remaining) + lease.expires -= time(0); if (!(add_lease(lease.chaddr, lease.yiaddr, lease.expires))) { bb_error_msg("too many leases while loading %s", file); break; Modified: trunk/busybox/networking/udhcp/leases.c =================================================================== --- trunk/busybox/networking/udhcp/leases.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/leases.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -119,8 +119,8 @@ uint32_t addr, ret; struct dhcpOfferedAddr *lease = NULL; - addr = ntohl(server_config.start); /* addr is in host order here */ - for (;addr <= ntohl(server_config.end); addr++) { + addr = server_config.start_ip; /* addr is in host order here */ + for (;addr <= server_config.end_ip; addr++) { /* ie, 192.168.55.0 */ if (!(addr & 0xFF)) continue; Modified: trunk/busybox/networking/udhcp/serverpacket.c =================================================================== --- trunk/busybox/networking/udhcp/serverpacket.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/serverpacket.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -122,19 +122,18 @@ if (!lease_expired(lease)) lease_time_align = lease->expires - time(0); packet.yiaddr = lease->yiaddr; - /* Or the client has a requested ip */ } else if ((req = get_option(oldpacket, DHCP_REQUESTED_IP)) - /* Don't look here (ugly hackish thing to do) */ - && memcpy(&req_align, req, 4) - /* and the ip is in the lease range */ - && ntohl(req_align) >= ntohl(server_config.start) - && ntohl(req_align) <= ntohl(server_config.end) - && !static_lease_ip /* Check that its not a static lease */ - /* and is not already taken/offered */ - && (!(lease = find_lease_by_yiaddr(req_align)) - /* or its taken, but expired */ /* ADDME: or maybe in here */ - || lease_expired(lease)) + /* Don't look here (ugly hackish thing to do) */ + && memcpy(&req_align, req, 4) + /* and the ip is in the lease range */ + && ntohl(req_align) >= server_config.start_ip + && ntohl(req_align) <= server_config.end_ip + && !static_lease_ip /* Check that its not a static lease */ + /* and is not already taken/offered */ + && (!(lease = find_lease_by_yiaddr(req_align)) + /* or its taken, but expired */ /* ADDME: or maybe in here */ + || lease_expired(lease)) ) { packet.yiaddr = req_align; /* FIXME: oh my, is there a host using this IP? */ /* otherwise, find a free IP */ @@ -142,7 +141,8 @@ /* Is it a static lease? (No, because find_address skips static lease) */ packet.yiaddr = find_address(0); /* try for an expired lease */ - if (!packet.yiaddr) packet.yiaddr = find_address(1); + if (!packet.yiaddr) + packet.yiaddr = find_address(1); } if (!packet.yiaddr) { @@ -209,7 +209,8 @@ init_packet(&packet, oldpacket, DHCPACK); packet.yiaddr = yiaddr; - if ((lease_time = get_option(oldpacket, DHCP_LEASE_TIME))) { + lease_time = get_option(oldpacket, DHCP_LEASE_TIME); + if (lease_time) { memcpy(&lease_time_align, lease_time, 4); lease_time_align = ntohl(lease_time_align); if (lease_time_align > server_config.lease) @@ -236,6 +237,10 @@ return -1; add_lease(packet.chaddr, packet.yiaddr, lease_time_align); + if (ENABLE_FEATURE_UDHCPD_WRITE_LEASES_EARLY) { + /* rewrite the file with leases at every new acceptance */ + write_leases(); + } return 0; } Modified: trunk/busybox/networking/udhcp/socket.c =================================================================== --- trunk/busybox/networking/udhcp/socket.c 2007-07-01 14:53:06 UTC (rev 18981) +++ trunk/busybox/networking/udhcp/socket.c 2007-07-01 17:05:57 UTC (rev 18982) @@ -43,7 +43,7 @@ struct ifreq ifr; struct sockaddr_in *our_ip; - memset(&ifr, 0, sizeof(struct ifreq)); + memset(&ifr, 0, sizeof(ifr)); fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW); if (fd < 0) { bb_perror_msg("socket failed"); @@ -54,7 +54,8 @@ strncpy(ifr.ifr_name, interface, sizeof(ifr.ifr_name)); if (addr) { if (ioctl(fd, SIOCGIFADDR, &ifr) != 0) { - bb_perror_msg("SIOCGIFADDR failed, is the interface up and configured?"); + bb_perror_msg("SIOCGIFADDR failed (is interface %s " + "up and configured?)", interface); close(fd); return -1; } @@ -117,7 +118,7 @@ return -1; } - if (bind(fd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) { + if (bind(fd, (struct sockaddr *)&addr, sizeof(addr)) == -1) { close(fd); return -1; } From vda at busybox.net Sun Jul 1 10:11:54 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 10:11:54 -0700 (PDT) Subject: svn commit: trunk/busybox/networking/udhcp Message-ID: <20070701171154.1E25CA65B5@busybox.net> Author: vda Date: 2007-07-01 10:11:54 -0700 (Sun, 01 Jul 2007) New Revision: 18983 Log: fix comment placement (no code changes) Modified: trunk/busybox/networking/udhcp/dhcpd.c Changeset: Modified: trunk/busybox/networking/udhcp/dhcpd.c =================================================================== --- trunk/busybox/networking/udhcp/dhcpd.c 2007-07-01 17:05:57 UTC (rev 18982) +++ trunk/busybox/networking/udhcp/dhcpd.c 2007-07-01 17:11:54 UTC (rev 18983) @@ -214,7 +214,8 @@ ) { sendNAK(&packet); } - } /* else remain silent */ + /* else remain silent */ + } } else { /* RENEWING or REBINDING State */ From vda at busybox.net Sun Jul 1 10:25:59 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 10:25:59 -0700 (PDT) Subject: svn commit: trunk/busybox/procps Message-ID: <20070701172559.B292CA659D@busybox.net> Author: vda Date: 2007-07-01 10:25:59 -0700 (Sun, 01 Jul 2007) New Revision: 18984 Log: ps: revert wrong "optimization": (i & 1) -> i Modified: trunk/busybox/procps/ps.c Changeset: Modified: trunk/busybox/procps/ps.c =================================================================== --- trunk/busybox/procps/ps.c 2007-07-01 17:11:54 UTC (rev 18983) +++ trunk/busybox/procps/ps.c 2007-07-01 17:25:59 UTC (rev 18984) @@ -368,7 +368,7 @@ i = getopt32(argc, argv, "Z"); #endif #if ENABLE_SELINUX - if (i && is_selinux_enabled()) + if ((i & 1) && is_selinux_enabled()) use_selinux = PSSCAN_CONTEXT; #endif #endif /* ENABLE_FEATURE_PS_WIDE || ENABLE_SELINUX */ From vda at busybox.net Sun Jul 1 10:29:44 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 10:29:44 -0700 (PDT) Subject: svn commit: trunk/busybox/findutils Message-ID: <20070701172944.96106A6801@busybox.net> Author: vda Date: 2007-07-01 10:29:44 -0700 (Sun, 01 Jul 2007) New Revision: 18985 Log: find: style fix Modified: trunk/busybox/findutils/find.c Changeset: Modified: trunk/busybox/findutils/find.c =================================================================== --- trunk/busybox/findutils/find.c 2007-07-01 17:25:59 UTC (rev 18984) +++ trunk/busybox/findutils/find.c 2007-07-01 17:29:44 UTC (rev 18985) @@ -758,12 +758,12 @@ #define XATOU_SFX xatoul_sfx #endif static const struct suffix_mult find_suffixes[] = { - { "c", 1 }, - { "w", 2 }, - { "b"+1, 512 }, - { "b", 512 }, - { "k", 1024 }, - { NULL, 0 } + { "c", 1 }, + { "w", 2 }, + { "b"+1, 512 }, + { "b", 512 }, + { "k", 1024 }, + { NULL, 0 } }; action_size *ap; ap = ALLOC_ACTION(size); From vda at busybox.net Sun Jul 1 10:35:19 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 10:35:19 -0700 (PDT) Subject: svn commit: trunk/busybox: findutils libbb Message-ID: <20070701173519.D7D6BA6812@busybox.net> Author: vda Date: 2007-07-01 10:35:17 -0700 (Sun, 01 Jul 2007) New Revision: 18986 Log: find: fix build failure on certain configs (found by Cristian Ionescu-Idbohrn ) Modified: trunk/busybox/findutils/find.c trunk/busybox/libbb/Kbuild Changeset: Modified: trunk/busybox/findutils/find.c =================================================================== --- trunk/busybox/findutils/find.c 2007-07-01 17:29:44 UTC (rev 18985) +++ trunk/busybox/findutils/find.c 2007-07-01 17:35:17 UTC (rev 18986) @@ -425,8 +425,9 @@ } #endif -#if ENABLE_FEATURE_FIND_PERM || ENABLE_FEATURE_FIND_MTIME \ - || ENABLE_FEATURE_FIND_MMIN +#if ENABLE_FEATURE_FIND_PERM \ + || ENABLE_FEATURE_FIND_MTIME || ENABLE_FEATURE_FIND_MMIN \ + || ENABLE_FEATURE_FIND_SIZE static const char* plus_minus_num(const char* str) { if (*str == '-' || *str == '+') Modified: trunk/busybox/libbb/Kbuild =================================================================== --- trunk/busybox/libbb/Kbuild 2007-07-01 17:29:44 UTC (rev 18985) +++ trunk/busybox/libbb/Kbuild 2007-07-01 17:35:17 UTC (rev 18986) @@ -126,3 +126,4 @@ lib-$(CONFIG_MDEV) += xregcomp.o lib-$(CONFIG_LESS) += xregcomp.o lib-$(CONFIG_DEVFSD) += xregcomp.o +lib-$(CONFIG_FEATURE_FIND_REGEX) += xregcomp.o From vda at busybox.net Sun Jul 1 11:18:55 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 11:18:55 -0700 (PDT) Subject: svn commit: trunk/busybox/miscutils Message-ID: <20070701181855.43867A680F@busybox.net> Author: vda Date: 2007-07-01 11:18:54 -0700 (Sun, 01 Jul 2007) New Revision: 18987 Log: devfsd: indentation fixes Modified: trunk/busybox/miscutils/devfsd.c Changeset: Modified: trunk/busybox/miscutils/devfsd.c =================================================================== --- trunk/busybox/miscutils/devfsd.c 2007-07-01 17:35:17 UTC (rev 18986) +++ trunk/busybox/miscutils/devfsd.c 2007-07-01 18:18:54 UTC (rev 18987) @@ -424,13 +424,13 @@ for (count = 2; count < argc; ++count) { if (argv[count][0] == '-') { if (argv[count][1] == 'v' && !argv[count][2]) /* -v */ - print_version = TRUE; + print_version = TRUE; else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'f' - && argv[count][2] == 'g' && !argv[count][3]) /* -fg */ - do_daemon = FALSE; + && argv[count][2] == 'g' && !argv[count][3]) /* -fg */ + do_daemon = FALSE; else if (ENABLE_DEVFSD_FG_NP && argv[count][1] == 'n' - && argv[count][2] == 'p' && !argv[count][3]) /* -np */ - no_polling = TRUE; + && argv[count][2] == 'p' && !argv[count][3]) /* -np */ + no_polling = TRUE; else bb_show_usage(); } @@ -453,7 +453,7 @@ msg_logger_and_die(LOG_ERR, "ioctl"); /*setup initial entries */ - for (curr = initial_symlinks; curr->dest != NULL; ++curr) + for (curr = initial_symlinks; curr->dest != NULL; ++curr) symlink(curr->dest, curr->name); /* NB: The check for CONFIG_FILE is done in read_config_file() */ From vda at busybox.net Sun Jul 1 11:33:37 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 11:33:37 -0700 (PDT) Subject: svn commit: trunk/busybox/coreutils Message-ID: <20070701183337.6D7A6A6806@busybox.net> Author: vda Date: 2007-07-01 11:33:35 -0700 (Sun, 01 Jul 2007) New Revision: 18988 Log: expr: small code shrink Modified: trunk/busybox/coreutils/expr.c Changeset: Modified: trunk/busybox/coreutils/expr.c =================================================================== --- trunk/busybox/coreutils/expr.c 2007-07-01 18:18:54 UTC (rev 18987) +++ trunk/busybox/coreutils/expr.c 2007-07-01 18:33:35 UTC (rev 18988) @@ -277,12 +277,15 @@ static VALUE *eval6(void) { - VALUE *l, *r, *v = NULL /* silence gcc */, *i1, *i2; static const char * const keywords[] = { "quote", "length", "match", "index", "substr", NULL }; - smalluint key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0; + VALUE *r, *i1, *i2; + VALUE *l = l; /* silence gcc */ + VALUE *v = v; /* silence gcc */ + int key = *G.args ? index_in_str_array(keywords, *G.args) + 1 : 0; + if (key == 0) /* not a keyword */ return eval7(); G.args++; /* We have a valid token, so get the next argument. */ @@ -320,8 +323,8 @@ i2 = eval6(); tostring(l); if (!toarith(i1) || !toarith(i2) - || i1->u.i > (arith_t) strlen(l->u.s) - || i1->u.i <= 0 || i2->u.i <= 0) + || i1->u.i > (arith_t) strlen(l->u.s) + || i1->u.i <= 0 || i2->u.i <= 0) v = str_value(""); else { v = xmalloc(sizeof(VALUE)); From vda at busybox.net Sun Jul 1 15:25:34 2007 From: vda at busybox.net (vda at busybox.net) Date: Sun, 1 Jul 2007 15:25:34 -0700 (PDT) Subject: svn commit: trunk/busybox/miscutils Message-ID: <20070701222534.537FEA6828@busybox.net> Author: vda Date: 2007-07-01 15:25:33 -0700 (Sun, 01 Jul 2007) New Revision: 18989 Log: devfsd: futher sanitization by Tito Modified: trunk/busybox/miscutils/devfsd.c Changeset: Modified: trunk/busybox/miscutils/devfsd.c =================================================================== --- trunk/busybox/miscutils/devfsd.c 2007-07-01 18:33:35 UTC (rev 18988) +++ trunk/busybox/miscutils/devfsd.c 2007-07-01 22:25:33 UTC (rev 18989) @@ -234,11 +234,8 @@ static char *write_old_sd_name(char *, unsigned, unsigned, const char *); /* busybox functions */ -static void msg_logger(int pri, const char * fmt, ...)__attribute__((format(printf, 2, 3))); -static void msg_logger_and_die(int pri, const char * fmt, ...)__attribute__((noreturn, format(printf, 2, 3))); -static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag); -static void fork_and_execute(int die, char *arg0, char **arg); -static int get_uid_gid(int, const char *); +static void do_ioctl_or_die(int fd, int request, unsigned long event_mask_flag); +static int get_uid_gid(int flag, const char *string); static void safe_memcpy(char * dest, const char * src, int len); static unsigned int scan_dev_name_common(const char *d, unsigned int n, int addendum, const char *ptr); static unsigned int scan_dev_name(const char *d, unsigned int n, const char *ptr); @@ -246,7 +243,7 @@ /* Structs and vars */ static struct config_entry_struct *first_config = NULL; static struct config_entry_struct *last_config = NULL; -static const char *mount_point = NULL; +static char *mount_point = NULL; static volatile int caught_signal = FALSE; static volatile int caught_sighup = FALSE; static struct initial_symlink_struct @@ -286,83 +283,27 @@ static const char * const bb_msg_small_buffer = "buffer too small"; static const char * const bb_msg_variable_not_found = "variable: %s not found"; -/* Busybox functions */ -static void msg_logger(int pri, const char * fmt, ...) -{ - va_list ap; - int ret; - - va_start(ap, fmt); - ret = access("/dev/log", F_OK); - if (ret == 0) { - openlog(applet_name, 0, LOG_DAEMON); - vsyslog(pri , fmt, ap); - /* Man: A trailing newline is added when needed. */ - closelog(); - } - /* ENABLE_DEVFSD_VERBOSE is always enabled if msg_logger is used */ - if ((ENABLE_DEVFSD_VERBOSE && ret) || ENABLE_DEBUG) { - bb_error_msg(fmt, ap); - } - va_end(ap); -} - -static void msg_logger_and_die(int pri, const char* fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - msg_logger(pri, fmt, ap); - va_end(ap); - exit(EXIT_FAILURE); -} - /* Busybox stuff */ -#if defined(CONFIG_DEVFSD_VERBOSE) || defined(CONFIG_DEBUG) -#define devfsd_error_msg(fmt, args...) bb_error_msg(fmt, ## args) -#define devfsd_perror_msg_and_die(fmt, args...) bb_perror_msg_and_die(fmt, ## args) -#define devfsd_error_msg_and_die(fmt, args...) bb_error_msg_and_die(fmt, ## args) +#if ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG +#define info_logger(p, fmt, args...) bb_info_msg(fmt, ## args) +#define msg_logger(p, fmt, args...) bb_error_msg(fmt, ## args) +#define msg_logger_and_die(p, fmt, args...) bb_error_msg_and_die(fmt, ## args) +#define error_logger(p, fmt, args...) bb_perror_msg(fmt, ## args) +#define error_logger_and_die(p, fmt, args...) bb_perror_msg_and_die(fmt, ## args) #else +#define info_logger(p, fmt, args...) #define msg_logger(p, fmt, args...) #define msg_logger_and_die(p, fmt, args...) exit(1) -#define devfsd_perror_msg_and_die(fmt, args...) exit(1) -#define devfsd_error_msg_and_die(fmt, args...) exit(1) -#define devfsd_error_msg(fmt, args...) +#define error_logger(p, fmt, args...) +#define error_logger_and_die(p, fmt, args...) exit(1) #endif -static void do_ioctl_and_die(int fd, int request, unsigned long event_mask_flag) +static void do_ioctl_or_die(int fd, int request, unsigned long event_mask_flag) { if (ioctl(fd, request, event_mask_flag) == -1) msg_logger_and_die(LOG_ERR, "ioctl"); } -static void fork_and_execute(int die, char *arg0, char **arg) -{ - switch (fork()) { - case 0: - /* Child */ - break; - case -1: - /* Parent: Error : die or return */ - msg_logger(LOG_ERR,(char *)bb_msg_memory_exhausted); - if (die) - exit(EXIT_FAILURE); - return; - default: - /* Parent : ok : return or exit */ - if (arg0 != NULL) { - wait(NULL); - return; - } - exit(EXIT_SUCCESS); - } - /* Child : if arg0 != NULL do execvp */ - if (arg0 != NULL) { - BB_EXECVP(arg0, arg); - msg_logger_and_die(LOG_ERR, "execvp"); - } -} - static void safe_memcpy(char *dest, const char *src, int len) { memcpy(dest , src, len); @@ -436,21 +377,17 @@ } } - /* strip last / from mount point, so we don't need to check for it later */ - while (argv[1][1] != '\0' && argv[1][strlen(argv[1]) - 1] == '/') - argv[1][strlen(argv[1]) - 1] = '\0'; + mount_point = bb_simplify_path(argv[1]); - mount_point = argv[1]; - xchdir(mount_point); fd = xopen(".devfsd", O_RDONLY); if (fcntl(fd, F_SETFD, FD_CLOEXEC) != 0) - devfsd_perror_msg_and_die("FD_CLOEXEC"); + bb_perror_msg_and_die("FD_CLOEXEC"); if (ioctl(fd, DEVFSDIOC_GET_PROTO_REV, &proto_rev) == -1) - msg_logger_and_die(LOG_ERR, "ioctl"); + bb_perror_msg_and_die("ioctl"); /*setup initial entries */ for (curr = initial_symlinks; curr->dest != NULL; ++curr) @@ -467,7 +404,7 @@ exit(EXIT_SUCCESS); /* -v */ } /* Tell kernel we are special(i.e. we get to see hidden entries) */ - do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, 0); + do_ioctl_or_die(fd, DEVFSDIOC_SET_EVENT_MASK, 0); sigemptyset(&new_action.sa_mask); new_action.sa_flags = 0; @@ -475,7 +412,7 @@ /* Set up SIGHUP and SIGUSR1 handlers */ new_action.sa_handler = signal_handler; if (sigaction(SIGHUP, &new_action, NULL) != 0 || sigaction(SIGUSR1, &new_action, NULL) != 0) - devfsd_error_msg_and_die("sigaction"); + bb_error_msg_and_die("sigaction"); printf("%s v%s started for %s\n",applet_name, DEVFSD_VERSION, mount_point); @@ -487,15 +424,23 @@ if (ENABLE_DEVFSD_FG_NP && no_polling) exit(0); + + if (ENABLE_DEVFSD_VERBOSE || ENABLE_DEBUG) + logmode = LOGMODE_BOTH; + else if (do_daemon == TRUE) + logmode = LOGMODE_SYSLOG; + /* This is the default */ + /*else + logmode = LOGMODE_STDIO; */ + if (do_daemon) { /* Release so that the child can grab it */ - do_ioctl_and_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); - fork_and_execute(DIE, NULL, NULL); - setsid(); /* Prevent hangups and become pgrp leader */ + do_ioctl_or_die(fd, DEVFSDIOC_RELEASE_EVENT_QUEUE, 0); + bb_daemonize_or_rexec(0, argv); } else if (ENABLE_DEVFSD_FG_NP) { setpgid(0, 0); /* Become process group leader */ } - + while (TRUE) { do_scan = do_servicing(fd, event_mask); @@ -504,6 +449,7 @@ if (do_scan) dir_operation(SERVICE, mount_point, 0, NULL); } + if (ENABLE_FEATURE_CLEAN_UP) free(mount_point); } /* End Function main */ @@ -522,24 +468,23 @@ FILE *fp; char buf[STRING_LENGTH]; char *line = NULL; + char *p; if (stat(path, &statbuf) == 0) { /* Don't read 0 length files: ignored */ /*if (statbuf.st_size == 0) return;*/ if (S_ISDIR(statbuf.st_mode)) { - /* strip last / from dirname so we don't need to check for it later */ - while (path && path[1] != '\0' && path[strlen(path) - 1] == '/') - path[strlen(path) - 1] = '\0'; - - dir_operation(READ_CONFIG, path, 0, event_mask); + p = bb_simplify_path(path); + dir_operation(READ_CONFIG, p, 0, event_mask); + free(p); return; } if ((fp = fopen(path, "r")) != NULL) { while (fgets(buf, STRING_LENGTH, fp) != NULL) { /* Skip whitespace */ - for (line = buf; isspace(*line); ++line) - /*VOID*/; + line = buf; + line = skip_whitespace(line); if (line[0] == '\0' || line[0] == '#') continue; process_config_line(line, event_mask); @@ -550,8 +495,8 @@ } } else { read_config_file_err: - if (optional == 0 && errno == ENOENT) - msg_logger_and_die(LOG_ERR, "read config file: %s: %m", path); + if (optional == 0 && errno == ENOENT) + error_logger_and_die(LOG_ERR, "read config file: %s", path); } } /* End Function read_config_file */ @@ -600,7 +545,7 @@ /* "INCLUDE" & "OPTIONAL_INCLUDE" */ if (i == 1 || i == 2) { st_expr_expand(name, STRING_LENGTH, name, get_variable, NULL); - msg_logger(LOG_INFO, "%sinclude: %s", (toupper(when[0]) == 'I') ? "": "optional_", name); + info_logger(LOG_INFO, "%sinclude: %s", (toupper(when[0]) == 'I') ? "": "optional_", name); read_config_file(name, (toupper(when[0]) == 'I') ? FALSE : TRUE, event_mask); return; } @@ -716,7 +661,7 @@ /* Tell devfs what events we care about */ tmp_event_mask = event_mask; - do_ioctl_and_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); + do_ioctl_or_die(fd, DEVFSDIOC_SET_EVENT_MASK, tmp_event_mask); while (!caught_signal) { errno = 0; bytes = read(fd,(char *) &info, sizeof info); @@ -809,11 +754,11 @@ { struct stat statbuf; - if (stat(info->devname, &statbuf) != 0 || - chmod(info->devname,(statbuf.st_mode & S_IFMT) |(entry->u.permissions.mode & ~S_IFMT)) != 0 || - chown(info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0 + if (stat(info->devname, &statbuf) != 0 + || chmod(info->devname, (statbuf.st_mode & S_IFMT) | (entry->u.permissions.mode & ~S_IFMT)) != 0 + || chown(info->devname, entry->u.permissions.uid, entry->u.permissions.gid) != 0 ) - msg_logger(LOG_ERR, "Can't chmod or chown: %s: %m", info->devname); + error_logger(LOG_ERR, "Can't chmod or chown: %s", info->devname); } /* End Function action_permissions */ static void action_modload(const struct devfsd_notify_struct *info, @@ -826,14 +771,14 @@ { char *argv[6]; - argv[0] =(char*)MODPROBE; - argv[1] =(char*)MODPROBE_SWITCH_1; /* "-k" */ - argv[2] =(char*)MODPROBE_SWITCH_2; /* "-C" */ - argv[3] =(char*)CONFIG_MODULES_DEVFS; + argv[0] = (char*)MODPROBE; + argv[1] = (char*)MODPROBE_SWITCH_1; /* "-k" */ + argv[2] = (char*)MODPROBE_SWITCH_2; /* "-C" */ + argv[3] = (char*)CONFIG_MODULES_DEVFS; argv[4] = concat_path_file("/dev", info->devname); /* device */ argv[5] = NULL; - fork_and_execute(DIE, argv[0], argv); + wait4pid(xspawn(argv)); free(argv[4]); } /* End Function action_modload */ @@ -865,7 +810,7 @@ argv[count] = largv[count]; } argv[count] = NULL; - fork_and_execute(NO_DIE, argv[0], argv); + wait4pid(spawn(argv)); } /* End Function action_execute */ @@ -913,7 +858,7 @@ new_mode |= S_ISVTX; ret = copy_inode(destination, &dest_stat, new_mode, source, &source_stat); if (ENABLE_DEBUG && ret && (errno != EEXIST)) - msg_logger(LOG_ERR, "copy_inode: %s to %s: %m", source, destination); + error_logger(LOG_ERR, "copy_inode: %s to %s", source, destination); } /* End Function action_copy */ static void action_compat(const struct devfsd_notify_struct *info, unsigned int action) @@ -1007,7 +952,7 @@ case AC_RMNEWCOMPAT: ret = unlink(compat_name); if (ENABLE_DEBUG && ret) - msg_logger(LOG_ERR, "unlink: %s: %m", compat_name); + error_logger(LOG_ERR, "unlink: %s", compat_name); break; /*esac*/ } /* switch (action) */ @@ -1022,7 +967,7 @@ dpath = concat_path_file(mount_point, spath + rootlen); lstat(dpath, &dest_stat); free(dpath); - if (S_ISLNK(source_stat.st_mode) ||(source_stat.st_mode & S_ISVTX)) + if (S_ISLNK(source_stat.st_mode) || (source_stat.st_mode & S_ISVTX)) copy_inode(dpath, &dest_stat,(source_stat.st_mode & ~S_ISVTX) , spath, &source_stat); if (S_ISDIR(source_stat.st_mode)) @@ -1198,7 +1143,7 @@ if (sig == SIGHUP) caught_sighup = TRUE; - msg_logger(LOG_INFO, "Caught signal %d", sig); + info_logger(LOG_INFO, "Caught signal %d", sig); } /* End Function signal_handler */ static const char *get_variable(const char *variable, void *info) @@ -1211,7 +1156,7 @@ int i; if (gethostname(hostname, STRING_LENGTH - 1) != 0) - msg_logger_and_die(LOG_ERR, "gethostname: %m"); + error_logger_and_die(LOG_ERR, "gethostname"); /* Here on error we should do exit(RV_SYS_ERROR), instead we do exit(EXIT_FAILURE) */ hostname[STRING_LENGTH - 1] = '\0'; @@ -1651,7 +1596,7 @@ if (isspace(ch) ||(ch == '/') ||(ch == '\0')) { /* User's own home directory: leave separator for next time */ if ((env = getenv("HOME")) == NULL) { - msg_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); + info_logger(LOG_INFO, bb_msg_variable_not_found, "HOME"); return FALSE; } len = strlen(env); @@ -1670,7 +1615,7 @@ safe_memcpy(tmp, input, len); input = ptr - 1; if ((pwent = getpwnam(tmp)) == NULL) { - msg_logger(LOG_INFO, "no pwent for: %s", tmp); + info_logger(LOG_INFO, "no pwent for: %s", tmp); return FALSE; } len = strlen(pwent->pw_dir); @@ -1695,7 +1640,7 @@ } return FALSE; st_expr_expand_out: - msg_logger(LOG_INFO, bb_msg_small_buffer); + info_logger(LOG_INFO, bb_msg_small_buffer); return FALSE; } /* End Function st_expr_expand */ @@ -1750,7 +1695,7 @@ safe_memcpy(tmp, input, len); input = ptr - 1; if ((env = get_variable_v2(tmp, func, info)) == NULL) { - msg_logger(LOG_INFO, bb_msg_variable_not_found, tmp); + info_logger(LOG_INFO, bb_msg_variable_not_found, tmp); return NULL; } len = strlen(env); @@ -1778,7 +1723,7 @@ return input + len; } if (ch != ':' || ptr[1] != '-') { - msg_logger(LOG_INFO, "illegal char in var name"); + info_logger(LOG_INFO, "illegal char in var name"); return NULL; } /* It's that handy "${var:-word}" expression. Check if var is defined */ @@ -1801,7 +1746,7 @@ --open_braces; break; case '\0': - msg_logger(LOG_INFO,"\"}\" not found in: %s", input); + info_logger(LOG_INFO,"\"}\" not found in: %s", input); return NULL; default: break; @@ -1840,7 +1785,7 @@ *out_pos += len; return input; expand_variable_out: - msg_logger(LOG_INFO, bb_msg_small_buffer); + info_logger(LOG_INFO, bb_msg_small_buffer); return NULL; } /* End Function expand_variable */ From vda at busybox.net Mon Jul 2 08:47:53 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 2 Jul 2007 08:47:53 -0700 (PDT) Subject: svn commit: trunk/busybox/networking Message-ID: <20070702154753.C9D6FA6590@busybox.net> Author: vda Date: 2007-07-02 08:47:52 -0700 (Mon, 02 Jul 2007) New Revision: 18994 Log: ping: fix non-fancy ping6 Modified: trunk/busybox/networking/ping.c Changeset: Modified: trunk/busybox/networking/ping.c =================================================================== --- trunk/busybox/networking/ping.c 2007-07-02 15:20:05 UTC (rev 18993) +++ trunk/busybox/networking/ping.c 2007-07-02 15:47:52 UTC (rev 18994) @@ -179,7 +179,8 @@ len_and_sockaddr *lsa; #if ENABLE_PING6 sa_family_t af = AF_UNSPEC; - while (++argv[0][0] == '-') { + + while ((++argv)[0] && argv[0][0] == '-') { if (argv[0][1] == '4') { af = AF_INET; continue; From bugs at busybox.net Mon Jul 2 23:11:06 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Mon, 2 Jul 2007 23:11:06 -0700 Subject: [BusyBox 0001418]: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Message-ID: <95691ed3e99256a9f04c2e4b44ad18ec@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1418 ====================================================================== Reported By: phire Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1418 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 07-02-2007 23:11 PDT Last Modified: 07-02-2007 23:11 PDT ====================================================================== Summary: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Description: When I cross compile busybox (manually, not with buildroot) with my uClibc x86 toolchain (uClibc 0.9.29 and GCC 4.1.2) More and less are broken. As far as I can tell, both are compiling, there are no errors or warning in the compile process (except a single warning for find) but when I try to run them I get cat instead. When I compile the same configration with glibc, more and less work as expected. ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 07-02-07 23:11 phire New Issue 07-02-07 23:11 phire Status new => assigned 07-02-07 23:11 phire Assigned To => BusyBox ====================================================================== From vda at busybox.net Mon Jul 2 23:15:43 2007 From: vda at busybox.net (vda at busybox.net) Date: Mon, 2 Jul 2007 23:15:43 -0700 (PDT) Subject: svn commit: trunk/busybox/libbb Message-ID: <20070703061543.46647A658A@busybox.net> Author: vda Date: 2007-07-02 23:15:42 -0700 (Mon, 02 Jul 2007) New Revision: 18995 Log: correct_password: do not print "no shadow passwd..." message function old new delta correct_password 204 191 -13 .rodata 129530 129466 -64 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-77) Total: -77 bytes text data bss dec hex filename 675984 2744 13968 692696 a91d8 busybox_old 675908 2744 13968 692620 a918c busybox_unstripped Modified: trunk/busybox/libbb/correct_password.c Changeset: Modified: trunk/busybox/libbb/correct_password.c =================================================================== --- trunk/busybox/libbb/correct_password.c 2007-07-02 15:47:52 UTC (rev 18994) +++ trunk/busybox/libbb/correct_password.c 2007-07-03 06:15:42 UTC (rev 18995) @@ -40,12 +40,6 @@ { char *unencrypted, *encrypted; const char *correct; -#if ENABLE_FEATURE_SHADOWPASSWDS - /* Using _r function to avoid pulling in static buffers */ - struct spwd spw; - struct spwd *result; - char buffer[256]; -#endif /* fake salt. crypt() can choke otherwise. */ correct = "aa"; @@ -55,11 +49,14 @@ } correct = pw->pw_passwd; #if ENABLE_FEATURE_SHADOWPASSWDS - if (LONE_CHAR(pw->pw_passwd, 'x') || LONE_CHAR(pw->pw_passwd, '*')) { - if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result)) - bb_error_msg("no valid shadow password, checking ordinary one"); - else + if ((correct[0] == 'x' || correct[0] == '*') && !correct[1]) { + /* Using _r function to avoid pulling in static buffers */ + struct spwd spw; + struct spwd *result; + char buffer[256]; + if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result) == 0) correct = spw.sp_pwdp; + /* else: no valid shadow password, checking ordinary one */ } #endif From bugs at busybox.net Tue Jul 3 00:37:05 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 00:37:05 -0700 Subject: [BusyBox 0001418]: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Message-ID: <6b36be0afd0458aec110e3c53ee1948a@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1418 ====================================================================== Reported By: phire Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1418 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 07-02-2007 23:11 PDT Last Modified: 07-03-2007 00:37 PDT ====================================================================== Summary: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Description: When I cross compile busybox (manually, not with buildroot) with my uClibc x86 toolchain (uClibc 0.9.29 and GCC 4.1.2) More and less are broken. As far as I can tell, both are compiling, there are no errors or warning in the compile process (except a single warning for find) but when I try to run them I get cat instead. When I compile the same configration with glibc, more and less work as expected. ====================================================================== ---------------------------------------------------------------------- phire - 07-03-07 00:37 ---------------------------------------------------------------------- I did some checking of the source code, Seams the problem come from Revision 18061: more: do not mess with "/dev/console" (!); fill whole 1st screen (was "screen sans one line"); fall back to cat if redirected or no ctty less: fall back to cat if no ctty (was exiting) resize: cosmetics uClibc (or at least the version I have) seams to fail to open CURRENT_TTY here: (line 1333 in miscutils/less.c) kbd_fd = open(CURRENT_TTY, O_RDONLY); if (kbd_fd < 0) return bb_cat(argv); Issue History Date Modified Username Field Change ====================================================================== 07-02-07 23:11 phire New Issue 07-02-07 23:11 phire Status new => assigned 07-02-07 23:11 phire Assigned To => BusyBox 07-03-07 00:37 phire Note Added: 0002547 ====================================================================== From bugs at busybox.net Tue Jul 3 01:00:30 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 01:00:30 -0700 Subject: [BusyBox 0001418]: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Message-ID: <3ed8093c572784349431421b382169be@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1418 ====================================================================== Reported By: phire Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1418 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 07-02-2007 23:11 PDT Last Modified: 07-03-2007 01:00 PDT ====================================================================== Summary: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Description: When I cross compile busybox (manually, not with buildroot) with my uClibc x86 toolchain (uClibc 0.9.29 and GCC 4.1.2) More and less are broken. As far as I can tell, both are compiling, there are no errors or warning in the compile process (except a single warning for find) but when I try to run them I get cat instead. When I compile the same configration with glibc, more and less work as expected. ====================================================================== ---------------------------------------------------------------------- phire - 07-03-07 00:37 ---------------------------------------------------------------------- I did some checking of the source code, Seams the problem come from Revision 18061: more: do not mess with "/dev/console" (!); fill whole 1st screen (was "screen sans one line"); fall back to cat if redirected or no ctty less: fall back to cat if no ctty (was exiting) resize: cosmetics uClibc (or at least the version I have) seams to fail to open CURRENT_TTY here: (line 1333 in miscutils/less.c) kbd_fd = open(CURRENT_TTY, O_RDONLY); if (kbd_fd < 0) return bb_cat(argv); ---------------------------------------------------------------------- phire - 07-03-07 01:00 ---------------------------------------------------------------------- I changed it from open to xopen (which is was before) and it kindly informed me: less: can't open '/dev/tty': No such file or directory I was in the process of working out how to mount the root file system when I came across this problem. I think its better to inform me that I have a problem, rather than falling back to cat. Issue History Date Modified Username Field Change ====================================================================== 07-02-07 23:11 phire New Issue 07-02-07 23:11 phire Status new => assigned 07-02-07 23:11 phire Assigned To => BusyBox 07-03-07 00:37 phire Note Added: 0002547 07-03-07 01:00 phire Note Added: 0002548 ====================================================================== From vda at busybox.net Tue Jul 3 01:26:26 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 3 Jul 2007 01:26:26 -0700 (PDT) Subject: svn commit: trunk/busybox/networking Message-ID: <20070703082626.CA6CBA6599@busybox.net> Author: vda Date: 2007-07-03 01:26:24 -0700 (Tue, 03 Jul 2007) New Revision: 18996 Log: ifupdown: kill -TERM is default, so drop -TERM ifupdown: ferror() does not set errno, don't use perror ifupdown: make netmask parsing smaller and more strict (was accepting 255.0.255.0, 255.1234.0.0 etc...) function old new delta count_bits 36 - -36 execute 2573 2535 -38 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 0/1 up/down: 0/-74) Total: -74 bytes text data bss dec hex filename 684204 2744 14000 700948 ab214 busybox_old 684132 2744 14000 700876 ab1cc busybox_unstripped Modified: trunk/busybox/networking/ifupdown.c Changeset: Modified: trunk/busybox/networking/ifupdown.c =================================================================== --- trunk/busybox/networking/ifupdown.c 2007-07-03 06:15:42 UTC (rev 18995) +++ trunk/busybox/networking/ifupdown.c 2007-07-03 08:26:24 UTC (rev 18996) @@ -104,31 +104,6 @@ #if ENABLE_FEATURE_IFUPDOWN_IPV4 || ENABLE_FEATURE_IFUPDOWN_IPV6 -#if ENABLE_FEATURE_IFUPDOWN_IP - -static unsigned count_bits(unsigned a) -{ - unsigned result; - result = (a & 0x55) + ((a >> 1) & 0x55); - result = (result & 0x33) + ((result >> 2) & 0x33); - return (result & 0x0F) + ((result >> 4) & 0x0F); -} - -static int count_netmask_bits(char *dotted_quad) -{ - unsigned result, a, b, c, d; - /* Found a netmask... Check if it is dotted quad */ - if (sscanf(dotted_quad, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) - return -1; - // FIXME: will be confused by e.g. 255.0.255.0 - result = count_bits(a); - result += count_bits(b); - result += count_bits(c); - result += count_bits(d); - return (int)result; -} -#endif - static void addstr(char **bufp, const char *str, size_t str_length) { /* xasprintf trick will be smaller, but we are often @@ -177,6 +152,39 @@ return NULL; } +#if ENABLE_FEATURE_IFUPDOWN_IP +static int count_netmask_bits(const char *dotted_quad) +{ +// int result; +// unsigned a, b, c, d; +// /* Found a netmask... Check if it is dotted quad */ +// if (sscanf(dotted_quad, "%u.%u.%u.%u", &a, &b, &c, &d) != 4) +// return -1; +// if ((a|b|c|d) >> 8) +// return -1; /* one of numbers is >= 256 */ +// d |= (a << 24) | (b << 16) | (c << 8); /* IP */ +// d = ~d; /* 11110000 -> 00001111 */ + + /* Shorter version */ + int result; + struct in_addr ip; + unsigned d; + + if (inet_aton(dotted_quad, &ip) == 0) + return -1; /* malformed dotted IP */ + d = ntohl(ip.s_addr); /* IP in host order */ + d = ~d; /* 11110000 -> 00001111 */ + if (d & (d+1)) /* check that it is in 00001111 form */ + return -1; /* no it is not */ + result = 32; + while (d) { + d >>= 1; + result--; + } + return result; +} +#endif + static char *parse(const char *command, struct interface_defn_t *ifd) { size_t old_pos[MAX_OPT_DEPTH] = { 0 }; @@ -246,11 +254,14 @@ if (strncmp(command, "bnmask", 6) == 0) { unsigned res; varvalue = get_var("netmask", 7, ifd); - if (varvalue && (res = count_netmask_bits(varvalue)) > 0) { - const char *argument = utoa(res); - addstr(&result, argument, strlen(argument)); - command = nextpercent + 1; - break; + if (varvalue) { + res = count_netmask_bits(varvalue); + if (res > 0) { + const char *argument = utoa(res); + addstr(&result, argument, strlen(argument)); + command = nextpercent + 1; + break; + } } } #endif @@ -463,7 +474,7 @@ }, { "udhcpc", "udhcpc -R -n -p /var/run/udhcpc.%iface%.pid -i %iface%[[ -H %hostname%]][[ -c %clientid%]][[ -s %script%]]", - "kill -TERM `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", + "kill `cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", }, }; #endif /* ENABLE_FEATURE_IFUPDOWN_EXTERNAL_DHCPC */ @@ -498,10 +509,10 @@ bb_error_msg("no dhcp clients found, using static interface shutdown"); return static_down(ifd, exec); #elif ENABLE_APP_UDHCPC - return execute("kill -TERM " + return execute("kill " "`cat /var/run/udhcpc.%iface%.pid` 2>/dev/null", ifd, exec); #else - return 0; /* no support for dhcp */ + return 0; /* no dhcp support */ #endif } @@ -834,7 +845,8 @@ free(buf); } if (ferror(f) != 0) { - bb_perror_msg_and_die("%s", filename); + /* ferror does NOT set errno! */ + bb_error_msg_and_die("%s: I/O error", filename); } fclose(f); @@ -884,9 +896,10 @@ for (i = 0; i < iface->n_options; i++) { if (strcmp(iface->option[i].name, "up") == 0 - || strcmp(iface->option[i].name, "down") == 0 - || strcmp(iface->option[i].name, "pre-up") == 0 - || strcmp(iface->option[i].name, "post-down") == 0) { + || strcmp(iface->option[i].name, "down") == 0 + || strcmp(iface->option[i].name, "pre-up") == 0 + || strcmp(iface->option[i].name, "post-down") == 0 + ) { continue; } *(environend++) = setlocalenv("IF_%s=%s", iface->option[i].name, iface->option[i].value); From bugs at busybox.net Tue Jul 3 03:26:02 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 03:26:02 -0700 Subject: [BusyBox 0001418]: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Message-ID: <72895ef3a502a82bade243c68c3b4f7c@busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1418 ====================================================================== Reported By: phire Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1418 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 07-02-2007 23:11 PDT Last Modified: 07-03-2007 03:26 PDT ====================================================================== Summary: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Description: When I cross compile busybox (manually, not with buildroot) with my uClibc x86 toolchain (uClibc 0.9.29 and GCC 4.1.2) More and less are broken. As far as I can tell, both are compiling, there are no errors or warning in the compile process (except a single warning for find) but when I try to run them I get cat instead. When I compile the same configration with glibc, more and less work as expected. ====================================================================== ---------------------------------------------------------------------- phire - 07-03-07 00:37 ---------------------------------------------------------------------- I did some checking of the source code, Seams the problem come from Revision 18061: more: do not mess with "/dev/console" (!); fill whole 1st screen (was "screen sans one line"); fall back to cat if redirected or no ctty less: fall back to cat if no ctty (was exiting) resize: cosmetics uClibc (or at least the version I have) seams to fail to open CURRENT_TTY here: (line 1333 in miscutils/less.c) kbd_fd = open(CURRENT_TTY, O_RDONLY); if (kbd_fd < 0) return bb_cat(argv); ---------------------------------------------------------------------- phire - 07-03-07 01:00 ---------------------------------------------------------------------- I changed it from open to xopen (which is was before) and it kindly informed me: less: can't open '/dev/tty': No such file or directory I was in the process of working out how to mount the root file system when I came across this problem. I think its better to inform me that I have a problem, rather than falling back to cat. ---------------------------------------------------------------------- vda - 07-03-07 03:26 ---------------------------------------------------------------------- If less or more cannot open /dev/tty, they think that they are run in a session without controlling tty (for such session opening /dev/tty fails with ENXIO: open("/dev/tty", O_RDONLY|O_LARGEFILE) = -1 ENXIO (No such device or address)). But in your case, you simply don't have /dev/tty node created, period. Just create it. Should be like this: # ls -l /dev/tty crw-rw-rw- 1 root root 5, 0 Jun 29 19:51 /dev/tty Issue History Date Modified Username Field Change ====================================================================== 07-02-07 23:11 phire New Issue 07-02-07 23:11 phire Status new => assigned 07-02-07 23:11 phire Assigned To => BusyBox 07-03-07 00:37 phire Note Added: 0002547 07-03-07 01:00 phire Note Added: 0002548 07-03-07 03:26 vda Note Added: 0002549 ====================================================================== From bugs at busybox.net Tue Jul 3 03:26:49 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 03:26:49 -0700 Subject: [BusyBox 0001418]: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Message-ID: The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1418 ====================================================================== Reported By: phire Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1418 Category: Other Reproducibility: always Severity: major Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 07-02-2007 23:11 PDT Last Modified: 07-03-2007 03:26 PDT ====================================================================== Summary: 'More' and 'less' seam to point to 'cat' when cross compiled with uClibc Description: When I cross compile busybox (manually, not with buildroot) with my uClibc x86 toolchain (uClibc 0.9.29 and GCC 4.1.2) More and less are broken. As far as I can tell, both are compiling, there are no errors or warning in the compile process (except a single warning for find) but when I try to run them I get cat instead. When I compile the same configration with glibc, more and less work as expected. ====================================================================== ---------------------------------------------------------------------- phire - 07-03-07 00:37 ---------------------------------------------------------------------- I did some checking of the source code, Seams the problem come from Revision 18061: more: do not mess with "/dev/console" (!); fill whole 1st screen (was "screen sans one line"); fall back to cat if redirected or no ctty less: fall back to cat if no ctty (was exiting) resize: cosmetics uClibc (or at least the version I have) seams to fail to open CURRENT_TTY here: (line 1333 in miscutils/less.c) kbd_fd = open(CURRENT_TTY, O_RDONLY); if (kbd_fd < 0) return bb_cat(argv); ---------------------------------------------------------------------- phire - 07-03-07 01:00 ---------------------------------------------------------------------- I changed it from open to xopen (which is was before) and it kindly informed me: less: can't open '/dev/tty': No such file or directory I was in the process of working out how to mount the root file system when I came across this problem. I think its better to inform me that I have a problem, rather than falling back to cat. ---------------------------------------------------------------------- vda - 07-03-07 03:26 ---------------------------------------------------------------------- If less or more cannot open /dev/tty, they think that they are run in a session without controlling tty (for such session opening /dev/tty fails with ENXIO: open("/dev/tty", O_RDONLY|O_LARGEFILE) = -1 ENXIO (No such device or address)). But in your case, you simply don't have /dev/tty node created, period. Just create it. Should be like this: # ls -l /dev/tty crw-rw-rw- 1 root root 5, 0 Jun 29 19:51 /dev/tty Issue History Date Modified Username Field Change ====================================================================== 07-02-07 23:11 phire New Issue 07-02-07 23:11 phire Status new => assigned 07-02-07 23:11 phire Assigned To => BusyBox 07-03-07 00:37 phire Note Added: 0002547 07-03-07 01:00 phire Note Added: 0002548 07-03-07 03:26 vda Note Added: 0002549 07-03-07 03:26 vda Status assigned => closed ====================================================================== From vda at busybox.net Tue Jul 3 03:28:47 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 3 Jul 2007 03:28:47 -0700 (PDT) Subject: svn commit: trunk/busybox/libbb Message-ID: <20070703102847.6B7A3A6104@busybox.net> Author: vda Date: 2007-07-03 03:28:46 -0700 (Tue, 03 Jul 2007) New Revision: 18997 Log: correct_password: if password is 'x' or '*' and there is no shadow, use fake encrypted password 'aa' (which is guaranteed to fail password check). Modified: trunk/busybox/libbb/correct_password.c Changeset: Modified: trunk/busybox/libbb/correct_password.c =================================================================== --- trunk/busybox/libbb/correct_password.c 2007-07-03 08:26:24 UTC (rev 18996) +++ trunk/busybox/libbb/correct_password.c 2007-07-03 10:28:46 UTC (rev 18997) @@ -54,13 +54,11 @@ struct spwd spw; struct spwd *result; char buffer[256]; - if (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result) == 0) - correct = spw.sp_pwdp; - /* else: no valid shadow password, checking ordinary one */ + correct = (getspnam_r(pw->pw_name, &spw, buffer, sizeof(buffer), &result)) ? "aa" : spw.sp_pwdp; } #endif - if (!correct || correct[0] == '\0') + if (!correct[0]) /* empty password field? */ return 1; fake_it: From vda at busybox.net Tue Jul 3 08:47:53 2007 From: vda at busybox.net (vda at busybox.net) Date: Tue, 3 Jul 2007 08:47:53 -0700 (PDT) Subject: svn commit: trunk/busybox/networking/udhcp Message-ID: <20070703154753.C1403A65A0@busybox.net> Author: vda Date: 2007-07-03 08:47:50 -0700 (Tue, 03 Jul 2007) New Revision: 18998 Log: udhcp: many small fixes: * arpping(): smaller and even probably fixed * lots of variables/params converted: ulong -> uint32_t * uptime() nuked in favor of monotonic_sec() * udhcp_get_packet(): only one "bad vendor", simplify function old new delta reservedIp 36 35 -1 udhcpc_main 2462 2460 -2 addStaticLease 64 62 -2 static.broken_vendors 16 - -16 uptime 19 - -19 udhcpd_main 1273 1238 -35 udhcp_get_packet 223 184 -39 .rodata 144162 144106 -56 arpping 690 609 -81 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/7 up/down: 0/-251) Total: -251 bytes text data bss dec hex filename 734241 3028 14400 751669 b7835 busybox_old 734005 3028 14400 751433 b7749 busybox_unstripped Modified: trunk/busybox/networking/udhcp/arpping.c trunk/busybox/networking/udhcp/clientpacket.c trunk/busybox/networking/udhcp/common.c trunk/busybox/networking/udhcp/common.h trunk/busybox/networking/udhcp/dhcpc.c trunk/busybox/networking/udhcp/dhcpc.h trunk/busybox/networking/udhcp/dhcpd.c trunk/busybox/networking/udhcp/dhcpd.h trunk/busybox/networking/udhcp/files.c trunk/busybox/networking/udhcp/leases.c trunk/busybox/networking/udhcp/packet.c Changeset: Modified: trunk/busybox/networking/udhcp/arpping.c =================================================================== --- trunk/busybox/networking/udhcp/arpping.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/arpping.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -15,45 +15,37 @@ struct arpMsg { /* Ethernet header */ - uint8_t h_dest[6]; /* destination ether addr */ - uint8_t h_source[6]; /* source ether addr */ - uint16_t h_proto; /* packet type ID field */ + uint8_t h_dest[6]; /* 00 destination ether addr */ + uint8_t h_source[6]; /* 06 source ether addr */ + uint16_t h_proto; /* 0c packet type ID field */ /* ARP packet */ - uint16_t htype; /* hardware type (must be ARPHRD_ETHER) */ - uint16_t ptype; /* protocol type (must be ETH_P_IP) */ - uint8_t hlen; /* hardware address length (must be 6) */ - uint8_t plen; /* protocol address length (must be 4) */ - uint16_t operation; /* ARP opcode */ - uint8_t sHaddr[6]; /* sender's hardware address */ - uint8_t sInaddr[4]; /* sender's IP address */ - uint8_t tHaddr[6]; /* target's hardware address */ - uint8_t tInaddr[4]; /* target's IP address */ - uint8_t pad[18]; /* pad for min. Ethernet payload (60 bytes) */ + uint16_t htype; /* 0e hardware type (must be ARPHRD_ETHER) */ + uint16_t ptype; /* 10 protocol type (must be ETH_P_IP) */ + uint8_t hlen; /* 12 hardware address length (must be 6) */ + uint8_t plen; /* 13 protocol address length (must be 4) */ + uint16_t operation; /* 14 ARP opcode */ + uint8_t sHaddr[6]; /* 16 sender's hardware address */ + uint8_t sInaddr[4]; /* 1c sender's IP address */ + uint8_t tHaddr[6]; /* 20 target's hardware address */ + uint8_t tInaddr[4]; /* 26 target's IP address */ + uint8_t pad[18]; /* 2a pad for min. ethernet payload (60 bytes) */ } ATTRIBUTE_PACKED; -/* args: yiaddr - what IP to ping - * ip - our ip - * mac - our arp address - * interface - interface to use - * retn: 1 addr free - * 0 addr used - * -1 error - */ -/* FIXME: match response against chaddr */ -int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *mac, char *interface) +/* Returns 1 if no reply received */ + +int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface) { - int timeout = 2; - int s; /* socket */ - int rv = 1; /* return value */ - struct sockaddr addr; /* for interface name */ - struct arpMsg arp; - fd_set fdset; - struct timeval tm; - time_t prevTime; + int timeout = 2; + int s; /* socket */ + int rv = 1; /* "no reply received" yet */ + struct sockaddr addr; /* for interface name */ + struct arpMsg arp; + fd_set fdset; + struct timeval tm; + unsigned prevTime; - s = socket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); if (s == -1) { bb_perror_msg(bb_msg_can_not_create_raw_socket); @@ -62,55 +54,58 @@ if (setsockopt_broadcast(s) == -1) { bb_perror_msg("cannot setsocketopt on raw socket"); - close(s); - return -1; + goto ret; } /* send arp request */ memset(&arp, 0, sizeof(arp)); - memcpy(arp.h_dest, MAC_BCAST_ADDR, 6); /* MAC DA */ - memcpy(arp.h_source, mac, 6); /* MAC SA */ - arp.h_proto = htons(ETH_P_ARP); /* protocol type (Ethernet) */ - arp.htype = htons(ARPHRD_ETHER); /* hardware type */ - arp.ptype = htons(ETH_P_IP); /* protocol type (ARP message) */ - arp.hlen = 6; /* hardware address length */ - arp.plen = 4; /* protocol address length */ - arp.operation = htons(ARPOP_REQUEST); /* ARP op code */ - memcpy(arp.sInaddr, &ip, sizeof(ip)); /* source IP address */ - memcpy(arp.sHaddr, mac, 6); /* source hardware address */ - memcpy(arp.tInaddr, &yiaddr, sizeof(yiaddr)); /* target IP address */ + memset(arp.h_dest, 0xff, 6); /* MAC DA */ + memcpy(arp.h_source, from_mac, 6); /* MAC SA */ + arp.h_proto = htons(ETH_P_ARP); /* protocol type (Ethernet) */ + arp.htype = htons(ARPHRD_ETHER); /* hardware type */ + arp.ptype = htons(ETH_P_IP); /* protocol type (ARP message) */ + arp.hlen = 6; /* hardware address length */ + arp.plen = 4; /* protocol address length */ + arp.operation = htons(ARPOP_REQUEST); /* ARP op code */ + memcpy(arp.sHaddr, from_mac, 6); /* source hardware address */ + memcpy(arp.sInaddr, &from_ip, sizeof(from_ip)); /* source IP address */ + /* tHaddr */ /* target hardware address */ + memcpy(arp.tInaddr, &test_ip, sizeof(test_ip)); /* target IP address */ memset(&addr, 0, sizeof(addr)); - strcpy(addr.sa_data, interface); + safe_strncpy(addr.sa_data, interface, sizeof(addr.sa_data)); if (sendto(s, &arp, sizeof(arp), 0, &addr, sizeof(addr)) < 0) - rv = 0; + goto ret; - /* wait arp reply, and check it */ - tm.tv_usec = 0; - prevTime = uptime(); - while (timeout > 0) { + /* wait for arp reply, and check it */ + do { + int r; + prevTime = monotonic_sec(); FD_ZERO(&fdset); FD_SET(s, &fdset); tm.tv_sec = timeout; - if (select(s + 1, &fdset, (fd_set *) NULL, (fd_set *) NULL, &tm) < 0) { + tm.tv_usec = 0; + r = select(s + 1, &fdset, NULL, NULL, &tm); + if (r < 0) { bb_perror_msg("error on ARPING request"); if (errno != EINTR) - rv = 0; - } else if (FD_ISSET(s, &fdset)) { + break; + } else if (r) { if (recv(s, &arp, sizeof(arp), 0) < 0) + break; + if (arp.operation == htons(ARPOP_REPLY) + && memcmp(arp.tHaddr, from_mac, 6) == 0 + && *((uint32_t *) arp.sInaddr) == test_ip + ) { rv = 0; - if (arp.operation == htons(ARPOP_REPLY) && - memcmp(arp.tHaddr, mac, 6) == 0 && - *((uint32_t *) arp.sInaddr) == yiaddr) { - DEBUG("Valid arp reply received for this address"); - rv = 0; break; } } - timeout -= uptime() - prevTime; - prevTime = uptime(); - } + timeout -= monotonic_sec() - prevTime; + } while (timeout > 0); + + ret: close(s); - DEBUG("%salid arp replies for this address", rv ? "No v" : "V"); + DEBUG("%srp reply received for this address", rv ? "No a" : "A"); return rv; } Modified: trunk/busybox/networking/udhcp/clientpacket.c =================================================================== --- trunk/busybox/networking/udhcp/clientpacket.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/clientpacket.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -25,7 +25,7 @@ /* Create a random xid */ -unsigned random_xid(void) +uint32_t random_xid(void) { static smallint initialized; @@ -44,8 +44,10 @@ memcpy(packet->chaddr, client_config.arp, 6); if (client_config.clientid) add_option_string(packet->options, client_config.clientid); - if (client_config.hostname) add_option_string(packet->options, client_config.hostname); - if (client_config.fqdn) add_option_string(packet->options, client_config.fqdn); + if (client_config.hostname) + add_option_string(packet->options, client_config.hostname); + if (client_config.fqdn) + add_option_string(packet->options, client_config.fqdn); add_option_string(packet->options, client_config.vendorclass); } @@ -69,7 +71,7 @@ /* Broadcast a DHCP discover packet to the network, with an optionally requested IP */ -int send_discover(unsigned long xid, unsigned long requested) +int send_discover(uint32_t xid, uint32_t requested) { struct dhcpMessage packet; @@ -86,7 +88,7 @@ /* Broadcasts a DHCP request message */ -int send_selecting(unsigned long xid, unsigned long server, unsigned long requested) +int send_selecting(uint32_t xid, uint32_t server, uint32_t requested) { struct dhcpMessage packet; struct in_addr addr; @@ -106,10 +108,9 @@ /* Unicasts or broadcasts a DHCP renew message */ -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr) +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; - int ret = 0; init_packet(&packet, DHCPREQUEST); packet.xid = xid; @@ -118,15 +119,15 @@ add_requests(&packet); bb_info_msg("Sending renew..."); if (server) - ret = udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); - else ret = udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, + return udhcp_kernel_packet(&packet, ciaddr, CLIENT_PORT, server, SERVER_PORT); + + return udhcp_raw_packet(&packet, INADDR_ANY, CLIENT_PORT, INADDR_BROADCAST, SERVER_PORT, MAC_BCAST_ADDR, client_config.ifindex); - return ret; } /* Unicasts a DHCP release message */ -int send_release(unsigned long server, unsigned long ciaddr) +int send_release(uint32_t server, uint32_t ciaddr) { struct dhcpMessage packet; @@ -214,5 +215,4 @@ } DEBUG("oooooh!!! got some!"); return bytes - (sizeof(packet.ip) + sizeof(packet.udp)); - } Modified: trunk/busybox/networking/udhcp/common.c =================================================================== --- trunk/busybox/networking/udhcp/common.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/common.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -10,31 +10,10 @@ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. */ -#include - #include "common.h" - const uint8_t MAC_BCAST_ADDR[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -long uptime(void) -{ - struct sysinfo info; - sysinfo(&info); - return info.uptime; -} - -static void create_pidfile(const char *pidfile) -{ - if (!pidfile) - return; - - if (!write_pidfile(pidfile)) { - bb_perror_msg("cannot create pidfile %s", pidfile); - return; - } -} - void udhcp_make_pidfile(const char *pidfile) { /* Make sure fd 0,1,2 are open */ @@ -44,7 +23,8 @@ setlinebuf(stdout); /* Create pidfile */ - create_pidfile(pidfile); + if (pidfile && !write_pidfile(pidfile)) + bb_perror_msg("cannot create pidfile %s", pidfile); bb_info_msg("%s (v%s) started", applet_name, BB_VER); } Modified: trunk/busybox/networking/udhcp/common.h =================================================================== --- trunk/busybox/networking/udhcp/common.h 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/common.h 2007-07-03 15:47:50 UTC (rev 18998) @@ -80,14 +80,14 @@ /* from dhcpd.h */ #define server_config udhcp_server_config -long uptime(void); void udhcp_sp_setup(void); int udhcp_sp_fd_set(fd_set *rfds, int extra_fd); int udhcp_sp_read(fd_set *rfds); int raw_socket(int ifindex); int read_interface(const char *interface, int *ifindex, uint32_t *addr, uint8_t *arp); int listen_socket(uint32_t ip, int port, const char *inf); -int arpping(uint32_t yiaddr, uint32_t ip, uint8_t *arp, char *interface); +/* Returns 1 if no reply received */ +int arpping(uint32_t test_ip, uint32_t from_ip, uint8_t *from_mac, const char *interface); #if ENABLE_FEATURE_UDHCP_DEBUG # define DEBUG(str, args...) bb_info_msg(str, ## args) Modified: trunk/busybox/networking/udhcp/dhcpc.c =================================================================== --- trunk/busybox/networking/udhcp/dhcpc.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/dhcpc.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -22,8 +22,8 @@ * in the code. Manpage says that struct in_addr has a member of type long (!) * which holds IPv4 address, and the struct is passed by value (!!) */ -static unsigned long timeout; -static unsigned long requested_ip; /* = 0 */ +static unsigned timeout; +static uint32_t requested_ip; /* = 0 */ static uint32_t server_addr; static int packet_num; /* = 0 */ static int sockfd = -1; @@ -84,13 +84,13 @@ /* perform a release */ static void perform_release(void) { - char buffer[16]; + char buffer[sizeof("255.255.255.255")]; struct in_addr temp_addr; /* send release packet */ if (state == BOUND || state == RENEWING || state == REBINDING) { temp_addr.s_addr = server_addr; - sprintf(buffer, "%s", inet_ntoa(temp_addr)); + strcpy(buffer, inet_ntoa(temp_addr)); temp_addr.s_addr = requested_ip; bb_info_msg("Unicasting a release of %s to %s", inet_ntoa(temp_addr), buffer); @@ -101,7 +101,7 @@ change_mode(LISTEN_NONE); state = RELEASED; - timeout = 0x7fffffff; + timeout = INT_MAX; } @@ -115,12 +115,13 @@ * will work on NOMMU too */ #else bb_daemonize(0); + logmode &= ~LOGMODE_STDIO; /* rewrite pidfile, as our pid is different now */ if (client_config.pidfile) write_pidfile(client_config.pidfile); - logmode &= ~LOGMODE_STDIO; #endif - client_config.foreground = 1; /* Do not fork again. */ + /* Do not fork again. */ + client_config.foreground = 1; client_config.background_if_no_lease = 0; } @@ -143,9 +144,11 @@ { uint8_t *temp, *message; char *str_c, *str_V, *str_h, *str_F, *str_r, *str_T, *str_t; - unsigned long t1 = 0, t2 = 0, xid = 0; - unsigned long start = 0, lease = 0; - long now; + uint32_t xid = 0; + uint32_t lease = 0; /* can be given as 32-bit quantity */ + unsigned t1 = 0, t2 = 0; + unsigned start = 0; + unsigned now; unsigned opt; int max_fd; int sig; @@ -292,7 +295,7 @@ change_mode(LISTEN_RAW); for (;;) { - tv.tv_sec = timeout - uptime(); + tv.tv_sec = timeout - monotonic_sec(); tv.tv_usec = 0; if (listen_mode != LISTEN_NONE && sockfd < 0) { @@ -308,7 +311,7 @@ retval = select(max_fd + 1, &rfds, NULL, NULL, &tv); } else retval = 0; /* If we already timed out, fall through */ - now = uptime(); + now = monotonic_sec(); if (retval == 0) { /* timeout dropped to zero */ switch (state) { @@ -398,7 +401,7 @@ break; case RELEASED: /* yah, I know, *you* say it would never happen */ - timeout = 0x7fffffff; + timeout = INT_MAX; break; } } else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(sockfd, &rfds)) { @@ -415,8 +418,8 @@ if (len < 0) continue; if (packet.xid != xid) { - DEBUG("Ignoring XID %lx (our xid is %lx)", - (unsigned long) packet.xid, xid); + DEBUG("Ignoring XID %x (our xid is %x)", + (unsigned)packet.xid, (unsigned)xid); continue; } @@ -471,10 +474,10 @@ t1 = lease / 2; /* little fixed point for n * .875 */ - t2 = (lease * 0x7) >> 3; + t2 = (lease * 7) >> 3; temp_addr.s_addr = packet.yiaddr; - bb_info_msg("Lease of %s obtained, lease time %ld", - inet_ntoa(temp_addr), lease); + bb_info_msg("Lease of %s obtained, lease time %u", + inet_ntoa(temp_addr), (unsigned)lease); start = now; timeout = t1 + start; requested_ip = packet.yiaddr; Modified: trunk/busybox/networking/udhcp/dhcpc.h =================================================================== --- trunk/busybox/networking/udhcp/dhcpc.h 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/dhcpc.h 2007-07-03 15:47:50 UTC (rev 18998) @@ -38,12 +38,12 @@ /*** clientpacket.h ***/ -unsigned random_xid(void); -int send_discover(unsigned long xid, unsigned long requested); -int send_selecting(unsigned long xid, unsigned long server, unsigned long requested); -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr); -int send_renew(unsigned long xid, unsigned long server, unsigned long ciaddr); -int send_release(unsigned long server, unsigned long ciaddr); +uint32_t random_xid(void); +int send_discover(uint32_t xid, uint32_t requested); +int send_selecting(uint32_t xid, uint32_t server, uint32_t requested); +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); +int send_renew(uint32_t xid, uint32_t server, uint32_t ciaddr); +int send_release(uint32_t server, uint32_t ciaddr); int get_raw_packet(struct dhcpMessage *payload, int fd); Modified: trunk/busybox/networking/udhcp/dhcpd.c =================================================================== --- trunk/busybox/networking/udhcp/dhcpd.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/dhcpd.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -30,7 +30,8 @@ struct dhcpMessage packet; uint8_t *state, *server_id, *requested; uint32_t server_id_align, requested_align, static_lease_ip; - unsigned long timeout_end, num_ips; + unsigned timeout_end; + unsigned num_ips; struct option_set *option; struct dhcpOfferedAddr *lease, static_lease; @@ -48,7 +49,7 @@ /* Would rather not do read_config before daemonization - * otherwise NOMMU machines will parse config twice */ - read_config(argc < 2 ? DHCPD_CONF_FILE : argv[1]); + read_config(argv[1] ? argv[1] : DHCPD_CONF_FILE); udhcp_make_pidfile(server_config.pidfile); @@ -62,9 +63,8 @@ /* Sanity check */ num_ips = server_config.end_ip - server_config.start_ip + 1; if (server_config.max_leases > num_ips) { - bb_error_msg("max_leases=%lu is too big, " - "setting to %lu", - server_config.max_leases, num_ips); + bb_error_msg("max_leases=%u is too big, setting to %u", + (unsigned)server_config.max_leases, num_ips); server_config.max_leases = num_ips; } @@ -80,7 +80,7 @@ /* Setup the signal pipe */ udhcp_sp_setup(); - timeout_end = time(0) + server_config.auto_time; + timeout_end = monotonic_sec() + server_config.auto_time; while (1) { /* loop until universe collapses */ if (server_socket < 0) { @@ -90,7 +90,7 @@ max_sock = udhcp_sp_fd_set(&rfds, server_socket); if (server_config.auto_time) { - tv.tv_sec = timeout_end - time(0); + tv.tv_sec = timeout_end - monotonic_sec(); tv.tv_usec = 0; } retval = 0; @@ -100,7 +100,7 @@ } if (retval == 0) { write_leases(); - timeout_end = time(0) + server_config.auto_time; + timeout_end = monotonic_sec() + server_config.auto_time; continue; } if (retval < 0 && errno != EINTR) { @@ -113,7 +113,7 @@ bb_info_msg("Received a SIGUSR1"); write_leases(); /* why not just reset the timeout, eh */ - timeout_end = time(0) + server_config.auto_time; + timeout_end = monotonic_sec() + server_config.auto_time; continue; case SIGTERM: bb_info_msg("Received a SIGTERM"); @@ -244,7 +244,7 @@ ret0: retval = 0; ret: - if (server_config.pidfile) + /*if (server_config.pidfile) - server_config.pidfile is never NULL */ remove_pidfile(server_config.pidfile); return retval; } Modified: trunk/busybox/networking/udhcp/dhcpd.h =================================================================== --- trunk/busybox/networking/udhcp/dhcpd.h 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/dhcpd.h 2007-07-03 15:47:50 UTC (rev 18998) @@ -20,37 +20,37 @@ }; struct static_lease { + struct static_lease *next; uint8_t *mac; uint32_t *ip; - struct static_lease *next; }; struct server_config_t { - uint32_t server; /* Our IP, in network order */ + uint32_t server; /* Our IP, in network order */ /* start,end are in host order: we need to compare start <= ip <= end */ - uint32_t start_ip; /* Start address of leases, in host order */ - uint32_t end_ip; /* End of leases, in host order */ - struct option_set *options; /* List of DHCP options loaded from the config file */ - char *interface; /* The name of the interface to use */ - int ifindex; /* Index number of the interface to use */ - uint8_t arp[6]; /* Our arp address */ - char remaining; /* should the lease file be interpreted as lease time remaining, or - * as the time the lease expires */ - unsigned long lease; /* lease time in seconds (host order) */ - unsigned long max_leases; /* maximum number of leases (including reserved address) */ - unsigned long auto_time; /* how long should udhcpd wait before writing a config file. - * if this is zero, it will only write one on SIGUSR1 */ - unsigned long decline_time; /* how long an address is reserved if a client returns a - * decline message */ - unsigned long conflict_time; /* how long an arp conflict offender is leased for */ - unsigned long offer_time; /* how long an offered address is reserved */ - unsigned long min_lease; /* minimum lease a client can request */ + uint32_t start_ip; /* Start address of leases, in host order */ + uint32_t end_ip; /* End of leases, in host order */ + struct option_set *options; /* List of DHCP options loaded from the config file */ + char *interface; /* The name of the interface to use */ + int ifindex; /* Index number of the interface to use */ + uint8_t arp[6]; /* Our arp address */ + char remaining; /* should the lease file be interpreted as lease time remaining, or + * as the time the lease expires */ + uint32_t lease; /* lease time in seconds (host order) */ + uint32_t max_leases; /* maximum number of leases (including reserved address) */ + uint32_t auto_time; /* how long should udhcpd wait before writing a config file. + * if this is zero, it will only write one on SIGUSR1 */ + uint32_t decline_time; /* how long an address is reserved if a client returns a + * decline message */ + uint32_t conflict_time; /* how long an arp conflict offender is leased for */ + uint32_t offer_time; /* how long an offered address is reserved */ + uint32_t min_lease; /* minimum lease a client can request */ char *lease_file; char *pidfile; - char *notify_file; /* What to run whenever leases are written */ - uint32_t siaddr; /* next server bootp option */ - char *sname; /* bootp server name */ - char *boot_file; /* bootp boot file option */ + char *notify_file; /* What to run whenever leases are written */ + uint32_t siaddr; /* next server bootp option */ + char *sname; /* bootp server name */ + char *boot_file; /* bootp boot file option */ struct static_lease *static_leases; /* List of ip/mac pairs to assign static leases */ }; Modified: trunk/busybox/networking/udhcp/files.c =================================================================== --- trunk/busybox/networking/udhcp/files.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/files.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -17,12 +17,11 @@ len_and_sockaddr *lsa; lsa = host_and_af2sockaddr(line, 0, AF_INET); - if (lsa) { - *(uint32_t*)arg = lsa->sin.sin_addr.s_addr; - free(lsa); - return 1; - } - return 0; + if (!lsa) + return 0; + *(uint32_t*)arg = lsa->sin.sin_addr.s_addr; + free(lsa); + return 1; } static int read_mac(const char *line, void *arg) Modified: trunk/busybox/networking/udhcp/leases.c =================================================================== --- trunk/busybox/networking/udhcp/leases.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/leases.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -95,24 +95,26 @@ /* check is an IP is taken, if it is, add it to the lease table */ -static int check_ip(uint32_t addr) +static int nobody_responds_to_arp(uint32_t addr) { static const uint8_t blank_chaddr[16]; /* 16 zero bytes */ struct in_addr temp; + int r; - if (arpping(addr, server_config.server, server_config.arp, server_config.interface) == 0) { - temp.s_addr = addr; - bb_info_msg("%s belongs to someone, reserving it for %ld seconds", - inet_ntoa(temp), server_config.conflict_time); - add_lease(blank_chaddr, addr, server_config.conflict_time); - return 1; - } + r = arpping(addr, server_config.server, server_config.arp, server_config.interface); + if (r) + return r; + + temp.s_addr = addr; + bb_info_msg("%s belongs to someone, reserving it for %u seconds", + inet_ntoa(temp), (unsigned)server_config.conflict_time); + add_lease(blank_chaddr, addr, server_config.conflict_time); return 0; } -/* find an assignable address, it check_expired is true, we check all the expired leases as well. +/* find an assignable address, if check_expired is true, we check all the expired leases as well. * Maybe this should try expired leases by age... */ uint32_t find_address(int check_expired) { @@ -129,15 +131,14 @@ if ((addr & 0xFF) == 0xFF) continue; /* Only do if it isn't assigned as a static lease */ - if (!reservedIp(server_config.static_leases, htonl(addr))) { - + ret = htonl(addr); + if (!reservedIp(server_config.static_leases, ret)) { /* lease is not taken */ - ret = htonl(addr); lease = find_lease_by_yiaddr(ret); /* no lease or it expired and we are checking for expired leases */ if ((!lease || (check_expired && lease_expired(lease))) - && /* and it isn't on the network */ !check_ip(ret) + && nobody_responds_to_arp(ret) /* it isn't used on the network */ ) { return ret; } Modified: trunk/busybox/networking/udhcp/packet.c =================================================================== --- trunk/busybox/networking/udhcp/packet.c 2007-07-03 10:28:46 UTC (rev 18997) +++ trunk/busybox/networking/udhcp/packet.c 2007-07-03 15:47:50 UTC (rev 18998) @@ -41,16 +41,17 @@ /* read a packet from socket fd, return -1 on read error, -2 on packet error */ int udhcp_get_packet(struct dhcpMessage *packet, int fd) { +#if 0 static const char broken_vendors[][8] = { "MSFT 98", "" }; +#endif int bytes; - int i; - char unsigned *vendor; + unsigned char *vendor; - memset(packet, 0, sizeof(struct dhcpMessage)); - bytes = read(fd, packet, sizeof(struct dhcpMessage)); + memset(packet, 0, sizeof(*packet)); + bytes = read(fd, packet, sizeof(*packet)); if (bytes < 0) { DEBUG("cannot read on listening socket, ignoring"); return -1; @@ -62,15 +63,28 @@ } DEBUG("Received a packet"); - if (packet->op == BOOTREQUEST && (vendor = get_option(packet, DHCP_VENDOR))) { - for (i = 0; broken_vendors[i][0]; i++) { - if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i]) - && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2]) + if (packet->op == BOOTREQUEST) { + vendor = get_option(packet, DHCP_VENDOR); + if (vendor) { +#if 0 + int i; + for (i = 0; broken_vendors[i][0]; i++) { + if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i]) + && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2]) + ) { + DEBUG("broken client (%s), forcing broadcast", + broken_vendors[i]); + packet->flags |= htons(BROADCAST_FLAG); + } + } +#else + if (vendor[OPT_LEN - 2] == (uint8_t)(sizeof("MSFT 98")-1) + && memcmp(vendor, "MSFT 98", sizeof("MSFT 98")-1) == 0 ) { - DEBUG("broken client (%s), forcing broadcast", - broken_vendors[i]); + DEBUG("broken client (%s), forcing broadcast", "MSFT 98"); packet->flags |= htons(BROADCAST_FLAG); } +#endif } } From bugs at busybox.net Tue Jul 3 10:21:47 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 10:21:47 -0700 Subject: [BusyBox 0001411]: chgrp with no arguments reports argument list for chown Message-ID: <4ad927abf68af5969023fd9fca3c77f5@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1411 ====================================================================== Reported By: kiltedknight Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1411 Category: Documentation Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 06-29-2007 08:54 PDT Last Modified: 07-03-2007 10:21 PDT ====================================================================== Summary: chgrp with no arguments reports argument list for chown Description: chgrp_main() should abort before even calling chown_main() when no or incorrect arguments are present, otherwise you list out arguments that are not used by chown. ====================================================================== ---------------------------------------------------------------------- vda - 06-30-07 10:17 ---------------------------------------------------------------------- Can you give an example? It works for me: # ./busybox chgrp BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chgrp [-RhLHPcvf]... GROUP FILE... Change the group membership of each FILE to GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v Verbose -f Hide errors # ./busybox chown BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chown [-RhLHPcvf]... OWNER[<.|:>[GROUP]] FILE... Change the owner and/or group of each FILE to OWNER and/or GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v List all files -f Hide errors ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:21 ---------------------------------------------------------------------- No... you don't understand. All of the listed options for chgrp are not needed, nor do they work for chgrp. Why display them? Issue History Date Modified Username Field Change ====================================================================== 06-29-07 08:54 kiltedknight New Issue 06-29-07 08:54 kiltedknight Status new => assigned 06-29-07 08:54 kiltedknight Assigned To => BusyBox 06-29-07 09:28 kiltedknight Issue Monitored: kiltedknight 06-30-07 10:17 vda Note Added: 0002539 07-03-07 10:21 kiltedknight Note Added: 0002550 ====================================================================== From bugs at busybox.net Tue Jul 3 10:23:36 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 10:23:36 -0700 Subject: [BusyBox 0001411]: chgrp with no arguments reports argument list for chown Message-ID: <3f065ce3dbe5a8501346118275fad9e6@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1411 ====================================================================== Reported By: kiltedknight Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1411 Category: Documentation Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 06-29-2007 08:54 PDT Last Modified: 07-03-2007 10:23 PDT ====================================================================== Summary: chgrp with no arguments reports argument list for chown Description: chgrp_main() should abort before even calling chown_main() when no or incorrect arguments are present, otherwise you list out arguments that are not used by chown. ====================================================================== ---------------------------------------------------------------------- vda - 06-30-07 10:17 ---------------------------------------------------------------------- Can you give an example? It works for me: # ./busybox chgrp BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chgrp [-RhLHPcvf]... GROUP FILE... Change the group membership of each FILE to GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v Verbose -f Hide errors # ./busybox chown BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chown [-RhLHPcvf]... OWNER[<.|:>[GROUP]] FILE... Change the owner and/or group of each FILE to OWNER and/or GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v List all files -f Hide errors ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:21 ---------------------------------------------------------------------- No... you don't understand. All of the listed options for chgrp are not needed, nor do they work for chgrp. Why display them? ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:23 ---------------------------------------------------------------------- In fact, the only option that should be listed for chgrp is -R, since it's the only one that actually works for that. Issue History Date Modified Username Field Change ====================================================================== 06-29-07 08:54 kiltedknight New Issue 06-29-07 08:54 kiltedknight Status new => assigned 06-29-07 08:54 kiltedknight Assigned To => BusyBox 06-29-07 09:28 kiltedknight Issue Monitored: kiltedknight 06-30-07 10:17 vda Note Added: 0002539 07-03-07 10:21 kiltedknight Note Added: 0002550 07-03-07 10:23 kiltedknight Note Added: 0002551 ====================================================================== From bugs at busybox.net Tue Jul 3 10:26:58 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 10:26:58 -0700 Subject: [BusyBox 0001411]: chgrp with no arguments reports argument list for chown Message-ID: <1ebf1ceeafb33ce118af186712ec7437@bugs.busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1411 ====================================================================== Reported By: kiltedknight Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1411 Category: Documentation Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 06-29-2007 08:54 PDT Last Modified: 07-03-2007 10:26 PDT ====================================================================== Summary: chgrp with no arguments reports argument list for chown Description: chgrp_main() should abort before even calling chown_main() when no or incorrect arguments are present, otherwise you list out arguments that are not used by chown. ====================================================================== ---------------------------------------------------------------------- vda - 06-30-07 10:17 ---------------------------------------------------------------------- Can you give an example? It works for me: # ./busybox chgrp BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chgrp [-RhLHPcvf]... GROUP FILE... Change the group membership of each FILE to GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v Verbose -f Hide errors # ./busybox chown BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chown [-RhLHPcvf]... OWNER[<.|:>[GROUP]] FILE... Change the owner and/or group of each FILE to OWNER and/or GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v List all files -f Hide errors ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:21 ---------------------------------------------------------------------- No... you don't understand. All of the listed options for chgrp are not needed, nor do they work for chgrp. Why display them? ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:23 ---------------------------------------------------------------------- In fact, the only option that should be listed for chgrp is -R, since it's the only one that actually works for that. ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:26 ---------------------------------------------------------------------- Bleh... ok... I've got to get with the other people here and have them be a bit more clear with things. Anyway, in 1.4.2, -c does not work as expected. Issue History Date Modified Username Field Change ====================================================================== 06-29-07 08:54 kiltedknight New Issue 06-29-07 08:54 kiltedknight Status new => assigned 06-29-07 08:54 kiltedknight Assigned To => BusyBox 06-29-07 09:28 kiltedknight Issue Monitored: kiltedknight 06-30-07 10:17 vda Note Added: 0002539 07-03-07 10:21 kiltedknight Note Added: 0002550 07-03-07 10:23 kiltedknight Note Added: 0002551 07-03-07 10:26 kiltedknight Note Added: 0002552 ====================================================================== From bugs at busybox.net Tue Jul 3 11:43:15 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Tue, 3 Jul 2007 11:43:15 -0700 Subject: [BusyBox 0001420]: invoked as /bin/md5sum, yields sha1sum Message-ID: The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1420 ====================================================================== Reported By: jfree Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1420 Category: Other Reproducibility: always Severity: major Priority: normal Status: assigned ====================================================================== Date Submitted: 07-03-2007 11:43 PDT Last Modified: 07-03-2007 11:43 PDT ====================================================================== Summary: invoked as /bin/md5sum, yields sha1sum Description: Busybox 1.6.0, on powerpc: When md5sum is invoked as /bin/md5sum, it yields the 40-character sha1sum instead of the 32-character md5sum: # md5sum /etc/passwd fe611ba27d0d7d92bbef243109fed95d /etc/passwd # /bin/md5sum /etc/passwd 8a20e2821a34d10a48d278d1095be4856c1bcdf0 /etc/passwd # sha1sum /etc/passwd 8a20e2821a34d10a48d278d1095be4856c1bcdf0 /etc/passwd ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 07-03-07 11:43 jfree New Issue 07-03-07 11:43 jfree Status new => assigned 07-03-07 11:43 jfree Assigned To => BusyBox ====================================================================== From bugs at busybox.net Wed Jul 4 07:16:03 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 4 Jul 2007 07:16:03 -0700 Subject: [BusyBox 0001421]: Add -m to grep Message-ID: <1295805fbfd5c646423a717a10f8377e@busybox.net> The following issue has been SUBMITTED. ====================================================================== http://busybox.net/bugs/view.php?id=1421 ====================================================================== Reported By: Patrick Verner Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1421 Category: New Features Reproducibility: N/A Severity: feature Priority: normal Status: assigned ====================================================================== Date Submitted: 07-04-2007 07:16 PDT Last Modified: 07-04-2007 07:16 PDT ====================================================================== Summary: Add -m to grep Description: It would be nice to have the -m option in grep. If I grep mtab for a certain device and if it is mounted more than once, grep grabs both lines. code example: grep -m 1 hda1 /etc/mtab ====================================================================== Issue History Date Modified Username Field Change ====================================================================== 07-04-07 07:16 Patrick Verner New Issue 07-04-07 07:16 Patrick Verner Status new => assigned 07-04-07 07:16 Patrick Verner Assigned To => BusyBox ====================================================================== From bugs at busybox.net Wed Jul 4 11:47:06 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 4 Jul 2007 11:47:06 -0700 Subject: [BusyBox 0001420]: invoked as /bin/md5sum, yields sha1sum Message-ID: The following issue has been CLOSED ====================================================================== http://busybox.net/bugs/view.php?id=1420 ====================================================================== Reported By: jfree Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1420 Category: Other Reproducibility: always Severity: major Priority: normal Status: closed Resolution: open Fixed in Version: ====================================================================== Date Submitted: 07-03-2007 11:43 PDT Last Modified: 07-04-2007 11:47 PDT ====================================================================== Summary: invoked as /bin/md5sum, yields sha1sum Description: Busybox 1.6.0, on powerpc: When md5sum is invoked as /bin/md5sum, it yields the 40-character sha1sum instead of the 32-character md5sum: # md5sum /etc/passwd fe611ba27d0d7d92bbef243109fed95d /etc/passwd # /bin/md5sum /etc/passwd 8a20e2821a34d10a48d278d1095be4856c1bcdf0 /etc/passwd # sha1sum /etc/passwd 8a20e2821a34d10a48d278d1095be4856c1bcdf0 /etc/passwd ====================================================================== ---------------------------------------------------------------------- vda - 07-04-07 11:47 ---------------------------------------------------------------------- Fixed in svn. Thanks for the report. Issue History Date Modified Username Field Change ====================================================================== 07-03-07 11:43 jfree New Issue 07-03-07 11:43 jfree Status new => assigned 07-03-07 11:43 jfree Assigned To => BusyBox 07-04-07 11:47 vda Status assigned => closed 07-04-07 11:47 vda Note Added: 0002554 ====================================================================== From bugs at busybox.net Wed Jul 4 11:55:15 2007 From: bugs at busybox.net (bugs at busybox.net) Date: Wed, 4 Jul 2007 11:55:15 -0700 Subject: [BusyBox 0001411]: chgrp with no arguments reports argument list for chown Message-ID: <43b046f73ec80ad092f905552bb56eee@busybox.net> A NOTE has been added to this issue. ====================================================================== http://busybox.net/bugs/view.php?id=1411 ====================================================================== Reported By: kiltedknight Assigned To: BusyBox ====================================================================== Project: BusyBox Issue ID: 1411 Category: Documentation Reproducibility: always Severity: minor Priority: normal Status: assigned ====================================================================== Date Submitted: 06-29-2007 08:54 PDT Last Modified: 07-04-2007 11:55 PDT ====================================================================== Summary: chgrp with no arguments reports argument list for chown Description: chgrp_main() should abort before even calling chown_main() when no or incorrect arguments are present, otherwise you list out arguments that are not used by chown. ====================================================================== ---------------------------------------------------------------------- vda - 06-30-07 10:17 ---------------------------------------------------------------------- Can you give an example? It works for me: # ./busybox chgrp BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chgrp [-RhLHPcvf]... GROUP FILE... Change the group membership of each FILE to GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v Verbose -f Hide errors # ./busybox chown BusyBox v1.7.0.svn (2007-06-30 12:02:05 CEST) multi-call binary Usage: chown [-RhLHPcvf]... OWNER[<.|:>[GROUP]] FILE... Change the owner and/or group of each FILE to OWNER and/or GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v List all files -f Hide errors ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:21 ---------------------------------------------------------------------- No... you don't understand. All of the listed options for chgrp are not needed, nor do they work for chgrp. Why display them? ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:23 ---------------------------------------------------------------------- In fact, the only option that should be listed for chgrp is -R, since it's the only one that actually works for that. ---------------------------------------------------------------------- kiltedknight - 07-03-07 10:26 ---------------------------------------------------------------------- Bleh... ok... I've got to get with the other people here and have them be a bit more clear with things. Anyway, in 1.4.2, -c does not work as expected. ---------------------------------------------------------------------- vda - 07-04-07 11:55 ---------------------------------------------------------------------- What option does not work? Let me check... # ./busybox chgrp --help BusyBox v1.7.0.svn (2007-07-01 20:20:44 CEST) multi-call binary Usage: chgrp [-RhLHPcvf]... GROUP FILE... Change the group membership of each FILE to GROUP Options: -R Recurse directories -h Affect symlinks instead of symlink targets -L Traverse all symlinks to directories -H Traverse symlinks on command line only -P Do not traverse symlinks (default) -c List changed files -v Verbose -f Hide errors # mkdir zz # ln -s zz zzl # >zz/file # ./busybox chgrp -Rv 1 zz changed ownership of 'zz' to 0:1 changed ownership of 'zz/file' to 0:1 # ./busybox chgrp -Rv 2 zzl changed ownership of 'zzl' to 0:2 # ls -ld zz zzl drwxr-xr-x 2 root 1 72 Jul 4 20:48 zz lrwxrwxrwx 1 root 2 2 Jul 4 20:47 zzl -> zz # ./busybox chgrp -RvL 3 zzl changed ownership of '/.1/usr/srcdevel/bbox/fix/busybox.t5/zz' to 0:3 changed ownership of '/.1/usr/srcdevel/bbox/fix/busybox.t5/zz/file' to 0:3 # ./busybox chgrp -RcL 4 zzl changed ownership of '/.1/usr/srcdevel/bbox/fix/busybox.t5/zz' to 0:4 changed ownership of '/.1/usr/srcdevel/bbox/fix/busybox.t5/zz/file' to 0:4 # ./busybox chgrp -RcL 4 zzl # _ Well, apart from -L unexpectedly giving fully-resolved names, at least -R -c -v -L seem to work. Issue History Date Modified Username Field Change ====================================================================== 06-29-07 08:54 kiltedknight New Issue 06-29-07 08:54 kiltedknight Status new => assigned 06-29-07 08:54 kiltedknight Assigned To => BusyBox 06-29-07 09:28 kiltedknight Issue Monitored: kiltedknight 06-30-07 10:17 vda Note Added: 0002539 07-03-07 10:21 kiltedknight Note Added: 0002550 07-03-07 10:23 kiltedknight Note Added: 0002551 07-03-07 10:26 kiltedknight Note Added: 0002552 07-04-07 11:55 vda Note Added: 0002555 ====================================================================== From vda at busybox.net Wed Jul 4 17:12:57 2007 From: vda at busybox.net (vda at busybox.net) Date: Wed, 4 Jul 2007 17:12:57 -0700 (PDT) Subject: svn commit: trunk/busybox: coreutils include libbb Message-ID: <20070705001257.B0FABA658B@busybox.net> Author: vda Date: 2007-07-04 17:12:55 -0700 (Wed, 04 Jul 2007) New Revision: 18999 Log: md5_sha1_sum: fix mishandling when run as /bin/md5sum (with path) chown/chgrp: completely match coreutils 6.8 wrt symlink handling function old new delta recursive_action 411 422 +11 arith 2033 2042 +9 collect_blk 467 474 +7 dhcprelay_main 1122 1125 +3 fsck_main 1909 1911 +2 singlemount 4555 4547 -8 xmalloc_realpath 14 - -14 get_lcm 123 105 -18 ed_main 3111 3084 -27 chown_main 217 183 -34 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 5/4 up/down: 32/-101) Total: -69 bytes text data bss dec hex filename 684132 2744 14000 700876 ab1cc busybox_old 684060 2744 14000 700804 ab184 busybox_unstripped Modified: trunk/busybox/coreutils/chown.c trunk/busybox/coreutils/md5_sha1_sum.c trunk/busybox/include/libbb.h trunk/busybox/libbb/recursive_action.c Changeset: Modified: trunk/busybox/coreutils/chown.c =================================================================== --- trunk/busybox/coreutils/chown.c 2007-07-03 15:47:50 UTC (rev 18998) +++ trunk/busybox/coreutils/chown.c 2007-07-05 00:12:55 UTC (rev 18999) @@ -65,6 +65,7 @@ int chown_main(int argc, char **argv) { int retval = EXIT_SUCCESS; + int flags; chown_fptr chown_func; opt_complementary = "-2"; @@ -80,23 +81,21 @@ chown_func = lchown; } + flags = ACTION_DEPTHFIRST; /* match coreutils order */ + if (OPT_RECURSE) + flags |= ACTION_RECURSE; + if (OPT_TRAVERSE_TOP) + flags |= ACTION_FOLLOWLINKS_L0; /* -H/-L: follow links on depth 0 */ + if (OPT_TRAVERSE) + flags |= ACTION_FOLLOWLINKS; /* follow links if -L */ + parse_chown_usergroup_or_die(&ugid, argv[0]); /* Ok, ready to do the deed now */ argv++; do { - char *arg = *argv; - - if (OPT_TRAVERSE_TOP) { - /* resolves symlink (even recursive) */ - arg = xmalloc_realpath(arg); - if (!arg) - continue; - } - - if (!recursive_action(arg, - (OPT_RECURSE ? ACTION_RECURSE : 0) | /* recurse */ - (OPT_TRAVERSE ? ACTION_FOLLOWLINKS : 0),/* follow links if -L */ + if (!recursive_action(*argv, + flags, /* flags */ fileAction, /* file action */ fileAction, /* dir action */ chown_func, /* user data */ @@ -104,9 +103,6 @@ ) { retval = EXIT_FAILURE; } - - if (OPT_TRAVERSE_TOP) - free(arg); } while (*++argv); return retval; @@ -137,8 +133,10 @@ tst() { create test1 create test2 - (cd test1; $t1 $1)