ktpd_session.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <unistd.h>
  6. #include <errno.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #include <fcntl.h>
  10. #include <sys/socket.h>
  11. #include <sys/un.h>
  12. #include <syslog.h>
  13. #include <poll.h>
  14. #include <sys/wait.h>
  15. #include <faux/str.h>
  16. #include <faux/async.h>
  17. #include <faux/msg.h>
  18. #include <faux/eloop.h>
  19. #include <klish/ksession.h>
  20. #include <klish/ksession_parse.h>
  21. #include <klish/ktp.h>
  22. #include <klish/ktp_session.h>
  23. typedef enum {
  24. KTPD_SESSION_STATE_DISCONNECTED = 'd',
  25. KTPD_SESSION_STATE_UNAUTHORIZED = 'a',
  26. KTPD_SESSION_STATE_IDLE = 'i',
  27. KTPD_SESSION_STATE_WAIT_FOR_PROCESS = 'p',
  28. } ktpd_session_state_e;
  29. struct ktpd_session_s {
  30. ksession_t *session;
  31. ktpd_session_state_e state;
  32. uid_t uid;
  33. gid_t gid;
  34. char *user;
  35. faux_async_t *async;
  36. faux_hdr_t *hdr; // Engine will receive header and then msg
  37. faux_eloop_t *eloop; // External link, dont's free()
  38. kexec_t *exec;
  39. bool_t exit;
  40. };
  41. // Static declarations
  42. static bool_t ktpd_session_read_cb(faux_async_t *async,
  43. faux_buf_t *buf, size_t len, void *user_data);
  44. static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  45. void *associated_data, void *user_data);
  46. bool_t client_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  47. void *associated_data, void *user_data);
  48. static bool_t ktpd_session_exec(ktpd_session_t *ktpd, const char *line,
  49. int *retcode, faux_error_t *error, bool_t dry_run);
  50. ktpd_session_t *ktpd_session_new(int sock, kscheme_t *scheme,
  51. const char *start_entry, faux_eloop_t *eloop)
  52. {
  53. ktpd_session_t *ktpd = NULL;
  54. if (sock < 0)
  55. return NULL;
  56. if (!eloop)
  57. return NULL;
  58. ktpd = faux_zmalloc(sizeof(*ktpd));
  59. assert(ktpd);
  60. if (!ktpd)
  61. return NULL;
  62. // Init
  63. ktpd->state = KTPD_SESSION_STATE_IDLE;
  64. ktpd->eloop = eloop;
  65. ktpd->session = ksession_new(scheme, start_entry);
  66. assert(ktpd->session);
  67. ktpd->exec = NULL;
  68. // Exit flag. It differs from ksession done flag because KTPD session
  69. // can't exit immediately. It must finish current command processing
  70. // before really stop the event loop. Note: User defined plugin
  71. // function must use ksession done flag. This exit flag is internal
  72. // feature of KTPD session.
  73. ktpd->exit = BOOL_FALSE;
  74. // Async object
  75. ktpd->async = faux_async_new(sock);
  76. assert(ktpd->async);
  77. // Receive message header first
  78. faux_async_set_read_limits(ktpd->async,
  79. sizeof(faux_hdr_t), sizeof(faux_hdr_t));
  80. faux_async_set_read_cb(ktpd->async, ktpd_session_read_cb, ktpd);
  81. ktpd->hdr = NULL;
  82. faux_async_set_stall_cb(ktpd->async, ktp_stall_cb, ktpd->eloop);
  83. // Eloop callbacks
  84. faux_eloop_add_fd(ktpd->eloop, ktpd_session_fd(ktpd), POLLIN,
  85. client_ev, ktpd);
  86. faux_eloop_add_signal(ktpd->eloop, SIGCHLD, wait_for_actions_ev, ktpd);
  87. return ktpd;
  88. }
  89. void ktpd_session_free(ktpd_session_t *ktpd)
  90. {
  91. if (!ktpd)
  92. return;
  93. kexec_free(ktpd->exec);
  94. ksession_free(ktpd->session);
  95. faux_free(ktpd->hdr);
  96. close(ktpd_session_fd(ktpd));
  97. faux_async_free(ktpd->async);
  98. faux_free(ktpd);
  99. }
  100. static bool_t ktpd_session_process_cmd(ktpd_session_t *ktpd, faux_msg_t *msg)
  101. {
  102. char *line = NULL;
  103. int retcode = -1;
  104. ktp_cmd_e cmd = KTP_CMD_ACK;
  105. faux_error_t *error = NULL;
  106. bool_t rc = BOOL_FALSE;
  107. bool_t dry_run = BOOL_FALSE;
  108. uint32_t status = KTP_STATUS_NONE;
  109. assert(ktpd);
  110. assert(msg);
  111. // Get line from message
  112. if (!(line = faux_msg_get_str_param_by_type(msg, KTP_PARAM_LINE))) {
  113. ktp_send_error(ktpd->async, cmd, "The line is not specified");
  114. return BOOL_FALSE;
  115. }
  116. // Get dry-run flag from message
  117. if (KTP_STATUS_IS_DRY_RUN(faux_msg_get_status(msg)))
  118. dry_run = BOOL_TRUE;
  119. error = faux_error_new();
  120. ktpd->exec = NULL;
  121. rc = ktpd_session_exec(ktpd, line, &retcode, error, dry_run);
  122. faux_str_free(line);
  123. // Command is scheduled. Eloop will wait for ACTION completion.
  124. // So inform client about it and about command features like
  125. // interactive/non-interactive.
  126. if (ktpd->exec) {
  127. faux_msg_t *ack = NULL;
  128. ktp_status_e status = KTP_STATUS_INCOMPLETED;
  129. ack = ktp_msg_preform(cmd, status);
  130. faux_msg_send_async(ack, ktpd->async);
  131. faux_msg_free(ack);
  132. faux_error_free(error);
  133. return BOOL_TRUE; // Continue and wait for ACTION
  134. }
  135. // Here we don't need to wait for the action. We have retcode already.
  136. if (ksession_done(ktpd->session)) {
  137. ktpd->exit = BOOL_TRUE;
  138. status |= KTP_STATUS_EXIT;
  139. }
  140. if (rc) {
  141. uint8_t retcode8bit = 0;
  142. faux_msg_t *ack = ktp_msg_preform(cmd, status);
  143. retcode8bit = (uint8_t)(retcode & 0xff);
  144. faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);
  145. faux_msg_send_async(ack, ktpd->async);
  146. faux_msg_free(ack);
  147. } else {
  148. char *err = faux_error_cstr(error);
  149. ktp_send_error(ktpd->async, cmd, err);
  150. faux_str_free(err);
  151. return BOOL_FALSE;
  152. }
  153. faux_error_free(error);
  154. return BOOL_TRUE;
  155. }
  156. static bool_t ktpd_session_process_completion(ktpd_session_t *ktpd, faux_msg_t *msg)
  157. {
  158. char *line = NULL;
  159. faux_msg_t *ack = NULL;
  160. kpargv_t *pargv = NULL;
  161. ktp_cmd_e cmd = KTP_COMPLETION_ACK;
  162. assert(ktpd);
  163. assert(msg);
  164. // Get line from message
  165. if (!(line = faux_msg_get_str_param_by_type(msg, KTP_PARAM_LINE))) {
  166. ktp_send_error(ktpd->async, cmd, NULL);
  167. return BOOL_FALSE;
  168. }
  169. // Parsing
  170. pargv = ksession_parse_for_completion(ktpd->session, line);
  171. faux_str_free(line);
  172. if (!pargv) {
  173. ktp_send_error(ktpd->async, cmd, NULL);
  174. return BOOL_FALSE;
  175. }
  176. kpargv_debug(pargv);
  177. kpargv_free(pargv);
  178. // Send ACK message
  179. ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);
  180. faux_msg_send_async(ack, ktpd->async);
  181. faux_msg_free(ack);
  182. return BOOL_TRUE;
  183. }
  184. static bool_t ktpd_session_process_help(ktpd_session_t *ktpd, faux_msg_t *msg)
  185. {
  186. char *line = NULL;
  187. faux_msg_t *ack = NULL;
  188. // kpargv_t *pargv = NULL;
  189. ktp_cmd_e cmd = KTP_HELP_ACK;
  190. assert(ktpd);
  191. assert(msg);
  192. // Get line from message
  193. if (!(line = faux_msg_get_str_param_by_type(msg, KTP_PARAM_LINE))) {
  194. ktp_send_error(ktpd->async, cmd, NULL);
  195. return BOOL_FALSE;
  196. }
  197. /* // Parsing
  198. pargv = ksession_parse_line(ktpd->session, line, KPURPOSE_HELP);
  199. faux_str_free(line);
  200. kpargv_free(pargv);
  201. */
  202. // Send ACK message
  203. ack = ktp_msg_preform(cmd, KTP_STATUS_NONE);
  204. faux_msg_send_async(ack, ktpd->async);
  205. faux_msg_free(ack);
  206. return BOOL_TRUE;
  207. }
  208. static bool_t ktpd_session_dispatch(ktpd_session_t *ktpd, faux_msg_t *msg)
  209. {
  210. uint16_t cmd = 0;
  211. assert(ktpd);
  212. if (!ktpd)
  213. return BOOL_FALSE;
  214. assert(msg);
  215. if (!msg)
  216. return BOOL_FALSE;
  217. cmd = faux_msg_get_cmd(msg);
  218. switch (cmd) {
  219. case KTP_CMD:
  220. ktpd_session_process_cmd(ktpd, msg);
  221. break;
  222. case KTP_COMPLETION:
  223. ktpd_session_process_completion(ktpd, msg);
  224. break;
  225. case KTP_HELP:
  226. ktpd_session_process_help(ktpd, msg);
  227. break;
  228. default:
  229. syslog(LOG_WARNING, "Unsupported command: 0x%04u\n", cmd);
  230. break;
  231. }
  232. return BOOL_TRUE;
  233. }
  234. /** @brief Low-level function to receive KTP message.
  235. *
  236. * Firstly function gets the header of message. Then it checks and parses
  237. * header and find out the length of whole message. Then it receives the rest
  238. * of message.
  239. */
  240. static bool_t ktpd_session_read_cb(faux_async_t *async,
  241. faux_buf_t *buf, size_t len, void *user_data)
  242. {
  243. ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
  244. faux_msg_t *completed_msg = NULL;
  245. char *data = NULL;
  246. assert(async);
  247. assert(buf);
  248. assert(ktpd);
  249. // Linearize buffer
  250. data = malloc(len);
  251. faux_buf_read(buf, data, len);
  252. // Receive header
  253. if (!ktpd->hdr) {
  254. size_t whole_len = 0;
  255. size_t msg_wo_hdr = 0;
  256. ktpd->hdr = (faux_hdr_t *)data;
  257. // Check for broken header
  258. if (!ktp_check_header(ktpd->hdr)) {
  259. faux_free(ktpd->hdr);
  260. ktpd->hdr = NULL;
  261. return BOOL_FALSE;
  262. }
  263. whole_len = faux_hdr_len(ktpd->hdr);
  264. // msg_wo_hdr >= 0 because ktp_check_header() validates whole_len
  265. msg_wo_hdr = whole_len - sizeof(faux_hdr_t);
  266. // Plan to receive message body
  267. if (msg_wo_hdr > 0) {
  268. faux_async_set_read_limits(async,
  269. msg_wo_hdr, msg_wo_hdr);
  270. return BOOL_TRUE;
  271. }
  272. // Here message is completed (msg body has zero length)
  273. completed_msg = faux_msg_deserialize_parts(ktpd->hdr, NULL, 0);
  274. // Receive message body
  275. } else {
  276. completed_msg = faux_msg_deserialize_parts(ktpd->hdr, data, len);
  277. faux_free(data);
  278. }
  279. // Plan to receive msg header
  280. faux_async_set_read_limits(ktpd->async,
  281. sizeof(faux_hdr_t), sizeof(faux_hdr_t));
  282. faux_free(ktpd->hdr);
  283. ktpd->hdr = NULL; // Ready to recv new header
  284. // Here message is completed
  285. ktpd_session_dispatch(ktpd, completed_msg);
  286. faux_msg_free(completed_msg);
  287. return BOOL_TRUE;
  288. }
  289. bool_t ktpd_session_connected(ktpd_session_t *ktpd)
  290. {
  291. assert(ktpd);
  292. if (!ktpd)
  293. return BOOL_FALSE;
  294. if (KTPD_SESSION_STATE_DISCONNECTED == ktpd->state)
  295. return BOOL_FALSE;
  296. return BOOL_TRUE;
  297. }
  298. int ktpd_session_fd(const ktpd_session_t *ktpd)
  299. {
  300. assert(ktpd);
  301. if (!ktpd)
  302. return BOOL_FALSE;
  303. return faux_async_fd(ktpd->async);
  304. }
  305. static bool_t wait_for_actions_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  306. void *associated_data, void *user_data)
  307. {
  308. int wstatus = 0;
  309. pid_t child_pid = -1;
  310. ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
  311. int retcode = -1;
  312. uint8_t retcode8bit = 0;
  313. faux_msg_t *ack = NULL;
  314. ktp_cmd_e cmd = KTP_CMD_ACK;
  315. uint32_t status = KTP_STATUS_NONE;
  316. if (!ktpd)
  317. return BOOL_FALSE;
  318. // Wait for any child process. Doesn't block.
  319. while ((child_pid = waitpid(-1, &wstatus, WNOHANG)) > 0) {
  320. if (ktpd->exec)
  321. kexec_continue_command_execution(ktpd->exec, child_pid,
  322. wstatus);
  323. }
  324. if (!ktpd->exec)
  325. return BOOL_TRUE;
  326. // Check if kexec is done now
  327. if (!kexec_retcode(ktpd->exec, &retcode))
  328. return BOOL_TRUE; // Continue
  329. faux_eloop_del_fd(eloop, kexec_stdout(ktpd->exec));
  330. faux_eloop_del_fd(eloop, kexec_stderr(ktpd->exec));
  331. kexec_free(ktpd->exec);
  332. ktpd->exec = NULL;
  333. ktpd->state = KTPD_SESSION_STATE_IDLE;
  334. // All kexec_t actions are done so can break the loop if needed.
  335. if (ksession_done(ktpd->session)) {
  336. ktpd->exit = BOOL_TRUE;
  337. status |= KTP_STATUS_EXIT; // Notify client about exiting
  338. }
  339. // Send ACK message
  340. ack = ktp_msg_preform(cmd, status);
  341. retcode8bit = (uint8_t)(retcode & 0xff);
  342. faux_msg_add_param(ack, KTP_PARAM_RETCODE, &retcode8bit, 1);
  343. faux_msg_send_async(ack, ktpd->async);
  344. faux_msg_free(ack);
  345. type = type; // Happy compiler
  346. associated_data = associated_data; // Happy compiler
  347. if (ktpd->exit)
  348. return BOOL_FALSE;
  349. return BOOL_TRUE;
  350. }
  351. static bool_t action_stdout_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  352. void *associated_data, void *user_data)
  353. {
  354. faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
  355. ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
  356. ssize_t r = -1;
  357. faux_buf_t *faux_buf = NULL;
  358. char *buf = NULL;
  359. ssize_t len = 0;
  360. faux_msg_t *ack = NULL;
  361. // Some errors or fd is closed so remove it from polling
  362. if (!(info->revents & POLLIN)) {
  363. faux_eloop_del_fd(eloop, info->fd);
  364. return BOOL_TRUE;
  365. }
  366. if (!ktpd)
  367. return BOOL_TRUE;
  368. if (!ktpd->exec)
  369. return BOOL_TRUE;
  370. faux_buf = kexec_bufout(ktpd->exec);
  371. assert(faux_buf);
  372. do {
  373. void *linear_buf = NULL;
  374. ssize_t really_readed = 0;
  375. ssize_t linear_len =
  376. faux_buf_dwrite_lock_easy(faux_buf, &linear_buf);
  377. // Non-blocked read. The fd became non-blocked while
  378. // kexec_prepare().
  379. r = read(info->fd, linear_buf, linear_len);
  380. if (r > 0)
  381. really_readed = r;
  382. faux_buf_dwrite_unlock_easy(faux_buf, really_readed);
  383. } while (r > 0);
  384. len = faux_buf_len(faux_buf);
  385. if (0 == len)
  386. return BOOL_TRUE;
  387. buf = malloc(len);
  388. faux_buf_read(faux_buf, buf, len);
  389. // Create KTP_STDOUT message to send to client
  390. ack = ktp_msg_preform(KTP_STDOUT, KTP_STATUS_NONE);
  391. faux_msg_add_param(ack, KTP_PARAM_LINE, buf, len);
  392. faux_msg_send_async(ack, ktpd->async);
  393. faux_msg_free(ack);
  394. free(buf);
  395. // Happy compiler
  396. eloop = eloop;
  397. type = type;
  398. return BOOL_TRUE;
  399. }
  400. static bool_t action_stderr_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  401. void *associated_data, void *user_data)
  402. {
  403. faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
  404. ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
  405. ssize_t r = -1;
  406. faux_buf_t *faux_buf = NULL;
  407. char *buf = NULL;
  408. ssize_t len = 0;
  409. faux_msg_t *ack = NULL;
  410. // Some errors or fd is closed so remove it from polling
  411. if (!(info->revents & POLLIN)) {
  412. faux_eloop_del_fd(eloop, info->fd);
  413. return BOOL_TRUE;
  414. }
  415. if (!ktpd)
  416. return BOOL_TRUE;
  417. if (!ktpd->exec)
  418. return BOOL_TRUE;
  419. faux_buf = kexec_buferr(ktpd->exec);
  420. assert(faux_buf);
  421. do {
  422. void *linear_buf = NULL;
  423. ssize_t really_readed = 0;
  424. ssize_t linear_len =
  425. faux_buf_dwrite_lock_easy(faux_buf, &linear_buf);
  426. // Non-blocked read. The fd became non-blocked while
  427. // kexec_prepare().
  428. r = read(info->fd, linear_buf, linear_len);
  429. if (r > 0)
  430. really_readed = r;
  431. faux_buf_dwrite_unlock_easy(faux_buf, really_readed);
  432. } while (r > 0);
  433. len = faux_buf_len(faux_buf);
  434. if (0 == len)
  435. return BOOL_TRUE;
  436. buf = malloc(len);
  437. faux_buf_read(faux_buf, buf, len);
  438. // Create KTP_STDERR message to send to client
  439. ack = ktp_msg_preform(KTP_STDERR, KTP_STATUS_NONE);
  440. faux_msg_add_param(ack, KTP_PARAM_LINE, buf, len);
  441. faux_msg_send_async(ack, ktpd->async);
  442. faux_msg_free(ack);
  443. free(buf);
  444. // Happy compiler
  445. eloop = eloop;
  446. type = type;
  447. return BOOL_TRUE;
  448. }
  449. static bool_t ktpd_session_exec(ktpd_session_t *ktpd, const char *line,
  450. int *retcode, faux_error_t *error, bool_t dry_run)
  451. {
  452. kexec_t *exec = NULL;
  453. assert(ktpd);
  454. if (!ktpd)
  455. return BOOL_FALSE;
  456. // Parsing
  457. exec = ksession_parse_for_exec(ktpd->session, line, error);
  458. if (!exec)
  459. return BOOL_FALSE;
  460. // Set dry-run flag
  461. kexec_set_dry_run(exec, dry_run);
  462. // Session status can be changed while parsing
  463. // NOTE: kexec_t is atomic now
  464. // if (ksession_done(ktpd->session)) {
  465. // kexec_free(exec);
  466. // return BOOL_FALSE; // Because action is not completed
  467. // }
  468. // Execute kexec and then wait for completion using global Eloop
  469. if (!kexec_exec(exec)) {
  470. kexec_free(exec);
  471. return BOOL_FALSE; // Something went wrong
  472. }
  473. // If kexec contains only non-exec (for example dry-run) ACTIONs then
  474. // we don't need event loop and can return here.
  475. if (kexec_retcode(exec, retcode)) {
  476. kexec_free(exec);
  477. return BOOL_TRUE;
  478. }
  479. // Save kexec pointer to use later
  480. ktpd->state = KTPD_SESSION_STATE_WAIT_FOR_PROCESS;
  481. ktpd->exec = exec;
  482. faux_eloop_add_fd(ktpd->eloop, kexec_stdout(exec), POLLIN,
  483. action_stdout_ev, ktpd);
  484. faux_eloop_add_fd(ktpd->eloop, kexec_stderr(exec), POLLIN,
  485. action_stderr_ev, ktpd);
  486. return BOOL_TRUE;
  487. }
  488. bool_t client_ev(faux_eloop_t *eloop, faux_eloop_type_e type,
  489. void *associated_data, void *user_data)
  490. {
  491. faux_eloop_info_fd_t *info = (faux_eloop_info_fd_t *)associated_data;
  492. ktpd_session_t *ktpd = (ktpd_session_t *)user_data;
  493. faux_async_t *async = ktpd->async;
  494. assert(async);
  495. // Write data
  496. if (info->revents & POLLOUT) {
  497. faux_eloop_exclude_fd_event(eloop, info->fd, POLLOUT);
  498. if (faux_async_out(async) < 0) {
  499. // Someting went wrong
  500. faux_eloop_del_fd(eloop, info->fd);
  501. syslog(LOG_ERR, "Problem with async output");
  502. return BOOL_FALSE; // Stop event loop
  503. }
  504. }
  505. // Read data
  506. if (info->revents & POLLIN) {
  507. if (faux_async_in(async) < 0) {
  508. // Someting went wrong
  509. faux_eloop_del_fd(eloop, info->fd);
  510. syslog(LOG_ERR, "Problem with async input");
  511. return BOOL_FALSE; // Stop event loop
  512. }
  513. }
  514. // EOF
  515. if (info->revents & POLLHUP) {
  516. faux_eloop_del_fd(eloop, info->fd);
  517. syslog(LOG_DEBUG, "Close connection %d", info->fd);
  518. return BOOL_FALSE; // Stop event loop
  519. }
  520. // POLLERR
  521. if (info->revents & POLLERR) {
  522. faux_eloop_del_fd(eloop, info->fd);
  523. syslog(LOG_DEBUG, "POLLERR received %d", info->fd);
  524. return BOOL_FALSE; // Stop event loop
  525. }
  526. // POLLNVAL
  527. if (info->revents & POLLNVAL) {
  528. faux_eloop_del_fd(eloop, info->fd);
  529. syslog(LOG_DEBUG, "POLLNVAL received %d", info->fd);
  530. return BOOL_FALSE; // Stop event loop
  531. }
  532. type = type; // Happy compiler
  533. // Session can be really finished here. Note KTPD session can't be
  534. // stopped immediately so it's only two places within code to really
  535. // break the loop. This one and within wait_for_action_ev().
  536. if (ktpd->exit)
  537. return BOOL_FALSE;
  538. return BOOL_TRUE;
  539. }
  540. #if 0
  541. static void ktpd_session_bad_socket(ktpd_session_t *ktpd)
  542. {
  543. assert(ktpd);
  544. if (!ktpd)
  545. return;
  546. ktpd->state = KTPD_SESSION_STATE_DISCONNECTED;
  547. }
  548. #endif