Skip to content

bitcoind: Daemonize using daemon(3)#8813

Merged
laanwj merged 1 commit intobitcoin:masterfrom
laanwj:2016_09_daemonize
Sep 30, 2016
Merged

bitcoind: Daemonize using daemon(3)#8813
laanwj merged 1 commit intobitcoin:masterfrom
laanwj:2016_09_daemonize

Conversation

@laanwj
Copy link
Member

@laanwj laanwj commented Sep 26, 2016

Simplified version of #8278. Assumes that every OS that (a) is supported by Bitcoin Core (b) supports daemonization has the daemon() function in its C library.

  • Removes the fallback path for operating systems that support daemonization but not daemon(). This prevents never-exercised code from ending up in the repository (see discussion here:
    Forking daemon #8278 (comment)).
  • Removes the windows-specific path. Windows doesn't support daemon(), so it doesn't support daemonization there, automatically. Give an explicit error if a user specifies -daemon on an OS where this is not supported.
  • Also made showing the help message depend on HAVE_DECL_DAEMON instead of !WIN32.

The original problem reported in #8278 was "When started with cron, the sendmail process hung around waiting for its stdin, bitcoind's stdout/err, to close..".

@laanwj laanwj mentioned this pull request Sep 26, 2016
src/bitcoind.cpp Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not true anymore.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two more lines that can be deleted, thanks.

@laanwj laanwj force-pushed the 2016_09_daemonize branch 3 times, most recently from a7ca7c8 to dbd66f1 Compare September 26, 2016 10:17
@laanwj laanwj changed the title bitcoind: Daemonise using daemon(3) bitcoind: Daemonize using daemon(3) Sep 26, 2016
Simplified version of bitcoin#8278. Assumes that every OS that (a) is supported
by Bitcoin Core (b) supports daemonization has the `daemon()` function
in its C library.

- Removes the fallback path for operating systems that support
  daemonization but not `daemon()`. This prevents never-exercised code from
  ending up in the repository (see discussion here:
  bitcoin#8278 (comment)).

- Removes the windows-specific path. Windows doesn't support `daemon()`,
  so it don't support daemonization there, automatically.

Original code by Matthew King, adapted by Wladimir van der Laan.
Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK a92bf4a (-comment nit mentioned by @sipa)

@jonasschnelli
Copy link
Contributor

Tested ACK (OSX) a92bf4a.
Binaries: https://bitcoin.jonasschnelli.ch/pulls/8813/

bildschirmfoto 2016-09-26 um 16 08 46

@maflcko
Copy link
Member

maflcko commented Sep 27, 2016

Possibly related: #4676 (haven't checked)

@sipa
Copy link
Member

sipa commented Sep 28, 2016

Concept ACK.

@laanwj
Copy link
Member Author

laanwj commented Sep 28, 2016

Possibly related: #4676 (haven't checked)

Yes, using daemonize() seems quite a step closer to standard UNIX daemon practices. Though we had to decide in #8278 to use the nochdir flag as, without further changes, it would have effects on option behavior.

@laanwj laanwj merged commit a92bf4a into bitcoin:master Sep 30, 2016
laanwj added a commit that referenced this pull request Sep 30, 2016
a92bf4a bitcoind: Daemonize using daemon(3) (Matthew King)
@laanwj
Copy link
Member Author

laanwj commented Sep 30, 2016

Note: if you end up here seeing the "Error: -daemon is not supported on this operating system" message while your OS does support it, this most likely means you need to re-run autogen.sh and configure.

@paveljanik
Copy link
Contributor

This brings new warning on OS X:

bitcoind.cpp:137:17: warning: 'daemon' is deprecated: first deprecated in OS X 10.5 [-Wdeprecated-declarations]
            if (daemon(1, 0)) {
                ^
/usr/include/stdlib.h:267:5: note: 'daemon' has been explicitly marked deprecated here
int daemon(int, int) __asm("_" "daemon" "$1050") __attribute__((availability(macosx,introduced=10.0,deprecated=10.5)));
    ^
1 warning generated.

@laanwj
Copy link
Member Author

laanwj commented Oct 22, 2016

You can't be friggin serious.
I'm going to revert this - it's only causing trouble.

@laanwj
Copy link
Member Author

laanwj commented Oct 22, 2016

@paveljanik Just curious do they suggest anything to use instead of daemon?

@jonasschnelli
Copy link
Contributor

jonasschnelli commented Oct 22, 2016

I wouldn't take the deprecation warning to serious.
OSX want devs to use its own launchd/launchctrl.
Removing the actual daemon() systemcall would break tons of applications and if - we would have at least 1-2 years to switch to launchd on OSX.

@laanwj
Copy link
Member Author

laanwj commented Oct 22, 2016

Apparently they recommend doing something Apple-specific with plists and such https://developer.apple.com/library/content/technotes/tn2083/_index.html#//%20apple_ref/doc/uid/DTS10003794-CH1-SUBSECTION64
Bah. Okay, reverting this isn't any help either then. Never mind that. I got upset.

@paveljanik
Copy link
Contributor

I agree with @jonasschnelli. No need to revert this. This only shows how Apple deprecates stuff.
10.5. Deprecated since October 26, 2007, still works now ;-)

What is the current status of daemon in the current macOS?

luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016
Simplified version of bitcoin#8278. Assumes that every OS that (a) is supported
by Bitcoin Core (b) supports daemonization has the `daemon()` function
in its C library.

- Removes the fallback path for operating systems that support
  daemonization but not `daemon()`. This prevents never-exercised code from
  ending up in the repository (see discussion here:
  bitcoin#8278 (comment)).

- Removes the windows-specific path. Windows doesn't support `daemon()`,
  so it don't support daemonization there, automatically.

Original code by Matthew King, adapted by Wladimir van der Laan.

Github-Pull: bitcoin#8813
Rebased-From: a92bf4a
codablock pushed a commit to codablock/dash that referenced this pull request Jan 12, 2018
a92bf4a bitcoind: Daemonize using daemon(3) (Matthew King)
andvgal pushed a commit to energicryptocurrency/gen2-energi that referenced this pull request Jan 6, 2019
a92bf4a bitcoind: Daemonize using daemon(3) (Matthew King)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants