Lines Matching refs:tm
209 static int handle_iacs(struct term_session *tm, int c, int fd) in handle_iacs() argument
214 curr = start = tm->buff2+tm->buff2_avail; in handle_iacs()
215 end = tm->buff2 + c -1; in handle_iacs()
216 tm->rem = 0; in handle_iacs()
233 tm->rem = 1; in handle_iacs()
250 tm->rem = end - curr; in handle_iacs()
259 curr++, tm->rem++; in handle_iacs()
262 tm->rem++; in handle_iacs()
265 tm->rem = 0; in handle_iacs()
273 memcpy(start + i, end - tm->rem, tm->rem); //put remaining if we break; in handle_iacs()
308 struct term_session *tm = NULL; in telnetd_main() local
324 tm = xzalloc(sizeof(struct term_session)); in telnetd_main()
325 tm->child_pid = TT.fork_pid; in telnetd_main()
326 tm->new_fd = 0; in telnetd_main()
327 tm->pty_fd = pty_fd; in telnetd_main()
329 tm->next = session_list; in telnetd_main()
330 session_list = tm; in telnetd_main()
331 } else session_list = tm; in telnetd_main()
346 tm = session_list; in telnetd_main()
347 while (tm) { in telnetd_main()
349 if (tm->pty_fd > 0 && tm->buff1_avail < BUFSIZE) FD_SET(tm->pty_fd, &rd); in telnetd_main()
350 if (tm->new_fd >= 0 && tm->buff2_avail < BUFSIZE) FD_SET(tm->new_fd, &rd); in telnetd_main()
351 if (tm->pty_fd > 0 && (tm->buff2_avail - tm->buff2_written) > 0) in telnetd_main()
352 FD_SET(tm->pty_fd, &wr); in telnetd_main()
353 if (tm->new_fd >= 0 && (tm->buff1_avail - tm->buff1_written) > 0) in telnetd_main()
354 FD_SET(tm->new_fd, &wr); in telnetd_main()
355 tm = tm->next; in telnetd_main()
372 tm = xzalloc(sizeof(struct term_session)); in telnetd_main()
373 tm->child_pid = TT.fork_pid; in telnetd_main()
374 tm->new_fd = new_fd; in telnetd_main()
375 tm->pty_fd = pty_fd; in telnetd_main()
377 tm->next = session_list; in telnetd_main()
378 session_list = tm; in telnetd_main()
379 } else session_list = tm; in telnetd_main()
382 tm = session_list; in telnetd_main()
383 for (;tm;tm=tm->next) { in telnetd_main()
384 if (FD_ISSET(tm->pty_fd, &rd)) { in telnetd_main()
385 if ((c = read(tm->pty_fd, tm->buff1 + tm->buff1_avail, in telnetd_main()
386 BUFSIZE-tm->buff1_avail)) <= 0) break; in telnetd_main()
387 tm->buff1_avail += c; in telnetd_main()
388 if ((w = dup_iacs(tm->buff1 + tm->buff1_written, tm->new_fd + inetd_m, in telnetd_main()
389 tm->buff1_avail - tm->buff1_written)) < 0) break; in telnetd_main()
390 tm->buff1_written += w; in telnetd_main()
392 if (FD_ISSET(tm->new_fd, &rd)) { in telnetd_main()
393 if ((c = read(tm->new_fd, tm->buff2+tm->buff2_avail, in telnetd_main()
394 BUFSIZE-tm->buff2_avail)) <= 0) break; in telnetd_main()
395 c = handle_iacs(tm, c, tm->pty_fd); in telnetd_main()
396 tm->buff2_avail += c; in telnetd_main()
397 if ((w = write(tm->pty_fd, tm->buff2+ tm->buff2_written, in telnetd_main()
398 tm->buff2_avail - tm->buff2_written)) < 0) break; in telnetd_main()
399 tm->buff2_written += w; in telnetd_main()
401 if (FD_ISSET(tm->pty_fd, &wr)) { in telnetd_main()
402 if ((w = write(tm->pty_fd, tm->buff2 + tm->buff2_written, in telnetd_main()
403 tm->buff2_avail - tm->buff2_written)) < 0) break; in telnetd_main()
404 tm->buff2_written += w; in telnetd_main()
406 if (FD_ISSET(tm->new_fd, &wr)) { in telnetd_main()
407 if ((w = dup_iacs(tm->buff1 + tm->buff1_written, tm->new_fd + inetd_m, in telnetd_main()
408 tm->buff1_avail - tm->buff1_written)) < 0) break; in telnetd_main()
409 tm->buff1_written += w; in telnetd_main()
411 if (tm->buff1_written == tm->buff1_avail) in telnetd_main()
412 tm->buff1_written = tm->buff1_avail = 0; in telnetd_main()
413 if (tm->buff2_written == tm->buff2_avail) in telnetd_main()
414 tm->buff2_written = tm->buff2_avail = 0; in telnetd_main()
431 for (tm = session_list; tm; tm = tm->next) { in telnetd_main()
432 if (tm->child_pid == pid) break; in telnetd_main()
433 prev = tm; in telnetd_main()
435 if (!tm) return; // reparented child we don't care about in telnetd_main()
439 else prev->next = tm->next; in telnetd_main()
441 xclose(tm->pty_fd); in telnetd_main()
442 xclose(tm->new_fd); in telnetd_main()
443 free(tm); in telnetd_main()