-LIBUSB_CFLAGS := $(shell pkg-config --cflags libusb-1.0)
-LIBUSB_LIBS := $(shell pkg-config --libs libusb-1.0)
+# PC=PKG_CONFIG_PATH=/home/mj/src/libucw/run/lib/pkgconfig pkg-config
+PC=PKG_CONFIG_PATH=/opt/lib/pkgconfig pkg-config
-LIBPULSE_CFLAGS := $(shell pkg-config --cflags libpulse)
-LIBPULSE_LIBS := $(shell pkg-config --libs libpulse)
+LIBUSB_CFLAGS := $(shell $(PC) --cflags libusb-1.0)
+LIBUSB_LIBS := $(shell $(PC) --libs libusb-1.0)
-LIBUCW_PKG := /home/mj/src/libucw/run/lib/pkgconfig
-LIBUCW_CFLAGS := $(shell PKG_CONFIG_PATH=$(LIBUCW_PKG) pkg-config --cflags libucw)
-LIBUCW_LIBS := $(shell PKG_CONFIG_PATH=$(LIBUCW_PKG) pkg-config --libs libucw)
+LIBPULSE_CFLAGS := $(shell $(PC) --cflags libpulse)
+LIBPULSE_LIBS := $(shell $(PC) --libs libpulse)
+
+LIBUCW_CFLAGS := $(shell $(PC) --cflags libucw)
+LIBUCW_LIBS := $(shell $(PC) --libs libucw)
CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 $(LIBUCW_CFLAGS) $(LIBUSB_CFLAGS) $(LIBPULSE_CFLAGS) -g2
LDLIBS=$(LIBUCW_LIBS) $(LIBUSB_LIBS) $(LIBPULSE_LIBS)
* (c) 2014 Martin Mares <mj@ucw.cz>
*/
-#define LOCAL_DEBUG
+#undef LOCAL_DEBUG
#include <ucw/lib.h>
#include <ucw/clists.h>
+#include <ucw/daemon.h>
+#include <ucw/log.h>
#include <ucw/mainloop.h>
+#include <ucw/opt.h>
#include <ucw/stkstring.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
+#include <syslog.h>
#include "ursaryd.h"
/*** Main entry point ***/
-int main(int argc UNUSED, char **argv)
+static void daemon_body(struct daemon_params *dp UNUSED)
{
- log_init(argv[0]);
main_init();
update_timer.handler = do_update;
pulse_init();
mpd_init();
- msg(L_DEBUG, "Entering main loop");
+ msg(L_INFO, "Ursary daemon starting");
main_loop();
+}
+
+static int debug;
+
+static struct opt_section options = {
+ OPT_ITEMS {
+ OPT_HELP("Control console for the Ursary"),
+ OPT_HELP(""),
+ OPT_HELP("Options:"),
+ OPT_HELP_OPTION,
+ OPT_BOOL('d', "debug", debug, 0, "\tEnable debugging mode (no fork etc.)"),
+ OPT_END
+ }
+};
+
+int main(int argc UNUSED, char **argv)
+{
+ opt_parse(&options, argv+1);
+ unsetenv("DISPLAY");
+ unsetenv("HOME");
+
+ struct daemon_params dp = {
+ .flags = (debug ? DAEMON_FLAG_SIMULATE : 0),
+ .pid_file = "/run/ursaryd.pid",
+ .run_as_user = "ursary",
+ };
+ daemon_init(&dp);
+
+ if (debug)
+ {
+ log_init(argv[0]);
+ }
+ else
+ {
+ struct log_stream *ls = log_new_syslog("daemon", LOG_PID);
+ log_set_default_stream(ls);
+ }
+ daemon_run(&dp, daemon_body);
return 0;
}