Re: Add possiblity to support specifying desired section of manpage

2020-12-21 Thread depsterr
My sincerest apologies, but it seems I've noticed yet another typo. There was 
an = where there should have been an |= resulting in an error message when 
looking at all pages (-a).

I am confident this is the final revision of the patch I will have to submit.

Again, apologies about sending multiple messages. Next time I'll test more 
thoroughly before submitting a patch.


‐‐‐ Original Message ‐‐‐
On Tuesday, December 22, 2020 3:19 AM, depsterr  wrote:

> Just noticed the double which in my description!
>
> Here is an updated patch without it!
>
> Apologies!
>
> ‐‐‐ Original Message ‐‐‐
> On Tuesday, December 22, 2020 3:10 AM, depsterr depst...@protonmail.com wrote:
>
> > Hello!
> > I've used and loved busybox for a while now, however something which has 
> > always bothered me has been the inability to specify from which section to 
> > grab a man page, so I've devised a patch to fix this!
> > This patch adds an option called "Support specifying section of page" 
> > (which depends on man). If enabled it "Lets the user specify which from 
> > which section they would like to retrieve their manpage from." - the help 
> > message for the option.
> > In practice this is done as such:
> > Usage: man [-aw] MANPAGE[.SECTION]...
> > This works perfectly with both existing flags and does not effect the 
> > behavior of man when disabled.
> > patch file is in attachments!

From a32123126a1a7950f8697234c4e7fb90b5d3dd4f Mon Sep 17 00:00:00 2001
From: depsterr 
Date: Tue, 22 Dec 2020 03:36:23 +0100
Subject: [PATCH] Added option to support specifying section of manpage

---
 miscutils/man.c | 73 +
 1 file changed, 55 insertions(+), 18 deletions(-)

diff --git a/miscutils/man.c b/miscutils/man.c
index 61086612a..d43a715e9 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -7,13 +7,20 @@
 //config:	default y
 //config:	help
 //config:	Format and display manual pages.
+//config:config FEATURE_MAN_SPECIFY_SECTION
+//config:	bool "Support specifying section of page"
+//config:	default y
+//config:	depends on MAN
+//config:	help
+//config:	Lets the user specify from which section they would
+//config:	like to retrieve their manpage from.
 
 //applet:IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_MAN) += man.o
 
 //usage:#define man_trivial_usage
-//usage:   "[-aw] MANPAGE..."
+//usage:   "[-aw] MANPAGE" IF_FEATURE_MAN_SPECIFY_SECTION("[.SECTION]") "..."
 //usage:#define man_full_usage "\n\n"
 //usage:   "Display manual page\n"
 //usage: "\n	-a	Display all pages"
@@ -240,6 +247,25 @@ static const char *if_redefined(const char *var, const char *key, const char *li
 	return xstrdup(skip_whitespace(line));
 }
 
+static const char check_path(const char* cur_path, const char* cur_sect, int sect_len, const char* man_name)
+{
+	char *man_filename;
+	int cat0man1 = 0;
+	int ret = 0;
+	while (cat0man1 < 2) {
+		man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
+cur_path,
+"cat\0man" + (cat0man1 * 4),
+sect_len, cur_sect,
+man_name,
+sect_len, cur_sect);
+		ret = show_manpage(man_filename, cat0man1, 0);
+		cat0man1 += ret + 1;
+		free(man_filename);
+	}
+	return ret;
+}
+
 int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int man_main(int argc UNUSED_PARAM, char **argv)
 {
@@ -316,35 +342,41 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		const char *cur_path;
 		int cur_mp;
 		int found = 0;
+		int sect_len;
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		char* section;
+#endif
 
 		if (strchr(*argv, '/')) {
 			found = show_manpage(*argv, /*man:*/ 1, 0);
 			goto check_found;
 		}
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		section = strrchr(*argv, '.');
+		if (section) {
+			*section = '\0';
+			section++;
+			sect_len = strlen(section);
+		}
+#endif
 		cur_mp = 0;
 		while ((cur_path = man_path_list[cur_mp++]) != NULL) {
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+			if (section) {
+found |= check_path(cur_path, section, sect_len, *argv);
+continue;
+			}
+#endif
 			/* for each MANPATH */
 			const char *cur_sect = sec_list;
 			do { /* for each section */
 char *next_sect = strchrnul(cur_sect, ':');
-int sect_len = next_sect - cur_sect;
-char *man_filename;
-int cat0man1 = 0;
+sect_len = next_sect - cur_sect;
 
 /* Search for cat, then man page */
-while (cat0man1 < 2) {
-	int found_here;
-	man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
-			cur_path,
-			"cat\0man" + (cat0man1 * 4),
-			sect_len, cur_sect,
-			*argv,
-			sect_len, cur_sect);
-	found_here = show_manpage(man_filename, cat0man1, 0);
-	found |= found_here;
-	cat0man1 += found_here + 1;
-	free(man_filename);
-}
+found |= check_path(cur_path, cur_sect, sect_len, *argv);
 
 if (found && !(opt & OPT_a))
 	goto next_arg;
@@ -355,7 +387,12 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		}
  check_found:
 		if (!found) {
-			

Re: Add possiblity to support specifying desired section of manpage

2020-12-21 Thread depsterr
Just noticed the double which in my description!

Here is an updated patch without it!

Apologies!


‐‐‐ Original Message ‐‐‐
On Tuesday, December 22, 2020 3:10 AM, depsterr  wrote:

> Hello!
>
> I've used and loved busybox for a while now, however something which has 
> always bothered me has been the inability to specify from which section to 
> grab a man page, so I've devised a patch to fix this!
>
> This patch adds an option called "Support specifying section of page" (which 
> depends on man). If enabled it "Lets the user specify which from which 
> section they would like to retrieve their manpage from." - the help message 
> for the option.
>
> In practice this is done as such:
>
> Usage: man [-aw] MANPAGE[.SECTION]...
>
> This works perfectly with both existing flags and does not effect the 
> behavior of man when disabled.
>
> patch file is in attachments!

From a6516a03cccee8a713313afddd9dba5445bb94da Mon Sep 17 00:00:00 2001
From: depsterr 
Date: Tue, 22 Dec 2020 02:52:55 +0100
Subject: [PATCH] Added option to support specifying section of manpage

---
 miscutils/man.c | 75 -
 1 file changed, 56 insertions(+), 19 deletions(-)

diff --git a/miscutils/man.c b/miscutils/man.c
index 61086612a..493d8cf14 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -7,13 +7,20 @@
 //config:	default y
 //config:	help
 //config:	Format and display manual pages.
+//config:config FEATURE_MAN_SPECIFY_SECTION
+//config:	bool "Support specifying section of page"
+//config:	default y
+//config:	depends on MAN
+//config:	help
+//config:	Lets the user specify from which section they would
+//config:	like to retrieve their manpage from.
 
 //applet:IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_MAN) += man.o
 
 //usage:#define man_trivial_usage
-//usage:   "[-aw] MANPAGE..."
+//usage:   "[-aw] MANPAGE" IF_FEATURE_MAN_SPECIFY_SECTION("[.SECTION]") "..."
 //usage:#define man_full_usage "\n\n"
 //usage:   "Display manual page\n"
 //usage: "\n	-a	Display all pages"
@@ -240,6 +247,25 @@ static const char *if_redefined(const char *var, const char *key, const char *li
 	return xstrdup(skip_whitespace(line));
 }
 
+static const char check_path(const char* cur_path, const char* cur_sect, int sect_len, const char* man_name)
+{
+	char *man_filename;
+	int cat0man1 = 0;
+	int ret = 0;
+	while (cat0man1 < 2) {
+		man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
+cur_path,
+"cat\0man" + (cat0man1 * 4),
+sect_len, cur_sect,
+man_name,
+sect_len, cur_sect);
+		ret = show_manpage(man_filename, cat0man1, 0);
+		cat0man1 += ret + 1;
+		free(man_filename);
+	}
+	return ret;
+}
+
 int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int man_main(int argc UNUSED_PARAM, char **argv)
 {
@@ -316,35 +342,41 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		const char *cur_path;
 		int cur_mp;
 		int found = 0;
+		int sect_len;
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		char* section;
+#endif
 
 		if (strchr(*argv, '/')) {
 			found = show_manpage(*argv, /*man:*/ 1, 0);
 			goto check_found;
 		}
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		section = strrchr(*argv, '.');
+		if (section) {
+			*section = '\0';
+			section++;
+			sect_len = strlen(section);
+		}
+#endif
 		cur_mp = 0;
 		while ((cur_path = man_path_list[cur_mp++]) != NULL) {
-			/* for each MANPATH */
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+			if (section) {
+found |= check_path(cur_path, section, sect_len, *argv);
+continue;
+			}
+#endif
+		/* for each MANPATH */
 			const char *cur_sect = sec_list;
 			do { /* for each section */
 char *next_sect = strchrnul(cur_sect, ':');
-int sect_len = next_sect - cur_sect;
-char *man_filename;
-int cat0man1 = 0;
+sect_len = next_sect - cur_sect;
 
 /* Search for cat, then man page */
-while (cat0man1 < 2) {
-	int found_here;
-	man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
-			cur_path,
-			"cat\0man" + (cat0man1 * 4),
-			sect_len, cur_sect,
-			*argv,
-			sect_len, cur_sect);
-	found_here = show_manpage(man_filename, cat0man1, 0);
-	found |= found_here;
-	cat0man1 += found_here + 1;
-	free(man_filename);
-}
+found = check_path(cur_path, cur_sect, sect_len, *argv);
 
 if (found && !(opt & OPT_a))
 	goto next_arg;
@@ -355,7 +387,12 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		}
  check_found:
 		if (!found) {
-			bb_error_msg("no manual entry for '%s'", *argv);
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+			if (section)
+bb_error_msg("no manual entry for '%s' in section '%s'", *argv, section);
+			else
+#endif
+bb_error_msg("no manual entry for '%s'", *argv);
 			not_found = 1;
 		}
  next_arg:
-- 
2.29.2

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Add possiblity to support specifying desired section of manpage

2020-12-21 Thread depsterr
Hello!

I've used and loved busybox for a while now, however something which has always 
bothered me has been the inability to specify from which section to grab a man 
page, so I've devised a patch to fix this!

This patch adds an option called "Support specifying section of page" (which 
depends on man). If enabled it "Lets the user specify which from which section 
they would like to retrieve their manpage from." - the help message for the 
option.

In practice this is done as such:

Usage: man [-aw] MANPAGE[.SECTION]...

This works perfectly with both existing flags and does not effect the behavior 
of man when disabled.

patch file is in attachments!From 1cff1d7943021398a6bca8e9862cd976660267b2 Mon Sep 17 00:00:00 2001
From: depsterr 
Date: Tue, 22 Dec 2020 02:52:55 +0100
Subject: [PATCH] Added option to support specifying section of manpage

---
 miscutils/man.c | 75 -
 1 file changed, 56 insertions(+), 19 deletions(-)

diff --git a/miscutils/man.c b/miscutils/man.c
index 61086612a..664caf0da 100644
--- a/miscutils/man.c
+++ b/miscutils/man.c
@@ -7,13 +7,20 @@
 //config:	default y
 //config:	help
 //config:	Format and display manual pages.
+//config:config FEATURE_MAN_SPECIFY_SECTION
+//config:	bool "Support specifying section of page"
+//config:	default y
+//config:	depends on MAN
+//config:	help
+//config:	Lets the user specify which from which section
+//config:	they would like to retrieve their manpage from.
 
 //applet:IF_MAN(APPLET(man, BB_DIR_USR_BIN, BB_SUID_DROP))
 
 //kbuild:lib-$(CONFIG_MAN) += man.o
 
 //usage:#define man_trivial_usage
-//usage:   "[-aw] MANPAGE..."
+//usage:   "[-aw] MANPAGE" IF_FEATURE_MAN_SPECIFY_SECTION("[.SECTION]") "..."
 //usage:#define man_full_usage "\n\n"
 //usage:   "Display manual page\n"
 //usage: "\n	-a	Display all pages"
@@ -240,6 +247,25 @@ static const char *if_redefined(const char *var, const char *key, const char *li
 	return xstrdup(skip_whitespace(line));
 }
 
+static const char check_path(const char* cur_path, const char* cur_sect, int sect_len, const char* man_name)
+{
+	char *man_filename;
+	int cat0man1 = 0;
+	int ret = 0;
+	while (cat0man1 < 2) {
+		man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
+cur_path,
+"cat\0man" + (cat0man1 * 4),
+sect_len, cur_sect,
+man_name,
+sect_len, cur_sect);
+		ret = show_manpage(man_filename, cat0man1, 0);
+		cat0man1 += ret + 1;
+		free(man_filename);
+	}
+	return ret;
+}
+
 int man_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 int man_main(int argc UNUSED_PARAM, char **argv)
 {
@@ -316,35 +342,41 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		const char *cur_path;
 		int cur_mp;
 		int found = 0;
+		int sect_len;
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		char* section;
+#endif
 
 		if (strchr(*argv, '/')) {
 			found = show_manpage(*argv, /*man:*/ 1, 0);
 			goto check_found;
 		}
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+		section = strrchr(*argv, '.');
+		if (section) {
+			*section = '\0';
+			section++;
+			sect_len = strlen(section);
+		}
+#endif
 		cur_mp = 0;
 		while ((cur_path = man_path_list[cur_mp++]) != NULL) {
-			/* for each MANPATH */
+
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+			if (section) {
+found |= check_path(cur_path, section, sect_len, *argv);
+continue;
+			}
+#endif
+		/* for each MANPATH */
 			const char *cur_sect = sec_list;
 			do { /* for each section */
 char *next_sect = strchrnul(cur_sect, ':');
-int sect_len = next_sect - cur_sect;
-char *man_filename;
-int cat0man1 = 0;
+sect_len = next_sect - cur_sect;
 
 /* Search for cat, then man page */
-while (cat0man1 < 2) {
-	int found_here;
-	man_filename = xasprintf("%s/%s%.*s/%s.%.*s",
-			cur_path,
-			"cat\0man" + (cat0man1 * 4),
-			sect_len, cur_sect,
-			*argv,
-			sect_len, cur_sect);
-	found_here = show_manpage(man_filename, cat0man1, 0);
-	found |= found_here;
-	cat0man1 += found_here + 1;
-	free(man_filename);
-}
+found = check_path(cur_path, cur_sect, sect_len, *argv);
 
 if (found && !(opt & OPT_a))
 	goto next_arg;
@@ -355,7 +387,12 @@ int man_main(int argc UNUSED_PARAM, char **argv)
 		}
  check_found:
 		if (!found) {
-			bb_error_msg("no manual entry for '%s'", *argv);
+#if ENABLE_FEATURE_MAN_SPECIFY_SECTION
+			if (section)
+bb_error_msg("no manual entry for '%s' in section '%s'", *argv, section);
+			else
+#endif
+bb_error_msg("no manual entry for '%s'", *argv);
 			not_found = 1;
 		}
  next_arg:
-- 
2.29.2

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: Better error checking of config file by build scripts

2020-12-21 Thread Paul Larkin
 As you suggested, I just tested using the command builtin command and 
unfortunately it doesn't seem to change anything from the original scripts' 
behavior whereas the errexit flag does cause the script and the calling make to 
abort on error. I don't know anything about the POSIX rules regarding /bin/sh 
but a google search found this document that mentions errexit throughout as a 
normal feature.

https://arxiv.org/pdf/1907.05308.pdf
After cloning busybox, I use the small script below to generate an error in the 
.config and see if the build aborts on error or continues blindly all the way 
through. I am using ubuntu 18.04 LTS which uses dash for non-interactive shells 
(but I also tested using bash).

#!/bin/sh
make defconfig
sed -i 's|./_install|$(PREFIX)|g' .config
make clean
make CONFIG_PREFIX="./_install"
Note that we are only setting the errexit flag briefly while sourcing a .config 
file which is also included by make. This means mostly simple variable 
assignments and comments should be in there not complex fringe shell construct 
cases.
Can others detect this error and abort the make without using the errexit flag? 
I'm ok with whatever works and is most portable.

Thanks.
On Monday, December 21, 2020, 2:23:02 a.m. EST, Bastian Bittorf 
 wrote:  
 
 On Mon, Dec 21, 2020 at 05:28:36AM +, Paul Larkin wrote:
>  #!/bin/sh
>  
> +set -e
>  . ./.config || exit 1
> +set +e

IMHO the posix way is

command . ./.config || exit 1

The set -e/+e seems fragile, see:
https://www.in-ulm.de/~mascheck/various/set-e/

Paul:
Can you please check if this works for you?

bye, Bastian
  ___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH v1] modprobe: Add support for modprobe.blacklist=module1, module2, ...

2020-12-21 Thread Denys Vlasenko
On Tue, Nov 3, 2020 at 4:31 PM Andy Shevchenko
 wrote:
>
> Add support for modprobe.blacklist=module1,module2,...
>
> On x86_64 (Debian Unstable) it gives +79 bytes.
>
> function old new   delta
> parse_and_add_kcmdline_module_options  - 212+212
> modprobe_main816 932+116
> do_modprobe  743 494-249
> --
> (add/remove: 1/0 grow/shrink: 1/1 up/down: 328/-249)   Total: 79 bytes
>
> On i586 with uClibc (Buildroot 2020.05.3) it gives +68 bytes
> add/remove: 1/0 grow/shrink: 1/1 up/down: 262/-194 (68)
>
> Signed-off-by: Andy Shevchenko 
> ---
>  modutils/modprobe.c | 19 +++
>  1 file changed, 19 insertions(+)
>
> diff --git a/modutils/modprobe.c b/modutils/modprobe.c
> index eeeff7609b36..18a501a151df 100644
> --- a/modutils/modprobe.c
> +++ b/modutils/modprobe.c
> @@ -663,6 +663,25 @@ int modprobe_main(int argc UNUSED_PARAM, char **argv)
> load_modules_dep();
> }
>
> +   /* Handle modprobe.blacklist=module1,module2,... */
> +   if (ENABLE_FEATURE_MODPROBE_BLACKLIST) {
> +   char *fn, *options, *substr;
> +
> +   options = parse_and_add_kcmdline_module_options(NULL, 
> "modprobe");
> +   while ((substr = strsep(, " ")) != NULL) {
> +   fn = is_prefixed_with(substr, "blacklist=");
> +   if (fn == NULL)
> +   continue;
> +
> +   while ((substr = strsep(, ",")) != NULL) {
> +   /* blacklist  */
> +   get_or_add_modentry(substr)->flags |= 
> MODULE_FLAG_BLACKLISTED;
> +   DBG("blacklist: %s", substr);
> +   }
> +   }
> +   free(options);

Bug. "options" is NULL (strsep does that).

> +   }
> +
> rc = 0;
> while ((me = llist_pop()) != NULL) {
> if (me->realnames == NULL) {


Applied. Thank you.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] mount: Surround syslog.h with the config check

2020-12-21 Thread Lauri Kasanen
This lets bb mount build for limited targets without syslog.h,
as long as the parts using it like NFS are disabled.

Signed-off-by: Lauri Kasanen 
---
 util-linux/mount.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util-linux/mount.c b/util-linux/mount.c
index 0814a52..831dab9 100644
--- a/util-linux/mount.c
+++ b/util-linux/mount.c
@@ -182,7 +182,9 @@
 //usage:   "Returns 0 for success, number of failed mounts for -a, or 
errno for one mount."

 #include 
+#if ENABLE_FEATURE_SYSLOG
 #include 
+#endif
 #include 
 // Grab more as needed from util-linux's mount/mount_constants.h
 #ifndef MS_DIRSYNC
--
2.6.2

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Better error checking of config file by build scripts

2020-12-21 Thread Paul Larkin
In the dd-wrt community build project we noticed some errors buried for years 
in the huge build log and traced them back to a malformed line in a busybox 
.config file (our fault). The existing busybox scripts' error checking will 
only get triggered if the malformed line is the last one executed in the 
.config being sourced.

The bad line (see below) passed the gnu make syntax checking but unknowingly 
failed /bin/sh syntax checking. 

CONFIG_PREFIX="$(PREFIX)"

Here's a possible way to trigger errors no matter on which line the error 
occurs. Note that the trylink script sources the .config file twice but the 
below patch only sets the "exit immediately" option during one of those times. 
In our case, one fatal error is enough to notice the bad .config file. Just 
noticed trylink does not have "|| exit 1" after sourcing so perhaps a 
missing/invalid .config is acceptable in that case and shouldn't be patched? I 
know nothing about busybox build scripts...

Have been a fan of busybox for years. Congrats on a cool product!

diff --git a/scripts/embedded_scripts b/scripts/embedded_scripts
index aa7bf3e8a..bb060e787 100755
--- a/scripts/embedded_scripts
+++ b/scripts/embedded_scripts
@@ -1,6 +1,8 @@
 #!/bin/sh
 
+set -e
 . ./.config || exit 1
+set +e
 
 target="$1"
 custom_loc="$2"
diff --git a/scripts/generate_BUFSIZ.sh b/scripts/generate_BUFSIZ.sh
index 718788e0b..dedf8e74e 100755
--- a/scripts/generate_BUFSIZ.sh
+++ b/scripts/generate_BUFSIZ.sh
@@ -3,7 +3,9 @@
 #
 # scripts/generate_BUFSIZ.sh include/common_bufsiz.h
 
+set -e
 . ./.config || exit 1
+set +e
 
 debug=false
 #debug=true
diff --git a/scripts/trylink b/scripts/trylink
index 6b74f092d..bf3f44d33 100755
--- a/scripts/trylink
+++ b/scripts/trylink
@@ -228,7 +228,9 @@ else
 }
 fi
 
+set -e
 . ./.config
+set +e
 
 sharedlib_dir="0_lib"
 
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox