tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [PATCH 1/1] fix system() behaviour when parameter is NULL
On Fri, Aug 22, 2008 at 12:27 PM, Hubert Feyrer <hubert%feyrer.de@localhost>
wrote:
>>>> +zero if none is available. Otherwise,
>>> s/shall/will/
>> Err.. sorry. There was copy'n'past from OpenGroup's manual.
Anyway in neighbour mail thread the other objection to resubmit the patch,
so, I put new one here
diff --git a/lib/libc/stdlib/system.3 b/lib/libc/stdlib/system.3
index 6c1c733..18b866e 100644
--- a/lib/libc/stdlib/system.3
+++ b/lib/libc/stdlib/system.3
@@ -67,7 +67,8 @@ is a
.Dv NULL
pointer,
.Fn system
-will return non-zero.
+will return non-zero, if the command interpreter is available, or zero if none
+is available.
Otherwise,
.Fn system
returns the termination status of the shell in the format specified by
diff --git a/lib/libc/stdlib/system.c b/lib/libc/stdlib/system.c
index 4cc3cbe..b156d67 100644
--- a/lib/libc/stdlib/system.c
+++ b/lib/libc/stdlib/system.c
@@ -64,8 +64,15 @@ system(command)
const char *argp[] = {"sh", "-c", NULL, NULL};
argp[2] = command;
- if (command == NULL) /* just checking... */
- return(1);
+ /*
+ * ISO/IEC 9899:1999 in 7.20.4.6 describes this special case.
+ * We need to check availability of a command interpreter.
+ */
+ if (command == NULL) {
+ if (access(_PATH_BSHELL, X_OK) == 0)
+ return 1;
+ return 0;
+ }
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
--
With Best Regards,
Andy Shevchenko
Home |
Main Index |
Thread Index |
Old Index