Template Version: @(#)sac_nextcase 1.68 02/23/09 SMI This information is Copyright 2009 Sun Microsystems 1. Introduction 1.1. Project/Component Working Name: daemon() in libc 1.2. Name of Document Author/Supplier: Author: Vladimir Kotal 1.3 Date of This Document: 17 August, 2009 4. Technical Description
Release binding is Patch/Micro. 1. Introduction 1.1. Project/Component Working Name: Add daemon() to libc 1.2. Name of Document Author/Supplier: Author: Vladimir Kotal 1.3. Date of This Document: 08/17/09 4. Technical Description Background ---------- Since early 90's the libc library shipped with BSD systems contained the daemon() function. It is still being used by daemons to go into background. Now, late in the first decade it's time to add the function to Solaris' libc. Proposal -------- This case proposes to add the daemon() function to libc. The goal of this case is to make it easier to port new software to OpenSolaris, make it more compatible with BSD systems and last but not least make OpenSolaris more approachable for Linux/BSD programmers. Comments -------- One could argue that the original daemon() does not offer much flexibility and that this approach to daemonization is actually not sufficient in SMF world. While this is true, it is out of scope of this case to provide modern alternative. Exported Interfaces ------------------- This case delivers the following interfaces: +----------------------------------------+----------------------+----------+ | Interfaces | Stability | CR | +----------------------------------------+----------------------+----------+ int daemon(int nochdir, int noclose) Committed 4471189 Man page update --------------- Standard C Library Functions daemon(3C) NAME daemon - basic daemonization function SYNOPSIS #include <stdlib.h> int daemon(int nochdir, int noclose); DESCRIPTION The daemon() function provides a way for applications to go into background. The function will ensure that the process calling this function: - runs in the background - deatches from the controlling terminal - forms a new process group - is not a session group leader The options to the function are treated as boolean variables and are evaluted using negative logic. If the nochdir option is other than zero the working directory will not be changed to the root directory, otherwise it will be. If the noclose option is other than zero the descriptors 0,1,2 (normally corresponding to standard input, output and error output, depending on the application) will not be redirected to /dev/null, otherwise they will be. RETURN VALUES Upon successful completion, daemon() returns 0. Otherwise it returns -1. EXAMPLES The main() function of a network server could look like this: int background; /* background flag */ /* Load and verify the configuration. */ /* Go into background. */ if (background && daemon(0, 0) < 0) err(1, "daemon"); /* Process requests here. */ ATTRIBUTES See attributes(5) for descriptions of the following attri- butes: ____________________________________________________________ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | |_____________________________|_____________________________| | Interface Stability | Committed | |_____________________________|_____________________________| | MT-Level | Async-Signal-Safe | |_____________________________|_____________________________| SEE ALSO attributes(5), fork(2), Intro(2), setsid(2) 6. Resources and Schedule 6.4. Steering Committee requested information 6.4.1. Consolidation C-team Name: ON 6.5. ARC review type: FastTrack 6.6. ARC Exposure: open