View Issue Details

IDProjectCategoryView StatusLast Update
00003861003.1(2008)/Issue 7System Interfacespublic2013-04-16 13:06
Reportereblake Assigned Toajosey  
PrioritynormalSeverityObjectionTypeEnhancement Request
Status ClosedResolutionAccepted As Marked 
NameEric Blake
OrganizationRed Hat
User Referenceebb.environ
Section2.2.2 The Name Space
Page Number469
Line Number15936
Interp Status---
Final Accepted TextSee 0000386:0000721
Summary0000386: environ should be declared in <unistd.h>
DescriptionThe standard appears to be ambiguous - XBD <unistd.h> does not list environ,
but XSH exec (line 25687) implies that #include <unistd.h> will provide
the declaration, rather than documenting the burden on the application to
declare it. Meanwhile, many implementations already declare environ in
<unistd.h> (possibly when requesting extensions to the standard), and it
seems awkward to require special-case treatment for environ. This proposal
changes things to remove the special casing.

If my Desired Action is not taken as-is, then we should at least update the
wording in XSH exec to make it explicit that the user must declare the
variable themselves (in fact, such wording might be useful in TC1, while
delaying this proposal to issue 8).
Desired ActionAt line 15126 [XBD <unistd.h>], insert:

extern char **environ;

At line 15936 [XSH 2.2.2 The Name Space], delete ", except environ,".

At line 26007 [XSH exec APPLICATION USAGE], add a paragraph:

Older versions of this standard required that applications provide the
declaration:

extern char **environ;

before using environ, since no standard header was required to
provide it. Code may safely keep such a declaration, even though this
version of the standard now requires <unistd.h> to declare environ.
Tagstc1-2008

Relationships

related to 0000167 Closedajosey 1003.1(2008)/Issue 7 getenv() and modifying environ directly 
has duplicate 0001246 Closed 1003.1(2016/18)/Issue7+TC2 environ missing. 

Activities

geoffclare

2011-02-23 11:49

manager   bugnote:0000677

There is also the environ pointer page to consider (page 763), which has no mention of <unistd.h> in the synopsis.

Don Cragun

2011-02-23 19:47

manager   bugnote:0000678

There are several warnings in the standard that using environ in a
multithreaded application causes undefined behavior as well as
statements that environ is not defined in any header (and the reasons
why this is the intended behavior of the standard). See XSH 2.2.2
(The Name Space) P469, L15936; 2.9.1 (Thread Safety) P508, L17516;
XSH exec DESCRIPTION P772, L25713; XSH exec APPLICATION USAGE P779,
L25989; XSH exec RATIONALE P781, L26059-26060; XSH getenv() DESCRIPTION
P1008, L33856; XSH getenv() RATIONALE P1008-1009, L33880-33897; XSH
setenv() DESCRIPTION P99347-99348; XSH unsetenv() DESCRIPTION P2161,
L68256-68257; XRAT A.8.1 (Environment Variable Definition) P3467,
L116537-116540 for examples of why environ should not be defined
in any header and the user should be required to define environ if
it is going to be used instead of the preferred getenv(), setenv(),
and putenv() functions.

I believe this change should be rejected.

eblake

2011-02-23 20:26

manager   bugnote:0000679

See 0000167 - TC1 is changing things to state that modification of
the array pointed to by environ, or of an entry in the array pointed to
by environ, is not multi-thread safe, but that reading environ in order
to initialize a const **char pointer to walk through and read the array,
as well as assignment to environ, _is_ safe, even in a multi-threaded
application. Therefore, your fears about accessing environ are unfounded,
and there no longer exists a reason to hide environ from being declared.

nick

2011-03-24 16:20

manager   bugnote:0000721

At line 25708, change "In addition, the following variable:" to

"In addition, the following variable, which must be declared by the user if it is to be used directly:"

Issue History

Date Modified Username Field Change
2011-02-22 23:58 eblake New Issue
2011-02-22 23:58 eblake Status New => Under Review
2011-02-22 23:58 eblake Assigned To => ajosey
2011-02-22 23:58 eblake Name => Eric Blake
2011-02-22 23:58 eblake Organization => Red Hat
2011-02-22 23:58 eblake User Reference => ebb.environ
2011-02-22 23:58 eblake Section => 2.2.2 The Name Space
2011-02-22 23:58 eblake Page Number => 469
2011-02-22 23:58 eblake Line Number => 15936
2011-02-22 23:58 eblake Interp Status => ---
2011-02-23 11:49 geoffclare Note Added: 0000677
2011-02-23 19:47 Don Cragun Note Added: 0000678
2011-02-23 20:25 eblake Relationship added related to 0000167
2011-02-23 20:26 eblake Note Added: 0000679
2011-03-24 16:20 nick Note Added: 0000721
2011-03-24 16:20 nick Status Under Review => Resolved
2011-03-24 16:20 nick Resolution Open => Accepted As Marked
2011-03-24 16:21 nick Final Accepted Text => See 0000386:0000721
2011-03-24 16:21 nick Tag Attached: tc1-2008
2013-04-16 13:06 ajosey Status Resolved => Closed
2019-04-16 07:38 geoffclare Relationship added has duplicate 0001246