klishd.c 17 KB

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