1 /* Utility functions to setup applications */
3 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
4 * (C) 2011 by Holger Hans Peter Freyther
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <osmocom/core/application.h>
25 #include <osmocom/core/logging.h>
34 struct log_target *osmo_stderr_target;
36 void osmo_init_ignore_signals(void)
38 /* Signals that by default would terminate */
39 signal(SIGPIPE, SIG_IGN);
40 signal(SIGALRM, SIG_IGN);
41 signal(SIGHUP, SIG_IGN);
42 signal(SIGIO, SIG_IGN);
45 int osmo_init_logging(const struct log_info *log_info)
48 osmo_stderr_target = log_target_create_stderr();
49 if (!osmo_stderr_target)
52 log_add_target(osmo_stderr_target);
53 log_set_all_filter(osmo_stderr_target, 1);
57 int osmo_daemonize(void)
62 /* Check if parent PID == init, in which case we are already a daemon */
66 /* Fork from the parent process */
69 /* some error happened */
74 /* if we have received a positive PID, then we are the parent
79 /* FIXME: do we really want this? */
82 /* Create a new session and set process group ID */
87 /* Change to the /tmp directory, which prevents the CWD from being locked
88 * and unable to remove it */
93 /* Redirect stdio to /dev/null */
94 /* since C89/C99 says stderr is a macro, we can safely do this! */
96 freopen("/dev/null", "r", stdin);
97 freopen("/dev/null", "w", stdout);
98 freopen("/dev/null", "w", stderr);