klishd.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. #define _GNU_SOURCE
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <stdio.h>
  5. #include <string.h>
  6. #include <assert.h>
  7. #include <signal.h>
  8. #include <syslog.h>
  9. #include <unistd.h>
  10. #include <errno.h>
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <fcntl.h>
  14. #include <sys/socket.h>
  15. #include <sys/un.h>
  16. #include <sys/fsuid.h>
  17. #include <sys/wait.h>
  18. #include <poll.h>
  19. #include <time.h>
  20. #include <faux/faux.h>
  21. #include <faux/str.h>
  22. #include <faux/argv.h>
  23. #include <faux/ini.h>
  24. #include <faux/log.h>
  25. #include <faux/sched.h>
  26. #include <faux/sysdb.h>
  27. #include <faux/net.h>
  28. #include <faux/list.h>
  29. #include <faux/conv.h>
  30. #include <faux/file.h>
  31. #include <faux/eloop.h>
  32. #include <faux/error.h>
  33. #include <klish/ktp.h>
  34. #include <klish/ktp_session.h>
  35. #include <klish/kscheme.h>
  36. #include <klish/ischeme.h>
  37. #include <klish/kcontext.h>
  38. #include <klish/ksession.h>
  39. #include <klish/kdb.h>
  40. #include <klish/kpargv.h>
  41. #include "private.h"
  42. // Local static functions
  43. bool_t daemonize(const char *pidfile);
  44. bool_t kentry_entrys_is_empty(const kentry_t *entry);
  45. static int create_listen_unix_sock(const char *path);
  46. static kscheme_t *load_all_dbs(const char *dbs,
  47. faux_ini_t *global_config, faux_error_t *error);
  48. static bool_t clear_scheme(kscheme_t *scheme, faux_error_t *error);
  49. // Main loop events
  50. static bool_t stop_loop_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  51. void *associated_data, void *user_data);
  52. static bool_t refresh_config_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  53. void *associated_data, void *user_data);
  54. static bool_t client_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  55. void *associated_data, void *user_data);
  56. static bool_t listen_socket_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  57. void *associated_data, void *user_data);
  58. static bool_t wait_for_child_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  59. void *associated_data, void *user_data);
  60. //static bool_t sched_once(faux_eloop_t *eloop, faux_eloop_type_e type,
  61. // void *associated_data, void *user_data);
  62. //static bool_t sched_periodic(faux_eloop_t *eloop, faux_eloop_type_e type,
  63. // void *associated_data, void *user_data);
  64. static bool_t fd_stall_cb(ktpd_session_t *session, void *user_data);
  65. /** @brief Main function
  66. */
  67. int main(int argc, char **argv)
  68. {
  69. int retval = -1;
  70. struct options *opts = NULL;
  71. int pidfd = -1;
  72. int logoptions = 0;
  73. faux_eloop_t *eloop = NULL;
  74. int listen_unix_sock = -1;
  75. ktpd_session_t *ktpd_session = NULL;
  76. kscheme_t *scheme = NULL;
  77. faux_error_t *error = faux_error_new();
  78. faux_ini_t *config = NULL;
  79. int client_fd = -1;
  80. // struct timespec delayed = { .tv_sec = 10, .tv_nsec = 0 };
  81. // struct timespec period = { .tv_sec = 3, .tv_nsec = 0 };
  82. // Parse command line options
  83. opts = opts_init();
  84. if (opts_parse(argc, argv, opts))
  85. goto err;
  86. // Initialize syslog
  87. logoptions = LOG_CONS;
  88. if (opts->foreground)
  89. logoptions |= LOG_PERROR;
  90. openlog(LOG_NAME, logoptions, opts->log_facility);
  91. if (!opts->verbose)
  92. setlogmask(LOG_UPTO(LOG_INFO));
  93. // Parse config file
  94. syslog(LOG_DEBUG, "Parse config file: %s\n", opts->cfgfile);
  95. if (!access(opts->cfgfile, R_OK)) {
  96. if (!(config = config_parse(opts->cfgfile, opts)))
  97. goto err;
  98. } else if (opts->cfgfile_userdefined) {
  99. // User defined config must be found
  100. fprintf(stderr, "Error: Can't find config file %s\n",
  101. opts->cfgfile);
  102. goto err;
  103. }
  104. // DEBUG: Show options
  105. opts_show(opts);
  106. syslog(LOG_INFO, "Start daemon.\n");
  107. // Fork the daemon if needed
  108. if (!opts->foreground && !daemonize(opts->pidfile))
  109. goto err;
  110. // Load scheme
  111. if (!(scheme = load_all_dbs(opts->dbs, config, error))) {
  112. fprintf(stderr, "Scheme errors:\n");
  113. goto err;
  114. }
  115. // Listen socket
  116. syslog(LOG_DEBUG, "Create listen UNIX socket: %s\n", opts->unix_socket_path);
  117. listen_unix_sock = create_listen_unix_sock(opts->unix_socket_path);
  118. if (listen_unix_sock < 0)
  119. goto err;
  120. syslog(LOG_DEBUG, "Listen socket %d", listen_unix_sock);
  121. // Event loop
  122. eloop = faux_eloop_new(NULL);
  123. // Signals
  124. faux_eloop_add_signal(eloop, SIGINT, stop_loop_ev, NULL);
  125. faux_eloop_add_signal(eloop, SIGTERM, stop_loop_ev, NULL);
  126. faux_eloop_add_signal(eloop, SIGQUIT, stop_loop_ev, NULL);
  127. faux_eloop_add_signal(eloop, SIGHUP, refresh_config_ev, opts);
  128. faux_eloop_add_signal(eloop, SIGCHLD, wait_for_child_ev, NULL);
  129. // Listen socket. Waiting for new connections
  130. faux_eloop_add_fd(eloop, listen_unix_sock, POLLIN,
  131. listen_socket_ev, &client_fd);
  132. // Scheduled events
  133. // faux_eloop_add_sched_once_delayed(eloop, &delayed, 1, sched_once, NULL);
  134. // faux_eloop_add_sched_periodic_delayed(eloop, 2, sched_periodic, NULL, &period, FAUX_SCHED_INFINITE);
  135. // Main loop
  136. faux_eloop_loop(eloop);
  137. faux_eloop_free(eloop);
  138. retval = 0;
  139. err:
  140. // Print errors
  141. if (faux_error_len(error) > 0)
  142. faux_error_show(error);
  143. faux_error_free(error);
  144. // Close listen socket
  145. if (listen_unix_sock >= 0)
  146. close(listen_unix_sock);
  147. // Finish listen daemon if it's not forked service process.
  148. if (client_fd < 0) {
  149. // Free scheme
  150. clear_scheme(scheme, error);
  151. // Free command line options
  152. opts_free(opts);
  153. faux_ini_free(config);
  154. // Remove pidfile
  155. if (pidfd >= 0) {
  156. if (unlink(opts->pidfile) < 0) {
  157. syslog(LOG_ERR, "Can't remove pid-file %s: %s\n",
  158. opts->pidfile, strerror(errno));
  159. }
  160. }
  161. syslog(LOG_INFO, "Stop daemon.\n");
  162. return retval;
  163. }
  164. // ATTENTION: It's a forked service process
  165. retval = -1; // Pessimism for service process
  166. // Re-Initialize syslog
  167. openlog(LOG_SERVICE_NAME, logoptions, opts->log_facility);
  168. if (!opts->verbose)
  169. setlogmask(LOG_UPTO(LOG_INFO));
  170. ktpd_session = ktpd_session_new(client_fd, scheme, NULL);
  171. assert(ktpd_session);
  172. if (!ktpd_session) {
  173. syslog(LOG_ERR, "Can't create KTPd session\n");
  174. close(client_fd);
  175. goto err_client;
  176. }
  177. // ktpd_session_set_stall_cb(ktpd_session, fd_stall_cb, eloop);
  178. // faux_eloop_add_fd(eloop, new_conn, POLLIN, client_ev, clients);
  179. syslog(LOG_DEBUG, "New connection %d\n", client_fd);
  180. // Event loop
  181. eloop = faux_eloop_new(NULL);
  182. // Signals
  183. faux_eloop_add_signal(eloop, SIGINT, stop_loop_ev, NULL);
  184. faux_eloop_add_signal(eloop, SIGTERM, stop_loop_ev, NULL);
  185. faux_eloop_add_signal(eloop, SIGQUIT, stop_loop_ev, NULL);
  186. // FDs
  187. ktpd_session_set_stall_cb(ktpd_session, fd_stall_cb, eloop);
  188. faux_eloop_add_fd(eloop, client_fd, POLLIN, client_ev, ktpd_session);
  189. // Main service loop
  190. faux_eloop_loop(eloop);
  191. faux_eloop_free(eloop);
  192. retval = 0;
  193. err_client:
  194. ktpd_session_free(ktpd_session);
  195. // Free scheme
  196. clear_scheme(scheme, error);
  197. // Free command line options
  198. opts_free(opts);
  199. faux_ini_free(config);
  200. return retval;
  201. }
  202. bool_t daemonize(const char *pidfile)
  203. {
  204. int pidfd = -1;
  205. // Daemonize
  206. syslog(LOG_DEBUG, "Daemonize\n");
  207. if (daemon(0, 0) < 0) {
  208. syslog(LOG_ERR, "Can't daemonize\n");
  209. return BOOL_FALSE;
  210. }
  211. // Write pidfile
  212. syslog(LOG_DEBUG, "Write PID file: %s\n", pidfile);
  213. if ((pidfd = open(pidfile,
  214. O_WRONLY | O_CREAT | O_EXCL | O_TRUNC,
  215. S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
  216. syslog(LOG_WARNING, "Can't open pidfile %s: %s\n",
  217. pidfile, strerror(errno));
  218. } else {
  219. char str[20];
  220. snprintf(str, sizeof(str), "%u\n", getpid());
  221. str[sizeof(str) - 1] = '\0';
  222. if (write(pidfd, str, strlen(str)) < 0)
  223. syslog(LOG_WARNING, "Can't write to %s: %s\n",
  224. pidfile, strerror(errno));
  225. close(pidfd);
  226. }
  227. return BOOL_TRUE;
  228. }
  229. static bool_t load_db(kscheme_t *scheme, const char *db_name,
  230. faux_ini_t *config, faux_error_t *error)
  231. {
  232. kdb_t *db = NULL;
  233. const char *sofile = NULL;
  234. assert(scheme);
  235. if (!scheme)
  236. return BOOL_FALSE;
  237. assert(db_name);
  238. if (!db_name)
  239. return BOOL_FALSE;
  240. // DB.libxml2.so = <so filename>
  241. if (config)
  242. sofile = faux_ini_find(config, "so");
  243. db = kdb_new(db_name, sofile);
  244. assert(db);
  245. if (!db)
  246. return BOOL_FALSE;
  247. kdb_set_ini(db, config);
  248. kdb_set_error(db, error);
  249. // Load DB plugin
  250. if (!kdb_load_plugin(db)) {
  251. faux_error_sprintf(error,
  252. "DB \"%s\": Can't load DB plugin", db_name);
  253. kdb_free(db);
  254. return BOOL_FALSE;
  255. }
  256. // Check plugin API version
  257. if ((kdb_major(db) != KDB_MAJOR) ||
  258. (kdb_minor(db) != KDB_MINOR)) {
  259. faux_error_sprintf(error,
  260. "DB \"%s\": Plugin's API version is %u.%u, need %u.%u",
  261. db_name,
  262. kdb_major(db), kdb_minor(db),
  263. KDB_MAJOR, KDB_MINOR);
  264. kdb_free(db);
  265. return BOOL_FALSE;
  266. }
  267. // Init plugin
  268. if (kdb_has_init_fn(db) && !kdb_init(db)) {
  269. faux_error_sprintf(error,
  270. "DB \"%s\": Can't init DB plugin", db_name);
  271. kdb_free(db);
  272. return BOOL_FALSE;
  273. }
  274. // Load scheme
  275. if (!kdb_has_load_fn(db) || !kdb_load_scheme(db, scheme)) {
  276. faux_error_sprintf(error,
  277. "DB \"%s\": Can't load scheme from DB plugin", db_name);
  278. kdb_fini(db);
  279. kdb_free(db);
  280. return BOOL_FALSE;
  281. }
  282. // Fini plugin
  283. if (kdb_has_fini_fn(db) && !kdb_fini(db)) {
  284. faux_error_sprintf(error,
  285. "DB \"%s\": Can't fini DB plugin", db_name);
  286. kdb_free(db);
  287. return BOOL_FALSE;
  288. }
  289. kdb_free(db);
  290. return BOOL_TRUE;
  291. }
  292. static kscheme_t *load_all_dbs(const char *dbs,
  293. faux_ini_t *global_config, faux_error_t *error)
  294. {
  295. kscheme_t *scheme = NULL;
  296. faux_argv_t *dbs_argv = NULL;
  297. faux_argv_node_t *iter = NULL;
  298. const char *db_name = NULL;
  299. bool_t retcode = BOOL_TRUE;
  300. kcontext_t *context = NULL;
  301. assert(dbs);
  302. if (!dbs)
  303. return NULL;
  304. scheme = kscheme_new();
  305. assert(scheme);
  306. if (!scheme)
  307. return NULL;
  308. dbs_argv = faux_argv_new();
  309. assert(dbs_argv);
  310. if (!dbs_argv) {
  311. kscheme_free(scheme);
  312. return NULL;
  313. }
  314. if (faux_argv_parse(dbs_argv, dbs) <= 0) {
  315. kscheme_free(scheme);
  316. faux_argv_free(dbs_argv);
  317. return NULL;
  318. }
  319. // For each DB
  320. iter = faux_argv_iter(dbs_argv);
  321. while ((db_name = faux_argv_each(&iter))) {
  322. faux_ini_t *config = NULL; // Sub-config for current DB
  323. char *prefix = NULL;
  324. prefix = faux_str_mcat(&prefix, "DB.", db_name, ".", NULL);
  325. if (config)
  326. config = faux_ini_extract_subini(global_config, prefix);
  327. if (!load_db(scheme, db_name, config, error))
  328. retcode = BOOL_FALSE;
  329. faux_ini_free(config);
  330. faux_str_free(prefix);
  331. }
  332. faux_argv_free(dbs_argv);
  333. // Something went wrong while loading DBs
  334. if (!retcode) {
  335. kscheme_free(scheme);
  336. return NULL;
  337. }
  338. // Prepare scheme
  339. context = kcontext_new(KCONTEXT_PLUGIN_INIT);
  340. retcode = kscheme_prepare(scheme, context, error);
  341. kcontext_free(context);
  342. if (!retcode) {
  343. kscheme_free(scheme);
  344. faux_error_sprintf(error, "Scheme preparing errors.\n");
  345. return NULL;
  346. }
  347. /*
  348. // Debug
  349. {
  350. kdb_t *deploy_db = NULL;
  351. // Deploy (for testing purposes)
  352. deploy_db = kdb_new("ischeme", NULL);
  353. kdb_load_plugin(deploy_db);
  354. kdb_init(deploy_db);
  355. kdb_deploy_scheme(deploy_db, scheme);
  356. kdb_fini(deploy_db);
  357. kdb_free(deploy_db);
  358. }
  359. */
  360. return scheme;
  361. }
  362. static bool_t clear_scheme(kscheme_t *scheme, faux_error_t *error)
  363. {
  364. kcontext_t *context = NULL;
  365. if (!scheme)
  366. return BOOL_TRUE; // It's not an error
  367. context = kcontext_new(KCONTEXT_PLUGIN_FINI);
  368. kscheme_fini(scheme, context, error);
  369. kcontext_free(context);
  370. kscheme_free(scheme);
  371. return BOOL_TRUE;
  372. }
  373. /** @brief Create listen socket
  374. *
  375. * Previously removes old socket's file from filesystem. Note daemon must check
  376. * for already working daemon to don't duplicate.
  377. *
  378. * @param [in] path Socket path within filesystem.
  379. * @return Socket descriptor of < 0 on error.
  380. */
  381. static int create_listen_unix_sock(const char *path)
  382. {
  383. int sock = -1;
  384. int opt = 1;
  385. struct sockaddr_un laddr = {};
  386. assert(path);
  387. if (!path)
  388. return -1;
  389. if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
  390. syslog(LOG_ERR, "Can't create socket: %s\n", strerror(errno));
  391. goto err;
  392. }
  393. if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt))) {
  394. syslog(LOG_ERR, "Can't set socket options: %s\n", strerror(errno));
  395. goto err;
  396. }
  397. // Remove old (lost) socket's file
  398. unlink(path);
  399. laddr.sun_family = AF_UNIX;
  400. strncpy(laddr.sun_path, path, USOCK_PATH_MAX);
  401. laddr.sun_path[USOCK_PATH_MAX - 1] = '\0';
  402. if (bind(sock, (struct sockaddr *)&laddr, sizeof(laddr))) {
  403. syslog(LOG_ERR, "Can't bind socket %s: %s\n", path, strerror(errno));
  404. goto err;
  405. }
  406. if (listen(sock, 128)) {
  407. unlink(path);
  408. syslog(LOG_ERR, "Can't listen on socket %s: %s\n", path, strerror(errno));
  409. goto err;
  410. }
  411. return sock;
  412. err:
  413. if (sock >= 0)
  414. close(sock);
  415. return -1;
  416. }
  417. /** @brief Stop main event loop.
  418. */
  419. static bool_t stop_loop_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  420. void *associated_data, void *user_data)
  421. {
  422. // Happy compiler
  423. eloop = eloop;
  424. type = type;
  425. associated_data = associated_data;
  426. user_data = user_data;
  427. return BOOL_FALSE; // Stop Event Loop
  428. }
  429. /** @brief Wait for child processes (service processes).
  430. */
  431. static bool_t wait_for_child_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  432. void *associated_data, void *user_data)
  433. {
  434. int wstatus = 0;
  435. pid_t child_pid = -1;
  436. // Wait for any child process. Doesn't block.
  437. while ((child_pid = waitpid(-1, &wstatus, WNOHANG)) > 0) {
  438. if (WIFSIGNALED(wstatus)) {
  439. syslog(LOG_ERR, "Service process %d was terminated "
  440. "by signal: %d",
  441. child_pid, WTERMSIG(wstatus));
  442. } else {
  443. syslog(LOG_ERR, "Service process %d was terminated: %d",
  444. child_pid, WEXITSTATUS(wstatus));
  445. }
  446. }
  447. // Happy compiler
  448. eloop = eloop;
  449. type = type;
  450. associated_data = associated_data;
  451. user_data = user_data;
  452. return BOOL_TRUE;
  453. }
  454. /** @brief Re-read config file.
  455. *
  456. * This function can refresh klishd options but plugins (dbs for example) are
  457. * already inited and there is no way to re-init them on-the-fly.
  458. */
  459. static bool_t refresh_config_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  460. void *associated_data, void *user_data)
  461. {
  462. struct options *opts = (struct options *)user_data;
  463. faux_ini_t *ini = NULL;
  464. if (access(opts->cfgfile, R_OK) == 0) {
  465. syslog(LOG_DEBUG, "Re-reading config file \"%s\"\n", opts->cfgfile);
  466. if (!(ini = config_parse(opts->cfgfile, opts)))
  467. syslog(LOG_ERR, "Error while config file parsing.\n");
  468. } else if (opts->cfgfile_userdefined) {
  469. syslog(LOG_ERR, "Can't find config file \"%s\"\n", opts->cfgfile);
  470. }
  471. faux_ini_free(ini); // No way to use it later
  472. // Happy compiler
  473. eloop = eloop;
  474. type = type;
  475. associated_data = associated_data;
  476. return BOOL_TRUE;
  477. }
  478. static bool_t fd_stall_cb(ktpd_session_t *session, void *user_data)
  479. {
  480. faux_eloop_t *eloop = (faux_eloop_t *)user_data;
  481. assert(session);
  482. assert(eloop);
  483. faux_eloop_include_fd_event(eloop, ktpd_session_fd(session), POLLOUT);
  484. return BOOL_TRUE;
  485. }
  486. /** @brief Event on listen socket. New remote client.
  487. */
  488. static bool_t listen_socket_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  489. void *associated_data, void *user_data)
  490. {
  491. int new_conn = -1;
  492. faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
  493. pid_t child_pid = -1;
  494. assert(user_data);
  495. new_conn = accept(info->fd, NULL, NULL);
  496. if (new_conn < 0) {
  497. syslog(LOG_ERR, "Can't accept() new connection");
  498. return BOOL_TRUE;
  499. }
  500. // Fork new instance for newly connected client
  501. child_pid = fork();
  502. if (child_pid < 0) {
  503. close(new_conn);
  504. syslog(LOG_ERR, "Can't fork service process for client");
  505. return BOOL_TRUE;
  506. }
  507. // Parent
  508. if (child_pid > 0) {
  509. close(new_conn); // It's needed by child but not for parent
  510. syslog(LOG_ERR, "Service process for client was forked: %d",
  511. child_pid);
  512. return BOOL_TRUE;
  513. }
  514. // Child (forked service process)
  515. // Pass new ktpd_session to main programm
  516. *((int *)user_data) = new_conn;
  517. type = type; // Happy compiler
  518. eloop = eloop;
  519. // Return BOOL_FALSE to break listen parent loop. Child will create its
  520. // own loop then.
  521. return BOOL_FALSE;
  522. }
  523. static bool_t client_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  524. void *associated_data, void *user_data)
  525. {
  526. faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
  527. ktpd_session_t *ktpd_session = (ktpd_session_t *)user_data;
  528. assert(ktpd_session);
  529. // Write data
  530. if (info->revents & POLLOUT) {
  531. faux_eloop_exclude_fd_event(eloop, info->fd, POLLOUT);
  532. if (!ktpd_session_async_out(ktpd_session)) {
  533. // Someting went wrong
  534. faux_eloop_del_fd(eloop, info->fd);
  535. syslog(LOG_ERR, "Problem with async output");
  536. return BOOL_FALSE; // Stop event loop
  537. }
  538. }
  539. // Read data
  540. if (info->revents & POLLIN) {
  541. if (!ktpd_session_async_in(ktpd_session)) {
  542. // Someting went wrong
  543. faux_eloop_del_fd(eloop, info->fd);
  544. syslog(LOG_ERR, "Problem with async input");
  545. return BOOL_FALSE; // Stop event loop
  546. }
  547. }
  548. // EOF
  549. if (info->revents & POLLHUP) {
  550. faux_eloop_del_fd(eloop, info->fd);
  551. syslog(LOG_DEBUG, "Close connection %d", info->fd);
  552. return BOOL_FALSE; // Stop event loop
  553. }
  554. type = type; // Happy compiler
  555. return BOOL_TRUE;
  556. }
  557. /*
  558. static bool_t sched_once(faux_eloop_t *eloop, faux_eloop_type_e type,
  559. void *associated_data, void *user_data)
  560. {
  561. faux_eloop_info_sched_t *info = (faux_eloop_info_sched_t *)associated_data;
  562. printf("Once %d\n", info->ev_id);
  563. // Happy compiler
  564. eloop = eloop;
  565. type = type;
  566. associated_data = associated_data;
  567. user_data = user_data;
  568. return BOOL_TRUE;
  569. }
  570. */
  571. /*
  572. static bool_t sched_periodic(faux_eloop_t *eloop, faux_eloop_type_e type,
  573. void *associated_data, void *user_data)
  574. {
  575. faux_eloop_info_sched_t *info = (faux_eloop_info_sched_t *)associated_data;
  576. printf("Periodic %d\n", info->ev_id);
  577. // Happy compiler
  578. eloop = eloop;
  579. type = type;
  580. associated_data = associated_data;
  581. user_data = user_data;
  582. return BOOL_TRUE;
  583. }
  584. */