mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-29 21:23:06 +00:00
lib: Do not blindly set the _read and _write pointers to NULL
Adding a read with the address of the thread pointer we want to use will allow lib/thread.c to properly handle your thread pointers. Instead we were setting the pointer to NULL before we passed into the _read and _write thread functions. Remove the NULL pointer set and just let thread.c handle everything. vty_stdio_resume and vty_read would blindly add read and write which would cause vty_event() to drop the thread pointer. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
67e42128db
commit
43b8ca995b
48
lib/vty.c
48
lib/vty.c
@ -1335,7 +1335,6 @@ static int vty_read(struct thread *thread)
|
|||||||
|
|
||||||
int vty_sock = THREAD_FD(thread);
|
int vty_sock = THREAD_FD(thread);
|
||||||
struct vty *vty = THREAD_ARG(thread);
|
struct vty *vty = THREAD_ARG(thread);
|
||||||
vty->t_read = NULL;
|
|
||||||
|
|
||||||
/* Read raw data from socket */
|
/* Read raw data from socket */
|
||||||
if ((nbytes = read(vty->fd, buf, VTY_READ_BUFSIZ)) <= 0) {
|
if ((nbytes = read(vty->fd, buf, VTY_READ_BUFSIZ)) <= 0) {
|
||||||
@ -1529,13 +1528,9 @@ static int vty_flush(struct thread *thread)
|
|||||||
int vty_sock = THREAD_FD(thread);
|
int vty_sock = THREAD_FD(thread);
|
||||||
struct vty *vty = THREAD_ARG(thread);
|
struct vty *vty = THREAD_ARG(thread);
|
||||||
|
|
||||||
vty->t_write = NULL;
|
|
||||||
|
|
||||||
/* Tempolary disable read thread. */
|
/* Tempolary disable read thread. */
|
||||||
if ((vty->lines == 0) && vty->t_read) {
|
if (vty->lines == 0)
|
||||||
thread_cancel(vty->t_read);
|
THREAD_OFF(vty->t_read);
|
||||||
vty->t_read = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Function execution continue. */
|
/* Function execution continue. */
|
||||||
erase = ((vty->status == VTY_MORE || vty->status == VTY_MORELINE));
|
erase = ((vty->status == VTY_MORE || vty->status == VTY_MORELINE));
|
||||||
@ -1713,12 +1708,9 @@ void vty_stdio_suspend(void)
|
|||||||
if (!stdio_vty)
|
if (!stdio_vty)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (stdio_vty->t_write)
|
THREAD_OFF(stdio_vty->t_write);
|
||||||
thread_cancel(stdio_vty->t_write);
|
THREAD_OFF(stdio_vty->t_read);
|
||||||
if (stdio_vty->t_read)
|
THREAD_OFF(stdio_vty->t_timeout);
|
||||||
thread_cancel(stdio_vty->t_read);
|
|
||||||
if (stdio_vty->t_timeout)
|
|
||||||
thread_cancel(stdio_vty->t_timeout);
|
|
||||||
|
|
||||||
if (stdio_termios)
|
if (stdio_termios)
|
||||||
tcsetattr(0, TCSANOW, &stdio_orig_termios);
|
tcsetattr(0, TCSANOW, &stdio_orig_termios);
|
||||||
@ -2077,7 +2069,6 @@ static int vtysh_read(struct thread *thread)
|
|||||||
|
|
||||||
sock = THREAD_FD(thread);
|
sock = THREAD_FD(thread);
|
||||||
vty = THREAD_ARG(thread);
|
vty = THREAD_ARG(thread);
|
||||||
vty->t_read = NULL;
|
|
||||||
|
|
||||||
if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) {
|
if ((nbytes = read(sock, buf, VTY_READ_BUFSIZ)) <= 0) {
|
||||||
if (nbytes < 0) {
|
if (nbytes < 0) {
|
||||||
@ -2157,7 +2148,6 @@ static int vtysh_write(struct thread *thread)
|
|||||||
{
|
{
|
||||||
struct vty *vty = THREAD_ARG(thread);
|
struct vty *vty = THREAD_ARG(thread);
|
||||||
|
|
||||||
vty->t_write = NULL;
|
|
||||||
vtysh_flush(vty);
|
vtysh_flush(vty);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -2193,12 +2183,9 @@ void vty_close(struct vty *vty)
|
|||||||
bool was_stdio = false;
|
bool was_stdio = false;
|
||||||
|
|
||||||
/* Cancel threads.*/
|
/* Cancel threads.*/
|
||||||
if (vty->t_read)
|
THREAD_OFF(vty->t_read);
|
||||||
thread_cancel(vty->t_read);
|
THREAD_OFF(vty->t_write);
|
||||||
if (vty->t_write)
|
THREAD_OFF(vty->t_timeout);
|
||||||
thread_cancel(vty->t_write);
|
|
||||||
if (vty->t_timeout)
|
|
||||||
thread_cancel(vty->t_timeout);
|
|
||||||
|
|
||||||
/* Flush buffer. */
|
/* Flush buffer. */
|
||||||
buffer_flush_all(vty->obuf, vty->wfd);
|
buffer_flush_all(vty->obuf, vty->wfd);
|
||||||
@ -2254,7 +2241,6 @@ static int vty_timeout(struct thread *thread)
|
|||||||
struct vty *vty;
|
struct vty *vty;
|
||||||
|
|
||||||
vty = THREAD_ARG(thread);
|
vty = THREAD_ARG(thread);
|
||||||
vty->t_timeout = NULL;
|
|
||||||
vty->v_timeout = 0;
|
vty->v_timeout = 0;
|
||||||
|
|
||||||
/* Clear buffer*/
|
/* Clear buffer*/
|
||||||
@ -2651,25 +2637,20 @@ static void vty_event(enum event event, int sock, struct vty *vty)
|
|||||||
vector_set_index(Vvty_serv_thread, sock, vty_serv_thread);
|
vector_set_index(Vvty_serv_thread, sock, vty_serv_thread);
|
||||||
break;
|
break;
|
||||||
case VTYSH_READ:
|
case VTYSH_READ:
|
||||||
vty->t_read = NULL;
|
|
||||||
thread_add_read(vty_master, vtysh_read, vty, sock,
|
thread_add_read(vty_master, vtysh_read, vty, sock,
|
||||||
&vty->t_read);
|
&vty->t_read);
|
||||||
break;
|
break;
|
||||||
case VTYSH_WRITE:
|
case VTYSH_WRITE:
|
||||||
vty->t_write = NULL;
|
|
||||||
thread_add_write(vty_master, vtysh_write, vty, sock,
|
thread_add_write(vty_master, vtysh_write, vty, sock,
|
||||||
&vty->t_write);
|
&vty->t_write);
|
||||||
break;
|
break;
|
||||||
#endif /* VTYSH */
|
#endif /* VTYSH */
|
||||||
case VTY_READ:
|
case VTY_READ:
|
||||||
vty->t_read = NULL;
|
|
||||||
thread_add_read(vty_master, vty_read, vty, sock, &vty->t_read);
|
thread_add_read(vty_master, vty_read, vty, sock, &vty->t_read);
|
||||||
|
|
||||||
/* Time out treatment. */
|
/* Time out treatment. */
|
||||||
if (vty->v_timeout) {
|
if (vty->v_timeout) {
|
||||||
if (vty->t_timeout)
|
THREAD_OFF(vty->t_timeout);
|
||||||
thread_cancel(vty->t_timeout);
|
|
||||||
vty->t_timeout = NULL;
|
|
||||||
thread_add_timer(vty_master, vty_timeout, vty,
|
thread_add_timer(vty_master, vty_timeout, vty,
|
||||||
vty->v_timeout, &vty->t_timeout);
|
vty->v_timeout, &vty->t_timeout);
|
||||||
}
|
}
|
||||||
@ -2679,15 +2660,10 @@ static void vty_event(enum event event, int sock, struct vty *vty)
|
|||||||
&vty->t_write);
|
&vty->t_write);
|
||||||
break;
|
break;
|
||||||
case VTY_TIMEOUT_RESET:
|
case VTY_TIMEOUT_RESET:
|
||||||
if (vty->t_timeout) {
|
THREAD_OFF(vty->t_timeout);
|
||||||
thread_cancel(vty->t_timeout);
|
if (vty->v_timeout)
|
||||||
vty->t_timeout = NULL;
|
|
||||||
}
|
|
||||||
if (vty->v_timeout) {
|
|
||||||
vty->t_timeout = NULL;
|
|
||||||
thread_add_timer(vty_master, vty_timeout, vty,
|
thread_add_timer(vty_master, vty_timeout, vty,
|
||||||
vty->v_timeout, &vty->t_timeout);
|
vty->v_timeout, &vty->t_timeout);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3024,7 +3000,7 @@ void vty_reset(void)
|
|||||||
for (i = 0; i < vector_active(Vvty_serv_thread); i++)
|
for (i = 0; i < vector_active(Vvty_serv_thread); i++)
|
||||||
if ((vty_serv_thread = vector_slot(Vvty_serv_thread, i))
|
if ((vty_serv_thread = vector_slot(Vvty_serv_thread, i))
|
||||||
!= NULL) {
|
!= NULL) {
|
||||||
thread_cancel(vty_serv_thread);
|
THREAD_OFF(vty_serv_thread);
|
||||||
vector_slot(Vvty_serv_thread, i) = NULL;
|
vector_slot(Vvty_serv_thread, i) = NULL;
|
||||||
close(i);
|
close(i);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user