3 * \author written by Emmanuel Roullit emmanuel.roullit@gmail.com (c) 2012
7 /* __LICENSE_HEADER_BEGIN__ */
10 * Copyright (C) 2012 Emmanuel Roullit <emmanuel.roullit@gmail.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or (at
15 * your option) any later version.
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 * You should have received a copy of the GNU General Public License along
23 * with this program; if not, write to the Free Software Foundation, Inc.,
24 * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
28 /* __LICENSE_HEADER_END__ */
36 #include <sys/types.h>
40 #include <dabbad/ipc.h>
41 #include <dabbad/help.h>
49 * \brief Dabbad options getter
50 * \return Dabbad option data structure
53 const struct option
*dabbad_options_get(void)
55 static const struct option dabbad_long_options
[] = {
56 {"daemonize", no_argument
, NULL
, OPT_DAEMONIZE
},
57 {"help", no_argument
, NULL
, OPT_HELP
},
61 return (dabbad_long_options
);
66 * \brief Create dabbad pidfile
67 * \return 0 on success, else on failure.
69 * This function creates start time a file containing dabbad process id.
72 static inline int dabbad_pidfile_create(void)
76 char pidstr
[8] = { 0 };
77 ssize_t pidstrlen
= 0;
79 pidfd
= creat(DABBAD_PID_FILE
, 0600);
84 pidstrlen
= snprintf(pidstr
, sizeof(pidstr
), "%i\n", getpid());
86 if (write(pidfd
, pidstr
, pidstrlen
) != pidstrlen
) {
95 * \brief Dabbad entry point
96 * \param[in] argc Argument counter
97 * \param[in] argv Argument vector
98 * \return 0 on success, else on failure
100 * This function is dabbad entry point.
101 * It parses given arguments, configure the daemon accordingly and start
102 * IPC message polling.
105 int main(int argc
, char **argv
)
114 getopt_long_only(argc
, argv
, "", dabbad_options_get(),
122 show_usage(dabbad_options_get());
131 perror("Could not daemonize process");
136 assert(dabbad_pidfile_create());
137 dabbad_ipc_msg_init();
139 return dabbad_ipc_msg_poll();