‘primitive-load’ should open files with O_CLOEXEC

  • Done
  • quality assurance status badge
Details
One participant
  • Ludovic Courtès
Owner
unassigned
Submitted by
Ludovic Courtès
Severity
normal
L
L
Ludovic Courtès wrote on 3 Sep 2022 21:24
(address . bug-guile@gnu.org)
877d2ktg6b.fsf@inria.fr
Hi,

Currently ‘primitive-load’ opens files without O_CLOEXEC:

port = scm_open_file_with_encoding (filename,
scm_from_latin1_string ("r"),
SCM_BOOL_T, /* guess_encoding */
scm_from_latin1_string ("UTF-8"));

We should fix that; here’s an example where it shows:

Toggle snippet (11 lines)
$ guix shell bash -- sh -c 'ls -l /proc/$$/fd'
total 0
lrwx------ 1 ludo users 64 Sep 3 21:20 0 -> /dev/pts/0
lrwx------ 1 ludo users 64 Sep 3 21:20 1 -> /dev/pts/0
lrwx------ 1 ludo users 64 Sep 3 21:20 2 -> /dev/pts/0
lr-x------ 1 ludo users 64 Sep 3 21:20 3 -> /proc/9563/fd
lr-x------ 1 ludo users 64 Sep 3 21:20 5 -> /gnu/store/4qbqaa4dgr2fwjjs9i2naqrd0djrcnw3-guix-command
$ head -1 $(type -P guix)
#!/gnu/store/9z95jms1r801z1kxpiq5xw594cxaw5jx-guile-wrapper/bin/guile --no-auto-compile

For a proper fix, one possibility would be to first augment
‘scm_i_mode_to_open_flags’ to recognize some letter for O_CLOEXEC. In
glibc, fopen(3) uses “e” for that.

Thoughts?

Ludo’.
L
L
Ludovic Courtès wrote on 7 Sep 2022 18:03
(address . 57567-done@debbugs.gnu.org)
87czc7qiij.fsf@gnu.org
Ludovic Courtès <ludo@gnu.org> skribis:

Toggle quote (7 lines)
> Currently ‘primitive-load’ opens files without O_CLOEXEC:
>
> port = scm_open_file_with_encoding (filename,
> scm_from_latin1_string ("r"),
> SCM_BOOL_T, /* guess_encoding */
> scm_from_latin1_string ("UTF-8"));

[...]

Toggle quote (4 lines)
> For a proper fix, one possibility would be to first augment
> ‘scm_i_mode_to_open_flags’ to recognize some letter for O_CLOEXEC. In
> glibc, fopen(3) uses “e” for that.

I went ahead and did that:

0aa1a9976 'primitive-load' opens files with O_CLOEXEC.
a356ceebe Add support for "e" flag (O_CLOEXEC) to 'open-file'.

Ludo’.
Closed
?