classification
Title: _Py_open does not work with O_CREAT
Type: behavior Stage: needs patch
Components: Interpreter Core Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alexandre.vassalotti, vstinner
Priority: normal Keywords:

Created on 2014-01-28 23:45 by alexandre.vassalotti, last changed 2014-02-03 01:14 by vstinner.

Messages (4)
msg209600 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2014-01-28 23:45
The _Py_open function in Python/fileutils.c cannot be given correctly the flag O_CREAT. According to the POSIX spec, open(2) _must_ be given an additional mode argument when O_CREAT is used.

_Py_open should be fixed to either to use a reasonable default value for the mode argument (e.g., O666) or to refuse the O_CREAT flag.
msg209602 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-01-29 00:03
I already search the "default mode" but I didn't see it in the manual page. Is it 0666?

> The _Py_open function in Python/fileutils.c cannot be given correctly the flag O_CREAT.

What is the current behaviour?

A new _Py_open_mode() function can be added. Where do you need O_CREAT?
msg209609 - (view) Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer) Date: 2014-01-29 01:11
> What is the current behaviour?

I don't think the behaviour is defined. At least, I know it causes recent GCC/glibc combination to throw a compilation error when _FORTIFY_SOURCE is defined:
 
http://www.eglibc.org/cgi-bin/viewvc.cgi/trunk/libc/io/open_2.c?view=markup

For example, this is the error I got when I tried to compile Python with LTO:

gcc-4.6 -pthread -flto -fuse-linker-plugin  -Xlinker -export-dynamic -o python Modules/python.o libpython3.4m.a -lpthread -ldl -lutil -lm  
bytesobject.o (symbol from plugin): warning: memset used with constant zero length parameter; this could be due to transposed parameters
In file included from ./Modules/_localemodule.c:404:0,
                 from :459:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h: In function ‘_Py_open’:
/usr/include/x86_64-linux-gnu/bits/fcntl2.h:51:24: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT in second argument needs 3 arguments
lto-wrapper: gcc-4.6 returned 1 exit status
/usr/bin/ld: lto-wrapper failed
collect2: ld returned 1 exit status
msg210066 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2014-02-03 01:14
> In file included from ./Modules/_localemodule.c:404:0,

I don't see where _Py_open() is used in _localemodule.c. I didn't find a call to _Py_open() using O_CREAT. In fact, O_CREAT is not used in the C code of Python. (Except dbmopen in the dbm module, but it doesn't call open(), it calls dbm_open()).

> I already search the "default mode" but I didn't see it in the manual page.

The glibc pass 0 for the mode by default, but for O_CREAT it reads it from the third "mode" parameter.
History
Date User Action Args
2014-02-03 01:14:35vstinnersetmessages: + msg210066
2014-01-29 01:11:17alexandre.vassalottisetmessages: + msg209609
2014-01-29 00:03:03vstinnersetmessages: + msg209602
2014-01-28 23:45:30alexandre.vassalotticreate