From 051665ef69568cf16a445a86a43d5ae74d303add Mon Sep 17 00:00:00 2001 From: Gray Wolf Date: Sat, 13 Jun 2020 02:00:48 +0200 Subject: crontab: Fix -e with editors saving using renaming strategy Some editors (like vim) use renaming strategy to save file. That means they save a file to some random name and then rename it to final location. The advantage is that such save is atomic. However, crontab -e holds open fd to the temporary file, meaning it never sees the changes. The temporary file needs to be re-opened after the editor terminates for the changes to properly save. Fixes #12491 Signed-off-by: Gray Wolf Signed-off-by: Denys Vlasenko --- miscutils/crontab.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miscutils/crontab.c b/miscutils/crontab.c index c71d914fc..411a18a50 100644 --- a/miscutils/crontab.c +++ b/miscutils/crontab.c @@ -165,8 +165,12 @@ int crontab_main(int argc UNUSED_PARAM, char **argv) close(fd); xlseek(src_fd, 0, SEEK_SET); } - close_on_exec_on(src_fd); /* don't want editor to see this fd */ + close(src_fd); edit_file(pas, tmp_fname); + /* The src_fd needs to be reopened to handle editors that do + * save the buffer as new file and rename it to tmp_fname (so + * for example vim). */ + src_fd = xopen3(tmp_fname, O_RDONLY, 0600); /* fall through */ case 0: /* Replace (no -l, -e, or -r were given) */ -- cgit v1.2.3-55-g6feb From 4468c569f7112f4f6892dad52fd784ef4c22c44e Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Thu, 9 Jul 2020 14:47:05 -0500 Subject: domain_codec: optimize dname_dec and convert_dname dname_dec: now iterates over the packet only once. convert_dname: remove redundant checks and code shrink. While testing I've noticed that some of the tests didn't compile properly, so I fixed them. function old new delta dname_dec 286 267 -19 dname_enc 166 143 -23 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-42) Total: -42 bytes Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- networking/udhcp/domain_codec.c | 157 ++++++++++++++++++++-------------------- 1 file changed, 79 insertions(+), 78 deletions(-) diff --git a/networking/udhcp/domain_codec.c b/networking/udhcp/domain_codec.c index 752c0a863..eab4da68b 100644 --- a/networking/udhcp/domain_codec.c +++ b/networking/udhcp/domain_codec.c @@ -10,10 +10,14 @@ # define _GNU_SOURCE # define FAST_FUNC /* nothing */ # define xmalloc malloc +# define xzalloc(s) calloc(s, 1) +# define xstrdup strdup +# define xrealloc realloc # include # include # include # include +# include #else # include "common.h" #endif @@ -26,86 +30,77 @@ /* Expand a RFC1035-compressed list of domain names "cstr", of length "clen"; - * returns a newly allocated string containing the space-separated domains, + * return a newly allocated string containing the space-separated domains, * prefixed with the contents of string pre, or NULL if an error occurs. */ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) { - char *ret = ret; /* for compiler */ - char *dst = NULL; + char *ret, *end; + unsigned len, crtpos, retpos, depth; - /* We make two passes over the cstr string. First, we compute - * how long the resulting string would be. Then we allocate a - * new buffer of the required length, and fill it in with the - * expanded content. The advantage of this approach is not - * having to deal with requiring callers to supply their own - * buffer, then having to check if it's sufficiently large, etc. - */ - while (1) { - /* note: "return NULL" below are leak-safe since - * dst isn't allocated yet */ + crtpos = retpos = depth = 0; + len = strlen(pre); + end = ret = xstrdup(pre); + + /* Scan the string once, allocating new memory as needed */ + while (crtpos < clen) { const uint8_t *c; - unsigned crtpos, retpos, depth, len; + c = cstr + crtpos; - crtpos = retpos = depth = len = 0; - while (crtpos < clen) { - c = cstr + crtpos; + if ((*c & NS_CMPRSFLGS) == NS_CMPRSFLGS) { + /* pointer */ + if (crtpos + 2 > clen) /* no offset to jump to? abort */ + goto error; + if (retpos == 0) /* toplevel? save return spot */ + retpos = crtpos + 2; + depth++; + crtpos = ((c[0] << 8) | c[1]) & 0x3fff; /* jump */ + } else if (*c) { + unsigned label_len; + /* label */ + if (crtpos + *c + 1 > clen) /* label too long? abort */ + goto error; + ret = xrealloc(ret, len + *c + 1); + /* \3com ---> "com." */ + end = (char *)mempcpy(ret + len, c + 1, *c); + *end = '.'; - if ((*c & NS_CMPRSFLGS) == NS_CMPRSFLGS) { - /* pointer */ - if (crtpos + 2 > clen) /* no offset to jump to? abort */ - return NULL; - if (retpos == 0) /* toplevel? save return spot */ - retpos = crtpos + 2; - depth++; - crtpos = ((c[0] & 0x3f) << 8) | c[1]; /* jump */ - } else if (*c) { - /* label */ - if (crtpos + *c + 1 > clen) /* label too long? abort */ - return NULL; - if (dst) - /* \3com ---> "com." */ - ((char*)mempcpy(dst + len, c + 1, *c))[0] = '.'; - len += *c + 1; - crtpos += *c + 1; + label_len = *c + 1; + len += label_len; + crtpos += label_len; + } else { + /* NUL: end of current domain name */ + if (retpos == 0) { + /* toplevel? keep going */ + crtpos++; } else { - /* NUL: end of current domain name */ - if (retpos == 0) { - /* toplevel? keep going */ - crtpos++; - } else { - /* return to toplevel saved spot */ - crtpos = retpos; - retpos = depth = 0; - } - if (dst && len != 0) - /* \4host\3com\0\4host and we are at \0: - * \3com was converted to "com.", change dot to space. - */ - dst[len - 1] = ' '; + /* return to toplevel saved spot */ + crtpos = retpos; + retpos = depth = 0; } - if (depth > NS_MAXDNSRCH /* too many jumps? abort, it's a loop */ - || len > NS_MAXDNAME * NS_MAXDNSRCH /* result too long? abort */ - ) { - return NULL; + if (len != 0) { + /* \4host\3com\0\4host and we are at \0: + * \3com was converted to "com.", change dot to space. + */ + ret[len - 1] = ' '; } } - if (!len) /* expanded string has 0 length? abort */ - return NULL; - - if (!dst) { /* first pass? */ - /* allocate dst buffer and copy pre */ - unsigned plen = strlen(pre); - ret = xmalloc(plen + len); - dst = stpcpy(ret, pre); - } else { - dst[len - 1] = '\0'; - break; + if (depth > NS_MAXDNSRCH /* too many jumps? abort, it's a loop */ + || len > NS_MAXDNAME * NS_MAXDNSRCH /* result too long? abort */ + ) { + goto error; } } + if (ret == end) { /* expanded string is empty? abort */ + error: + free(ret); + return NULL; + } + + *end = '\0'; return ret; } @@ -115,42 +110,40 @@ char* FAST_FUNC dname_dec(const uint8_t *cstr, int clen, const char *pre) */ static uint8_t *convert_dname(const char *src, int *retlen) { - uint8_t c, *res, *lenptr, *dst; - int len; + uint8_t *res, *lenptr, *dst; - res = xmalloc(strlen(src) + 2); + res = xzalloc(strlen(src) + 2); dst = lenptr = res; dst++; for (;;) { + uint8_t c; + int len; + c = (uint8_t)*src++; if (c == '.' || c == '\0') { /* end of label */ len = dst - lenptr - 1; - /* label too long, too short, or two '.'s in a row? abort */ - if (len > NS_MAXLABEL || len == 0 || (c == '.' && *src == '.')) { - free(res); - *retlen = 0; - return NULL; - } + /* label too long, too short, or two '.'s in a row (len will be 0) */ + if (len > NS_MAXLABEL || len == 0) + goto error; + *lenptr = len; if (c == '\0' || *src == '\0') /* "" or ".": end of src */ break; lenptr = dst++; continue; } - if (c >= 'A' && c <= 'Z') /* uppercase? convert to lower */ - c += ('a' - 'A'); - *dst++ = c; + *dst++ = tolower(c); } - if (dst - res >= NS_MAXCDNAME) { /* dname too long? abort */ + *retlen = dst + 1 - res; + if (*retlen > NS_MAXCDNAME) { /* dname too long? abort */ + error: free(res); *retlen = 0; return NULL; } - *dst++ = 0; - *retlen = dst - res; return res; } @@ -245,6 +238,7 @@ int main(int argc, char **argv) printf("test4:'%s'\n", DNAME_DEC("\4host\3com\0\xC0\5", "")); printf("test5:'%s'\n", DNAME_DEC("\4host\3com\0\xC0\5\1z\xC0\xA", "")); +#if 0 #define DNAME_ENC(cache,source,lenp) dname_enc((uint8_t*)(cache), sizeof(cache), (source), (lenp)) encoded = dname_enc(NULL, 0, "test.net", &len); printf("test6:'%s' len:%d\n", dname_dec(encoded, len, ""), len); @@ -252,6 +246,13 @@ int main(int argc, char **argv) printf("test7:'%s' len:%d\n", dname_dec(encoded, len, ""), len); encoded = DNAME_ENC("\4test\3net\0", "test.net", &len); printf("test8:'%s' len:%d\n", dname_dec(encoded, len, ""), len); +#endif + + encoded = dname_enc("test.net", &len); + printf("test6:'%s' len:%d\n", dname_dec(encoded, len, ""), len); + encoded = dname_enc("test.host.com", &len); + printf("test7:'%s' len:%d\n", dname_dec(encoded, len, ""), len); + return 0; } #endif -- cgit v1.2.3-55-g6feb From 79a4032eefe405a1e7d4a644614fcc4a07b98d88 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 19 Jul 2020 20:49:22 +0200 Subject: libbb: shrink last_char_is(), no longer allow NULL string argument function old new delta last_char_is 40 28 -12 Signed-off-by: Denys Vlasenko --- libbb/last_char_is.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/libbb/last_char_is.c b/libbb/last_char_is.c index 918526e6c..fba05f974 100644 --- a/libbb/last_char_is.c +++ b/libbb/last_char_is.c @@ -11,14 +11,9 @@ /* Find out if the last character of a string matches the one given */ char* FAST_FUNC last_char_is(const char *s, int c) { - if (s) { - size_t sz = strlen(s); - /* Don't underrun the buffer if the string length is 0 */ - if (sz != 0) { - s += sz - 1; - if ((unsigned char)*s == c) - return (char*)s; - } - } - return NULL; + if (!s[0]) + return NULL; + while (s[1]) + s++; + return (*s == (char)c) ? (char *) s : NULL; } -- cgit v1.2.3-55-g6feb From 06a407c6283b06307854649e522729a839017401 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sun, 19 Jul 2020 20:59:35 +0200 Subject: networking: support ftp PASV responses not ending with ')' Patch by Baruch Burstein function old new delta parse_pasv_epsv 153 181 +28 Signed-off-by: Denys Vlasenko --- networking/parse_pasv_epsv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/networking/parse_pasv_epsv.c b/networking/parse_pasv_epsv.c index 14f4d4258..314237be6 100644 --- a/networking/parse_pasv_epsv.c +++ b/networking/parse_pasv_epsv.c @@ -38,6 +38,8 @@ int FAST_FUNC parse_pasv_epsv(char *buf) * Server's IP is N1.N2.N3.N4 (we ignore it) * Server's port for data connection is P1*256+P2 */ ptr = strrchr(buf, ')'); + if (!ptr) ptr = strrchr(buf, '\r'); /* for PASV responses not ending with ')' */ + if (!ptr) ptr = strrchr(buf, '\n'); /* for PASV responses not ending with ')' */ if (ptr) *ptr = '\0'; ptr = strrchr(buf, ','); -- cgit v1.2.3-55-g6feb From 9a2d899273e3a8a58bdb4c3834d65d22658e7821 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 20 Jul 2020 00:04:33 +0200 Subject: ntpd: fix refid reported in server mode, closes 13056 function old new delta resolve_peer_hostname 129 196 +67 recv_and_process_peer_pkt 2475 2476 +1 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 2/0 up/down: 68/0) Total: 68 bytes Signed-off-by: Denys Vlasenko --- include/libbb.h | 7 +++++++ mailutils/popmaildir.c | 2 +- networking/ntpd.c | 37 +++++++++++++++++++++++++++++++++---- networking/tls.c | 2 -- 4 files changed, 41 insertions(+), 7 deletions(-) diff --git a/include/libbb.h b/include/libbb.h index 6be934994..8c7978456 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -2063,6 +2063,13 @@ unsigned sha3_end(sha3_ctx_t *ctx, void *resbuf) FAST_FUNC; typedef struct md5_ctx_t md5sha_ctx_t; #define md5sha_hash md5_hash #define sha_end sha1_end +enum { + MD5_OUTSIZE = 16, + SHA1_OUTSIZE = 20, + SHA256_OUTSIZE = 32, + SHA512_OUTSIZE = 64, + SHA3_OUTSIZE = 28, +}; extern uint32_t *global_crc32_table; uint32_t *crc32_filltable(uint32_t *tbl256, int endian) FAST_FUNC; diff --git a/mailutils/popmaildir.c b/mailutils/popmaildir.c index 6927e3a58..c5522f1b7 100644 --- a/mailutils/popmaildir.c +++ b/mailutils/popmaildir.c @@ -156,7 +156,7 @@ int popmaildir_main(int argc UNUSED_PARAM, char **argv) md5_ctx_t ctx; char hex[16 * 2 + 1]; } md5; - uint32_t res[16 / 4]; + uint32_t res[MD5_OUTSIZE / 4]; char *s = strchr(buf, '>'); if (s) diff --git a/networking/ntpd.c b/networking/ntpd.c index 0f12409f9..b08de504e 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -337,6 +337,9 @@ typedef struct { #endif int p_fd; int datapoint_idx; +#if ENABLE_FEATURE_NTPD_SERVER + uint32_t p_refid; +#endif uint32_t lastpkt_refid; uint8_t lastpkt_status; uint8_t lastpkt_stratum; @@ -413,7 +416,9 @@ struct globals { * in stratum 2+ packets, it's IPv4 address or 4 first bytes * of MD5 hash of IPv6 */ +#if ENABLE_FEATURE_NTPD_SERVER uint32_t refid; +#endif uint8_t ntp_status; /* precision is defined as the larger of the resolution and time to * read the clock, in log2 units. For instance, the precision of a @@ -836,6 +841,24 @@ reset_peer_stats(peer_t *p, double offset) VERB6 bb_error_msg("%s->lastpkt_recv_time=%f", p->p_dotted, p->lastpkt_recv_time); } +#if ENABLE_FEATURE_NTPD_SERVER +static uint32_t calculate_refid(len_and_sockaddr *lsa) +{ +# if ENABLE_FEATURE_IPV6 + if (lsa->u.sa.sa_family == AF_INET6) { + md5_ctx_t md5; + uint32_t res[MD5_OUTSIZE / 4]; + + md5_begin(&md5); + md5_hash(&md5, &lsa->u.sin6.sin6_addr, sizeof(lsa->u.sin6.sin6_addr)); + md5_end(&md5, res); + return res[0]; + } +# endif + return lsa->u.sin.sin_addr.s_addr; +} +#endif + static len_and_sockaddr* resolve_peer_hostname(peer_t *p) { @@ -847,6 +870,9 @@ resolve_peer_hostname(peer_t *p) p->p_dotted = xmalloc_sockaddr2dotted_noport(&lsa->u.sa); VERB1 if (strcmp(p->p_hostname, p->p_dotted) != 0) bb_error_msg("'%s' is %s", p->p_hostname, p->p_dotted); +#if ENABLE_FEATURE_NTPD_SERVER + p->p_refid = calculate_refid(p->p_lsa); +#endif p->dns_errors = 0; return lsa; } @@ -1764,7 +1790,10 @@ update_local_clock(peer_t *p) G.reftime = G.cur_time; G.ntp_status = p->lastpkt_status; - G.refid = p->lastpkt_refid; +#if ENABLE_FEATURE_NTPD_SERVER + /* Our current refid is the IPv4 (or md5-hashed IPv6) address of the peer we took time from: */ + G.refid = p->p_refid; +#endif G.rootdelay = p->lastpkt_rootdelay + p->lastpkt_delay; dtemp = p->filter_jitter; // SQRT(SQUARE(p->filter_jitter) + SQUARE(G.cluster_jitter)); dtemp += MAXD(p->filter_dispersion + FREQ_TOLERANCE * (G.cur_time - p->lastpkt_recv_time) + abs_offset, MINDISP); @@ -2249,11 +2278,11 @@ recv_and_process_client_pkt(void /*int fd*/) * We don't support this. */ -#if ENABLE_FEATURE_NTP_AUTH +# if ENABLE_FEATURE_NTP_AUTH if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH && size != NTP_MSGSIZE_SHA1_AUTH) -#else +# else if (size != NTP_MSGSIZE_NOAUTH && size != NTP_MSGSIZE_MD5_AUTH) -#endif +# endif { char *addr; if (size < 0) { diff --git a/networking/tls.c b/networking/tls.c index 854937302..341225207 100644 --- a/networking/tls.c +++ b/networking/tls.c @@ -212,8 +212,6 @@ enum { SHA_INSIZE = 64, - SHA1_OUTSIZE = 20, - SHA256_OUTSIZE = 32, AES128_KEYSIZE = 16, AES256_KEYSIZE = 32, -- cgit v1.2.3-55-g6feb From 2dd82f465e16f9df991d5677114370298a2ffade Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 20 Jul 2020 02:03:02 +0200 Subject: lsscsi: code shrink function old new delta lsscsi_main 298 302 +4 get_line 56 45 -11 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 4/-11) Total: -7 bytes Signed-off-by: Denys Vlasenko --- miscutils/lsscsi.c | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c index f737d33d9..76c281264 100644 --- a/miscutils/lsscsi.c +++ b/miscutils/lsscsi.c @@ -27,25 +27,21 @@ static const char scsi_dir[] ALIGN1 = "/sys/bus/scsi/devices"; -static char *get_line(const char *filename, char *buf, unsigned *bufsize_p) +static char *get_line(const char *filename, char *buf, char *bufend) { - unsigned bufsize = *bufsize_p; - ssize_t sz; + ssize_t sz = bufend - buf - 2; /* -2 for two NULs */ - if ((int)(bufsize - 2) <= 0) + if (sz <= 0) return buf; - sz = open_read_close(filename, buf, bufsize - 2); + sz = open_read_close(filename, buf, sz); if (sz < 0) sz = 0; buf[sz] = '\0'; - sz = (trim(buf) - buf) + 1; - bufsize -= sz; - buf += sz; + buf = trim(buf) + 1; buf[0] = '\0'; - *bufsize_p = bufsize; return buf; } @@ -61,7 +57,6 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) while ((de = readdir(dir)) != NULL) { char buf[256]; char *ptr; - unsigned bufsize; const char *vendor; const char *type_str; const char *type_name; @@ -76,15 +71,17 @@ int lsscsi_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM) if (chdir(de->d_name) != 0) continue; - bufsize = sizeof(buf); vendor = buf; - ptr = get_line("vendor", buf, &bufsize); + ptr = get_line("vendor", buf, buf + sizeof(buf)); + type_str = ptr; - ptr = get_line("type", ptr, &bufsize); + ptr = get_line("type", ptr, buf + sizeof(buf)); + model = ptr; - ptr = get_line("model", ptr, &bufsize); + ptr = get_line("model", ptr, buf + sizeof(buf)); + rev = ptr; - ptr = get_line("rev", ptr, &bufsize); + /*ptr =*/ get_line("rev", ptr, buf + sizeof(buf)); printf("[%s]\t", de->d_name); -- cgit v1.2.3-55-g6feb From 197ae0f9ae71c2c313a56f7ce8807411f8a2562a Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 10 Jul 2020 22:48:12 +0300 Subject: httpd_indexcgi.c: minimize style CSS Remove new lines \n and some semicolons ;. This minimize page style size from 655 to 604 Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd_indexcgi.c | 74 ++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index 562cd7fbe..f5f18959d 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c @@ -52,43 +52,43 @@ httpd_indexcgi.c -o index.cgi * to elements. Edit stylesheet to your liking and recompile. */ #define STYLE_STR \ -"" "\n"\ +"" \ typedef struct dir_list_t { char *dl_name; -- cgit v1.2.3-55-g6feb From a088da4476012e067a9a49de997031ea64ac401e Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Fri, 10 Jul 2020 22:48:13 +0300 Subject: httpd_indexcgi.c: use CSS for odd/even rows Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd_indexcgi.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/networking/httpd_indexcgi.c b/networking/httpd_indexcgi.c index f5f18959d..47b1159f4 100644 --- a/networking/httpd_indexcgi.c +++ b/networking/httpd_indexcgi.c @@ -76,9 +76,8 @@ httpd_indexcgi.c -o index.cgi "border-color:black;" /* black black black black; */ \ "white-space:nowrap" \ "}" \ +"tr:nth-child(odd) { background-color:#ffffff }" \ "tr.hdr { background-color:#eee5de }" \ -"tr.o { background-color:#ffffff }" \ -/* tr.e { ... } - for even rows (currently none) */ \ "tr.foot { background-color:#eee5de }" \ "th.cnt { text-align:left }" \ "th.sz { text-align:right }" \ @@ -220,7 +219,6 @@ int main(int argc, char *argv[]) unsigned count_dirs; unsigned count_files; unsigned long long size_total; - int odd; DIR *dirp; char *location; @@ -291,7 +289,6 @@ int main(int argc, char *argv[]) "" "\n" "NameSizeLast modified" "\n"); - odd = 0; count_dirs = 0; count_files = 0; size_total = 0; @@ -307,9 +304,7 @@ int main(int argc, char *argv[]) } else goto next; - fmt_str("dl_name); /* %20 etc */ if (S_ISDIR(cdir->dl_mode)) *dst++ = '/'; @@ -330,7 +325,6 @@ int main(int argc, char *argv[]) fmt_02u(ptm->tm_sec); *dst++ = '\n'; - odd = 1 - odd; next: cdir++; } -- cgit v1.2.3-55-g6feb From 39925026f6857979cbe603efd42073eb63f8d9de Mon Sep 17 00:00:00 2001 From: Christian Eggers Date: Mon, 29 Jun 2020 17:57:24 +0200 Subject: shell: Fix "read -d ''" behavior With bash's read builtin it is possible to read from a file (e.g. device-tree) until the first '\0' character: IFS= read -r -d '' VARIABLE < file In busybox ash the -d extension is also implemented, but checking the read character for '\0' has to be performed after comparing with the delimiter. Signed-off-by: Christian Eggers Signed-off-by: Denys Vlasenko --- shell/ash_test/ash-read/read_d0.right | 1 + shell/ash_test/ash-read/read_d0.tests | 1 + shell/hush_test/hush-read/read_d0.right | 1 + shell/hush_test/hush-read/read_d0.tests | 1 + shell/shell_common.c | 4 ++-- 5 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 shell/ash_test/ash-read/read_d0.right create mode 100755 shell/ash_test/ash-read/read_d0.tests create mode 100644 shell/hush_test/hush-read/read_d0.right create mode 100755 shell/hush_test/hush-read/read_d0.tests diff --git a/shell/ash_test/ash-read/read_d0.right b/shell/ash_test/ash-read/read_d0.right new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/shell/ash_test/ash-read/read_d0.right @@ -0,0 +1 @@ +test diff --git a/shell/ash_test/ash-read/read_d0.tests b/shell/ash_test/ash-read/read_d0.tests new file mode 100755 index 000000000..630d80787 --- /dev/null +++ b/shell/ash_test/ash-read/read_d0.tests @@ -0,0 +1 @@ +printf 'test\0zest\n' | (read -d '' reply; echo "$reply") diff --git a/shell/hush_test/hush-read/read_d0.right b/shell/hush_test/hush-read/read_d0.right new file mode 100644 index 000000000..9daeafb98 --- /dev/null +++ b/shell/hush_test/hush-read/read_d0.right @@ -0,0 +1 @@ +test diff --git a/shell/hush_test/hush-read/read_d0.tests b/shell/hush_test/hush-read/read_d0.tests new file mode 100755 index 000000000..630d80787 --- /dev/null +++ b/shell/hush_test/hush-read/read_d0.tests @@ -0,0 +1 @@ +printf 'test\0zest\n' | (read -d '' reply; echo "$reply") diff --git a/shell/shell_common.c b/shell/shell_common.c index 12c4a073c..42c4c9c97 100644 --- a/shell/shell_common.c +++ b/shell/shell_common.c @@ -209,8 +209,6 @@ shell_builtin_read(struct builtin_read_params *params) } c = buffer[bufpos]; - if (c == '\0') - continue; if (!(read_flags & BUILTIN_READ_RAW)) { if (backslash) { backslash = 0; @@ -225,6 +223,8 @@ shell_builtin_read(struct builtin_read_params *params) } if (c == delim) /* '\n' or -d CHAR */ break; + if (c == '\0') + continue; /* $IFS splitting. NOT done if we run "read" * without variable names (bash compat). -- cgit v1.2.3-55-g6feb From 31d34f3bd8b0cc41db5e893942d9dc5c14e4dd3c Mon Sep 17 00:00:00 2001 From: Christian Eggers Date: Mon, 29 Jun 2020 17:57:25 +0200 Subject: ip: Add support for "noprefixroute" option The "noprefixroute" option suppresses automatic generation of a routing table entry based on the interface's ip address. The ifa_flags field has only 8 bit. If higher bits are set, rta_tb[IFA_FLAGS] has to be used instead. Signed-off-by: Christian Eggers Signed-off-by: Denys Vlasenko --- networking/ip.c | 4 +++- networking/libiproute/ipaddress.c | 45 ++++++++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/networking/ip.c b/networking/ip.c index 034ee4fc8..45bf1dc0a 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -146,11 +146,13 @@ //usage:#define ipaddr_trivial_usage //usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]" //usage:#define ipaddr_full_usage "\n\n" -//usage: "ipaddr add|change|replace|delete dev IFACE IFADDR\n" +//usage: "ipaddr add|change|replace|delete dev IFACE [CONFFLAG-LIST] IFADDR\n" //usage: " IFADDR := PREFIX | ADDR peer PREFIX [broadcast ADDR|+|-]\n" //usage: " [anycast ADDR] [label STRING] [scope SCOPE]\n" //usage: " PREFIX := ADDR[/MASK]\n" //usage: " SCOPE := [host|link|global|NUMBER]\n" +//usage: " CONFFLAG-LIST := [CONFFLAG-LIST] CONFFLAG\n" +//usage: " CONFFLAG := [noprefixroute]\n" //usage: "ipaddr show|flush [dev IFACE] [scope SCOPE] [to PREFIX] [label PATTERN]" //usage: //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79 diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 86cf3beea..6cfd3c398 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -217,6 +217,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, { struct ifaddrmsg *ifa = NLMSG_DATA(n); int len = n->nlmsg_len; + unsigned int ifa_flags; struct rtattr *rta_tb[IFA_MAX+1]; if (n->nlmsg_type != RTM_NEWADDR && n->nlmsg_type != RTM_DELADDR) @@ -233,6 +234,8 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, //memset(rta_tb, 0, sizeof(rta_tb)); - parse_rtattr does this parse_rtattr(rta_tb, IFA_MAX, IFA_RTA(ifa), n->nlmsg_len - NLMSG_LENGTH(sizeof(*ifa))); + ifa_flags = rta_tb[IFA_FLAGS] ? *(__u32*)RTA_DATA(rta_tb[IFA_FLAGS]) : ifa->ifa_flags; + if (!rta_tb[IFA_LOCAL]) rta_tb[IFA_LOCAL] = rta_tb[IFA_ADDRESS]; if (!rta_tb[IFA_ADDRESS]) @@ -242,7 +245,7 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, return 0; if ((G_filter.scope ^ ifa->ifa_scope) & G_filter.scopemask) return 0; - if ((G_filter.flags ^ ifa->ifa_flags) & G_filter.flagmask) + if ((G_filter.flags ^ ifa_flags) & G_filter.flagmask) return 0; if (G_filter.label) { const char *label; @@ -322,28 +325,32 @@ static int FAST_FUNC print_addrinfo(const struct sockaddr_nl *who UNUSED_PARAM, ); } printf("scope %s ", rtnl_rtscope_n2a(ifa->ifa_scope)); - if (ifa->ifa_flags & IFA_F_SECONDARY) { - ifa->ifa_flags &= ~IFA_F_SECONDARY; + if (ifa_flags & IFA_F_SECONDARY) { + ifa_flags &= ~IFA_F_SECONDARY; printf("secondary "); } - if (ifa->ifa_flags & IFA_F_TENTATIVE) { - ifa->ifa_flags &= ~IFA_F_TENTATIVE; + if (ifa_flags & IFA_F_TENTATIVE) { + ifa_flags &= ~IFA_F_TENTATIVE; printf("tentative "); } - if (ifa->ifa_flags & IFA_F_DADFAILED) { - ifa->ifa_flags &= ~IFA_F_DADFAILED; + if (ifa_flags & IFA_F_DADFAILED) { + ifa_flags &= ~IFA_F_DADFAILED; printf("dadfailed "); } - if (ifa->ifa_flags & IFA_F_DEPRECATED) { - ifa->ifa_flags &= ~IFA_F_DEPRECATED; + if (ifa_flags & IFA_F_DEPRECATED) { + ifa_flags &= ~IFA_F_DEPRECATED; printf("deprecated "); } - if (!(ifa->ifa_flags & IFA_F_PERMANENT)) { + if (!(ifa_flags & IFA_F_PERMANENT)) { printf("dynamic "); } else - ifa->ifa_flags &= ~IFA_F_PERMANENT; - if (ifa->ifa_flags) - printf("flags %02x ", ifa->ifa_flags); + ifa_flags &= ~IFA_F_PERMANENT; + if (ifa_flags & IFA_F_NOPREFIXROUTE) { + ifa_flags &= ~IFA_F_NOPREFIXROUTE; + printf("noprefixroute "); + } + if (ifa_flags) + printf("flags %02x ", ifa_flags); if (rta_tb[IFA_LABEL]) fputs((char*)RTA_DATA(rta_tb[IFA_LABEL]), stdout); if (rta_tb[IFA_CACHEINFO]) { @@ -600,7 +607,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) /* If you add stuff here, update ipaddr_full_usage */ static const char option[] ALIGN1 = "peer\0""remote\0""broadcast\0""brd\0" - "anycast\0""scope\0""dev\0""label\0""local\0"; + "anycast\0""scope\0""dev\0""label\0""noprefixroute\0""local\0"; #define option_peer option #define option_broadcast (option + sizeof("peer") + sizeof("remote")) #define option_anycast (option_broadcast + sizeof("broadcast") + sizeof("brd")) @@ -619,6 +626,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) int brd_len = 0; int any_len = 0; bool scoped = 0; + unsigned int ifa_flags = 0; memset(&req, 0, sizeof(req)); @@ -630,7 +638,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) while (*argv) { unsigned arg = index_in_strings(option, *argv); /* if search fails, "local" is assumed */ - if ((int)arg >= 0) + if ((int)arg >= 0 && arg != 8) NEXT_ARG(); if (arg <= 1) { /* peer, remote */ @@ -683,6 +691,8 @@ static int ipaddr_modify(int cmd, int flags, char **argv) } else if (arg == 7) { /* label */ l = *argv; addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1); + } else if (arg == 8) { /* noprefixroute */ + ifa_flags |= IFA_F_NOPREFIXROUTE; } else { /* local (specified or assumed) */ if (local_len) { @@ -698,6 +708,11 @@ static int ipaddr_modify(int cmd, int flags, char **argv) argv++; } + if (ifa_flags <= 0xff) + req.ifa.ifa_flags = ifa_flags; + else + addattr32(&req.n, sizeof(req), IFA_FLAGS, ifa_flags); + if (!d) { /* There was no "dev IFACE", but we need that */ bb_simple_error_msg_and_die("need \"dev IFACE\""); -- cgit v1.2.3-55-g6feb From 8a485b0a363935309f976866b8a30988362fadc0 Mon Sep 17 00:00:00 2001 From: Christian Eggers Date: Mon, 29 Jun 2020 17:57:26 +0200 Subject: ip address: Add support for "valid_lft" and "preferred_lft" options Signed-off-by: Christian Eggers Signed-off-by: Denys Vlasenko --- networking/libiproute/ip_common.h | 4 +++ networking/libiproute/ipaddress.c | 65 ++++++++++++++++++++++++++++++++++----- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/networking/libiproute/ip_common.h b/networking/libiproute/ip_common.h index 40171bed9..894e380f8 100644 --- a/networking/libiproute/ip_common.h +++ b/networking/libiproute/ip_common.h @@ -33,4 +33,8 @@ int FAST_FUNC do_iplink(char **argv); POP_SAVED_FUNCTION_VISIBILITY +#ifndef INFINITY_LIFE_TIME +#define INFINITY_LIFE_TIME 0xFFFFFFFFU +#endif + #endif diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c index 6cfd3c398..71e8fb6a7 100644 --- a/networking/libiproute/ipaddress.c +++ b/networking/libiproute/ipaddress.c @@ -592,6 +592,14 @@ int FAST_FUNC ipaddr_list_or_flush(char **argv, int flush) return 0; } +static void set_lifetime(unsigned int *lifetime, char *argv, const char *errmsg) +{ + if (strcmp(argv, "forever") == 0) + *lifetime = INFINITY_LIFE_TIME; + else + *lifetime = get_u32(argv, errmsg); +} + static int default_scope(inet_prefix *lcl) { if (lcl->family == AF_INET) { @@ -607,10 +615,13 @@ static int ipaddr_modify(int cmd, int flags, char **argv) /* If you add stuff here, update ipaddr_full_usage */ static const char option[] ALIGN1 = "peer\0""remote\0""broadcast\0""brd\0" - "anycast\0""scope\0""dev\0""label\0""noprefixroute\0""local\0"; + "anycast\0""valid_lft\0""preferred_lft\0" + "scope\0""dev\0""label\0""noprefixroute\0""local\0"; #define option_peer option #define option_broadcast (option + sizeof("peer") + sizeof("remote")) #define option_anycast (option_broadcast + sizeof("broadcast") + sizeof("brd")) +#define option_valid_lft (option_anycast + sizeof("anycast")) +#define option_pref_lft (option_valid_lft + sizeof("valid_lft")) struct rtnl_handle rth; struct { struct nlmsghdr n; @@ -619,6 +630,8 @@ static int ipaddr_modify(int cmd, int flags, char **argv) } req; char *d = NULL; char *l = NULL; + char *valid_lftp = NULL; + char *preferred_lftp = NULL; inet_prefix lcl; inet_prefix peer; int local_len = 0; @@ -626,6 +639,8 @@ static int ipaddr_modify(int cmd, int flags, char **argv) int brd_len = 0; int any_len = 0; bool scoped = 0; + __u32 valid_lft = INFINITY_LIFE_TIME; + __u32 preferred_lft = INFINITY_LIFE_TIME; unsigned int ifa_flags = 0; memset(&req, 0, sizeof(req)); @@ -638,10 +653,9 @@ static int ipaddr_modify(int cmd, int flags, char **argv) while (*argv) { unsigned arg = index_in_strings(option, *argv); /* if search fails, "local" is assumed */ - if ((int)arg >= 0 && arg != 8) - NEXT_ARG(); if (arg <= 1) { /* peer, remote */ + NEXT_ARG(); if (peer_len) { duparg(option_peer, *argv); } @@ -654,6 +668,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) req.ifa.ifa_prefixlen = peer.bitlen; } else if (arg <= 3) { /* broadcast, brd */ inet_prefix addr; + NEXT_ARG(); if (brd_len) { duparg(option_broadcast, *argv); } @@ -670,6 +685,7 @@ static int ipaddr_modify(int cmd, int flags, char **argv) } } else if (arg == 4) { /* anycast */ inet_prefix addr; + NEXT_ARG(); if (any_len) { duparg(option_anycast, *argv); } @@ -679,22 +695,39 @@ static int ipaddr_modify(int cmd, int flags, char **argv) } addattr_l(&req.n, sizeof(req), IFA_ANYCAST, &addr.data, addr.bytelen); any_len = addr.bytelen; - } else if (arg == 5) { /* scope */ + } else if (arg == 5) { /* valid_lft */ + if (valid_lftp) + duparg(option_valid_lft, *argv); + NEXT_ARG(); + valid_lftp = *argv; + set_lifetime(&valid_lft, *argv, option_valid_lft); + } else if (arg == 6) { /* preferred_lft */ + if (preferred_lftp) + duparg(option_pref_lft, *argv); + NEXT_ARG(); + preferred_lftp = *argv; + set_lifetime(&preferred_lft, *argv, option_pref_lft); + } else if (arg == 7) { /* scope */ uint32_t scope = 0; + NEXT_ARG(); if (rtnl_rtscope_a2n(&scope, *argv)) { invarg_1_to_2(*argv, "scope"); } req.ifa.ifa_scope = scope; scoped = 1; - } else if (arg == 6) { /* dev */ + } else if (arg == 8) { /* dev */ + NEXT_ARG(); d = *argv; - } else if (arg == 7) { /* label */ + } else if (arg == 9) { /* label */ + NEXT_ARG(); l = *argv; addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l) + 1); - } else if (arg == 8) { /* noprefixroute */ + } else if (arg == 10) { /* noprefixroute */ ifa_flags |= IFA_F_NOPREFIXROUTE; } else { /* local (specified or assumed) */ + if ((int)arg >= 0) + NEXT_ARG(); if (local_len) { duparg2("local", *argv); } @@ -755,6 +788,24 @@ static int ipaddr_modify(int cmd, int flags, char **argv) req.ifa.ifa_index = xll_name_to_index(d); + if (valid_lftp || preferred_lftp) { + struct ifa_cacheinfo cinfo = {}; + + if (!valid_lft) { + fprintf(stderr, "valid_lft is zero\n"); + return 1; + } + if (valid_lft < preferred_lft) { + fprintf(stderr, "preferred_lft is greater than valid_lft\n"); + return 1; + } + + cinfo.ifa_prefered = preferred_lft; + cinfo.ifa_valid = valid_lft; + addattr_l(&req.n, sizeof(req), IFA_CACHEINFO, &cinfo, + sizeof(cinfo)); + } + if (rtnl_talk(&rth, &req.n, 0, 0, NULL, NULL, NULL) < 0) return 2; -- cgit v1.2.3-55-g6feb From 9914d8b861a0edb42051bd68a37bceb0562daa70 Mon Sep 17 00:00:00 2001 From: Martin Lewis Date: Tue, 4 Aug 2020 17:27:16 -0500 Subject: udhcpc: add support for long options Duplicate options are currently overridden (only the last option is kept). This leads to unexpected behavior when using long options. The patch adds support for long options in compliance with RFC 3396. Fixes #13136. function old new delta udhcp_run_script 601 725 +124 optitem_unset_env_and_free - 38 +38 putenvp 46 59 +13 static.xmalloc_optname_optval 718 717 -1 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/1 up/down: 175/-1) Total: 174 bytes Signed-off-by: Martin Lewis Signed-off-by: Denys Vlasenko --- networking/udhcp/dhcpc.c | 138 +++++++++++++++++++++++++++++++++++------------ networking/udhcp/dhcpc.h | 1 + 2 files changed, 104 insertions(+), 35 deletions(-) diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 50dfead63..e13eb3f9f 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c @@ -115,6 +115,13 @@ enum { /*** Script execution code ***/ +struct dhcp_optitem { + unsigned len; + uint8_t code; + uint8_t malloced; + uint8_t *data; + char *env; +}; /* get a rough idea of how long an option will be (rounding up...) */ static const uint8_t len_of_option_as_string[] ALIGN1 = { @@ -186,15 +193,15 @@ static int good_hostname(const char *name) #endif /* Create "opt_name=opt_value" string */ -static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_optflag *optflag, const char *opt_name) +static NOINLINE char *xmalloc_optname_optval(const struct dhcp_optitem *opt_item, const struct dhcp_optflag *optflag, const char *opt_name) { unsigned upper_length; int len, type, optlen; char *dest, *ret; + uint8_t *option; - /* option points to OPT_DATA, need to go back to get OPT_LEN */ - len = option[-OPT_DATA + OPT_LEN]; - + option = opt_item->data; + len = opt_item->len; type = optflag->flags & OPTION_TYPE_MASK; optlen = dhcp_option_lengths[type]; upper_length = len_of_option_as_string[type] @@ -386,11 +393,70 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ return ret; } -static void putenvp(llist_t **envp, char *new_opt) +static void optitem_unset_env_and_free(void *item) { - putenv(new_opt); + struct dhcp_optitem *opt_item = item; + bb_unsetenv_and_free(opt_item->env); + if (opt_item->malloced) + free(opt_item->data); + free(opt_item); +} + +/* Used by static options (interface, siaddr, etc) */ +static void putenvp(char *new_opt) +{ + struct dhcp_optitem *opt_item; + + opt_item = xzalloc(sizeof(*opt_item)); + /* opt_item->code = 0, so it won't appear in concat_option's lookup */ + /* opt_item->malloced = 0 */ + /* opt_item->data = NULL */ + opt_item->env = new_opt; + llist_add_to(&client_data.envp, opt_item); log2(" %s", new_opt); - llist_add_to(envp, new_opt); + putenv(new_opt); +} + +/* Support RFC3396 Long Encoded Options */ +static struct dhcp_optitem *concat_option(uint8_t *data, uint8_t len, uint8_t code) +{ + llist_t *item; + struct dhcp_optitem *opt_item; + + /* Check if an option with the code already exists. + * A possible optimization is to create a bitmap of all existing options in the packet, + * and iterate over the option list only if they exist. + * This will result in bigger code, and because dhcp packets don't have too many options it + * shouldn't have a big impact on performance. + */ + for (item = client_data.envp; item != NULL; item = item->link) { + opt_item = (struct dhcp_optitem *)item->data; + if (opt_item->code == code) { + /* This option was seen already, concatenate */ + uint8_t *new_data; + + new_data = xmalloc(len + opt_item->len); + memcpy( + mempcpy(new_data, opt_item->data, opt_item->len), + data, len + ); + opt_item->len += len; + if (opt_item->malloced) + free(opt_item->data); + opt_item->malloced = 1; + opt_item->data = new_data; + return opt_item; + } + } + + /* This is a new option, add a new dhcp_optitem to the list */ + opt_item = xzalloc(sizeof(*opt_item)); + opt_item->code = code; + /* opt_item->malloced = 0 */ + opt_item->data = data; + opt_item->len = len; + llist_add_to(&client_data.envp, opt_item); + return opt_item; } static const char* get_optname(uint8_t code, const struct dhcp_optflag **dh) @@ -403,7 +469,7 @@ static const char* get_optname(uint8_t code, const struct dhcp_optflag **dh) * and they'll count as unknown options. */ for (*dh = dhcp_optflags; (*dh)->code && (*dh)->code < code; (*dh)++) - continue; + continue; if ((*dh)->code == code) return nth_string(dhcp_option_strings, (*dh - dhcp_optflags)); @@ -412,50 +478,54 @@ static const char* get_optname(uint8_t code, const struct dhcp_optflag **dh) } /* put all the parameters into the environment */ -static llist_t *fill_envp(struct dhcp_packet *packet) +static void fill_envp(struct dhcp_packet *packet) { uint8_t *optptr; struct dhcp_scan_state scan_state; char *new_opt; - llist_t *envp = NULL; - putenvp(&envp, xasprintf("interface=%s", client_data.interface)); + putenvp(xasprintf("interface=%s", client_data.interface)); if (!packet) - return envp; + return; init_scan_state(packet, &scan_state); /* Iterate over the packet options. * Handle each option based on whether it's an unknown / known option. - * There may be (although unlikely) duplicate options. For now, only the last - * appearing option will be stored in the environment, and all duplicates - * are freed properly. - * Long options may be implemented in the future (see RFC 3396) if needed. + * Long options are supported in compliance with RFC 3396. */ while ((optptr = udhcp_scan_options(packet, &scan_state)) != NULL) { const struct dhcp_optflag *dh; const char *opt_name; + struct dhcp_optitem *opt_item; uint8_t code = optptr[OPT_CODE]; uint8_t len = optptr[OPT_LEN]; uint8_t *data = optptr + OPT_DATA; + opt_item = concat_option(data, len, code); opt_name = get_optname(code, &dh); if (opt_name) { - new_opt = xmalloc_optname_optval(data, dh, opt_name); - if (code == DHCP_SUBNET && len == 4) { + new_opt = xmalloc_optname_optval(opt_item, dh, opt_name); + if (opt_item->code == DHCP_SUBNET && opt_item->len == 4) { + /* Generate extra envvar for DHCP_SUBNET, $mask */ uint32_t subnet; - putenvp(&envp, new_opt); - move_from_unaligned32(subnet, data); - new_opt = xasprintf("mask=%u", mton(subnet)); + move_from_unaligned32(subnet, opt_item->data); + putenvp(xasprintf("mask=%u", mton(subnet))); } } else { unsigned ofs; - new_opt = xmalloc(sizeof("optNNN=") + 1 + len*2); - ofs = sprintf(new_opt, "opt%u=", code); - bin2hex(new_opt + ofs, (char *)data, len)[0] = '\0'; + new_opt = xmalloc(sizeof("optNNN=") + 1 + opt_item->len*2); + ofs = sprintf(new_opt, "opt%u=", opt_item->code); + bin2hex(new_opt + ofs, (char *)opt_item->data, opt_item->len)[0] = '\0'; } - putenvp(&envp, new_opt); + log2(" %s", new_opt); + putenv(new_opt); + /* putenv will replace the existing environment variable in case of a duplicate. + * Free the previous occurrence (NULL if it's the first one). + */ + free(opt_item->env); + opt_item->env = new_opt; } /* Export BOOTP fields. Fields we don't (yet?) export: @@ -473,41 +543,38 @@ static llist_t *fill_envp(struct dhcp_packet *packet) /* Most important one: yiaddr as $ip */ new_opt = xmalloc(sizeof("ip=255.255.255.255")); sprint_nip(new_opt, "ip=", (uint8_t *) &packet->yiaddr); - putenvp(&envp, new_opt); + putenvp(new_opt); if (packet->siaddr_nip) { /* IP address of next server to use in bootstrap */ new_opt = xmalloc(sizeof("siaddr=255.255.255.255")); sprint_nip(new_opt, "siaddr=", (uint8_t *) &packet->siaddr_nip); - putenvp(&envp, new_opt); + putenvp(new_opt); } if (packet->gateway_nip) { /* IP address of DHCP relay agent */ new_opt = xmalloc(sizeof("giaddr=255.255.255.255")); sprint_nip(new_opt, "giaddr=", (uint8_t *) &packet->gateway_nip); - putenvp(&envp, new_opt); + putenvp(new_opt); } if (!(scan_state.overload & FILE_FIELD) && packet->file[0]) { /* watch out for invalid packets */ new_opt = xasprintf("boot_file=%."DHCP_PKT_FILE_LEN_STR"s", packet->file); - putenvp(&envp, new_opt); + putenvp(new_opt); } if (!(scan_state.overload & SNAME_FIELD) && packet->sname[0]) { /* watch out for invalid packets */ new_opt = xasprintf("sname=%."DHCP_PKT_SNAME_LEN_STR"s", packet->sname); - putenvp(&envp, new_opt); + putenvp(new_opt); } - - return envp; } /* Call a script with a par file and env vars */ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) { - llist_t *envp; char *argv[3]; - envp = fill_envp(packet); + fill_envp(packet); /* call script */ log1("executing %s %s", client_data.script, name); @@ -517,7 +584,8 @@ static void udhcp_run_script(struct dhcp_packet *packet, const char *name) spawn_and_wait(argv); /* Free all allocated environment variables */ - llist_free(envp, (void (*)(void *))bb_unsetenv_and_free); + llist_free(client_data.envp, optitem_unset_env_and_free); + client_data.envp = NULL; } diff --git a/networking/udhcp/dhcpc.h b/networking/udhcp/dhcpc.h index b407a6cdb..7ad01ea8f 100644 --- a/networking/udhcp/dhcpc.h +++ b/networking/udhcp/dhcpc.h @@ -21,6 +21,7 @@ struct client_data_t { uint8_t *vendorclass; /* Optional vendor class-id to use */ uint8_t *hostname; /* Optional hostname to use */ uint8_t *fqdn; /* Optional fully qualified domain name to use */ + llist_t *envp; /* list of DHCP options used for env vars */ unsigned first_secs; unsigned last_secs; -- cgit v1.2.3-55-g6feb From 5c69ad0ecdc18cf51b312c7c82848f4438fe1c8d Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Tue, 4 Aug 2020 08:24:19 +0100 Subject: build system: drop PLATFORM_LINUX PLATFORM_LINUX is a hidden configuration option which is disabled by default and enabled at over a hundred locations for features that are deemed to be Linux specific. The only effect of PLATFORM_LINUX is to control compilation of libbb/match_fstype.c. This file is only needed by mount and umount. Remove all references to PLATFORM_LINUX and compile match_fstype.c if mount or umount is enabled. Signed-off-by: Ron Yorston Signed-off-by: Denys Vlasenko --- Config.in | 12 ------------ configs/android2_defconfig | 1 - configs/android_502_defconfig | 1 - configs/android_defconfig | 1 - configs/android_ndk_defconfig | 1 - configs/cygwin_defconfig | 1 - configs/freebsd_defconfig | 1 - console-tools/chvt.c | 1 - console-tools/deallocvt.c | 1 - console-tools/dumpkmap.c | 1 - console-tools/fgconsole.c | 1 - console-tools/kbd_mode.c | 1 - console-tools/loadfont.c | 2 -- console-tools/loadkmap.c | 1 - console-tools/openvt.c | 1 - console-tools/setconsole.c | 1 - console-tools/setkeycodes.c | 1 - console-tools/setlogcons.c | 1 - console-tools/showkey.c | 1 - coreutils/date.c | 1 - coreutils/stat.c | 1 - e2fsprogs/lsattr.c | 1 - klibc-utils/run-init.c | 1 - libbb/Config.src | 2 -- libbb/Kbuild.src | 3 ++- miscutils/adjtimex.c | 1 - miscutils/beep.c | 1 - miscutils/conspy.c | 1 - miscutils/devfsd.c | 2 -- miscutils/fbsplash.c | 1 - miscutils/hdparm.c | 1 - miscutils/i2c_tools.c | 5 ----- miscutils/lsscsi.c | 1 - miscutils/nandwrite.c | 2 -- miscutils/partprobe.c | 1 - miscutils/raidautorun.c | 1 - miscutils/readahead.c | 1 - miscutils/rfkill.c | 1 - miscutils/rx.c | 1 - miscutils/setserial.c | 1 - miscutils/ubi_tools.c | 6 ------ miscutils/ubirename.c | 1 - miscutils/watchdog.c | 1 - modutils/depmod.c | 1 - modutils/insmod.c | 1 - modutils/lsmod.c | 1 - modutils/modinfo.c | 1 - modutils/modprobe.c | 1 - modutils/rmmod.c | 1 - networking/arp.c | 1 - networking/arping.c | 1 - networking/brctl.c | 1 - networking/ether-wake.c | 1 - networking/ifconfig.c | 1 - networking/ifenslave.c | 1 - networking/ifplugd.c | 1 - networking/ip.c | 7 ------- networking/nameif.c | 1 - networking/netstat.c | 1 - networking/ntpd.c | 1 - networking/ping.c | 1 - networking/route.c | 1 - networking/slattach.c | 1 - networking/traceroute.c | 1 - networking/tunctl.c | 1 - networking/udhcp/Config.src | 2 -- networking/vconfig.c | 1 - networking/zcip.c | 1 - procps/free.c | 1 - procps/ps.c | 1 - procps/uptime.c | 1 - sysklogd/klogd.c | 1 - sysklogd/syslogd.c | 1 - util-linux/acpid.c | 1 - util-linux/blkdiscard.c | 1 - util-linux/blkid.c | 1 - util-linux/dmesg.c | 1 - util-linux/eject.c | 1 - util-linux/fatattr.c | 1 - util-linux/fbset.c | 1 - util-linux/fdformat.c | 1 - util-linux/fdisk.c | 1 - util-linux/findfs.c | 1 - util-linux/freeramdisk.c | 2 -- util-linux/fsfreeze.c | 1 - util-linux/fstrim.c | 1 - util-linux/hwclock.c | 1 - util-linux/ionice.c | 1 - util-linux/ipcs.c | 1 - util-linux/losetup.c | 1 - util-linux/lspci.c | 1 - util-linux/lsusb.c | 1 - util-linux/mdev.c | 1 - util-linux/mkfs_ext2.c | 2 -- util-linux/mkfs_minix.c | 1 - util-linux/mkfs_reiser.c | 1 - util-linux/mkfs_vfat.c | 2 -- util-linux/mount.c | 1 - util-linux/nsenter.c | 1 - util-linux/pivot_root.c | 1 - util-linux/readprofile.c | 1 - util-linux/rtcwake.c | 1 - util-linux/setarch.c | 3 --- util-linux/setpriv.c | 1 - util-linux/swaponoff.c | 2 -- util-linux/switch_root.c | 1 - util-linux/uevent.c | 1 - util-linux/umount.c | 1 - util-linux/unshare.c | 1 - 109 files changed, 2 insertions(+), 146 deletions(-) diff --git a/Config.in b/Config.in index b62b2abb8..ac5b13b8d 100644 --- a/Config.in +++ b/Config.in @@ -312,7 +312,6 @@ config BUSYBOX_EXEC_PATH config SELINUX bool "Support NSA Security Enhanced Linux" default n - select PLATFORM_LINUX help Enable support for SELinux in applets ls, ps, and id. Also provide the option of compiling in SELinux applets. @@ -358,17 +357,6 @@ config FEATURE_SYSLOG #This option is auto-selected when you select any applet which may #send its output to syslog. You do not need to select it manually. -config PLATFORM_LINUX - bool #No description makes it a hidden option - default n - #help - #For the most part, busybox requires only POSIX compatibility - #from the target system, but some applets and features use - #Linux-specific interfaces. - # - #This is automatically selected if any applet or feature requires - #Linux-specific interfaces. You do not need to select it manually. - comment 'Build Options' config STATIC diff --git a/configs/android2_defconfig b/configs/android2_defconfig index 03323654d..d4b8f1616 100644 --- a/configs/android2_defconfig +++ b/configs/android2_defconfig @@ -16,7 +16,6 @@ CONFIG_HAVE_DOT_CONFIG=y # CONFIG_EXTRA_COMPAT is not set # CONFIG_INCLUDE_SUSv2 is not set # CONFIG_USE_PORTABLE_CODE is not set -CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/configs/android_502_defconfig b/configs/android_502_defconfig index 6b640bfb7..503157c12 100644 --- a/configs/android_502_defconfig +++ b/configs/android_502_defconfig @@ -87,7 +87,6 @@ CONFIG_DESKTOP=y # CONFIG_EXTRA_COMPAT is not set CONFIG_INCLUDE_SUSv2=y # CONFIG_USE_PORTABLE_CODE is not set -CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/configs/android_defconfig b/configs/android_defconfig index 3b34f37aa..92a66048a 100644 --- a/configs/android_defconfig +++ b/configs/android_defconfig @@ -16,7 +16,6 @@ CONFIG_DESKTOP=y # CONFIG_EXTRA_COMPAT is not set # CONFIG_INCLUDE_SUSv2 is not set # CONFIG_USE_PORTABLE_CODE is not set -CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/configs/android_ndk_defconfig b/configs/android_ndk_defconfig index 7f65d544c..03d497d2e 100644 --- a/configs/android_ndk_defconfig +++ b/configs/android_ndk_defconfig @@ -16,7 +16,6 @@ CONFIG_DESKTOP=y # CONFIG_EXTRA_COMPAT is not set # CONFIG_INCLUDE_SUSv2 is not set # CONFIG_USE_PORTABLE_CODE is not set -CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/configs/cygwin_defconfig b/configs/cygwin_defconfig index ee370a61d..c09bc9281 100644 --- a/configs/cygwin_defconfig +++ b/configs/cygwin_defconfig @@ -16,7 +16,6 @@ CONFIG_DESKTOP=y # CONFIG_EXTRA_COMPAT is not set CONFIG_INCLUDE_SUSv2=y # CONFIG_USE_PORTABLE_CODE is not set -CONFIG_PLATFORM_LINUX=y CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/configs/freebsd_defconfig b/configs/freebsd_defconfig index 47e705963..6cbd54895 100644 --- a/configs/freebsd_defconfig +++ b/configs/freebsd_defconfig @@ -16,7 +16,6 @@ CONFIG_HAVE_DOT_CONFIG=y # CONFIG_EXTRA_COMPAT is not set CONFIG_INCLUDE_SUSv2=y CONFIG_USE_PORTABLE_CODE=y -# CONFIG_PLATFORM_LINUX is not set CONFIG_FEATURE_BUFFERS_USE_MALLOC=y # CONFIG_FEATURE_BUFFERS_GO_ON_STACK is not set # CONFIG_FEATURE_BUFFERS_GO_IN_BSS is not set diff --git a/console-tools/chvt.c b/console-tools/chvt.c index 75380a90b..7c2814d1c 100644 --- a/console-tools/chvt.c +++ b/console-tools/chvt.c @@ -9,7 +9,6 @@ //config:config CHVT //config: bool "chvt (2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program is used to change to another terminal. //config: Example: chvt 4 (change to terminal /dev/tty4) diff --git a/console-tools/deallocvt.c b/console-tools/deallocvt.c index 05731fb78..6cd54653c 100644 --- a/console-tools/deallocvt.c +++ b/console-tools/deallocvt.c @@ -10,7 +10,6 @@ //config:config DEALLOCVT //config: bool "deallocvt (1.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program deallocates unused virtual consoles. diff --git a/console-tools/dumpkmap.c b/console-tools/dumpkmap.c index fd4fd5623..3d8de6bed 100644 --- a/console-tools/dumpkmap.c +++ b/console-tools/dumpkmap.c @@ -9,7 +9,6 @@ //config:config DUMPKMAP //config: bool "dumpkmap (1.6 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program dumps the kernel's keyboard translation table to //config: stdout, in binary format. You can then use loadkmap to load it. diff --git a/console-tools/fgconsole.c b/console-tools/fgconsole.c index 554a32403..9bfb68017 100644 --- a/console-tools/fgconsole.c +++ b/console-tools/fgconsole.c @@ -9,7 +9,6 @@ //config:config FGCONSOLE //config: bool "fgconsole (1.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program prints active (foreground) console number. diff --git a/console-tools/kbd_mode.c b/console-tools/kbd_mode.c index cee37ab50..b0b963ee0 100644 --- a/console-tools/kbd_mode.c +++ b/console-tools/kbd_mode.c @@ -11,7 +11,6 @@ //config:config KBD_MODE //config: bool "kbd_mode (4.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program reports and sets keyboard mode. diff --git a/console-tools/loadfont.c b/console-tools/loadfont.c index caad7d9ac..7533b0aad 100644 --- a/console-tools/loadfont.c +++ b/console-tools/loadfont.c @@ -12,14 +12,12 @@ //config:config LOADFONT //config: bool "loadfont (5.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program loads a console font from standard input. //config: //config:config SETFONT //config: bool "setfont (24 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Allows to load console screen map. Useful for i18n. //config: diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index 91ef50884..c038e2d22 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c @@ -9,7 +9,6 @@ //config:config LOADKMAP //config: bool "loadkmap (1.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program loads a keyboard translation table from //config: standard input. diff --git a/console-tools/openvt.c b/console-tools/openvt.c index 9e6cffecc..db2f073b2 100644 --- a/console-tools/openvt.c +++ b/console-tools/openvt.c @@ -10,7 +10,6 @@ //config:config OPENVT //config: bool "openvt (7.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program is used to start a command on an unused //config: virtual terminal. diff --git a/console-tools/setconsole.c b/console-tools/setconsole.c index 0bc587241..461a98c6a 100644 --- a/console-tools/setconsole.c +++ b/console-tools/setconsole.c @@ -10,7 +10,6 @@ //config:config SETCONSOLE //config: bool "setconsole (3.6 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Redirect writes to /dev/console to another device, //config: like the current tty while logged in via telnet. diff --git a/console-tools/setkeycodes.c b/console-tools/setkeycodes.c index 259946dbb..5de18b8ea 100644 --- a/console-tools/setkeycodes.c +++ b/console-tools/setkeycodes.c @@ -11,7 +11,6 @@ //config:config SETKEYCODES //config: bool "setkeycodes (2.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program loads entries into the kernel's scancode-to-keycode //config: map, allowing unusual keyboards to generate usable keycodes. diff --git a/console-tools/setlogcons.c b/console-tools/setlogcons.c index 0fad6600a..e9c2f516e 100644 --- a/console-tools/setlogcons.c +++ b/console-tools/setlogcons.c @@ -11,7 +11,6 @@ //config:config SETLOGCONS //config: bool "setlogcons (1.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: This program redirects the output console of kernel messages. diff --git a/console-tools/showkey.c b/console-tools/showkey.c index 8f0e9d938..4d7a9b9e5 100644 --- a/console-tools/showkey.c +++ b/console-tools/showkey.c @@ -9,7 +9,6 @@ //config:config SHOWKEY //config: bool "showkey (4.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Shows keys pressed. diff --git a/coreutils/date.c b/coreutils/date.c index b9b7fd2cb..d84e1c31a 100644 --- a/coreutils/date.c +++ b/coreutils/date.c @@ -37,7 +37,6 @@ //config: bool "Support %[num]N nanosecond format specifier" //config: default n # stat's nanosecond field is a bit non-portable //config: depends on DATE -//config: select PLATFORM_LINUX //config: help //config: Support %[num]N format specifier. Adds ~250 bytes of code. //config: diff --git a/coreutils/stat.c b/coreutils/stat.c index fa9ac7b10..8a23d687b 100644 --- a/coreutils/stat.c +++ b/coreutils/stat.c @@ -31,7 +31,6 @@ //config: bool "Enable display of filesystem status (-f)" //config: default y //config: depends on STAT -//config: select PLATFORM_LINUX # statfs() //config: help //config: Without this, stat will not support the '-f' option to display //config: information about filesystem status. diff --git a/e2fsprogs/lsattr.c b/e2fsprogs/lsattr.c index be1488b79..91205ff65 100644 --- a/e2fsprogs/lsattr.c +++ b/e2fsprogs/lsattr.c @@ -12,7 +12,6 @@ //config:config LSATTR //config: bool "lsattr (5.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: lsattr lists the file attributes on a second extended file system. diff --git a/klibc-utils/run-init.c b/klibc-utils/run-init.c index 77fc0e60c..73c677bab 100644 --- a/klibc-utils/run-init.c +++ b/klibc-utils/run-init.c @@ -8,7 +8,6 @@ //config:config RUN_INIT //config: bool "run-init (7.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The run-init utility is used from initramfs to select a new //config: root device. Under initramfs, you have to use this instead of diff --git a/libbb/Config.src b/libbb/Config.src index 312aa1831..f97de8ef7 100644 --- a/libbb/Config.src +++ b/libbb/Config.src @@ -334,7 +334,6 @@ config FEATURE_VERBOSE_CP_MESSAGE config FEATURE_USE_SENDFILE bool "Use sendfile system call" default y - select PLATFORM_LINUX help When enabled, busybox will use the kernel sendfile() function instead of read/write loops to copy data between file descriptors @@ -376,7 +375,6 @@ config FEATURE_SKIP_ROOTFS config MONOTONIC_SYSCALL bool "Use clock_gettime(CLOCK_MONOTONIC) syscall" default y - select PLATFORM_LINUX help Use clock_gettime(CLOCK_MONOTONIC) syscall for measuring time intervals (time, ping, traceroute etc need this). diff --git a/libbb/Kbuild.src b/libbb/Kbuild.src index 8c9ba8cca..676300801 100644 --- a/libbb/Kbuild.src +++ b/libbb/Kbuild.src @@ -112,7 +112,8 @@ lib-y += xgethostbyname.o lib-y += xreadlink.o lib-y += xrealloc_vector.o -lib-$(CONFIG_PLATFORM_LINUX) += match_fstype.o +lib-$(CONFIG_MOUNT) += match_fstype.o +lib-$(CONFIG_UMOUNT) += match_fstype.o lib-$(CONFIG_FEATURE_UTMP) += utmp.o diff --git a/miscutils/adjtimex.c b/miscutils/adjtimex.c index 8ca90d58a..a9de0f9aa 100644 --- a/miscutils/adjtimex.c +++ b/miscutils/adjtimex.c @@ -13,7 +13,6 @@ //config:config ADJTIMEX //config: bool "adjtimex (4.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Adjtimex reads and optionally sets adjustment parameters for //config: the Linux clock adjustment algorithm. diff --git a/miscutils/beep.c b/miscutils/beep.c index 92faa1cd5..1669332fd 100644 --- a/miscutils/beep.c +++ b/miscutils/beep.c @@ -9,7 +9,6 @@ //config:config BEEP //config: bool "beep (2.4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The beep applets beeps in a given freq/Hz. //config: diff --git a/miscutils/conspy.c b/miscutils/conspy.c index a0e0d4e4b..fac11d339 100644 --- a/miscutils/conspy.c +++ b/miscutils/conspy.c @@ -12,7 +12,6 @@ //config:config CONSPY //config: bool "conspy (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: A text-mode VNC like program for Linux virtual terminals. //config: example: conspy NUM shared access to console num diff --git a/miscutils/devfsd.c b/miscutils/devfsd.c index d47ee4d47..17d8fb6b9 100644 --- a/miscutils/devfsd.c +++ b/miscutils/devfsd.c @@ -56,7 +56,6 @@ //config:config DEVFSD //config: bool "devfsd (obsolete)" //config: default n -//config: select PLATFORM_LINUX //config: select FEATURE_SYSLOG //config: help //config: This is deprecated and should NOT be used anymore. @@ -99,7 +98,6 @@ //config:config FEATURE_DEVFS //config: bool "Use devfs names for all devices (obsolete)" //config: default n -//config: select PLATFORM_LINUX //config: help //config: This is obsolete and should NOT be used anymore. //config: Use linux >= 2.6 (optionally with hotplug) and mdev instead! diff --git a/miscutils/fbsplash.c b/miscutils/fbsplash.c index 141957809..2934d8eb7 100644 --- a/miscutils/fbsplash.c +++ b/miscutils/fbsplash.c @@ -23,7 +23,6 @@ //config:config FBSPLASH //config: bool "fbsplash (26 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Shows splash image and progress bar on framebuffer device. //config: Can be used during boot phase of an embedded device. diff --git a/miscutils/hdparm.c b/miscutils/hdparm.c index beabb1ad5..d25a2466e 100644 --- a/miscutils/hdparm.c +++ b/miscutils/hdparm.c @@ -14,7 +14,6 @@ //config:config HDPARM //config: bool "hdparm (25 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Get/Set hard drive parameters. Primarily intended for ATA //config: drives. diff --git a/miscutils/i2c_tools.c b/miscutils/i2c_tools.c index 82a559f74..cc8b99a92 100644 --- a/miscutils/i2c_tools.c +++ b/miscutils/i2c_tools.c @@ -11,35 +11,30 @@ //config:config I2CGET //config: bool "i2cget (5.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Read from I2C/SMBus chip registers. //config: //config:config I2CSET //config: bool "i2cset (6.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Set I2C registers. //config: //config:config I2CDUMP //config: bool "i2cdump (7.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Examine I2C registers. //config: //config:config I2CDETECT //config: bool "i2cdetect (7.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Detect I2C chips. //config: //config:config I2CTRANSFER //config: bool "i2ctransfer (4.0 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Send user-defined I2C messages in one transfer. //config: diff --git a/miscutils/lsscsi.c b/miscutils/lsscsi.c index 76c281264..8f7eda761 100644 --- a/miscutils/lsscsi.c +++ b/miscutils/lsscsi.c @@ -9,7 +9,6 @@ //config:config LSSCSI //config: bool "lsscsi (2.5 kb)" //config: default y -//config: #select PLATFORM_LINUX //config: help //config: lsscsi is a utility for displaying information about SCSI buses in the //config: system and devices connected to them. diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c index f111c6363..52bf49434 100644 --- a/miscutils/nandwrite.c +++ b/miscutils/nandwrite.c @@ -10,14 +10,12 @@ //config:config NANDWRITE //config: bool "nandwrite (4.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Write to the specified MTD device, with bad blocks awareness //config: //config:config NANDDUMP //config: bool "nanddump (5.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Dump the content of raw NAND chip diff --git a/miscutils/partprobe.c b/miscutils/partprobe.c index 0abed6ff1..0fb1927b7 100644 --- a/miscutils/partprobe.c +++ b/miscutils/partprobe.c @@ -7,7 +7,6 @@ //config:config PARTPROBE //config: bool "partprobe (3.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Ask kernel to rescan partition table. diff --git a/miscutils/raidautorun.c b/miscutils/raidautorun.c index 39816ab1f..905862cf7 100644 --- a/miscutils/raidautorun.c +++ b/miscutils/raidautorun.c @@ -9,7 +9,6 @@ //config:config RAIDAUTORUN //config: bool "raidautorun (1.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: raidautorun tells the kernel md driver to //config: search and start RAID arrays. diff --git a/miscutils/readahead.c b/miscutils/readahead.c index cc0ba5ba3..d2bed2092 100644 --- a/miscutils/readahead.c +++ b/miscutils/readahead.c @@ -13,7 +13,6 @@ //config: bool "readahead (1.5 kb)" //config: default y //config: depends on LFS -//config: select PLATFORM_LINUX //config: help //config: Preload the files listed on the command line into RAM cache so that //config: subsequent reads on these files will not block on disk I/O. diff --git a/miscutils/rfkill.c b/miscutils/rfkill.c index db7c83750..9d91ea82f 100644 --- a/miscutils/rfkill.c +++ b/miscutils/rfkill.c @@ -9,7 +9,6 @@ //config:config RFKILL //config: bool "rfkill (4.4 kb)" //config: default n # doesn't build on Ubuntu 9.04 -//config: select PLATFORM_LINUX //config: help //config: Enable/disable wireless devices. //config: diff --git a/miscutils/rx.c b/miscutils/rx.c index 319ec1d49..d8b041480 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c @@ -17,7 +17,6 @@ //config:config RX //config: bool "rx (2.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Receive files using the Xmodem protocol. diff --git a/miscutils/setserial.c b/miscutils/setserial.c index 71b274568..1e75bf433 100644 --- a/miscutils/setserial.c +++ b/miscutils/setserial.c @@ -10,7 +10,6 @@ //config:config SETSERIAL //config: bool "setserial (6.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Retrieve or set Linux serial port. diff --git a/miscutils/ubi_tools.c b/miscutils/ubi_tools.c index 8318df0f9..94a637eee 100644 --- a/miscutils/ubi_tools.c +++ b/miscutils/ubi_tools.c @@ -6,42 +6,36 @@ //config:config UBIATTACH //config: bool "ubiattach (4.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Attach MTD device to an UBI device. //config: //config:config UBIDETACH //config: bool "ubidetach (4.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Detach MTD device from an UBI device. //config: //config:config UBIMKVOL //config: bool "ubimkvol (5.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Create a UBI volume. //config: //config:config UBIRMVOL //config: bool "ubirmvol (4.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Delete a UBI volume. //config: //config:config UBIRSVOL //config: bool "ubirsvol (4.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Resize a UBI volume. //config: //config:config UBIUPDATEVOL //config: bool "ubiupdatevol (5.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Update a UBI volume. diff --git a/miscutils/ubirename.c b/miscutils/ubirename.c index e7c56640c..06a0adacf 100644 --- a/miscutils/ubirename.c +++ b/miscutils/ubirename.c @@ -9,7 +9,6 @@ //config:config UBIRENAME //config: bool "ubirename (2.4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Utility to rename UBI volumes diff --git a/miscutils/watchdog.c b/miscutils/watchdog.c index 86600b72f..8c8d7217f 100644 --- a/miscutils/watchdog.c +++ b/miscutils/watchdog.c @@ -11,7 +11,6 @@ //config:config WATCHDOG //config: bool "watchdog (5.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The watchdog utility is used with hardware or software watchdog //config: device drivers. It opens the specified watchdog device special file diff --git a/modutils/depmod.c b/modutils/depmod.c index b5244fc60..318e7cdc7 100644 --- a/modutils/depmod.c +++ b/modutils/depmod.c @@ -10,7 +10,6 @@ //config:config DEPMOD //config: bool "depmod (27 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: depmod generates modules.dep (and potentially modules.alias //config: and modules.symbols) that contain dependency information diff --git a/modutils/insmod.c b/modutils/insmod.c index 4dc0b6608..bd79a0f26 100644 --- a/modutils/insmod.c +++ b/modutils/insmod.c @@ -9,7 +9,6 @@ //config:config INSMOD //config: bool "insmod (22 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: insmod is used to load specified modules in the running kernel. diff --git a/modutils/lsmod.c b/modutils/lsmod.c index 39dc8e6b7..2beb12362 100644 --- a/modutils/lsmod.c +++ b/modutils/lsmod.c @@ -10,7 +10,6 @@ //config:config LSMOD //config: bool "lsmod (1.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: lsmod is used to display a list of loaded modules. //config: diff --git a/modutils/modinfo.c b/modutils/modinfo.c index 1e63f745f..c5cdc7980 100644 --- a/modutils/modinfo.c +++ b/modutils/modinfo.c @@ -8,7 +8,6 @@ //config:config MODINFO //config: bool "modinfo (24 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Show information about a Linux Kernel module diff --git a/modutils/modprobe.c b/modutils/modprobe.c index 0a372a049..70c45903a 100644 --- a/modutils/modprobe.c +++ b/modutils/modprobe.c @@ -10,7 +10,6 @@ //config:config MODPROBE //config: bool "modprobe (28 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Handle the loading of modules, and their dependencies on a high //config: level. diff --git a/modutils/rmmod.c b/modutils/rmmod.c index 8d4639f50..2b3c39153 100644 --- a/modutils/rmmod.c +++ b/modutils/rmmod.c @@ -10,7 +10,6 @@ //config:config RMMOD //config: bool "rmmod (3.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: rmmod is used to unload specified modules from the kernel. diff --git a/networking/arp.c b/networking/arp.c index 6519f8156..16783ab95 100644 --- a/networking/arp.c +++ b/networking/arp.c @@ -15,7 +15,6 @@ //config:config ARP //config: bool "arp (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Manipulate the system ARP cache. diff --git a/networking/arping.c b/networking/arping.c index 2a256aaa0..d44d7d697 100644 --- a/networking/arping.c +++ b/networking/arping.c @@ -8,7 +8,6 @@ //config:config ARPING //config: bool "arping (9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Ping hosts by ARP packets. diff --git a/networking/brctl.c b/networking/brctl.c index 2f4ac4a87..f057f9b60 100644 --- a/networking/brctl.c +++ b/networking/brctl.c @@ -12,7 +12,6 @@ //config:config BRCTL //config: bool "brctl (4.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Manage ethernet bridges. //config: Supports addbr/delbr and addif/delif. diff --git a/networking/ether-wake.c b/networking/ether-wake.c index f45d43609..36e90acfb 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c @@ -66,7 +66,6 @@ //config:config ETHER_WAKE //config: bool "ether-wake (4.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Send a magic packet to wake up sleeping machines. diff --git a/networking/ifconfig.c b/networking/ifconfig.c index b566d91a9..3c9a2dfb3 100644 --- a/networking/ifconfig.c +++ b/networking/ifconfig.c @@ -27,7 +27,6 @@ //config:config IFCONFIG //config: bool "ifconfig (12 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Ifconfig is used to configure the kernel-resident network interfaces. //config: diff --git a/networking/ifenslave.c b/networking/ifenslave.c index 5e769b61d..bdb9894be 100644 --- a/networking/ifenslave.c +++ b/networking/ifenslave.c @@ -100,7 +100,6 @@ //config:config IFENSLAVE //config: bool "ifenslave (13 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Userspace application to bind several interfaces //config: to a logical interface (use with kernel bonding driver). diff --git a/networking/ifplugd.c b/networking/ifplugd.c index fa18edd57..0d17b7d8c 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c @@ -9,7 +9,6 @@ //config:config IFPLUGD //config: bool "ifplugd (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Network interface plug detection daemon. diff --git a/networking/ip.c b/networking/ip.c index 45bf1dc0a..7d3faf7f8 100644 --- a/networking/ip.c +++ b/networking/ip.c @@ -11,7 +11,6 @@ //config:config IP //config: bool "ip (35 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The "ip" applet is a TCP/IP interface configuration and routing //config: utility. @@ -23,7 +22,6 @@ //config: bool "ipaddr (14 kb)" //config: default y //config: select FEATURE_IP_ADDRESS -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip addr" //config: @@ -31,7 +29,6 @@ //config: bool "iplink (17 kb)" //config: default y //config: select FEATURE_IP_LINK -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip link" //config: @@ -39,7 +36,6 @@ //config: bool "iproute (15 kb)" //config: default y //config: select FEATURE_IP_ROUTE -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip route" //config: @@ -47,7 +43,6 @@ //config: bool "iptunnel (9.6 kb)" //config: default y //config: select FEATURE_IP_TUNNEL -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip tunnel" //config: @@ -55,7 +50,6 @@ //config: bool "iprule (10 kb)" //config: default y //config: select FEATURE_IP_RULE -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip rule" //config: @@ -63,7 +57,6 @@ //config: bool "ipneigh (8.3 kb)" //config: default y //config: select FEATURE_IP_NEIGH -//config: select PLATFORM_LINUX //config: help //config: Short form of "ip neigh" //config: diff --git a/networking/nameif.c b/networking/nameif.c index 91d50536a..854594c83 100644 --- a/networking/nameif.c +++ b/networking/nameif.c @@ -12,7 +12,6 @@ //config:config NAMEIF //config: bool "nameif (6.6 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select FEATURE_SYSLOG //config: help //config: nameif is used to rename network interface by its MAC address. diff --git a/networking/netstat.c b/networking/netstat.c index c7934423b..936610f89 100644 --- a/networking/netstat.c +++ b/networking/netstat.c @@ -16,7 +16,6 @@ //config:config NETSTAT //config: bool "netstat (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: netstat prints information about the Linux networking subsystem. //config: diff --git a/networking/ntpd.c b/networking/ntpd.c index b08de504e..d721fe80c 100644 --- a/networking/ntpd.c +++ b/networking/ntpd.c @@ -43,7 +43,6 @@ //config:config NTPD //config: bool "ntpd (22 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The NTP client/server daemon. //config: diff --git a/networking/ping.c b/networking/ping.c index a47342fee..47b6ab1b2 100644 --- a/networking/ping.c +++ b/networking/ping.c @@ -27,7 +27,6 @@ //config:config PING //config: bool "ping (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: ping uses the ICMP protocol's mandatory ECHO_REQUEST datagram to //config: elicit an ICMP ECHO_RESPONSE from a host or gateway. diff --git a/networking/route.c b/networking/route.c index e785b1da6..4d9aad6cc 100644 --- a/networking/route.c +++ b/networking/route.c @@ -27,7 +27,6 @@ //config:config ROUTE //config: bool "route (8.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Route displays or manipulates the kernel's IP routing tables. diff --git a/networking/slattach.c b/networking/slattach.c index 659822a91..51fbc1f49 100644 --- a/networking/slattach.c +++ b/networking/slattach.c @@ -15,7 +15,6 @@ //config:config SLATTACH //config: bool "slattach (6.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: slattach configures serial line as SLIP network interface. diff --git a/networking/traceroute.c b/networking/traceroute.c index 06d3f19da..5068f654b 100644 --- a/networking/traceroute.c +++ b/networking/traceroute.c @@ -212,7 +212,6 @@ //config:config TRACEROUTE //config: bool "traceroute (11 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Utility to trace the route of IP packets. //config: diff --git a/networking/tunctl.c b/networking/tunctl.c index a0e3926e9..0f010e196 100644 --- a/networking/tunctl.c +++ b/networking/tunctl.c @@ -12,7 +12,6 @@ //config:config TUNCTL //config: bool "tunctl (6.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: tunctl creates or deletes tun devices. //config: diff --git a/networking/udhcp/Config.src b/networking/udhcp/Config.src index 8ef24748e..7d04bb246 100644 --- a/networking/udhcp/Config.src +++ b/networking/udhcp/Config.src @@ -6,7 +6,6 @@ config UDHCPD bool "udhcpd (21 kb)" default y - select PLATFORM_LINUX help udhcpd is a DHCP server geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. @@ -62,7 +61,6 @@ config DHCPRELAY config UDHCPC bool "udhcpc (24 kb)" default y - select PLATFORM_LINUX help udhcpc is a DHCP client geared primarily toward embedded systems, while striving to be fully functional and RFC compliant. diff --git a/networking/vconfig.c b/networking/vconfig.c index 3cc5f2460..4f1fbe280 100644 --- a/networking/vconfig.c +++ b/networking/vconfig.c @@ -9,7 +9,6 @@ //config:config VCONFIG //config: bool "vconfig (2.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Creates, removes, and configures VLAN interfaces diff --git a/networking/zcip.c b/networking/zcip.c index 134dfb2df..311dfbe4c 100644 --- a/networking/zcip.c +++ b/networking/zcip.c @@ -16,7 +16,6 @@ //config:config ZCIP //config: bool "zcip (8.4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select FEATURE_SYSLOG //config: help //config: ZCIP provides ZeroConf IPv4 address selection, according to RFC 3927. diff --git a/procps/free.c b/procps/free.c index 1e5d36742..b33506b9e 100644 --- a/procps/free.c +++ b/procps/free.c @@ -9,7 +9,6 @@ //config:config FREE //config: bool "free (3.1 kb)" //config: default y -//config: select PLATFORM_LINUX #sysinfo() //config: help //config: free displays the total amount of free and used physical and swap //config: memory in the system, as well as the buffers used by the kernel. diff --git a/procps/ps.c b/procps/ps.c index 815c11578..48f96209f 100644 --- a/procps/ps.c +++ b/procps/ps.c @@ -35,7 +35,6 @@ //config: bool "Enable -o time and -o etime specifiers" //config: default y //config: depends on (PS || MINIPS) && DESKTOP -//config: select PLATFORM_LINUX //config: //config:config FEATURE_PS_UNUSUAL_SYSTEMS //config: bool "Support Linux prior to 2.4.0 and non-ELF systems" diff --git a/procps/uptime.c b/procps/uptime.c index 31581271f..4fd0c9d2d 100644 --- a/procps/uptime.c +++ b/procps/uptime.c @@ -14,7 +14,6 @@ //config:config UPTIME //config: bool "uptime (3.7 kb)" //config: default y -//config: select PLATFORM_LINUX #sysinfo() //config: help //config: uptime gives a one line display of the current time, how long //config: the system has been running, how many users are currently logged diff --git a/sysklogd/klogd.c b/sysklogd/klogd.c index bdd0b6325..c0ec1c0bf 100644 --- a/sysklogd/klogd.c +++ b/sysklogd/klogd.c @@ -33,7 +33,6 @@ //config: bool "Use the klogctl() interface" //config: default y //config: depends on KLOGD -//config: select PLATFORM_LINUX //config: help //config: The klogd applet supports two interfaces for reading //config: kernel messages. Linux provides the klogctl() interface diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index ab50f4a28..f61da9de5 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -109,7 +109,6 @@ //config: bool "Linux kernel printk buffer support" //config: default y //config: depends on SYSLOGD -//config: select PLATFORM_LINUX //config: help //config: When you enable this feature, the syslogd utility will //config: write system log message to the Linux kernel's printk buffer. diff --git a/util-linux/acpid.c b/util-linux/acpid.c index fc8215cce..d473e24fc 100644 --- a/util-linux/acpid.c +++ b/util-linux/acpid.c @@ -9,7 +9,6 @@ //config:config ACPID //config: bool "acpid (9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: acpid listens to ACPI events coming either in textual form from //config: /proc/acpi/event (though it is marked deprecated it is still widely diff --git a/util-linux/blkdiscard.c b/util-linux/blkdiscard.c index a77c7d057..ff2101ed0 100644 --- a/util-linux/blkdiscard.c +++ b/util-linux/blkdiscard.c @@ -8,7 +8,6 @@ //config:config BLKDISCARD //config: bool "blkdiscard (4.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: blkdiscard discards sectors on a given device. diff --git a/util-linux/blkid.c b/util-linux/blkid.c index 008ae5d9e..4a820771f 100644 --- a/util-linux/blkid.c +++ b/util-linux/blkid.c @@ -9,7 +9,6 @@ //config:config BLKID //config: bool "blkid (12 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select VOLUMEID //config: help //config: Lists labels and UUIDs of all filesystems. diff --git a/util-linux/dmesg.c b/util-linux/dmesg.c index a1f269142..dc4e57169 100644 --- a/util-linux/dmesg.c +++ b/util-linux/dmesg.c @@ -11,7 +11,6 @@ //config:config DMESG //config: bool "dmesg (3.7 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: dmesg is used to examine or control the kernel ring buffer. When the //config: Linux kernel prints messages to the system log, they are stored in diff --git a/util-linux/eject.c b/util-linux/eject.c index 3ccb4ae89..29b0a86bd 100644 --- a/util-linux/eject.c +++ b/util-linux/eject.c @@ -15,7 +15,6 @@ //config:config EJECT //config: bool "eject (4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Used to eject cdroms. (defaults to /dev/cdrom) //config: diff --git a/util-linux/fatattr.c b/util-linux/fatattr.c index 770b1d2f9..afd70c45d 100644 --- a/util-linux/fatattr.c +++ b/util-linux/fatattr.c @@ -11,7 +11,6 @@ //config:config FATATTR //config: bool "fatattr (1.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: fatattr lists or changes the file attributes on a fat file system. diff --git a/util-linux/fbset.c b/util-linux/fbset.c index 699a19372..0b9a9a6bc 100644 --- a/util-linux/fbset.c +++ b/util-linux/fbset.c @@ -14,7 +14,6 @@ //config:config FBSET //config: bool "fbset (5.9 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: fbset is used to show or change the settings of a Linux frame buffer //config: device. The frame buffer device provides a simple and unique diff --git a/util-linux/fdformat.c b/util-linux/fdformat.c index e1c8561d6..f0466fdbd 100644 --- a/util-linux/fdformat.c +++ b/util-linux/fdformat.c @@ -8,7 +8,6 @@ //config:config FDFORMAT //config: bool "fdformat (4.4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: fdformat is used to low-level format a floppy disk. diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c index f568fe92c..0fb2e3e17 100644 --- a/util-linux/fdisk.c +++ b/util-linux/fdisk.c @@ -10,7 +10,6 @@ //config:config FDISK //config: bool "fdisk (37 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The fdisk utility is used to divide hard disks into one or more //config: logical disks, which are generally called partitions. This utility diff --git a/util-linux/findfs.c b/util-linux/findfs.c index 7ca9dc96b..f5621a1fa 100644 --- a/util-linux/findfs.c +++ b/util-linux/findfs.c @@ -10,7 +10,6 @@ //config:config FINDFS //config: bool "findfs (12 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select VOLUMEID //config: help //config: Prints the name of a filesystem with given label or UUID. diff --git a/util-linux/freeramdisk.c b/util-linux/freeramdisk.c index d27113d97..309169d25 100644 --- a/util-linux/freeramdisk.c +++ b/util-linux/freeramdisk.c @@ -11,7 +11,6 @@ //config:config FDFLUSH //config: bool "fdflush (1.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: fdflush is only needed when changing media on slightly-broken //config: removable media drives. It is used to make Linux believe that a @@ -24,7 +23,6 @@ //config:config FREERAMDISK //config: bool "freeramdisk (1.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Linux allows you to create ramdisks. This utility allows you to //config: delete them and completely free all memory that was used for the diff --git a/util-linux/fsfreeze.c b/util-linux/fsfreeze.c index fb0b3c4bd..6e2ff0a54 100644 --- a/util-linux/fsfreeze.c +++ b/util-linux/fsfreeze.c @@ -7,7 +7,6 @@ //config:config FSFREEZE //config: bool "fsfreeze (3.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select LONG_OPTS //config: help //config: Halt new accesses and flush writes on a mounted filesystem. diff --git a/util-linux/fstrim.c b/util-linux/fstrim.c index 48948e839..8d29a6d54 100644 --- a/util-linux/fstrim.c +++ b/util-linux/fstrim.c @@ -10,7 +10,6 @@ //config:config FSTRIM //config: bool "fstrim (4.4 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Discard unused blocks on a mounted filesystem. diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index dc97d8fb4..357906cca 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c @@ -9,7 +9,6 @@ //config:config HWCLOCK //config: bool "hwclock (5.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The hwclock utility is used to read and set the hardware clock //config: on a system. This is primarily used to set the current time on diff --git a/util-linux/ionice.c b/util-linux/ionice.c index daf64d537..40c04d5e0 100644 --- a/util-linux/ionice.c +++ b/util-linux/ionice.c @@ -9,7 +9,6 @@ //config:config IONICE //config: bool "ionice (3.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Set/set program io scheduling class and priority //config: Requires kernel >= 2.6.13 diff --git a/util-linux/ipcs.c b/util-linux/ipcs.c index df86cfb9d..ef2529c05 100644 --- a/util-linux/ipcs.c +++ b/util-linux/ipcs.c @@ -10,7 +10,6 @@ //config:config IPCS //config: bool "ipcs (11 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The ipcs utility is used to provide information on the currently //config: allocated System V interprocess (IPC) objects in the system. diff --git a/util-linux/losetup.c b/util-linux/losetup.c index cc6c2b1d5..ac8b79502 100644 --- a/util-linux/losetup.c +++ b/util-linux/losetup.c @@ -9,7 +9,6 @@ //config:config LOSETUP //config: bool "losetup (5.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: losetup is used to associate or detach a loop device with a regular //config: file or block device, and to query the status of a loop device. This diff --git a/util-linux/lspci.c b/util-linux/lspci.c index a6b4e850f..2f0b5fab9 100644 --- a/util-linux/lspci.c +++ b/util-linux/lspci.c @@ -9,7 +9,6 @@ //config:config LSPCI //config: bool "lspci (6.3 kb)" //config: default y -//config: #select PLATFORM_LINUX //config: help //config: lspci is a utility for displaying information about PCI buses in the //config: system and devices connected to them. diff --git a/util-linux/lsusb.c b/util-linux/lsusb.c index e27aa7f31..64a00eee2 100644 --- a/util-linux/lsusb.c +++ b/util-linux/lsusb.c @@ -9,7 +9,6 @@ //config:config LSUSB //config: bool "lsusb (4.2 kb)" //config: default y -//config: #select PLATFORM_LINUX //config: help //config: lsusb is a utility for displaying information about USB buses in the //config: system and devices connected to them. diff --git a/util-linux/mdev.c b/util-linux/mdev.c index 207a112c1..f42bebc20 100644 --- a/util-linux/mdev.c +++ b/util-linux/mdev.c @@ -10,7 +10,6 @@ //config:config MDEV //config: bool "mdev (17 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: mdev is a mini-udev implementation for dynamically creating device //config: nodes in the /dev directory. diff --git a/util-linux/mkfs_ext2.c b/util-linux/mkfs_ext2.c index d568f4be5..1f525d75b 100644 --- a/util-linux/mkfs_ext2.c +++ b/util-linux/mkfs_ext2.c @@ -10,14 +10,12 @@ //config:config MKE2FS //config: bool "mke2fs (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Utility to create EXT2 filesystems. //config: //config:config MKFS_EXT2 //config: bool "mkfs.ext2 (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Alias to "mke2fs". diff --git a/util-linux/mkfs_minix.c b/util-linux/mkfs_minix.c index 8f791cf66..3c72e5419 100644 --- a/util-linux/mkfs_minix.c +++ b/util-linux/mkfs_minix.c @@ -65,7 +65,6 @@ //config:config MKFS_MINIX //config: bool "mkfs.minix (10 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The minix filesystem is a nice, small, compact, read-write filesystem //config: with little overhead. If you wish to be able to create minix diff --git a/util-linux/mkfs_reiser.c b/util-linux/mkfs_reiser.c index d2eaf5f94..44a743147 100644 --- a/util-linux/mkfs_reiser.c +++ b/util-linux/mkfs_reiser.c @@ -9,7 +9,6 @@ //config:config MKFS_REISER //config: bool "mkfs_reiser" //config: default n -//config: select PLATFORM_LINUX //config: help //config: Utility to create ReiserFS filesystems. //config: Note: this applet needs a lot of testing and polishing. diff --git a/util-linux/mkfs_vfat.c b/util-linux/mkfs_vfat.c index 16c1fac00..844d965f8 100644 --- a/util-linux/mkfs_vfat.c +++ b/util-linux/mkfs_vfat.c @@ -10,14 +10,12 @@ //config:config MKDOSFS //config: bool "mkdosfs (7.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Utility to create FAT32 filesystems. //config: //config:config MKFS_VFAT //config: bool "mkfs.vfat (7.2 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Alias to "mkdosfs". diff --git a/util-linux/mount.c b/util-linux/mount.c index 84c85c057..b92e2c297 100644 --- a/util-linux/mount.c +++ b/util-linux/mount.c @@ -20,7 +20,6 @@ //config:config MOUNT //config: bool "mount (23 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: All files and filesystems in Unix are arranged into one big directory //config: tree. The 'mount' utility is used to graft a filesystem onto a diff --git a/util-linux/nsenter.c b/util-linux/nsenter.c index 304f2d748..c48dcf885 100644 --- a/util-linux/nsenter.c +++ b/util-linux/nsenter.c @@ -9,7 +9,6 @@ //config:config NSENTER //config: bool "nsenter (6.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Run program with namespaces of other processes. diff --git a/util-linux/pivot_root.c b/util-linux/pivot_root.c index 41f29da32..ecc891100 100644 --- a/util-linux/pivot_root.c +++ b/util-linux/pivot_root.c @@ -11,7 +11,6 @@ //config:config PIVOT_ROOT //config: bool "pivot_root (1.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The pivot_root utility swaps the mount points for the root filesystem //config: with some other mounted filesystem. This allows you to do all sorts diff --git a/util-linux/readprofile.c b/util-linux/readprofile.c index c4ea374be..32d9987e7 100644 --- a/util-linux/readprofile.c +++ b/util-linux/readprofile.c @@ -34,7 +34,6 @@ //config:config READPROFILE //config: bool "readprofile (7.1 kb)" //config: default y -//config: #select PLATFORM_LINUX //config: help //config: This allows you to parse /proc/profile for basic profiling. diff --git a/util-linux/rtcwake.c b/util-linux/rtcwake.c index cad0f9d64..823e55662 100644 --- a/util-linux/rtcwake.c +++ b/util-linux/rtcwake.c @@ -25,7 +25,6 @@ //config:config RTCWAKE //config: bool "rtcwake (6.8 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Enter a system sleep state until specified wakeup time. diff --git a/util-linux/setarch.c b/util-linux/setarch.c index 57051a683..cf8ef0064 100644 --- a/util-linux/setarch.c +++ b/util-linux/setarch.c @@ -9,7 +9,6 @@ //config:config SETARCH //config: bool "setarch (3.6 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The linux32 utility is used to create a 32bit environment for the //config: specified program (usually a shell). It only makes sense to have @@ -19,14 +18,12 @@ //config:config LINUX32 //config: bool "linux32 (3.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Alias to "setarch linux32". //config: //config:config LINUX64 //config: bool "linux64 (3.3 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Alias to "setarch linux64". diff --git a/util-linux/setpriv.c b/util-linux/setpriv.c index e5cf96957..37e8821a1 100644 --- a/util-linux/setpriv.c +++ b/util-linux/setpriv.c @@ -9,7 +9,6 @@ //config:config SETPRIV //config: bool "setpriv (6.6 kb)" //config: default y -//config: select PLATFORM_LINUX //config: select LONG_OPTS //config: help //config: Run a program with different Linux privilege settings. diff --git a/util-linux/swaponoff.c b/util-linux/swaponoff.c index 567869cc7..e2ff4b5cc 100644 --- a/util-linux/swaponoff.c +++ b/util-linux/swaponoff.c @@ -9,7 +9,6 @@ //config:config SWAPON //config: bool "swapon (15 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: Once you have created some swap space using 'mkswap', you also need //config: to enable your swap space with the 'swapon' utility. The 'swapoff' @@ -36,7 +35,6 @@ //config:config SWAPOFF //config: bool "swapoff (14 kb)" //config: default y -//config: select PLATFORM_LINUX //config: //config:config FEATURE_SWAPONOFF_LABEL //config: bool "Support specifying devices by label or UUID" diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index a483893ed..c65096c27 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c @@ -9,7 +9,6 @@ //config:config SWITCH_ROOT //config: bool "switch_root (5.5 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: The switch_root utility is used from initramfs to select a new //config: root device. Under initramfs, you have to use this instead of diff --git a/util-linux/uevent.c b/util-linux/uevent.c index 7a1d7d4a7..57d9328ef 100644 --- a/util-linux/uevent.c +++ b/util-linux/uevent.c @@ -6,7 +6,6 @@ //config:config UEVENT //config: bool "uevent (3.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: uevent is a netlink listener for kernel uevent notifications //config: sent via netlink. It is usually used for dynamic device creation. diff --git a/util-linux/umount.c b/util-linux/umount.c index 077b635c8..63a3bf504 100644 --- a/util-linux/umount.c +++ b/util-linux/umount.c @@ -10,7 +10,6 @@ //config:config UMOUNT //config: bool "umount (5.1 kb)" //config: default y -//config: select PLATFORM_LINUX //config: help //config: When you want to remove a mounted filesystem from its current mount //config: point, for example when you are shutting down the system, the diff --git a/util-linux/unshare.c b/util-linux/unshare.c index a943e7b03..2087413e8 100644 --- a/util-linux/unshare.c +++ b/util-linux/unshare.c @@ -10,7 +10,6 @@ //config: bool "unshare (7.2 kb)" //config: default y //config: depends on !NOMMU -//config: select PLATFORM_LINUX //config: select LONG_OPTS //config: help //config: Run program with some namespaces unshared from parent. -- cgit v1.2.3-55-g6feb From a77f3ecf68c63081934f5e0800eab80b5098bb24 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 15 Aug 2020 00:39:30 +0200 Subject: grep: for -L, exitcode 0 means files *without* matches were found, closes 13151 This is a recent change in GNU grep as well (after 3.1) function old new delta grep_file 1215 1228 +13 Signed-off-by: Denys Vlasenko --- findutils/grep.c | 29 ++++++++++++++--------------- testsuite/grep.tests | 8 ++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/findutils/grep.c b/findutils/grep.c index 55e9c0a8f..b456ed467 100644 --- a/findutils/grep.c +++ b/findutils/grep.c @@ -167,13 +167,11 @@ enum { OPT_z = IF_EXTRA_COMPAT( (1 << OPTBIT_z)) + 0, }; -#define PRINT_FILES_WITH_MATCHES (option_mask32 & OPT_l) #define PRINT_LINE_NUM (option_mask32 & OPT_n) #define BE_QUIET (option_mask32 & OPT_q) #define SUPPRESS_ERR_MSGS (option_mask32 & OPT_s) #define PRINT_MATCH_COUNTS (option_mask32 & OPT_c) #define FGREP_FLAG (option_mask32 & OPT_F) -#define PRINT_FILES_WITHOUT_MATCHES (option_mask32 & OPT_L) #define NUL_DELIMITED (option_mask32 & OPT_z) struct globals { @@ -476,13 +474,13 @@ static int grep_file(FILE *file) * even if errors were detected" */ exit(EXIT_SUCCESS); } - /* if we're just printing filenames, we stop after the first match */ - if (PRINT_FILES_WITH_MATCHES) { + /* -l "print filenames with matches": stop after the first match */ + if (option_mask32 & OPT_l) { puts(cur_file); - /* fall through to "return 1" */ + return 1; } - /* OPT_L aka PRINT_FILES_WITHOUT_MATCHES: return early */ - return 1; /* one match */ + /* -L "print filenames without matches": return early too */ + return 0; /* 0: we do not print fname, hence it's "not a match" */ } #if ENABLE_FEATURE_GREP_CONTEXT @@ -602,15 +600,16 @@ static int grep_file(FILE *file) printf("%d\n", nmatches); } - /* grep -L: print just the filename */ - if (PRINT_FILES_WITHOUT_MATCHES) { + /* grep -L: "print filenames without matches" */ + if (option_mask32 & OPT_L) { /* nmatches is zero, no need to check it: - * we return 1 early if we detected a match - * and PRINT_FILES_WITHOUT_MATCHES is set */ + * we return 0 early if -L and we detect a match + */ puts(cur_file); + return 1; /* 1: we printed fname, hence it's "a match" */ } - return nmatches; + return nmatches != 0; /* we return not a count, but a boolean */ } #if ENABLE_FEATURE_CLEAN_UP @@ -687,7 +686,7 @@ static int FAST_FUNC file_action_grep(const char *filename, return 0; } cur_file = filename; - *(int*)matched += grep_file(file); + *(int*)matched |= grep_file(file); fclose(file); return 1; } @@ -844,7 +843,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) if (stat(cur_file, &st) == 0 && S_ISDIR(st.st_mode)) { if (!(option_mask32 & OPT_h)) print_filename = 1; - matched += grep_dir(cur_file); + matched |= grep_dir(cur_file); goto grep_done; } } @@ -857,7 +856,7 @@ int grep_main(int argc UNUSED_PARAM, char **argv) continue; } } - matched += grep_file(file); + matched |= grep_file(file); fclose_if_not_stdin(file); grep_done: ; } while (*argv && *++argv); diff --git a/testsuite/grep.tests b/testsuite/grep.tests index e38278810..66498a989 100755 --- a/testsuite/grep.tests +++ b/testsuite/grep.tests @@ -96,6 +96,14 @@ testing "grep -x -F (partial match 1)" "grep -x -F foo input ; echo \$?" \ testing "grep -x -F (partial match 2)" "grep -x -F foo input ; echo \$?" \ "1\n" "bar foo\n" "" +# -L "show filenames which do not match" has inverted exitcode (if it printed something, it's "success") +testing "grep -L exitcode 0" "grep -L qwe input; echo \$?" \ + "input\n0\n" "asd\n" "" +testing "grep -L exitcode 0 #2" "grep -L qwe input -; echo \$?" \ + "(standard input)\n0\n" "qwe\n" "asd\n" +testing "grep -L exitcode 1" "grep -L qwe input; echo \$?" \ + "1\n" "qwe\n" "" + optional EGREP testing "grep -E supports extended regexps" "grep -E fo+" "foo\n" "" \ "b\ar\nfoo\nbaz" -- cgit v1.2.3-55-g6feb From 1a5d6fcbb5e606ab4acdf22afa26361a25f1d43b Mon Sep 17 00:00:00 2001 From: Eddie James Date: Mon, 10 Aug 2020 09:59:02 -0500 Subject: hwclock: Fix settimeofday for glibc v2.31+ The glibc implementation changed for settimeofday, resulting in "invalid argument" error when attempting to set both timezone and time with a single call. Fix this by calling settimeofday twice Signed-off-by: Eddie James Signed-off-by: Denys Vlasenko --- util-linux/hwclock.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/util-linux/hwclock.c b/util-linux/hwclock.c index 357906cca..e85bca2b2 100644 --- a/util-linux/hwclock.c +++ b/util-linux/hwclock.c @@ -121,16 +121,20 @@ static void to_sys_clock(const char **pp_rtcname, int utc) struct timeval tv; struct timezone tz; - tz.tz_minuteswest = timezone/60; + tz.tz_minuteswest = timezone / 60; /* ^^^ used to also subtract 60*daylight, but it's wrong: * daylight!=0 means "this timezone has some DST * during the year", not "DST is in effect now". */ tz.tz_dsttime = 0; + /* glibc v2.31+ returns an error if both args are non-NULL */ + if (settimeofday(NULL, &tz)) + bb_simple_perror_msg_and_die("settimeofday"); + tv.tv_sec = read_rtc(pp_rtcname, NULL, utc); tv.tv_usec = 0; - if (settimeofday(&tv, &tz)) + if (settimeofday(&tv, NULL)) bb_simple_perror_msg_and_die("settimeofday"); } @@ -282,7 +286,11 @@ static void set_system_clock_timezone(int utc) gettimeofday(&tv, NULL); if (!utc) tv.tv_sec += tz.tz_minuteswest * 60; - if (settimeofday(&tv, &tz)) + + /* glibc v2.31+ returns an error if both args are non-NULL */ + if (settimeofday(NULL, &tz)) + bb_simple_perror_msg_and_die("settimeofday"); + if (settimeofday(&tv, NULL)) bb_simple_perror_msg_and_die("settimeofday"); } -- cgit v1.2.3-55-g6feb From b414cdf5b4a3950ac09b630d0d8b7d2844a7cf81 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 9 Aug 2020 01:23:31 +0300 Subject: httpd: Update to HTTP/1.1 HTTP v1.1 was released in 1999 year and it's time to update BB HTTPD. Browsers may behave badly with HTTP/1.0 E.g. Chrome does not send the If-None-Match header with ETag. Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index f4e95768f..9141442c8 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -269,7 +269,7 @@ static const char DEFAULT_PATH_HTTPD_CONF[] ALIGN1 = "/etc"; static const char HTTPD_CONF[] ALIGN1 = "httpd.conf"; -static const char HTTP_200[] ALIGN1 = "HTTP/1.0 200 OK\r\n"; +static const char HTTP_200[] ALIGN1 = "HTTP/1.1 200 OK\r\n"; static const char index_html[] ALIGN1 = "index.html"; typedef struct has_next_ptr { @@ -1074,7 +1074,7 @@ static void send_headers(unsigned responseNum) strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ len = sprintf(iobuf, - "HTTP/1.0 %u %s\r\n" + "HTTP/1.1 %u %s\r\n" "Date: %s\r\n" "Connection: close\r\n", responseNum, responseString, @@ -1099,7 +1099,7 @@ static void send_headers(unsigned responseNum) #endif if (responseNum == HTTP_MOVED_TEMPORARILY) { /* Responding to "GET /dir" with - * "HTTP/1.0 302 Found" "Location: /dir/" + * "HTTP/1.1 302 Found" "Location: /dir/" * - IOW, asking them to repeat with a slash. * Here, overflow IS possible, can't use sprintf: * mkdir test @@ -1409,7 +1409,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post count = safe_read(fromCgi_rd, rbuf + out_cnt, IOBUF_SIZE - 8); if (count <= 0) { /* eof (or error) and there was no "HTTP", - * send "HTTP/1.0 200 OK\r\n", then send received data */ + * send "HTTP/1.1 200 OK\r\n", then send received data */ if (out_cnt) { full_write(STDOUT_FILENO, HTTP_200, sizeof(HTTP_200)-1); full_write(STDOUT_FILENO, rbuf, out_cnt); @@ -1420,10 +1420,10 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post count = 0; /* "Status" header format is: "Status: 302 Redirected\r\n" */ if (out_cnt >= 8 && memcmp(rbuf, "Status: ", 8) == 0) { - /* send "HTTP/1.0 " */ + /* send "HTTP/1.1 " */ if (full_write(STDOUT_FILENO, HTTP_200, 9) != 9) break; - /* skip "Status: " (including space, sending "HTTP/1.0 NNN" is wrong) */ + /* skip "Status: " (including space, sending "HTTP/1.1 NNN" is wrong) */ rbuf += 8; count = out_cnt - 8; out_cnt = -1; /* buffering off */ @@ -1439,7 +1439,7 @@ static NOINLINE void cgi_io_loop_and_exit(int fromCgi_rd, int toCgi_wr, int post full_write(s, "Content-type: text/plain\r\n\r\n", 28); } * Counter-example of valid CGI without Content-type: - * echo -en "HTTP/1.0 302 Found\r\n" + * echo -en "HTTP/1.1 302 Found\r\n" * echo -en "Location: http://www.busybox.net\r\n" * echo -en "\r\n" */ @@ -1546,7 +1546,7 @@ static void send_cgi_and_exit( /* (Older versions of bbox seem to do some decoding) */ setenv1("QUERY_STRING", g_query); putenv((char*)"SERVER_SOFTWARE=busybox httpd/"BB_VER); - putenv((char*)"SERVER_PROTOCOL=HTTP/1.0"); + putenv((char*)"SERVER_PROTOCOL=HTTP/1.1"); putenv((char*)"GATEWAY_INTERFACE=CGI/1.1"); /* Having _separate_ variables for IP and port defeats * the purpose of having socket abstraction. Which "port" -- cgit v1.2.3-55-g6feb From 68f75bb9cecbed3a1bed29219de77373fcba7a88 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 9 Aug 2020 01:23:32 +0300 Subject: httpd: Don't add Date header to response RFC 2616 sec. 14.18 says that server MUST send Date header. But in fact the header make sense only for Cache-Control and can be omitted. In the same time the Date eats power, CPU and network resources which are critical for embedded systems. Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 9141442c8..a1f841aa8 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -214,6 +214,14 @@ //config: help //config: Makes httpd send files using GZIP content encoding if the //config: client supports it and a pre-compressed .gz exists. +//config: +//config:config FEATURE_HTTPD_DATE +//config: bool "Add Date header to response" +//config: default y +//config: depends on HTTPD +//config: help +//config: RFC2616 says that server MUST add Date header to response. +//config: But it is almost useless and can be omitted. //applet:IF_HTTPD(APPLET(httpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -1071,14 +1079,20 @@ static void send_headers(unsigned responseNum) * always fit into those kbytes. */ +#if ENABLE_FEATURE_HTTPD_DATE strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ +#endif len = sprintf(iobuf, "HTTP/1.1 %u %s\r\n" +#if ENABLE_FEATURE_HTTPD_DATE "Date: %s\r\n" +#endif "Connection: close\r\n", - responseNum, responseString, - date_str + responseNum, responseString +#if ENABLE_FEATURE_HTTPD_DATE + ,date_str +#endif ); if (responseNum != HTTP_OK || found_mime_type) { -- cgit v1.2.3-55-g6feb From b6efac31d864cffdf618744fd8a6fddbdee3eb4b Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 9 Aug 2020 01:23:33 +0300 Subject: httpd: Don't add Last-Modified header to response The Last-Modified header is used for caching. The client (browser) will send back the received date to server via If-Modified-Since request header. But both headers MUST be an RFC 1123 formatted string. And the formatting consumes resources on request parsing and response generation. Instead we can use ETag header. This simplifies logic and the only downside is that in JavaScript the document.lastModified will return null. Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index a1f841aa8..94f7297ad 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -215,6 +215,16 @@ //config: Makes httpd send files using GZIP content encoding if the //config: client supports it and a pre-compressed .gz exists. //config: +//config:config FEATURE_HTTPD_LAST_MODIFIED +//config: bool "Add Last-Modified header to response" +//config: default y +//config: depends on HTTPD +//config: help +//config: The Last-Modified header is used for cache validation. +//config: The client sends last seen mtime to server in If-Modified-Since. +//config: Both headers MUST be an RFC 1123 formatted, which is hard to parse. +//config: Use ETag header instead. +//config: //config:config FEATURE_HTTPD_DATE //config: bool "Add Date header to response" //config: default y @@ -1046,11 +1056,12 @@ static void log_and_exit(void) */ static void send_headers(unsigned responseNum) { +#if ENABLE_FEATURE_HTTPD_DATE || ENABLE_FEATURE_HTTPD_LAST_MODIFIED static const char RFC1123FMT[] ALIGN1 = "%a, %d %b %Y %H:%M:%S GMT"; /* Fixed size 29-byte string. Example: Sun, 06 Nov 1994 08:49:37 GMT */ char date_str[40]; /* using a bit larger buffer to paranoia reasons */ - struct tm tm; +#endif const char *responseString = ""; const char *infoString = NULL; #if ENABLE_FEATURE_HTTPD_ERROR_PAGES @@ -1058,7 +1069,6 @@ static void send_headers(unsigned responseNum) #endif unsigned len; unsigned i; - time_t timer = time(NULL); for (i = 0; i < ARRAY_SIZE(http_response_type); i++) { if (http_response_type[i] == responseNum) { @@ -1079,11 +1089,13 @@ static void send_headers(unsigned responseNum) * always fit into those kbytes. */ + { #if ENABLE_FEATURE_HTTPD_DATE - strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); - /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ + time_t timer = time(NULL); + strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&timer, &tm)); + /* ^^^ using gmtime_r() instead of gmtime() to not use static data */ #endif - len = sprintf(iobuf, + len = sprintf(iobuf, "HTTP/1.1 %u %s\r\n" #if ENABLE_FEATURE_HTTPD_DATE "Date: %s\r\n" @@ -1093,7 +1105,8 @@ static void send_headers(unsigned responseNum) #if ENABLE_FEATURE_HTTPD_DATE ,date_str #endif - ); + ); + } if (responseNum != HTTP_OK || found_mime_type) { len += sprintf(iobuf + len, @@ -1145,7 +1158,9 @@ static void send_headers(unsigned responseNum) #endif if (file_size != -1) { /* file */ +#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED strftime(date_str, sizeof(date_str), RFC1123FMT, gmtime_r(&last_mod, &tm)); +#endif #if ENABLE_FEATURE_HTTPD_RANGES if (responseNum == HTTP_PARTIAL_CONTENT) { len += sprintf(iobuf + len, @@ -1190,7 +1205,9 @@ static void send_headers(unsigned responseNum) #if ENABLE_FEATURE_HTTPD_RANGES "Accept-Ranges: bytes\r\n" #endif +#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED "Last-Modified: %s\r\n" +#endif /* Because of 4.4 (5), we can forgo sending of "Content-Length" * since we close connection afterwards, but it helps clients * to e.g. estimate download times, show progress bars etc. @@ -1198,7 +1215,9 @@ static void send_headers(unsigned responseNum) * but de-facto standard is to send it (see comment below). */ "Content-Length: %"OFF_FMT"u\r\n", +#if ENABLE_FEATURE_HTTPD_LAST_MODIFIED date_str, +#endif file_size ); } -- cgit v1.2.3-55-g6feb From 4864a685967bd098307a0d64293b5de1fc5f8210 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sat, 15 Aug 2020 23:52:48 +0200 Subject: httpd: Support caching via ETag header If server responds with ETag then next time client can resend it via If-None-Match header. Then httpd will check if file wasn't modified and if not return 304 Not Modified status code. The ETag value is constructed from file's last modification date in unix epoch and it's size: "hex(last_mod)-hex(file_size)" e.g. "5e132e20-417" (with quotes). That means that it's not completely reliable as hash functions but fair enough. The same form of ETag is used by Nginx so load balancing of static content is safe. function old new delta handle_incoming_and_exit 2135 2201 +66 http_response 88 96 +8 send_headers 676 683 +7 parse_conf 1362 1365 +3 http_response_type 22 24 +2 send_file_and_exit 847 841 -6 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 5/1 up/down: 86/-6) Total: 80 bytes Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 3 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 94f7297ad..0297cf9ec 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -215,6 +215,19 @@ //config: Makes httpd send files using GZIP content encoding if the //config: client supports it and a pre-compressed .gz exists. //config: +//config:config FEATURE_HTTPD_ETAG +//config: bool "Support caching via ETag header" +//config: default y +//config: depends on HTTPD +//config: help +//config: If server responds with ETag then next time client (browser) +//config: resend it via If-None-Match header. +//config: Then httpd will check if file wasn't modified and if not, +//config: return 304 Not Modified status code. +//config: The ETag value is constructed from last modification date +//config: in unix epoch, and size: "hex(last_mod)-hex(file_size)". +//config: It's not completely reliable as hash functions but fair enough. +//config: //config:config FEATURE_HTTPD_LAST_MODIFIED //config: bool "Add Last-Modified header to response" //config: default y @@ -328,6 +341,7 @@ enum { HTTP_OK = 200, HTTP_PARTIAL_CONTENT = 206, HTTP_MOVED_TEMPORARILY = 302, + HTTP_NOT_MODIFIED = 304, HTTP_BAD_REQUEST = 400, /* malformed syntax */ HTTP_UNAUTHORIZED = 401, /* authentication needed, respond with auth hdr */ HTTP_NOT_FOUND = 404, @@ -345,7 +359,6 @@ enum { HTTP_NO_CONTENT = 204, HTTP_MULTIPLE_CHOICES = 300, HTTP_MOVED_PERMANENTLY = 301, - HTTP_NOT_MODIFIED = 304, HTTP_PAYMENT_REQUIRED = 402, HTTP_BAD_GATEWAY = 502, HTTP_SERVICE_UNAVAILABLE = 503, /* overload, maintenance */ @@ -358,6 +371,9 @@ static const uint16_t http_response_type[] ALIGN2 = { HTTP_PARTIAL_CONTENT, #endif HTTP_MOVED_TEMPORARILY, +#if ENABLE_FEATURE_HTTPD_ETAG + HTTP_NOT_MODIFIED, +#endif HTTP_REQUEST_TIMEOUT, HTTP_NOT_IMPLEMENTED, #if ENABLE_FEATURE_HTTPD_BASIC_AUTH @@ -374,7 +390,6 @@ static const uint16_t http_response_type[] ALIGN2 = { HTTP_NO_CONTENT, HTTP_MULTIPLE_CHOICES, HTTP_MOVED_PERMANENTLY, - HTTP_NOT_MODIFIED, HTTP_BAD_GATEWAY, HTTP_SERVICE_UNAVAILABLE, #endif @@ -389,6 +404,9 @@ static const struct { { "Partial Content", NULL }, #endif { "Found", NULL }, +#if ENABLE_FEATURE_HTTPD_ETAG + { "Not Modified" }, +#endif { "Request Timeout", "No request appeared within 60 seconds" }, { "Not Implemented", "The requested method is not recognized" }, #if ENABLE_FEATURE_HTTPD_BASIC_AUTH @@ -405,7 +423,6 @@ static const struct { { "No Content" }, { "Multiple Choices" }, { "Moved Permanently" }, - { "Not Modified" }, { "Bad Gateway", "" }, { "Service Unavailable", "" }, #endif @@ -419,6 +436,9 @@ struct globals { smallint content_gzip; #endif time_t last_mod; +#if ENABLE_FEATURE_HTTPD_ETAG + char *if_none_match; +#endif char *rmt_ip_str; /* for $REMOTE_ADDR and $REMOTE_PORT */ const char *bind_addr_or_port; @@ -453,6 +473,9 @@ struct globals { #define sizeof_hdr_buf COMMON_BUFSIZE char *hdr_ptr; int hdr_cnt; +#if ENABLE_FEATURE_HTTPD_ETAG + char etag[sizeof("'%llx-%llx'") + 2 * sizeof(long long)*3]; +#endif #if ENABLE_FEATURE_HTTPD_ERROR_PAGES const char *http_error_page[ARRAY_SIZE(http_response_type)]; #endif @@ -1208,6 +1231,10 @@ static void send_headers(unsigned responseNum) #if ENABLE_FEATURE_HTTPD_LAST_MODIFIED "Last-Modified: %s\r\n" #endif +#if ENABLE_FEATURE_HTTPD_ETAG + "ETag: %s\r\n" +#endif + /* Because of 4.4 (5), we can forgo sending of "Content-Length" * since we close connection afterwards, but it helps clients * to e.g. estimate download times, show progress bars etc. @@ -1217,6 +1244,9 @@ static void send_headers(unsigned responseNum) "Content-Length: %"OFF_FMT"u\r\n", #if ENABLE_FEATURE_HTTPD_LAST_MODIFIED date_str, +#endif +#if ENABLE_FEATURE_HTTPD_ETAG + G.etag, #endif file_size ); @@ -1730,6 +1760,7 @@ static NOINLINE void send_file_and_exit(const char *url, int what) } } else { fd = open(url, O_RDONLY); + /* file_size and last_mod are already populated */ } if (fd < 0) { if (DEBUG) @@ -1741,6 +1772,19 @@ static NOINLINE void send_file_and_exit(const char *url, int what) send_headers_and_exit(HTTP_NOT_FOUND); log_and_exit(); } +#if ENABLE_FEATURE_HTTPD_ETAG + /* ETag is "hex(last_mod)-hex(file_size)" e.g. "5e132e20-417" */ + sprintf(G.etag, "\"%llx-%llx\"", (unsigned long long)last_mod, (unsigned long long)file_size); + + if (G.if_none_match) { + if (DEBUG) + bb_perror_msg("If-None-Match and file's ETag are: '%s' '%s'\n", G.if_none_match, G.etag); + /* Weak ETag comparision. + * If-None-Match may have many ETags but they are quoted so we can use simple substring search */ + if (strstr(G.if_none_match, G.etag)) + send_headers_and_exit(HTTP_NOT_MODIFIED); + } +#endif /* If you want to know about EPIPE below * (happens if you abort downloads from local httpd): */ signal(SIGPIPE, SIG_IGN); @@ -2480,6 +2524,13 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) continue; } #endif +#if ENABLE_FEATURE_HTTPD_ETAG + if (STRNCASECMP(iobuf, "If-None-Match:") == 0) { + free(G.if_none_match); + G.if_none_match = xstrdup(skip_whitespace(iobuf + sizeof("If-None-Match:") - 1)); + continue; + } +#endif #if ENABLE_FEATURE_HTTPD_CGI if (cgi_type != CGI_NONE) { bool ct = (STRNCASECMP(iobuf, "Content-Type:") == 0); -- cgit v1.2.3-55-g6feb From a949399d178f7b052ada2099c62621736eafce44 Mon Sep 17 00:00:00 2001 From: Sergey Ponomarev Date: Sun, 16 Aug 2020 14:58:31 +0200 Subject: httpd: Make Deny/Allow by IP config support optional When disabled: function old new delta if_ip_denied_send_HTTP_FORBIDDEN_and_exit 52 - -52 handle_incoming_and_exit 2201 2097 -104 scan_ip 170 - -170 parse_conf 1365 1065 -300 ------------------------------------------------------------------------------ (add/remove: 0/2 grow/shrink: 0/2 up/down: 0/-626) Total: -626 bytes Signed-off-by: Sergey Ponomarev Signed-off-by: Denys Vlasenko --- networking/httpd.c | 62 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 44 insertions(+), 18 deletions(-) diff --git a/networking/httpd.c b/networking/httpd.c index 0297cf9ec..2946b2a54 100644 --- a/networking/httpd.c +++ b/networking/httpd.c @@ -245,6 +245,13 @@ //config: help //config: RFC2616 says that server MUST add Date header to response. //config: But it is almost useless and can be omitted. +//config: +//config:config FEATURE_HTTPD_ACL_IP +//config: bool "ACL IP" +//config: default y +//config: depends on HTTPD +//config: help +//config: Support IP deny/allow rules //applet:IF_HTTPD(APPLET(httpd, BB_DIR_USR_SBIN, BB_SUID_DROP)) @@ -314,6 +321,7 @@ typedef struct Htaccess { char before_colon[1]; /* really bigger, must be last */ } Htaccess; +#if ENABLE_FEATURE_HTTPD_ACL_IP /* Must have "next" as a first member */ typedef struct Htaccess_IP { struct Htaccess_IP *next; @@ -321,6 +329,7 @@ typedef struct Htaccess_IP { unsigned mask; int allow_deny; } Htaccess_IP; +#endif /* Must have "next" as a first member */ typedef struct Htaccess_Proxy { @@ -449,7 +458,9 @@ struct globals { const char *found_mime_type; const char *found_moved_temporarily; +#if ENABLE_FEATURE_HTTPD_ACL_IP Htaccess_IP *ip_a_d; /* config allow/deny lines */ +#endif IF_FEATURE_HTTPD_BASIC_AUTH(const char *g_realm;) IF_FEATURE_HTTPD_BASIC_AUTH(char *remoteuser;) @@ -499,7 +510,6 @@ struct globals { #define found_mime_type (G.found_mime_type ) #define found_moved_temporarily (G.found_moved_temporarily) #define last_mod (G.last_mod ) -#define ip_a_d (G.ip_a_d ) #define g_realm (G.g_realm ) #define remoteuser (G.remoteuser ) #define file_size (G.file_size ) @@ -560,11 +570,14 @@ static ALWAYS_INLINE void free_Htaccess_list(Htaccess **pptr) free_llist((has_next_ptr**)pptr); } +#if ENABLE_FEATURE_HTTPD_ACL_IP static ALWAYS_INLINE void free_Htaccess_IP_list(Htaccess_IP **pptr) { free_llist((has_next_ptr**)pptr); } +#endif +#if ENABLE_FEATURE_HTTPD_ACL_IP /* Returns presumed mask width in bits or < 0 on error. * Updates strp, stores IP at provided pointer */ static int scan_ip(const char **strp, unsigned *ipp, unsigned char endc) @@ -649,6 +662,7 @@ static int scan_ip_mask(const char *str, unsigned *ipp, unsigned *maskp) *maskp = (uint32_t)(~mask); return 0; } +#endif /* * Parse configuration file into in-memory linked list. @@ -678,7 +692,9 @@ static void parse_conf(const char *path, int flag) char buf[160]; /* discard old rules */ - free_Htaccess_IP_list(&ip_a_d); +#if ENABLE_FEATURE_HTTPD_ACL_IP + free_Htaccess_IP_list(&G.ip_a_d); +#endif flg_deny_all = 0; /* retain previous auth and mime config only for subdir parse */ if (flag != SUBDIR_PARSE) { @@ -783,6 +799,7 @@ static void parse_conf(const char *path, int flag) continue; } +#if ENABLE_FEATURE_HTTPD_ACL_IP if (ch == 'A' || ch == 'D') { Htaccess_IP *pip; @@ -804,13 +821,13 @@ static void parse_conf(const char *path, int flag) pip->allow_deny = ch; if (ch == 'D') { /* Deny:from_IP - prepend */ - pip->next = ip_a_d; - ip_a_d = pip; + pip->next = G.ip_a_d; + G.ip_a_d = pip; } else { /* A:from_IP - append (thus all D's precedes A's) */ - Htaccess_IP *prev_IP = ip_a_d; + Htaccess_IP *prev_IP = G.ip_a_d; if (prev_IP == NULL) { - ip_a_d = pip; + G.ip_a_d = pip; } else { while (prev_IP->next) prev_IP = prev_IP->next; @@ -819,6 +836,7 @@ static void parse_conf(const char *path, int flag) } continue; } +#endif #if ENABLE_FEATURE_HTTPD_ERROR_PAGES if (flag == FIRST_PARSE && ch == 'E') { @@ -1920,11 +1938,12 @@ static NOINLINE void send_file_and_exit(const char *url, int what) log_and_exit(); } +#if ENABLE_FEATURE_HTTPD_ACL_IP static void if_ip_denied_send_HTTP_FORBIDDEN_and_exit(unsigned remote_ip) { Htaccess_IP *cur; - for (cur = ip_a_d; cur; cur = cur->next) { + for (cur = G.ip_a_d; cur; cur = cur->next) { #if DEBUG fprintf(stderr, "checkPermIP: '%s' ? '%u.%u.%u.%u/%u.%u.%u.%u'\n", @@ -1949,6 +1968,9 @@ static void if_ip_denied_send_HTTP_FORBIDDEN_and_exit(unsigned remote_ip) if (flg_deny_all) /* depends on whether we saw "D:*" */ send_headers_and_exit(HTTP_FORBIDDEN); } +#else +# define if_ip_denied_send_HTTP_FORBIDDEN_and_exit(arg) ((void)0) +#endif #if ENABLE_FEATURE_HTTPD_BASIC_AUTH @@ -2184,7 +2206,9 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) char *urlcopy; char *urlp; char *tptr; +#if ENABLE_FEATURE_HTTPD_ACL_IP unsigned remote_ip; +#endif #if ENABLE_FEATURE_HTTPD_CGI unsigned total_headers_len; #endif @@ -2206,17 +2230,6 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) * (IOW, server process doesn't need to waste 8k) */ iobuf = xmalloc(IOBUF_SIZE); - remote_ip = 0; - if (fromAddr->u.sa.sa_family == AF_INET) { - remote_ip = ntohl(fromAddr->u.sin.sin_addr.s_addr); - } -#if ENABLE_FEATURE_IPV6 - if (fromAddr->u.sa.sa_family == AF_INET6 - && fromAddr->u.sin6.sin6_addr.s6_addr32[0] == 0 - && fromAddr->u.sin6.sin6_addr.s6_addr32[1] == 0 - && ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[2]) == 0xffff) - remote_ip = ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[3]); -#endif if (ENABLE_FEATURE_HTTPD_CGI || DEBUG || verbose) { /* NB: can be NULL (user runs httpd -i by hand?) */ rmt_ip_str = xmalloc_sockaddr2dotted(&fromAddr->u.sa); @@ -2228,7 +2241,20 @@ static void handle_incoming_and_exit(const len_and_sockaddr *fromAddr) if (verbose > 2) bb_simple_error_msg("connected"); } +#if ENABLE_FEATURE_HTTPD_ACL_IP + remote_ip = 0; + if (fromAddr->u.sa.sa_family == AF_INET) { + remote_ip = ntohl(fromAddr->u.sin.sin_addr.s_addr); + } +# if ENABLE_FEATURE_IPV6 + if (fromAddr->u.sa.sa_family == AF_INET6 + && fromAddr->u.sin6.sin6_addr.s6_addr32[0] == 0 + && fromAddr->u.sin6.sin6_addr.s6_addr32[1] == 0 + && ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[2]) == 0xffff) + remote_ip = ntohl(fromAddr->u.sin6.sin6_addr.s6_addr32[3]); +# endif if_ip_denied_send_HTTP_FORBIDDEN_and_exit(remote_ip); +#endif /* Install timeout handler. get_line() needs it. */ signal(SIGALRM, send_REQUEST_TIMEOUT_and_exit); -- cgit v1.2.3-55-g6feb