Bug 72213 - dispatch test on FreeBSD says "Fd 5 did not have the close-on-exec flag set!"
Summary: dispatch test on FreeBSD says "Fd 5 did not have the close-on-exec flag set!"
Status: RESOLVED FIXED
Alias: None
Product: dbus
Classification: Unclassified
Component: core (show other bugs)
Version: 1.5
Hardware: Other All
: medium normal
Assignee: Havoc Pennington
QA Contact:
URL:
Whiteboard: review?
Keywords: patch
Depends on:
Blocks:
 
Reported: 2013-12-02 04:53 UTC by Chengwei Yang
Modified: 2014-04-04 10:15 UTC (History)
4 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Fix the "Fd 5 did not have the close-on-exec flag set!" test warning (910 bytes, patch)
2013-12-02 04:57 UTC, Chengwei Yang
Details | Splinter Review

Description Chengwei Yang 2013-12-02 04:53:04 UTC
When doing "./bus/bus-test test/data dispatch" test, it warns that

  "Fd 5 did not have the close-on-exec flag set!"

many times, and at last it fails like

  "
Activating service name='org.freedesktop.DBus.TestSuiteEchoService'
Fd 5 did not have the close-on-exec flag set!
Successfully activated service 'org.freedesktop.DBus.TestSuiteEchoService'
Activating service name='org.freedesktop.DBus.TestSuiteEchoService'
Fd 5 did not have the close-on-exec flag set!
Failed to activate service 'org.freedesktop.DBus.TestSuiteEchoService': timed out
Did not expect error org.freedesktop.DBus.Error.TimedOut
existent_service_no_auto_start failed during oom
File "dispatch.c" line 4445 process 19024 should not have been reached: test failed
  D-Bus not compiled with backtrace support so unable to print a backtrace
Abort trap (core dumped)
  "
Comment 1 Chengwei Yang 2013-12-02 04:57:19 UTC
Created attachment 90073 [details] [review]
Fix the "Fd 5 did not have the close-on-exec flag set!" test warning
Comment 2 Simon McVittie 2013-12-02 12:18:13 UTC
(Cc'ing semi-recent contributors from FreeBSD, NetBSD.)

How long has each of the *BSD family had O_CLOEXEC? In other words, do we still need to support any systems that have kqueue but not O_CLOEXEC?

If in doubt, I assume we probably want the usual portability goo:

-          fd = open (new_dirs[i], O_RDONLY);
+#ifdef O_CLOEXEC
+          fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC);
+
+          if (retval < 0 && errno == EINVAL)
+#endif
+            fd = open (new_dirs[i], O_RDONLY);
+
+          _dbus_fd_set_close_on_exec (fd);

Elsewhere in libdbus, we sometimes avoid _dbus_fd_set_close_on_exec() if it would be a no-op, to save a syscall - but this is something that happens O(1) times per bus daemon, so life's too short to worry about syscall efficiency.

Indeed, we could just add the _dbus_fd_set_close_on_exec() call instead of using O_CLOEXEC at all. This code only executes in the dbus-daemon, which is single-threaded, so there's no thread-safety benefit to using O_CLOEXEC.
Comment 3 Simon McVittie 2013-12-02 12:22:51 UTC
(In reply to comment #2)
> (Cc'ing semi-recent contributors from FreeBSD, NetBSD.)

Sorry, make that FreeBSD and OpenBSD. If anyone else has any interest in keeping dbus working on *BSD (presumably it has some sort of maintainer in each ports tree?), please direct them to this bug tracker.

(In reply to comment #1)
> Fix the "Fd 5 did not have the close-on-exec flag set!" test warning

Does this also fix the test failure, or do the tests still fail?
Comment 4 Antoine Jacoutot 2013-12-02 14:03:40 UTC
(In reply to comment #2)
> (Cc'ing semi-recent contributors from FreeBSD, NetBSD.)
> 
> How long has each of the *BSD family had O_CLOEXEC? In other words, do we
> still need to support any systems that have kqueue but not O_CLOEXEC?

In OpenBSD we have it since more than 2 years -- so as far as OpenBSD is concerned, there is no need to support kqueue but not O_CLOEXEC.
Comment 5 Chengwei Yang 2013-12-02 14:21:13 UTC
(In reply to comment #3)
> (In reply to comment #2)
> > (Cc'ing semi-recent contributors from FreeBSD, NetBSD.)
> 
> Sorry, make that FreeBSD and OpenBSD. If anyone else has any interest in
> keeping dbus working on *BSD (presumably it has some sort of maintainer in
> each ports tree?), please direct them to this bug tracker.
> 
> (In reply to comment #1)
> > Fix the "Fd 5 did not have the close-on-exec flag set!" test warning
> 
> Does this also fix the test failure, or do the tests still fail?

Yes, still fail with 

"
Failed to activate service 'org.freedesktop.DBus.TestSuiteEchoService': timed out
Did not expect error org.freedesktop.DBus.Error.TimedOut
"

haven't work out a patch so far, seems the activated test-service blocking at wait "Hello" reply from message bus. So the test get a "TimedOut" error.
Comment 6 Chengwei Yang 2013-12-02 14:23:28 UTC
(In reply to comment #4)
> (In reply to comment #2)
> > (Cc'ing semi-recent contributors from FreeBSD, NetBSD.)
> > 
> > How long has each of the *BSD family had O_CLOEXEC? In other words, do we
> > still need to support any systems that have kqueue but not O_CLOEXEC?
> 
> In OpenBSD we have it since more than 2 years -- so as far as OpenBSD is
> concerned, there is no need to support kqueue but not O_CLOEXEC.

Great to know that from OpenBSD, I'm not sure since when O_CLOEXEC got supported in different *BSD, and its (on FreeBSD 9.1) man page doesn't tell me more, so I just assume it's well supported.
Comment 7 Chengwei Yang 2013-12-02 14:27:09 UTC
(In reply to comment #2)
> (Cc'ing semi-recent contributors from FreeBSD, NetBSD.)
> 
> How long has each of the *BSD family had O_CLOEXEC? In other words, do we
> still need to support any systems that have kqueue but not O_CLOEXEC?
> 
> If in doubt, I assume we probably want the usual portability goo:
> 
> -          fd = open (new_dirs[i], O_RDONLY);
> +#ifdef O_CLOEXEC
> +          fd = open (new_dirs[i], O_RDONLY | O_CLOEXEC);
> +
> +          if (retval < 0 && errno == EINVAL)
> +#endif
> +            fd = open (new_dirs[i], O_RDONLY);
> +
> +          _dbus_fd_set_close_on_exec (fd);
> 
> Elsewhere in libdbus, we sometimes avoid _dbus_fd_set_close_on_exec() if it
> would be a no-op, to save a syscall - but this is something that happens
> O(1) times per bus daemon, so life's too short to worry about syscall
> efficiency.
> 
> Indeed, we could just add the _dbus_fd_set_close_on_exec() call instead of
> using O_CLOEXEC at all. This code only executes in the dbus-daemon, which is
> single-threaded, so there's no thread-safety benefit to using O_CLOEXEC.

Agree, Seems a reasonable solution if we can not get enough information from *BSD community.
Comment 8 Joe Marcus Clarke 2013-12-02 15:23:45 UTC
O_CLOEXEC has been supported in FreeBSD since 8.X, which is the earliest supported version at the moment, so you can consider it properly supported there.  It was added to FreeBSD over two years ago
Comment 9 Chengwei Yang 2013-12-03 01:18:13 UTC
Opened a separate bug to track the timed out failure, see #bug72251.
Comment 10 Antoine Jacoutot 2013-12-27 16:14:49 UTC
Hi. Is there any information missing or can this or a variation or it be pushed?
Comment 11 Simon McVittie 2014-01-06 16:31:22 UTC
Fixed in git for 1.7.10, thanks.
Comment 12 Simon McVittie 2014-04-04 10:15:36 UTC
(In reply to comment #2)
> How long has each of the *BSD family had O_CLOEXEC? In other words, do we
> still need to support any systems that have kqueue but not O_CLOEXEC?

This turns out to break Mac OS X 10.6 (Bug #77032).


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.