ktpd_session.c 16 KB

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