#include "afb-hsrv.h"
#include "afb-context.h"
#include "afb-hreq.h"
-#include "afb-sig-handler.h"
-#include "afb-thread.h"
+#include "sig-monitor.h"
+#include "jobs.h"
#include "afb-session.h"
#include "verbose.h"
#include "afb-common.h"
return -1;
}
+/*---------------------------------------------------------
+ | main event processing
+ +--------------------------------------------------------- */
+
+static void main_event_wait_and_dispatch(int signum, void *closure)
+{
+ struct sd_event *event = closure;
+ if (signum == 0)
+ sd_event_run(event, 30000000);
+}
+
/*---------------------------------------------------------
| main
| Parse option and launch action
int main(int argc, char *argv[])
{
struct afb_hsrv *hsrv;
- struct sd_event *eventloop;
+
+ // let's run this program with a low priority
+ nice(20);
LOGAUTH("afb-daemon");
config = afb_config_parse_arguments(argc, argv);
atexit(exit_handler);
+ if (sig_monitor_init() < 0) {
+ ERROR("failed to initialise signal handlers");
+ return 1;
+ }
+
+ if (jobs_init(3, 1, 20) < 0) {
+ ERROR("failed to initialise threading");
+ return 1;
+ }
+
// ------------------ sanity check ----------------------------------------
if (config->httpdPort <= 0) {
ERROR("no port is defined");
start_list(config->ldpaths, afb_api_so_add_pathset, "the binding path set");
start_list(config->so_bindings, afb_api_so_add_binding, "the binding");
- afb_session_init(config->nbSessionMax, config->cntxTimeout, config->token, afb_apis_count());
+ afb_session_init(config->nbSessionMax, config->cntxTimeout, config->token);
start_list(config->dbus_servers, afb_api_dbus_add_server, "the afb-dbus service");
start_list(config->ws_servers, afb_api_ws_add_server, "the afb-websocket service");
exit(1);
}
- if (afb_sig_handler_init() < 0) {
- ERROR("failed to initialise signal handlers");
- return 1;
- }
-
// set the root dir
if (afb_common_rootdir_set(config->rootdir) < 0) {
ERROR("failed to set common root directory");
return 1;
}
- if (afb_thread_init(3, 1, 20) < 0) {
- ERROR("failed to initialise threading");
- return 1;
- }
- // let's run this program with a low priority
- nice(20);
-
// ------------------ Finaly Process Commands -----------------------------
// let's not take the risk to run as ROOT
//if (getuid() == 0) goto errorNoRoot;
if (execute_command() < 0)
exit(1);
- /* signal that ready */
- if (config->readyfd != 0) {
- static const char readystr[] = "READY=1";
- write(config->readyfd, readystr, sizeof(readystr) - 1);
- close(config->readyfd);
+ /* records the loop */
+ if (jobs_add_events(NULL, 0, main_event_wait_and_dispatch, afb_common_get_event_loop()) < 0) {
+ ERROR("failed to set main_event_wait_and_dispatch");
+ return 1;
}
- // infinite loop
- eventloop = afb_common_get_event_loop();
+ /* ready */
sd_notify(1, "READY=1");
- for (;;)
- sd_event_run(eventloop, 30000000);
-
- WARNING("hoops returned from infinite loop [report bug]");
+ /* turn as processing thread */
+ jobs_add_me();
+ WARNING("hoops returned from jobs_add_me! [report bug]");
return 0;
}