wdlkmpx | 30 May 15:05 2016
Picon

[PATCH] volume_id: add minix detection

---
 util-linux/volume_id/minix.c              | 71 +++++++++++++++++++++++++
 util-linux/volume_id/unused_minix.c       | 86 -------------------------------
 util-linux/volume_id/volume_id.c          |  2 +-
 util-linux/volume_id/volume_id_internal.h |  2 +-
 4 files changed, 73 insertions(+), 88 deletions(-)
 create mode 100644 util-linux/volume_id/minix.c
 delete mode 100644 util-linux/volume_id/unused_minix.c

diff --git a/util-linux/volume_id/minix.c b/util-linux/volume_id/minix.c
new file mode 100644
index 0000000..f9edf3e
--- /dev/null
+++ b/util-linux/volume_id/minix.c
 <at>  <at>  -0,0 +1,71  <at>  <at> 
+/*
+ * volume_id - reads filesystem label and uuid
+ *
+ * Copyright (C) 2005 Kay Sievers <kay.sievers <at> vrfy.org>
+ *
+ *	This library is free software; you can redistribute it and/or
+ *	modify it under the terms of the GNU Lesser General Public
+ *	License as published by the Free Software Foundation; either
+ *	version 2.1 of the License, or (at your option) any later version.
+ *
+ *	This library is distributed in the hope that it will be useful,
+ *	but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ *	Lesser General Public License for more details.
+ *
(Continue reading)

wdlkmpx | 27 May 18:08 2016
Picon

[PATCH] New applet: vercmp (compare version strings)

Usage: vercmp version1 lt|gt|le|ge|eq version2
return value 0 if true, else 1

It's a shorter version of this:
http://svn.openmoko.org/trunk/src/host/opkg-utils/opkg-compare-versions.c

It produces the same results..

It's meant to work like this:

ver1="3.1.2-9"
ver2="3.1.3-1"

if vercmp ${ver1} gt ${ver2} ; then
    ..actions..
fi

or you can uncomment this line:

//printf("%s\n", res == 0 ? "true" : "false");

Then it will print true or false, it's up to you..

This is just a suggestion in the form of a patch..
---
 miscutils/vercmp.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)
 create mode 100644 miscutils/vercmp.c

diff --git a/miscutils/vercmp.c b/miscutils/vercmp.c
(Continue reading)

James Hanley | 26 May 17:43 2016
Gravatar

Fwd: bug submission failed

Cross posting to the more appropriate list even though Bugzilla recommends the first.

---------- Forwarded message ----------
From: James Hanley <jhanley <at> dgtlrift.com>
Date: Thu, May 26, 2016 at 11:22 AM
Subject: bug submission failed
To: uclibc-admins <at> lists.busybox.net


I'm trying to submit a bug through bugzilla and the server keeps spinning nowhere... the message at the top says:
"This Bugzilla instance has been updated. If you experience troubles, please file a bug, or notify uclibc-admins <at> if that fails."

The bug I'm attempting to file is:
Product: Busybox
Component: Other
Version: 1.24.x
Summary: Bash Compatible sub string of variable when evaluating negative value causes seg fault
Description:
When referencing a sub-string of a variable, using a negative value stored in another variable, the shell will seg-fault.

Steps to reproduce:
/ # s=abcdefg
/ # n=2
/ # echo ${s:$n}
cdefg
/ # n=-2
/ # echo ${s:$n}
Segmentation fault

Expected behavior:
/ # s=abcdefg
/ # n=2
/ # echo ${s:$n}
cdefg
/ # n=-2
/ # echo ${s:$n}
fg



_______________________________________________
busybox mailing list
busybox <at> busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
Yariv Rachmani | 25 May 23:29 2016
Picon

How to enable SCTP in kernel

Hi

I am trying to build Cirros image with busybox. i have to build kernel with SCTP support,

My busybox release is 1.24.1

How do i enable it?



BR Yariv
_______________________________________________
busybox mailing list
busybox <at> busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
Vito Mulè | 25 May 17:24 2016
Picon
Gravatar

[PATCH] bug 8926 - Arping dropping leading 0 from mac address

friendly ping

---------- Forwarded message ----------
From: Vito Mulè <mule.vito <at> gmail.com>
Date: 16 May 2016 at 18:16
Subject: Fwd: bug 8926 - Arping dropping leading 0 from mac address
To: busybox <at> busybox.net


Hello,
not sure if this is necessary since I've opened the bug already, apologies in case it's not.
Bug link: https://bugs.busybox.net/show_bug.cgi?id=8926


Not sure if this is intende but busybox arping is not consistent with arping on linux, printing MAC addressed. root <at> agent4:/home/vmule# arping 192.168.1.159 ARPING 192.168.1.159 60 bytes from 08:00:27:86:47:9d (192.168.1.159): index=0 time=1.002 sec and this is busybox arping root <at> agent4:/home/vmule# busybox arping 192.168.1.159 ARPING to 192.168.1.159 from 192.168.1.157 via eth0 Unicast reply from 192.168.1.159 [8:0:27:86:47:9d] 0.314ms I wrote a small patch to fix it: diff --git a/networking/arping.c b/networking/arping.c index 6b0de4d..2b22451 100644 --- a/networking/arping.c +++ b/networking/arping.c <at> <at> -230,12 +230,15 <at> <at> static void recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) } if (!(option_mask32 & QUIET)) { int s_printed = 0; + struct ether_addr* mac = (struct ether_addr *) p; - printf("%scast re%s from %s [%s]", + printf("%scast re%s from %s [%02x:%02x:%02x:%02x:%02x:%02x] ", FROM->sll_pkttype == PACKET_HOST ? "Uni" : "Broad", ah->ar_op == htons(ARPOP_REPLY) ? "ply" : "quest", inet_ntoa(src_ip), - ether_ntoa((struct ether_addr *) p)); + mac->ether_addr_octet[0], mac->ether_addr_octet[1], + mac->ether_addr_octet[2], mac->ether_addr_octet[3], + mac->ether_addr_octet[4], mac->ether_addr_octet[5]); if (dst_ip.s_addr != src.s_addr) { printf("for %s ", inet_ntoa(dst_ip)); s_printed = 1; <at> <at> -243,8 +246,11 <at> <at> static void recv_pack(unsigned char *buf, int len, struct sockaddr_ll *FROM) if (memcmp(p + ah->ar_hln + 4, me.sll_addr, ah->ar_hln)) { if (!s_printed) printf("for "); - printf("[%s]", - ether_ntoa((struct ether_addr *) p + ah->ar_hln + 4)); + struct ether_addr* mac2 = mac + ah->ar_hln + 4; + printf("[%02x:%02x:%02x:%02x:%02x:%02x]", + mac2->ether_addr_octet[0], mac2->ether_addr_octet[1], + mac2->ether_addr_octet[2], mac2->ether_addr_octet[3], + mac2->ether_addr_octet[4], mac2->ether_addr_octet[5]); } if (last) { Ideas?
Cheers


_______________________________________________
busybox mailing list
busybox <at> busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
wdlkmpx | 22 May 16:26 2016
Picon

[PATCH] (v2) cp: add -u/--update and --remove-destination

This matches the behavior of GNU coreutils cp
when ENABLE_FEATURE_NON_POSIX_CP is not set
and ENABLE_FEATURE_CP_LONG_OPTIONS is defined

The verbose option now shows the same message
when --remove-destination is used

It works the same in most combinations.
Needs more testing to detect issues...
---
 coreutils/cp.c    | 15 ++++++++++++---
 include/libbb.h   |  2 ++
 libbb/copy_file.c | 21 +++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/coreutils/cp.c b/coreutils/cp.c
index 247ed0f..b42c3b2 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
 <at>  <at>  -31,6 +31,7  <at>  <at> 
 //usage:     "\n	-f	Overwrite"
 //usage:     "\n	-i	Prompt before overwrite"
 //usage:     "\n	-l,-s	Create (sym)links"
+//usage:     "\n	-u	Copy if SOURCE file is newer than the destination"

 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
 <at>  <at>  -53,8 +54,10  <at>  <at>  int cp_main(int argc, char **argv)
 		OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
 		OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
 		OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
+		OPT_u = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
-		OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+		OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+		OPT_rmdest  = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+5),
 #endif
 	};

 <at>  <at>  -76,10 +79,12  <at>  <at>  int cp_main(int argc, char **argv)
 		"recursive\0"      No_argument "R"
 		"symbolic-link\0"  No_argument "s"
 		"verbose\0"        No_argument "v"
-		"parents\0"        No_argument "\xff"
+		"update\0"         No_argument "u"
+		"parents\0"        No_argument "\xfe"
+		"remove-destination\0" No_argument "\xff"
 		;
 #endif
-	flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
+	flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPvu");
 	/* Options of cp from GNU coreutils 6.10:
 	 * -a, --archive
 	 * -f, --force
 <at>  <at>  -161,6 +166,10  <at>  <at>  int cp_main(int argc, char **argv)
 				bb_error_msg_and_die("with --parents, the destination must be a directory");
 			}
 		}
+		if (flags & OPT_rmdest) {
+			flags |= FILEUTILS_FORCE;
+			flags |= FILEUTILS_RMDEST;
+		}
 #endif

 		/* ...if neither is a directory...  */
diff --git a/include/libbb.h b/include/libbb.h
index fd40ef7..ece5f32 100644
--- a/include/libbb.h
+++ b/include/libbb.h
 <at>  <at>  -368,6 +368,8  <at>  <at>  enum {	/* DO NOT CHANGE THESE VALUES!  cp.c, mv.c, install.c depend on them. */
 	FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
 	/* -v */
 	FILEUTILS_VERBOSE         = (1 << 12) * ENABLE_FEATURE_VERBOSE,
+	FILEUTILS_UPDATE          = 1 << 13, /* -u */
+	FILEUTILS_RMDEST          = 1 << 14, /* cp --remove-destination */
 };
 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
 extern int remove_file(const char *path, int flags) FAST_FUNC;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4be875..23bcf2e 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
 <at>  <at>  -64,6 +64,11  <at>  <at>  static int ask_and_unlink(const char *dest, int flags)
 		bb_perror_msg("can't create '%s'", dest);
 		return -1; /* error */
 	}
+#if ENABLE_FEATURE_CP_LONG_OPTIONS
+	if (flags & FILEUTILS_RMDEST)
+		if (flags & FILEUTILS_VERBOSE)
+			printf("removed '%s'\n", dest);
+#endif
 	return 1; /* ok (to try again) */
 }

 <at>  <at>  -210,6 +215,22  <at>  <at>  int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
 		goto preserve_mode_ugid_time;
 	}

+	if (dest_exists) {
+		if (flags & FILEUTILS_UPDATE) {
+			if (source_stat.st_mtime <= dest_stat.st_mtime) {
+				return 0; /* source file must be newer */
+			}
+		}
+#if ENABLE_FEATURE_CP_LONG_OPTIONS
+		if (flags & FILEUTILS_RMDEST) {
+			ovr = ask_and_unlink(dest, flags);
+			if (ovr <= 0)
+				return ovr;
+			dest_exists = 0;
+		}
+#endif
+	}
+
 	if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
 		int (*lf)(const char *oldpath, const char *newpath);
  make_links:
--

-- 
2.8.3
wdlkmpx | 22 May 00:13 2016
Picon

[PATCH] cp: add -u/--update and --remove-destination

This matches the behavior of GNU coreutils
---
 coreutils/cp.c    | 14 +++++++++++---
 include/libbb.h   |  2 ++
 libbb/copy_file.c | 22 ++++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/coreutils/cp.c b/coreutils/cp.c
index 247ed0f..cd947be 100644
--- a/coreutils/cp.c
+++ b/coreutils/cp.c
 <at>  <at>  -31,6 +31,7  <at>  <at> 
 //usage:     "\n	-f	Overwrite"
 //usage:     "\n	-i	Prompt before overwrite"
 //usage:     "\n	-l,-s	Create (sym)links"
+//usage:     "\n	-u	Copy if SOURCE file is newer than the destination"

 #include "libbb.h"
 #include "libcoreutils/coreutils.h"
 <at>  <at>  -53,8 +54,10  <at>  <at>  int cp_main(int argc, char **argv)
 		OPT_r = 1 << (sizeof(FILEUTILS_CP_OPTSTR)),
 		OPT_P = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+1),
 		OPT_v = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+2),
+		OPT_u = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
 #if ENABLE_FEATURE_CP_LONG_OPTIONS
-		OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+3),
+		OPT_parents = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+4),
+		OPT_rmdest  = 1 << (sizeof(FILEUTILS_CP_OPTSTR)+5),
 #endif
 	};

 <at>  <at>  -76,10 +79,12  <at>  <at>  int cp_main(int argc, char **argv)
 		"recursive\0"      No_argument "R"
 		"symbolic-link\0"  No_argument "s"
 		"verbose\0"        No_argument "v"
-		"parents\0"        No_argument "\xff"
+		"update\0"         No_argument "u"
+		"parents\0"        No_argument "\xfe"
+		"remove-destination\0" No_argument "\xff"
 		;
 #endif
-	flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPv");
+	flags = getopt32(argv, FILEUTILS_CP_OPTSTR "arPvu");
 	/* Options of cp from GNU coreutils 6.10:
 	 * -a, --archive
 	 * -f, --force
 <at>  <at>  -161,6 +166,9  <at>  <at>  int cp_main(int argc, char **argv)
 				bb_error_msg_and_die("with --parents, the destination must be a directory");
 			}
 		}
+		if (flags & OPT_rmdest) {
+			flags |= FILEUTILS_RMDEST;
+		}
 #endif

 		/* ...if neither is a directory...  */
diff --git a/include/libbb.h b/include/libbb.h
index fd40ef7..ece5f32 100644
--- a/include/libbb.h
+++ b/include/libbb.h
 <at>  <at>  -368,6 +368,8  <at>  <at>  enum {	/* DO NOT CHANGE THESE VALUES!  cp.c, mv.c, install.c depend on them. */
 	FILEUTILS_IGNORE_CHMOD_ERR = 1 << 11,
 	/* -v */
 	FILEUTILS_VERBOSE         = (1 << 12) * ENABLE_FEATURE_VERBOSE,
+	FILEUTILS_UPDATE          = 1 << 13, /* -u */
+	FILEUTILS_RMDEST          = 1 << 14, /* cp --remove-destination */
 };
 #define FILEUTILS_CP_OPTSTR "pdRfilsLH" IF_SELINUX("c")
 extern int remove_file(const char *path, int flags) FAST_FUNC;
diff --git a/libbb/copy_file.c b/libbb/copy_file.c
index a4be875..44031f2 100644
--- a/libbb/copy_file.c
+++ b/libbb/copy_file.c
 <at>  <at>  -208,6 +208,28  <at>  <at>  int FAST_FUNC copy_file(const char *source, const char *dest, int flags)
 			/* retval = -1; - WRONG! copy *WAS* made */
 		}
 		goto preserve_mode_ugid_time;
+	} else {
+		/* Not a directory */
+		if (dest_exists) {
+			if (flags & FILEUTILS_UPDATE) {
+				if (source_stat.st_mtime <= dest_stat.st_mtime) {
+					return 0; /* source file must be newer */
+				}
+			}
+			if (flags & FILEUTILS_RMDEST) {
+				if (unlink(dest) < 0) {
+					if (flags & FILEUTILS_VERBOSE) {
+						printf("can't remove '%s'\n", dest);
+					}
+					return -1;
+				} else {
+					if (flags & FILEUTILS_VERBOSE) {
+						printf("removed '%s'\n", dest);
+					}
+					dest_exists = 0;
+				}
+			}
+		}
 	}

 	if (flags & (FILEUTILS_MAKE_SOFTLINK|FILEUTILS_MAKE_HARDLINK)) {
--

-- 
2.8.3
Ron Yorston | 20 May 14:06 2016
Picon

[PATCH] Make busybox an applet

function                                             old     new   delta
busybox_main                                           -     647    +647
applet_names                                        2536    2544      +8
run_applet_no_and_exit                               451     458      +7
applet_main                                         1468    1472      +4
main                                                 119     120      +1
.rodata                                           147032  147027      -5
packed_usage                                       30751   30738     -13
run_applet_and_exit                                  675      23    -652
------------------------------------------------------------------------------
(add/remove: 2/0 grow/shrink: 4/3 up/down: 667/-670)           Total: -3 bytes

Signed-off-by: Ron Yorston <rmy <at> pobox.com>
---
 Config.in               |  21 +++--
 applets/applet_tables.c |  18 ++--
 include/busybox.h       |   4 -
 libbb/appletlib.c       | 199 ++-----------------------------------------
 libbb/busybox.c         | 220 ++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/trylink         |  20 -----
 6 files changed, 248 insertions(+), 234 deletions(-)
 create mode 100644 libbb/busybox.c

diff --git a/Config.in b/Config.in
index 0a0b5d7..eff733a 100644
--- a/Config.in
+++ b/Config.in
 <at>  <at>  -116,9 +116,21  <at>  <at>  config FEATURE_COMPRESS_USAGE
 	  and have very little memory, this might not be a win. Otherwise,
 	  you probably want this.

+config BUSYBOX
+	bool "Include busybox applet"
+	default y
+	help
+	  The busybox applet provides general help regarding busybox and
+	  allows the included applets to be listed.  It's also required
+	  if applet links are to be installed at runtime.
+
+	  If you can live without these features disabling this will save
+	  some space.
+
 config FEATURE_INSTALLER
 	bool "Support --install [-s] to install applet links at runtime"
 	default y
+	depends on BUSYBOX
 	help
 	  Enable 'busybox --install [-s]' support. This will allow you to use
 	  busybox at runtime to create hard links or symlinks for all the
 <at>  <at>  -577,15 +589,6  <at>  <at>  config FEATURE_INDIVIDUAL

 	  You need to have a working dynamic linker.

-config FEATURE_SHARED_BUSYBOX
-	bool "Produce additional busybox binary linked against libbusybox"
-	default y
-	depends on BUILD_LIBBUSYBOX
-	help
-	  Build busybox, dynamically linked against libbusybox.so.N.N.N.
-
-	  You need to have a working dynamic linker.
-
 ### config BUILD_AT_ONCE
 ###	bool "Compile all sources at once"
 ###	default n
diff --git a/applets/applet_tables.c b/applets/applet_tables.c
index 843f2ec..a2917cd 100644
--- a/applets/applet_tables.c
+++ b/applets/applet_tables.c
 <at>  <at>  -98,8 +98,15  <at>  <at>  int main(int argc, char **argv)
 		printf("#define SINGLE_APPLET_STR \"%s\"\n", applets[0].name);
 		printf("#define SINGLE_APPLET_MAIN %s_main\n", applets[0].main);
 	}
-
 	printf("#define KNOWN_APPNAME_OFFSETS %u\n\n", KNOWN_APPNAME_OFFSETS);
+
+	for (i = 0; i < NUM_APPLETS; i++) {
+		if (str_isalnum_(applets[i].name))
+			printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
+	}
+	printf("\n\n");
+
+	printf("#ifndef SKIP_definitions\n");
 	if (KNOWN_APPNAME_OFFSETS > 0) {
 		int ofs, offset[KNOWN_APPNAME_OFFSETS], index[KNOWN_APPNAME_OFFSETS];
 		for (i = 0; i < KNOWN_APPNAME_OFFSETS; i++)
 <at>  <at>  -120,7 +127,6  <at>  <at>  int main(int argc, char **argv)
 		printf("};\n\n");
 	}

-	//printf("#ifndef SKIP_definitions\n");
 	printf("const char applet_names[] ALIGN1 = \"\"\n");
 	for (i = 0; i < NUM_APPLETS; i++) {
 		printf("\"%s\" \"\\0\"\n", applets[i].name);
 <at>  <at>  -129,12 +135,6  <at>  <at>  int main(int argc, char **argv)
 	}
 	printf(";\n\n");

-	for (i = 0; i < NUM_APPLETS; i++) {
-		if (str_isalnum_(applets[i].name))
-			printf("#define APPLET_NO_%s %d\n", applets[i].name, i);
-	}
-	printf("\n");
-
 	printf("#ifndef SKIP_applet_main\n");
 	printf("int (*const applet_main[])(int argc, char **argv) = {\n");
 	for (i = 0; i < NUM_APPLETS; i++) {
 <at>  <at>  -189,7 +189,7  <at>  <at>  int main(int argc, char **argv)
 	}
 	printf("};\n");
 #endif
-	//printf("#endif /* SKIP_definitions */\n");
+	printf("#endif /* SKIP_definitions */\n");
 //	printf("\n");
 //	printf("#define MAX_APPLET_NAME_LEN %u\n", MAX_APPLET_NAME_LEN);

diff --git a/include/busybox.h b/include/busybox.h
index 737627b..4af6a11 100644
--- a/include/busybox.h
+++ b/include/busybox.h
 <at>  <at>  -44,12 +44,8  <at>  <at>  extern const uint8_t applet_install_loc[] ALIGN1;
  * and "individual" binaries. Keep them short.
  */
 #if ENABLE_BUILD_LIBBUSYBOX
-#if ENABLE_FEATURE_SHARED_BUSYBOX
-int lbb_main(char **argv) EXTERNALLY_VISIBLE;
-#else
 int lbb_main(char **argv);
 #endif
-#endif

 POP_SAVED_FUNCTION_VISIBILITY

diff --git a/libbb/appletlib.c b/libbb/appletlib.c
index b682e6b..4a6ad25 100644
--- a/libbb/appletlib.c
+++ b/libbb/appletlib.c
 <at>  <at>  -655,195 +655,6  <at>  <at>  static void check_suid(int applet_no)
 #  define check_suid(x) ((void)0)
 # endif /* FEATURE_SUID */

-
-# if ENABLE_FEATURE_INSTALLER
-static const char usr_bin [] ALIGN1 = "/usr/bin/";
-static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
-static const char *const install_dir[] = {
-	&usr_bin [8], /* "/" */
-	&usr_bin [4], /* "/bin/" */
-	&usr_sbin[4]  /* "/sbin/" */
-#  if !ENABLE_INSTALL_NO_USR
-	,usr_bin
-	,usr_sbin
-#  endif
-};
-
-/* create (sym)links for each applet */
-static void install_links(const char *busybox, int use_symbolic_links,
-		char *custom_install_dir)
-{
-	/* directory table
-	 * this should be consistent w/ the enum,
-	 * busybox.h::bb_install_loc_t, or else... */
-	int (*lf)(const char *, const char *);
-	char *fpc;
-        const char *appname = applet_names;
-	unsigned i;
-	int rc;
-
-	lf = link;
-	if (use_symbolic_links)
-		lf = symlink;
-
-	for (i = 0; i < ARRAY_SIZE(applet_main); i++) {
-		fpc = concat_path_file(
-				custom_install_dir ? custom_install_dir : install_dir[APPLET_INSTALL_LOC(i)],
-				appname);
-		// debug: bb_error_msg("%slinking %s to busybox",
-		//		use_symbolic_links ? "sym" : "", fpc);
-		rc = lf(busybox, fpc);
-		if (rc != 0 && errno != EEXIST) {
-			bb_simple_perror_msg(fpc);
-		}
-		free(fpc);
-		while (*appname++ != '\0')
-			continue;
-	}
-}
-# else
-static void install_links(const char *busybox UNUSED_PARAM,
-		int use_symbolic_links UNUSED_PARAM,
-		char *custom_install_dir UNUSED_PARAM)
-{
-}
-# endif
-
-/* If we were called as "busybox..." */
-static int busybox_main(char **argv)
-{
-	if (!argv[1]) {
-		/* Called without arguments */
-		const char *a;
-		int col;
-		unsigned output_width;
- help:
-		output_width = 80;
-		if (ENABLE_FEATURE_AUTOWIDTH) {
-			/* Obtain the terminal width */
-			output_width = get_terminal_width(2);
-		}
-
-		dup2(1, 2);
-		full_write2_str(bb_banner); /* reuse const string */
-		full_write2_str(" multi-call binary.\n"); /* reuse */
-		full_write2_str(
-			"BusyBox is copyrighted by many authors between 1998-2015.\n"
-			"Licensed under GPLv2. See source distribution for detailed\n"
-			"copyright notices.\n"
-			"\n"
-			"Usage: busybox [function [arguments]...]\n"
-			"   or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
-			IF_FEATURE_INSTALLER(
-			"   or: busybox --install [-s] [DIR]\n"
-			)
-			"   or: function [arguments]...\n"
-			"\n"
-			IF_NOT_FEATURE_SH_STANDALONE(
-			"\tBusyBox is a multi-call binary that combines many common Unix\n"
-			"\tutilities into a single executable.  Most people will create a\n"
-			"\tlink to busybox for each function they wish to use and BusyBox\n"
-			"\twill act like whatever it was invoked as.\n"
-			)
-			IF_FEATURE_SH_STANDALONE(
-			"\tBusyBox is a multi-call binary that combines many common Unix\n"
-			"\tutilities into a single executable.  The shell in this build\n"
-			"\tis configured to run built-in utilities without $PATH search.\n"
-			"\tYou don't need to install a link to busybox for each utility.\n"
-			"\tTo run external program, use full path (/sbin/ip instead of ip).\n"
-			)
-			"\n"
-			"Currently defined functions:\n"
-		);
-		col = 0;
-		a = applet_names;
-		/* prevent last comma to be in the very last pos */
-		output_width--;
-		while (*a) {
-			int len2 = strlen(a) + 2;
-			if (col >= (int)output_width - len2) {
-				full_write2_str(",\n");
-				col = 0;
-			}
-			if (col == 0) {
-				col = 6;
-				full_write2_str("\t");
-			} else {
-				full_write2_str(", ");
-			}
-			full_write2_str(a);
-			col += len2;
-			a += len2 - 1;
-		}
-		full_write2_str("\n\n");
-		return 0;
-	}
-
-	if (is_prefixed_with(argv[1], "--list")) {
-		unsigned i = 0;
-		const char *a = applet_names;
-		dup2(1, 2);
-		while (*a) {
-# if ENABLE_FEATURE_INSTALLER
-			if (argv[1][6]) /* --list-full? */
-				full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
-# endif
-			full_write2_str(a);
-			full_write2_str("\n");
-			i++;
-			while (*a++ != '\0')
-				continue;
-		}
-		return 0;
-	}
-
-	if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
-		int use_symbolic_links;
-		const char *busybox;
-
-		busybox = xmalloc_readlink(bb_busybox_exec_path);
-		if (!busybox) {
-			/* bb_busybox_exec_path is usually "/proc/self/exe".
-			 * In chroot, readlink("/proc/self/exe") usually fails.
-			 * In such case, better use argv[0] as symlink target
-			 * if it is a full path name.
-			 */
-			if (argv[0][0] != '/')
-				bb_error_msg_and_die("'%s' is not an absolute path", argv[0]);
-			busybox = argv[0];
-		}
-		/* busybox --install [-s] [DIR]:
-		 * -s: make symlinks
-		 * DIR: directory to install links to
-		 */
-		use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
-		install_links(busybox, use_symbolic_links, argv[2]);
-		return 0;
-	}
-
-	if (strcmp(argv[1], "--help") == 0) {
-		/* "busybox --help [<applet>]" */
-		if (!argv[2])
-			goto help;
-		/* convert to "<applet> --help" */
-		argv[0] = argv[2];
-		argv[2] = NULL;
-	} else {
-		/* "busybox <applet> arg1 arg2 ..." */
-		argv++;
-	}
-	/* We support "busybox /a/path/to/applet args..." too. Allows for
-	 * "#!/bin/busybox"-style wrappers */
-	applet_name = bb_get_last_path_component_nostrip(argv[0]);
-	run_applet_and_exit(applet_name, argv);
-
-	/*bb_error_msg_and_die("applet not found"); - sucks in printf */
-	full_write2_str(applet_name);
-	full_write2_str(": applet not found\n");
-	/* POSIX: "If a command is not found, the exit status shall be 127" */
-	exit(127);
-}
-
 void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
 {
 	int argc = 1;
 <at>  <at>  -870,6 +681,9  <at>  <at>  void FAST_FUNC run_applet_no_and_exit(int applet_no, char **argv)
 #if defined APPLET_NO_false
 	 && applet_no != APPLET_NO_false
 #endif
+#if defined APPLET_NO_busybox
+	 && applet_no != APPLET_NO_busybox
+#endif
 	) {
 		if (argc == 2 && strcmp(argv[1], "--help") == 0) {
 			/* Make "foo --help" exit with 0: */
 <at>  <at>  -886,9 +700,6  <at>  <at>  void FAST_FUNC run_applet_and_exit(const char *name, char **argv)
 {
 	int applet;

-	if (is_prefixed_with(name, "busybox"))
-		exit(busybox_main(argv));
-	/* find_applet_by_name() search is more expensive, so goes second */
 	applet = find_applet_by_name(name);
 	if (applet >= 0)
 		run_applet_no_and_exit(applet, argv);
 <at>  <at>  -952,6 +763,10  <at>  <at>  int main(int argc UNUSED_PARAM, char **argv)
 #else
 	lbb_prepare("busybox" IF_FEATURE_INDIVIDUAL(, argv));

+#if !defined(CONFIG_BUSYBOX)
+	if (argv[1] && is_prefixed_with(bb_basename(argv[0]), "busybox"))
+		argv++;
+#endif
 	applet_name = argv[0];
 	if (applet_name[0] == '-')
 		applet_name++;
diff --git a/libbb/busybox.c b/libbb/busybox.c
new file mode 100644
index 0000000..368cd55
--- /dev/null
+++ b/libbb/busybox.c
 <at>  <at>  -0,0 +1,220  <at>  <at> 
+/* vi: set sw=4 ts=4: */
+/*
+ * busybox applet
+ *
+ * Copyright (C) tons of folks.  Tracking down who wrote what
+ * isn't something I'm going to worry about...  If you wrote something
+ * here, please feel free to acknowledge your work.
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this source tree.
+ */
+
+#include "busybox.h"
+#define SKIP_definitions
+#include "applet_tables.h"
+
+//applet:IF_BUSYBOX(APPLET(busybox, BB_DIR_USR_BIN, BB_SUID_DROP))
+
+//kbuild:lib-$(CONFIG_BUSYBOX) += busybox.o
+
+//usage:#define busybox_trivial_usage
+//usage:       ""
+//usage:#define busybox_full_usage
+//usage:       ""
+
+# if ENABLE_FEATURE_INSTALLER
+static const char usr_bin [] ALIGN1 = "/usr/bin/";
+static const char usr_sbin[] ALIGN1 = "/usr/sbin/";
+static const char *const install_dir[] = {
+	&usr_bin [8], /* "/" */
+	&usr_bin [4], /* "/bin/" */
+	&usr_sbin[4]  /* "/sbin/" */
+#  if !ENABLE_INSTALL_NO_USR
+	,usr_bin
+	,usr_sbin
+#  endif
+};
+
+/* create (sym)links for each applet */
+static void install_links(const char *busybox, int use_symbolic_links,
+		char *custom_install_dir)
+{
+	/* directory table
+	 * this should be consistent w/ the enum,
+	 * busybox.h::bb_install_loc_t, or else... */
+	int (*lf)(const char *, const char *);
+	char *fpc;
+        const char *appname = applet_names;
+	unsigned i;
+	int rc;
+
+	lf = link;
+	if (use_symbolic_links)
+		lf = symlink;
+
+	for (i = 0; i < NUM_APPLETS; i++) {
+#if defined APPLET_NO_busybox
+		if (i == APPLET_NO_busybox)
+			goto skip_name;
+#endif
+		fpc = concat_path_file(
+				custom_install_dir ? custom_install_dir : install_dir[APPLET_INSTALL_LOC(i)],
+				appname);
+		// debug: bb_error_msg("%slinking %s to busybox",
+		//		use_symbolic_links ? "sym" : "", fpc);
+		rc = lf(busybox, fpc);
+		if (rc != 0 && errno != EEXIST) {
+			bb_simple_perror_msg(fpc);
+		}
+		free(fpc);
+ skip_name:
+		while (*appname++ != '\0')
+			continue;
+	}
+}
+# else
+static void install_links(const char *busybox UNUSED_PARAM,
+		int use_symbolic_links UNUSED_PARAM,
+		char *custom_install_dir UNUSED_PARAM)
+{
+}
+# endif
+
+int busybox_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
+int busybox_main(int argc UNUSED_PARAM, char **argv)
+{
+	if (!argv[1]) {
+		/* Called without arguments */
+		const char *a;
+		int col;
+		unsigned output_width;
+ help:
+		output_width = 80;
+		if (ENABLE_FEATURE_AUTOWIDTH) {
+			/* Obtain the terminal width */
+			output_width = get_terminal_width(2);
+		}
+
+		dup2(1, 2);
+		full_write2_str(bb_banner); /* reuse const string */
+		full_write2_str(" multi-call binary.\n"); /* reuse */
+		full_write2_str(
+			"BusyBox is copyrighted by many authors between 1998-2015.\n"
+			"Licensed under GPLv2. See source distribution for detailed\n"
+			"copyright notices.\n"
+			"\n"
+			"Usage: busybox [function [arguments]...]\n"
+			"   or: busybox --list"IF_FEATURE_INSTALLER("[-full]")"\n"
+			IF_FEATURE_INSTALLER(
+			"   or: busybox --install [-s] [DIR]\n"
+			)
+			"   or: function [arguments]...\n"
+			"\n"
+			IF_NOT_FEATURE_SH_STANDALONE(
+			"\tBusyBox is a multi-call binary that combines many common Unix\n"
+			"\tutilities into a single executable.  Most people will create a\n"
+			"\tlink to busybox for each function they wish to use and BusyBox\n"
+			"\twill act like whatever it was invoked as.\n"
+			)
+			IF_FEATURE_SH_STANDALONE(
+			"\tBusyBox is a multi-call binary that combines many common Unix\n"
+			"\tutilities into a single executable.  The shell in this build\n"
+			"\tis configured to run built-in utilities without $PATH search.\n"
+			"\tYou don't need to install a link to busybox for each utility.\n"
+			"\tTo run external program, use full path (/sbin/ip instead of ip).\n"
+			)
+			"\n"
+			"Currently defined functions:\n"
+		);
+		col = 0;
+		a = applet_names;
+		/* prevent last comma to be in the very last pos */
+		output_width--;
+		while (*a) {
+			int len2 = strlen(a) + 2;
+			if (col >= (int)output_width - len2) {
+				full_write2_str(",\n");
+				col = 0;
+			}
+			if (col == 0) {
+				col = 6;
+				full_write2_str("\t");
+			} else {
+				full_write2_str(", ");
+			}
+			full_write2_str(a);
+			col += len2;
+			a += len2 - 1;
+		}
+		full_write2_str("\n\n");
+		return 0;
+	}
+
+	if (is_prefixed_with(argv[1], "--list")) {
+		unsigned i = 0;
+		const char *a = applet_names;
+		dup2(1, 2);
+		while (*a) {
+			if (ENABLE_FEATURE_INSTALLER && argv[1][6]) { /* --list-full? */
+#if defined APPLET_NO_busybox
+				if (i == APPLET_NO_busybox)
+					goto skip_name;
+#endif
+				full_write2_str(install_dir[APPLET_INSTALL_LOC(i)] + 1);
+			}
+			full_write2_str(a);
+			full_write2_str("\n");
+ skip_name:
+			i++;
+			while (*a++ != '\0')
+				continue;
+		}
+		return 0;
+	}
+
+	if (ENABLE_FEATURE_INSTALLER && strcmp(argv[1], "--install") == 0) {
+		int use_symbolic_links;
+		const char *busybox;
+
+		busybox = xmalloc_readlink(bb_busybox_exec_path);
+		if (!busybox) {
+			/* bb_busybox_exec_path is usually "/proc/self/exe".
+			 * In chroot, readlink("/proc/self/exe") usually fails.
+			 * In such case, better use argv[0] as symlink target
+			 * if it is a full path name.
+			 */
+			if (argv[0][0] != '/')
+				bb_error_msg_and_die("'%s' is not an absolute path", argv[0]);
+			busybox = argv[0];
+		}
+		/* busybox --install [-s] [DIR]:
+		 * -s: make symlinks
+		 * DIR: directory to install links to
+		 */
+		use_symbolic_links = (argv[2] && strcmp(argv[2], "-s") == 0 && ++argv);
+		install_links(busybox, use_symbolic_links, argv[2]);
+		return 0;
+	}
+
+	if (strcmp(argv[1], "--help") == 0) {
+		/* "busybox --help [<applet>]" */
+		if (!argv[2])
+			goto help;
+		/* convert to "<applet> --help" */
+		argv[0] = argv[2];
+		argv[2] = NULL;
+	} else {
+		/* "busybox <applet> arg1 arg2 ..." */
+		argv++;
+	}
+	/* We support "busybox /a/path/to/applet args..." too. Allows for
+	 * "#!/bin/busybox"-style wrappers */
+	applet_name = bb_get_last_path_component_nostrip(argv[0]);
+	run_applet_and_exit(applet_name, argv);
+
+	/*bb_error_msg_and_die("applet not found"); - sucks in printf */
+	full_write2_str(applet_name);
+	full_write2_str(": applet not found\n");
+	/* POSIX: "If a command is not found, the exit status shall be 127" */
+	exit(127);
+}
diff --git a/scripts/trylink b/scripts/trylink
index 129570a..daa8c1f 100755
--- a/scripts/trylink
+++ b/scripts/trylink
 <at>  <at>  -269,26 +269,6  <at>  <at>  if test "$CONFIG_BUILD_LIBBUSYBOX" = y; then
     echo "libbusybox: $sharedlib_dir/libbusybox.so.$BB_VER"
 fi

-if test "$CONFIG_FEATURE_SHARED_BUSYBOX" = y; then
-    EXE="$sharedlib_dir/busybox_unstripped"
-    try $CC $CFLAGS $LDFLAGS \
-	    -o $EXE \
-	    $SORT_COMMON \
-	    $SORT_SECTION \
-	    $GC_SECTIONS \
-	    $START_GROUP $O_FILES $END_GROUP \
-	    -L"$sharedlib_dir" -lbusybox \
-	    $l_list \
-	    $INFO_OPTS \
-    || {
-	echo "Linking $EXE failed"
-	cat $EXE.out
-	exit 1
-    }
-    $STRIP -s --remove-section=.note --remove-section=.comment $EXE -o "$sharedlib_dir/busybox"
-    echo "busybox linked against libbusybox: $sharedlib_dir/busybox"
-fi
-
 if test "$CONFIG_FEATURE_INDIVIDUAL" = y; then
     echo "Linking individual applets against libbusybox (see $sharedlib_dir/*)"
     gcc -DNAME_MAIN -E -include include/autoconf.h include/applets.h \
--

-- 
2.5.5
Ron Yorston | 20 May 14:06 2016
Picon

Should busybox be an applet?

Yesterday I sent a patch which treated the busybox command as if it were
a built-in applet in standalone shell mode.  It's a bit annoying to have
this as a special case.  I wondered what would happen if I turned the code
to handle 'busybox --list' and 'busybox --install' into an actual applet.

It works, but I ended up with different special cases to filter busybox
out of 'busybox --list-all' and 'busybox --install'.  Then again, you
can save lots of space by disabling the busybox applet if you don't need
it ;-)

Ron
Natanael Copa | 19 May 16:54 2016
Gravatar

[PATCH] libbb: fix time parsing of [[CC]YY]MMDDhhmm[.SS]

If SS is not given a value, it is assumed to be zero.
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/touch.html

closes 8951

Signed-off-by: Natanael Copa <ncopa <at> alpinelinux.org>
---
 libbb/time.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/libbb/time.c b/libbb/time.c
index aa19a47..44dd4aa 100644
--- a/libbb/time.c
+++ b/libbb/time.c
 <at>  <at>  -159,6 +159,8  <at>  <at>  void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
 					&ptm->tm_hour,
 					&ptm->tm_min,
 					&end) >= 5) {
+			/* assume zero if [.SS] is not given */
+			ptm->tm_sec = 0;
 			/* Adjust month from 1-12 to 0-11 */
 			ptm->tm_mon -= 1;
 			if ((int)cur_year >= 50) { /* >= 1950 */
 <at>  <at>  -181,6 +183,8  <at>  <at>  void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
 					&ptm->tm_hour,
 					&ptm->tm_min,
 					&end) >= 5) {
+			/* assume zero if [.SS] is not given */
+			ptm->tm_sec = 0;
 			ptm->tm_year -= 1900; /* Adjust years */
 			ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
 		} else {
--

-- 
2.8.2
Ron Yorston | 19 May 12:55 2016
Picon

[PATCH] lineedit: tweak tab completion of commands in standalone shell mode

When tab-completing commands in standalone shell mode:

  don't search the list of applet names if the command includes a
  path separator;

  since "busybox" doesn't appear in the list of applet names check
  for it separately.

function                                             old     new   delta
add_partial_match                                      -      33     +33
complete_cmd_dir_file                                705     708      +3
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 1/0 up/down: 36/0)               Total: 36 bytes

Signed-off-by: Ron Yorston <rmy <at> pobox.com>
---
 libbb/lineedit.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/libbb/lineedit.c b/libbb/lineedit.c
index 3e62f46..6e9f655 100644
--- a/libbb/lineedit.c
+++ b/libbb/lineedit.c
 <at>  <at>  -637,6 +637,14  <at>  <at>  static void add_match(char *matched)
 	num_matches++;
 }

+#if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1
+static void add_partial_match(const char *part, const char *full, int plen)
+{
+	if (strncmp(part, full, plen) == 0)
+		add_match(xstrdup(full));
+}
+#endif
+
 # if ENABLE_FEATURE_USERNAME_COMPLETION
 /* Replace "~user/..." with "/homedir/...".
  * The parameter is malloced, free it or return it
 <at>  <at>  -776,15 +784,15  <at>  <at>  static NOINLINE unsigned complete_cmd_dir_file(const char *command, int type)
 	pf_len = strlen(pfind);

 #if ENABLE_FEATURE_SH_STANDALONE && NUM_APPLETS != 1
-	if (type == FIND_EXE_ONLY) {
+	if (type == FIND_EXE_ONLY && dirbuf == NULL) {
 		const char *p = applet_names;

 		while (*p) {
-			if (strncmp(pfind, p, pf_len) == 0)
-				add_match(xstrdup(p));
+			add_partial_match(pfind, p, pf_len);
 			while (*p++ != '\0')
 				continue;
 		}
+		add_partial_match(pfind, "busybox", pf_len);
 	}
 #endif

--

-- 
2.5.5

Gmane