Re: [PATCH] find: implement -ok
On Sun, Jan 29, 2023 at 3:14 AM David Leonard wrote: > Resending patch for 'find -ok'. I re-ran bloatcheck (x86_64). findutils/find.c: In function ‘do_exec’: findutils/find.c:837:12: error: ‘rc’ may be used uninitialized in this function [-Werror=maybe-uninitialized] 837 | return rc == 0; /* return 1 if exitcode 0 */ | ~~~^~~~ This is indeed the case (rc is used uninitialized). > +testing "find -ok" \ > + "cd find.tempdir && find testfile -ok true {} + 2>&1; echo \$?" \ > + "true testfile ?\n0\n" \ > + "" "y" The test actually failed (extra "\n"). "-ok CMD +" is not accepted by GNU findutils 4.9.0> Fixing the test. Applied the result. Thank you. ___ busybox mailing list busybox@busybox.net http://lists.busybox.net/mailman/listinfo/busybox
Re: [PATCH] find: implement -ok
Resending patch for 'find -ok'. I re-ran bloatcheck (x86_64). Subject: [PATCH] find: implement -ok https://pubs.opengroup.org/onlinepubs/9699919799/utilities/find.html -ok utility_name [argument ...] ; The -ok primary shall be equivalent to -exec, except that the use of a to punctuate the end of the primary expression need not be supported, and find shall request affirmation of the invocation of utility_name using the current file as an argument by writing to standard error as described in the STDERR section. If the response on standard input is affirmative, the utility shall be invoked. Otherwise, the command shall not be invoked and the value of the -ok operand shall be false. function old new delta do_exec 438 517 +79 parse_params18331845 +12 static.params288 292 +4 .rodata 100771 100775 +4 packed_usage 34543 34541 -2 -- (add/remove: 0/0 grow/shrink: 4/1 up/down: 99/-2) Total: 97 bytes textdata bss dec hex filename 1064433 165871816 1082836 1085d4 busybox_old 1064530 165871816 1082933 108635 busybox_unstripped --- findutils/find.c | 32 ++-- testsuite/find.tests | 6 ++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/findutils/find.c b/findutils/find.c index bb6ad31e5..40f66ab2e 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -180,6 +180,13 @@ //config: Without this option, -exec + is a synonym for -exec ; //config: (IOW: it works correctly, but without expected speedup) //config: +//config:config FEATURE_FIND_EXEC_OK +//config: bool "Enable -ok: execute confirmed commands" +//config: default y +//config: depends on FEATURE_FIND_EXEC +//config: help +//config: Support the 'find -ok' option which prompts before executing. +//config: //config:config FEATURE_FIND_USER //config: bool "Enable -user: username/uid matching" //config: default y @@ -395,6 +402,9 @@ //usage: IF_FEATURE_FIND_EXEC_PLUS( //usage: "\n -exec CMD ARG + Run CMD with {} replaced by list of file names" //usage: ) +//usage: IF_FEATURE_FIND_EXEC_OK( +//usage: "\n -ok CMD ARG ; Prompt and run CMD with {} replaced" +//usage: ) //usage: IF_FEATURE_FIND_DELETE( //usage: "\n -delete Delete current file/directory. Turns on -depth option" //usage: ) @@ -467,6 +477,9 @@ IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; /* -exec ARGS */ unsigned *subst_count; int exec_argc; /* count of ARGS */ + IF_FEATURE_FIND_EXEC_OK( + int ok; /* -ok */ + ) IF_FEATURE_FIND_EXEC_PLUS( /* * filelist is NULL if "exec ;" @@ -802,10 +815,22 @@ static int do_exec(action_exec *ap, const char *fileName) } # endif +# if ENABLE_FEATURE_FIND_EXEC_OK + if (ap->ok) { + for (i = 0; argv[i]; i++) + fprintf(stderr, "%s ", argv[i]); + fprintf(stderr, "?"); + if (!bb_ask_y_confirmation()) + goto not_ok; + } +# endif rc = spawn_and_wait(argv); if (rc < 0) bb_simple_perror_msg(argv[0]); +# if ENABLE_FEATURE_FIND_EXEC_OK +not_ok: +# endif i = 0; while (argv[i]) free(argv[i++]); @@ -1120,6 +1145,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_DELETE( PARM_delete,) IF_FEATURE_FIND_EMPTY( PARM_empty ,) IF_FEATURE_FIND_EXEC( PARM_exec ,) + IF_FEATURE_FIND_EXEC_OK(PARM_ok,) IF_FEATURE_FIND_EXECUTABLE(PARM_executable,) IF_FEATURE_FIND_PAREN( PARM_char_brace,) /* All options/actions starting from here require argument */ @@ -1171,6 +1197,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_DELETE( "-delete\0" ) IF_FEATURE_FIND_EMPTY( "-empty\0" ) IF_FEATURE_FIND_EXEC( "-exec\0" ) + IF_FEATURE_FIND_EXEC_OK("-ok\0" ) IF_FEATURE_FIND_EXECUTABLE("-executable\0") IF_FEATURE_FIND_PAREN( "(\0" ) /* All options/actions starting from here requir
[PATCH] find: implement -ok
Implements POSIX's -ok primary for find. This is the same as -exec, execpt that the user is prompted before running the command. function old new delta do_exec 782 904+122 parse_params3363 +30 packed_usage 34437 34464 +27 .rodata 119440 119448 +8 static.params271 275 +4 -- (add/remove: 0/0 grow/shrink: 5/0 up/down: 191/0) Total: 191 bytesFrom 7ac4795a2767e1fc2a5fbc759290f8ce22000864 Mon Sep 17 00:00:00 2001 From: David Leonard Date: Mon, 28 Mar 2022 10:55:18 +1000 Subject: [PATCH 1/2] find: implement -ok function old new delta do_exec 782 904+122 parse_params3363 +30 packed_usage 34437 34464 +27 .rodata 119440 119448 +8 static.params271 275 +4 -- (add/remove: 0/0 grow/shrink: 5/0 up/down: 191/0) Total: 191 bytes text data bss dec hex filename 1734640 16476 1816 1752932 1abf64 busybox_old 1734831 16476 1816 1753123 1ac023 busybox_unstripped --- findutils/find.c | 32 ++-- testsuite/find.tests | 6 ++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/findutils/find.c b/findutils/find.c index bb6ad31e5..40f66ab2e 100644 --- a/findutils/find.c +++ b/findutils/find.c @@ -180,6 +180,13 @@ //config: Without this option, -exec + is a synonym for -exec ; //config: (IOW: it works correctly, but without expected speedup) //config: +//config:config FEATURE_FIND_EXEC_OK +//config: bool "Enable -ok: execute confirmed commands" +//config: default y +//config: depends on FEATURE_FIND_EXEC +//config: help +//config: Support the 'find -ok' option which prompts before executing. +//config: //config:config FEATURE_FIND_USER //config: bool "Enable -user: username/uid matching" //config: default y @@ -395,6 +402,9 @@ //usage: IF_FEATURE_FIND_EXEC_PLUS( //usage: "\n -exec CMD ARG + Run CMD with {} replaced by list of file names" //usage: ) +//usage: IF_FEATURE_FIND_EXEC_OK( +//usage: "\n -ok CMD ARG ; Prompt and run CMD with {} replaced" +//usage: ) //usage: IF_FEATURE_FIND_DELETE( //usage: "\n -delete Delete current file/directory. Turns on -depth option" //usage: ) @@ -467,6 +477,9 @@ IF_FEATURE_FIND_EXEC( ACTS(exec, char **exec_argv; /* -exec ARGS */ unsigned *subst_count; int exec_argc; /* count of ARGS */ +IF_FEATURE_FIND_EXEC_OK( +int ok; /* -ok */ +) IF_FEATURE_FIND_EXEC_PLUS( /* * filelist is NULL if "exec ;" @@ -802,10 +815,22 @@ static int do_exec(action_exec *ap, const char *fileName) } # endif +# if ENABLE_FEATURE_FIND_EXEC_OK + if (ap->ok) { + for (i = 0; argv[i]; i++) + fprintf(stderr, "%s ", argv[i]); + fprintf(stderr, "?"); + if (!bb_ask_y_confirmation()) + goto not_ok; + } +# endif rc = spawn_and_wait(argv); if (rc < 0) bb_simple_perror_msg(argv[0]); +# if ENABLE_FEATURE_FIND_EXEC_OK +not_ok: +# endif i = 0; while (argv[i]) free(argv[i++]); @@ -1120,6 +1145,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_DELETE( PARM_delete,) IF_FEATURE_FIND_EMPTY( PARM_empty ,) IF_FEATURE_FIND_EXEC( PARM_exec ,) + IF_FEATURE_FIND_EXEC_OK(PARM_ok,) IF_FEATURE_FIND_EXECUTABLE(PARM_executable,) IF_FEATURE_FIND_PAREN( PARM_char_brace,) /* All options/actions starting from here require argument */ @@ -1171,6 +1197,7 @@ static action*** parse_params(char **argv) IF_FEATURE_FIND_DELETE( "-delete\0" ) IF_FEATURE_FIND_EMPTY( "-empty\0" ) IF_FEATURE_FIND_EXEC( "-exec\0" ) + IF_FEATURE_FIND_EXEC_OK("-ok\0" ) IF_FEATURE_FIND_EXECUTABLE("-executable\0") IF_FEATURE_FIND_PAREN( "(\0" ) /* All options/actions starting from here require argument */ @@ -1351,18 +1378,19 @@ static action*** parse_params(char **argv) } #endif #if ENABLE_FEATURE_FIND_EXEC - else if (parm == PARM_exec) { + else if (parm == PARM_exec IF_FEATURE_FIND_EXEC_OK(|| parm == PARM_ok)) { int i; action_exec *ap; IF_FEATURE_FIND_EXEC_PLUS(int all_subst = 0;) dbg("%d", __LINE__); G.need_print = 0; ap = ALLOC_ACTION(exec); + IF_FEATURE_FIND_EXEC_OK(ap->ok = (parm == PARM_ok);) ap->exec_argv = ++argv; /* first arg after -exec */ /*ap->exec_argc = 0; - ALLOC_ACTION did it */ while (1) { if (!*argv) /* did not