Re: [RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Ron Yorston
Kang-Che Sung wrote:
>Let no script applets individually configurable in menuconfig. Let users
>resolve the dependencies of whatever they put in applets_sh.

My view is that if script applets are provided as part of BusyBox they
should have all the features of native applets, including the usual
configuration facilities.

The 'embed' directory is available for user-provided scripts.  These
don't get the same level of support and it's up to the user to ensure
their dependencies are met.

>In my opinion, if we were to resolve script applets' dependencies in
>menuconfig, then the applets should have a potential to be re-implemented
>with C, with libbb, which would reduce dependencies on other applets.

Allowing for alternative implementations of applets, script or native, is
another issue.  It would certainly make configuration more complex if
users were allowed this choice.

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


Re: [RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Ron Yorston
Aaro Koskinen wrote:
>Not sure if either of these are good.

OK, we could use the old 'add another level of indirection' trick:

   config NOLOGIN_DEPENDENCIES
  bool "Dependencies for nologin"
  default y
  depends on NOLOGIN
  select CAT
  select ECHO
  select SLEEP
  help
  nologin is implemented as a shell script. It requires the
  following in the runtime environment:
 cat echo sleep
  If you know these will be available externally you can
  disable this option.

This documents the dependencies, turns them on by default but makes it
possible to turn them off.

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


Re: [RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Kang-Che Sung
Can we do this instead:

Let no script applets individually configurable in menuconfig. Let users
resolve the dependencies of whatever they put in applets_sh.

If user needs to temporarily not embed a particular applet in that folder,
then we can provide a "DISABLE" file that specifies which applets should
not embed to the binary.

In my opinion, if we were to resolve script applets' dependencies in
menuconfig, then the applets should have a potential to be re-implemented
with C, with libbb, which would reduce dependencies on other applets.

Don't complicate menuconfig with those dependencies they are not designed
to resolve.
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Aaro Koskinen
On Tue, Nov 06, 2018 at 08:36:11PM +, Ron Yorston wrote:
> For the rest I suppose there are a couple of ways to look at it.  The
> dependencies could be specified explicitly:
> 
>depends on ASH_EMBEDDED_SCRIPTS && (ECHO || ASH_ECHO) && CAT && SLEEP
> 
> Though this means that scripted applets aren't very discoverable because
> they'll only appear in the configuration menu if all their dependencies
> are enabled first.
> 
> Alternatively the dependencies could be selected automatically:
> 
>select ECHO
>select CAT
>select SLEEP
> 
> But in this case it wouldn't be possible to turn off sleep from the
> configuration menu if nologin is enabled.  And it isn't obvious why.

Not sure if either of these are good. The user could have e.g. toybox
or even GNU bloat to implement/replace some of the programs, but still
want to use an applet script from busybox. Maybe the config help text
should just list needed programs?

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


Re: [RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Ron Yorston
Aaro Koskinen wrote:
>Should users be told they are enabling a scripted applet? E.g. in this
>case they should also enable some other busybox applets to make it work
>(like "cat")... I wonder how it's going to work in practice.

Because of the 'depends on ASH_EMBEDDED_SCRIPTS' we known that we have
a shell available, at least!

For the rest I suppose there are a couple of ways to look at it.  The
dependencies could be specified explicitly:

   depends on ASH_EMBEDDED_SCRIPTS && (ECHO || ASH_ECHO) && CAT && SLEEP

Though this means that scripted applets aren't very discoverable because
they'll only appear in the configuration menu if all their dependencies
are enabled first.

Alternatively the dependencies could be selected automatically:

   select ECHO
   select CAT
   select SLEEP

But in this case it wouldn't be possible to turn off sleep from the
configuration menu if nologin is enabled.  And it isn't obvious why.

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


[RFC PATCH v2] Allow applets to be implemented as scripts

2018-11-06 Thread Ron Yorston
Now that scripts can be embedded in the BusyBox binary it's possible
to implement applets as scripts.

Such scripts should be placed in the 'applets_sh' directory.  A stub
C program should be written to provide the usual applet configuration
details and placed in a suitable subsystem directory.

This patch implements the 'nologin' applet as a script.

The 'embed' directory can be used for scripts that aren't intended
to be treated as applets.

v2: Tidy up config settings and embedded_scripts script
If custom scripts are presents add a 'busybox --scripts' option to
list them.

Signed-off-by: Ron Yorston 
---
 .gitignore|  5 +++
 applets/busybox.mkscripts | 16 
 {embed => applets_sh}/nologin |  0
 include/applets.src.h | 15 +++
 include/libbb.h   |  1 +
 libbb/appletlib.c | 76 ++-
 scripts/embedded_scripts  | 59 +++
 shell/ash.c   |  4 ++
 util-linux/nologin.c  | 13 ++
 9 files changed, 143 insertions(+), 46 deletions(-)
 create mode 100755 applets/busybox.mkscripts
 rename {embed => applets_sh}/nologin (100%)
 create mode 100644 util-linux/nologin.c

diff --git a/.gitignore b/.gitignore
index c03c2e8a6..becd9bf6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -56,3 +56,8 @@ cscope.po.out
 #
 tags
 TAGS
+
+#
+# user-supplied scripts
+#
+/embed
diff --git a/applets/busybox.mkscripts b/applets/busybox.mkscripts
new file mode 100755
index 0..935685cba
--- /dev/null
+++ b/applets/busybox.mkscripts
@@ -0,0 +1,16 @@
+#!/bin/sh
+# Make busybox scripted applet list file.
+
+# input $1: full path to Config.h
+# input $2: full path to applets.h
+# output (stdout): list of pathnames that should be linked to busybox
+
+export LC_ALL=POSIX
+export LC_CTYPE=POSIX
+
+CONFIG_H=${1:-include/autoconf.h}
+APPLETS_H=${2:-include/applets.h}
+$HOSTCC -E -DMAKE_SCRIPTS -include $CONFIG_H $APPLETS_H |
+  awk '/^[ \t]*SCRIPT/{
+   print $2
+  }'
diff --git a/embed/nologin b/applets_sh/nologin
similarity index 100%
rename from embed/nologin
rename to applets_sh/nologin
diff --git a/include/applets.src.h b/include/applets.src.h
index 2ddf120ad..161a97ee8 100644
--- a/include/applets.src.h
+++ b/include/applets.src.h
@@ -27,36 +27,49 @@ s - suid type:
 # define APPLET_ODDNAME(name,main,l,s,help)  int main##_main(int argc, char 
**argv) MAIN_EXTERNALLY_VISIBLE;
 # define APPLET_NOEXEC(name,main,l,s,help)   int main##_main(int argc, char 
**argv) MAIN_EXTERNALLY_VISIBLE;
 # define APPLET_NOFORK(name,main,l,s,help)   int main##_main(int argc, char 
**argv) MAIN_EXTERNALLY_VISIBLE;
+# define APPLET_SCRIPTED(name,main,l,s,help)
 
 #elif defined(NAME_MAIN)
 # define APPLET(name,l,s)name name##_main
 # define APPLET_ODDNAME(name,main,l,s,help)  name main##_main
 # define APPLET_NOEXEC(name,main,l,s,help)   name main##_main
 # define APPLET_NOFORK(name,main,l,s,help)   name main##_main
+# define APPLET_SCRIPTED(name,main,l,s,help) name scripted_main
 
 #elif defined(MAKE_USAGE) && ENABLE_FEATURE_VERBOSE_USAGE
 # define APPLET(name,l,s)MAKE_USAGE(#name, 
name##_trivial_usage name##_full_usage)
 # define APPLET_ODDNAME(name,main,l,s,help)  MAKE_USAGE(#name, 
help##_trivial_usage help##_full_usage)
 # define APPLET_NOEXEC(name,main,l,s,help)   MAKE_USAGE(#name, 
help##_trivial_usage help##_full_usage)
 # define APPLET_NOFORK(name,main,l,s,help)   MAKE_USAGE(#name, 
help##_trivial_usage help##_full_usage)
+# define APPLET_SCRIPTED(name,main,l,s,help) MAKE_USAGE(#name, 
help##_trivial_usage help##_full_usage)
 
 #elif defined(MAKE_USAGE) && !ENABLE_FEATURE_VERBOSE_USAGE
 # define APPLET(name,l,s)MAKE_USAGE(#name, 
name##_trivial_usage)
 # define APPLET_ODDNAME(name,main,l,s,help)  MAKE_USAGE(#name, 
help##_trivial_usage)
 # define APPLET_NOEXEC(name,main,l,s,help)   MAKE_USAGE(#name, 
help##_trivial_usage)
 # define APPLET_NOFORK(name,main,l,s,help)   MAKE_USAGE(#name, 
help##_trivial_usage)
+# define APPLET_SCRIPTED(name,main,l,s,help) MAKE_USAGE(#name, 
help##_trivial_usage)
 
 #elif defined(MAKE_LINKS)
 # define APPLET(name,l,c)LINK l name
 # define APPLET_ODDNAME(name,main,l,s,help)  LINK l name
 # define APPLET_NOEXEC(name,main,l,s,help)   LINK l name
 # define APPLET_NOFORK(name,main,l,s,help)   LINK l name
+# define APPLET_SCRIPTED(name,main,l,s,help) LINK l name
 
 #elif defined(MAKE_SUID)
 # define APPLET(name,l,s)SUID s l name
 # define APPLET_ODDNAME(name,main,l,s,help)  SUID s l name
 # define APPLET_NOEXEC(name,main,l,s,help)   SUID s l name
 # define APPLET_NOFORK(name,main,l,s,help)   SUID s l name
+# define APPLET_SCRIPTED(name,main,l,s,help) SUID s l name
+
+#elif defined(MAKE_SCRIPTS)
+# define APPLET(name,l,s)
+# define APPLET_ODDNAME(name,main,l,s,help)
+# define APPLET_NOEXEC(name,main,l,s,help)
+# define APPLET_NOFORK(name,main,l,s,help)
+# define