| Summary: | Patch to env(1) for Unix 98 compatability | ||||||
|---|---|---|---|---|---|---|---|
| Product: | Base System | Reporter: | howardjp <howardjp> | ||||
| Component: | bin | Assignee: | Sheldon Hearn <sheldonh> | ||||
| Status: | Closed FIXED | ||||||
| Severity: | Affects Only Me | ||||||
| Priority: | Normal | ||||||
| Version: | 3.2-STABLE | ||||||
| Hardware: | Any | ||||||
| OS: | Any | ||||||
| Attachments: |
|
||||||
|
Description
Bill Fumerola
1999-08-25 02:59:52 UTC
Unix 98 requires that env(1) take the option -i to destroy the inherited environment. This would be identical to the currently existing - option. This diff adds a fallthrough so that -i is handled as Unix 98 specifies. This does not include a change for the man page, I did not think it was necessary. How-To-Repeat: env -i gives error about illegal option On Tue, 24 Aug 1999, Bill Fumerola wrote:
> style(9) says this can be written as
>
> /* For Unix 98 compatability. */
> /* FALLTHROUGH */
Okay, here is a modified diff. I also mispelled "compatibility" so I
fixed that too.
*** /usr/src/usr.bin/env/env.c Sun Dec 6 22:58:22 1998
--- /usr/local/src/env/env.c Tue Aug 24 20:33:03 1999
***************
*** 60,67 ****
char *cleanenv[1];
int ch;
! while ((ch = getopt(argc, argv, "-")) != -1)
switch(ch) {
case '-':
environ = cleanenv;
cleanenv[0] = NULL;
--- 60,72 ----
char *cleanenv[1];
int ch;
! while ((ch = getopt(argc, argv, "i-")) != -1)
switch(ch) {
+ case 'i':
+ /* For Unix 98 compatibility. */
+ /* FALLTHROUGH */
case '-':
environ = cleanenv;
cleanenv[0] = NULL;
On Tue, 24 Aug 1999 22:42:09 -0400, James Howard wrote:
> ! while ((ch = getopt(argc, argv, "i-")) != -1)
> switch(ch) {
> + case 'i':
> + /*
> + * For Unix 98 compatability.
> + */
> + /* FALLTHROUGH */
Hi James/Jamie (which do you prefer?),
Bill Fumerola replied telling you that style(9) requires a slightly
different format for your comments. While it's true, the example he gave
you doesn't appear in style(9).
I'd do this:
case 'i': /* Unix 98 compatibility option */
/* FALLTHROUGH */
Personally, I wouldn't provide the comment at all. Focus on the manpage
instead. :-P
Oh, and note the spelling of compatibility. :-)
later,
Sheldon.
Due to the sheer number of complaints about my style here is a new patch
for env which should make everyone happy :) Following it is a diff to
printenv.1.
--- /usr/src/usr.bin/env/env.c Sun Dec 6 17:58:22 1998
+++ env.c Wed Aug 25 17:45:39 1999
@@ -60,8 +60,9 @@
char *cleanenv[1];
int ch;
- while ((ch = getopt(argc, argv, "-")) != -1)
+ while ((ch = getopt(argc, argv, "i-")) != -1)
switch(ch) {
+ case 'i':
case '-':
environ = cleanenv;
cleanenv[0] = NULL;
@@ -85,6 +86,6 @@
usage()
{
(void)fprintf(stderr,
- "usage: env [-] [name=value ...] [command]\n");
+ "usage: env [-] [-i] [name=value ...] [command]\n");
exit(1);
}
------------CUT HERE-----------------
--- /usr/src/usr.bin/printenv/printenv.1 Mon Jul 12 16:23:52 1999
+++ printenv.1 Wed Aug 25 17:45:42 1999
@@ -45,6 +44,7 @@
.Op Ar name
.Nm env
.Op Fl
+.Op Fl i
.Op Ar name=value ...
.Op Ar command
.Sh DESCRIPTION
@@ -72,12 +72,20 @@
.Ar name ,
with a value of
.Ar value .
-The option
-.Sq Fl
-causes
+The options to
+.Nm env
+are as follows:
+.Pp
+.Bl -tag -width indent
+.It Fl
+Force
.Nm env
to completely ignore the environment
it inherits.
+.It Fl i
+Equivalent to
+.Fl .
+.El
.Pp
If no command is specified,
.Nm env
On Wed, 25 Aug 1999 17:57:56 -0400, James Howard wrote: > - while ((ch = getopt(argc, argv, "-")) != -1) > + while ((ch = getopt(argc, argv, "i-")) != -1) > switch(ch) { > + case 'i': > case '-': You don't seem to have addressed the case disordering that Bruce commented on. :-) > +.It Fl i > +Equivalent to > +.Fl . This text begs the question "why?". I'd also suggest that the behaviour of the two options be described under -i, with - being declared the compatibility option. This should encourage people to use -i for portability. This is how the Single UNIX Spec does it. :-P Ciao, Sheldon. Index: usr.bin/printenv/printenv.1 =================================================================== RCS file: /home/ncvs/src/usr.bin/printenv/printenv.1,v retrieving revision 1.3 diff -u -d -r1.3 printenv.1 --- printenv.1 1999/07/12 20:23:52 1.3 +++ printenv.1 1999/08/26 13:02:02 @@ -45,6 +45,7 @@ .Op Ar name .Nm env .Op Fl +.Op Fl i .Op Ar name=value ... .Op Ar command .Sh DESCRIPTION @@ -72,12 +73,21 @@ .Ar name , with a value of .Ar value . -The option -.Sq Fl -causes +.Pp +The options are as follows: +.Bl -tag -width indent +.It Fl i +Execute the +.Ar command +with only those environment values specified. The environment inherited +by .Nm env -to completely ignore the environment -it inherits. +is ignored completely. +.It Fl +Identical to the +.Fl i +option, available for backward compatibility. +.El .Pp If no command is specified, .Nm env Index: usr.bin/env/env.c =================================================================== RCS file: /home/ncvs/src/usr.bin/env/env.c,v retrieving revision 1.4 diff -u -d -r1.4 env.c --- env.c 1998/12/06 22:58:22 1.4 +++ env.c 1999/08/26 12:57:34 @@ -60,9 +60,10 @@ char *cleanenv[1]; int ch; - while ((ch = getopt(argc, argv, "-")) != -1) + while ((ch = getopt(argc, argv, "-i")) != -1) switch(ch) { case '-': + case 'i': environ = cleanenv; cleanenv[0] = NULL; break; @@ -85,6 +86,6 @@ usage() { (void)fprintf(stderr, - "usage: env [-] [name=value ...] [command]\n"); + "usage: env [-] [-i] [name=value ...] [command]\n"); exit(1); } Responsible Changed From-To: freebsd-bugs->sheldonh I'll take this one. On Thu, 26 Aug 1999, Sheldon Hearn wrote:
> This text begs the question "why?". I'd also suggest that the behaviour
> of the two options be described under -i, with - being declared the
> compatibility option. This should encourage people to use -i for
> portability. This is how the Single UNIX Spec does it. :-P
I completely agree with this but I didn't want to push it down their
throats. As I said previously, the draft of XPG6 removes ``-'' in favor
of ``-i''. To me, this means don't even bother documenting ``-'' and
leave it in quietly as a compatibility option. I personally view it as a
bad idea to to have done ``-'' in the first place. However, I was 7 when
this was first done (possibly younger). I will not question it further :)
Jamie
State Changed From-To: open->analyzed Committed to CURRENT. I'll leave it in this state for MFC. State Changed From-To: analyzed->closed Damn, I left this in the wrong state for MFC. Since it missed 3.4-RELEASE, and since there isn't going to be another release thereafter on the RELENG_3 line, an MFC now would be silly. |