mirror of
https://github.com/weechat/weechat.git
synced 2026-07-05 15:45:42 +02:00
core: fix crash if a file descriptor used in hook_fd() is too high (> 1024 on Linux/BSD) (closes #465)
The calls to select() are replaced by poll(), which doesn't have limitation on file descriptor number.
This commit is contained in:
@@ -19,6 +19,8 @@ https://weechat.org/files/releasenotes/ReleaseNotes-devel.html[release notes]
|
||||
|
||||
=== New features
|
||||
|
||||
* core: fix crash if a file descriptor used in hook_fd() is too high
|
||||
(> 1024 on Linux/BSD) (closes #465)
|
||||
* core: add option weechat.look.confirm_upgrade (closes #463)
|
||||
* core: allow ctrl-C to exit WeeChat when the passphrase is asked on startup
|
||||
(closes #452)
|
||||
|
||||
@@ -7228,6 +7228,8 @@ hook = weechat.hook_timer(20 * 1000, 0, 0, "my_timer_cb", "")
|
||||
|
||||
==== hook_fd
|
||||
|
||||
_Updated in 1.3._
|
||||
|
||||
Hook a file descriptor (file or socket).
|
||||
|
||||
Prototype:
|
||||
@@ -7249,6 +7251,7 @@ Arguments:
|
||||
* 'flag_read': 1 = catch read event, 0 = ignore
|
||||
* 'flag_write': 1 = catch write event, 0 = ignore
|
||||
* 'flag_exception': 1 = catch exception event, 0 = ignore
|
||||
(_WeeChat ≥ 1.3_: this argument is ignored and not used any more)
|
||||
* 'callback': function called a selected event occurs for file (or socket),
|
||||
arguments and return value:
|
||||
** 'void *data': pointer
|
||||
|
||||
@@ -7352,6 +7352,8 @@ hook = weechat.hook_timer(20 * 1000, 0, 0, "my_timer_cb", "")
|
||||
|
||||
==== hook_fd
|
||||
|
||||
_Mis à jour dans la 1.3._
|
||||
|
||||
Accrocher un descripteur de fichier (fichier ou socket).
|
||||
|
||||
Prototype :
|
||||
@@ -7373,6 +7375,7 @@ Paramètres :
|
||||
* 'flag_read' : 1 = intercepter un évènement de lecture, 0 = ignorer
|
||||
* 'flag_write' : 1 = intercepter un évènement d'écriture, 0 = ignorer
|
||||
* 'flag_exception' : 1 = intercepter un évènement d'exception, 0 = ignorer
|
||||
(_WeeChat ≥ 1.3_ : ce paramètre est ignoré et n'est plus utilisé)
|
||||
* 'callback' : fonction appelée lorsqu'un des évènements sélectionnés se
|
||||
produit pour le fichier (ou le socket), paramètres et valeur de retour :
|
||||
** 'void *data' : pointeur
|
||||
|
||||
@@ -7391,6 +7391,9 @@ hook = weechat.hook_timer(20 * 1000, 0, 0, "my_timer_cb", "")
|
||||
|
||||
==== hook_fd
|
||||
|
||||
// TRANSLATION MISSING
|
||||
_Updated in 1.3._
|
||||
|
||||
Hook su un descrittore file (file oppure socket).
|
||||
|
||||
Prototipo:
|
||||
@@ -7411,7 +7414,9 @@ Argomenti:
|
||||
* 'fd': descrittore file
|
||||
* 'flag_read': 1 = cattura l'evento lettura (read), 0 = ignora
|
||||
* 'flag_write': 1 = cattura l'evento scrittura (write), 0 = ignora
|
||||
// TRANSLATION MISSING
|
||||
* 'flag_exception': 1 = cattura l'eccezione evento (event), 0 = ignora
|
||||
(_WeeChat ≥ 1.3_: this argument is ignored and not used any more)
|
||||
* 'callback': funzione che chiama un evento selezionato che si verifica
|
||||
per un file (o un socket), argomenti e valore restituito:
|
||||
** 'void *data': puntatore
|
||||
|
||||
@@ -7227,6 +7227,8 @@ hook = weechat.hook_timer(20 * 1000, 0, 0, "my_timer_cb", "")
|
||||
|
||||
==== hook_fd
|
||||
|
||||
_バージョン 1.3 で更新。_
|
||||
|
||||
ファイルディスクリプタ (ファイルやソケット) をフック。
|
||||
|
||||
プロトタイプ:
|
||||
@@ -7247,7 +7249,9 @@ struct t_hook *weechat_hook_fd (int fd,
|
||||
* 'fd': ファイルディスクリプタ
|
||||
* 'flag_read': 1 = 読み込みイベントをキャッチ、0 = 無視
|
||||
* 'flag_write': 1 = 書き込みイベントをキャッチ、0 = 無視
|
||||
// TRANSLATION MISSING
|
||||
* 'flag_exception': 1 = 例外イベントをキャッチ、0 = 無視
|
||||
(_WeeChat ≥ 1.3_: this argument is ignored and not used any more)
|
||||
* 'callback': ファイル (またはソケット) に対してキャッチしたいイベントが発生した場合に実行する関数、
|
||||
引数と戻り値:
|
||||
** 'void *data': ポインタ
|
||||
|
||||
+153
-104
File diff suppressed because it is too large
Load Diff
+1
-5
@@ -467,17 +467,13 @@ extern struct t_hook *hook_timer (struct t_weechat_plugin *plugin,
|
||||
int max_calls,
|
||||
t_hook_callback_timer *callback,
|
||||
void *callback_data);
|
||||
extern void hook_timer_time_to_next (struct timeval *tv_timeout);
|
||||
extern void hook_timer_exec ();
|
||||
extern struct t_hook *hook_fd (struct t_weechat_plugin *plugin, int fd,
|
||||
int flag_read, int flag_write,
|
||||
int flag_exception,
|
||||
t_hook_callback_fd *callback,
|
||||
void *callback_data);
|
||||
extern int hook_fd_set (fd_set *read_fds, fd_set *write_fds,
|
||||
fd_set *exception_fds);
|
||||
extern void hook_fd_exec (fd_set *read_fds, fd_set *write_fds,
|
||||
fd_set *exception_fds);
|
||||
extern void hook_fd_exec ();
|
||||
extern struct t_hook *hook_process (struct t_weechat_plugin *plugin,
|
||||
const char *command,
|
||||
int timeout,
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/select.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
@@ -611,7 +611,7 @@ network_pass_proxy (const char *proxy, int sock, const char *address, int port)
|
||||
int
|
||||
network_connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
{
|
||||
fd_set write_fds;
|
||||
struct pollfd poll_fd;
|
||||
int ready, value;
|
||||
socklen_t len;
|
||||
|
||||
@@ -628,9 +628,12 @@ network_connect (int sock, const struct sockaddr *addr, socklen_t addrlen)
|
||||
*/
|
||||
while (1)
|
||||
{
|
||||
FD_ZERO (&write_fds);
|
||||
FD_SET (sock, &write_fds);
|
||||
ready = select (sock + 1, NULL, &write_fds, NULL, NULL);
|
||||
poll_fd.fd = sock;
|
||||
poll_fd.events = POLLOUT;
|
||||
poll_fd.revents = 0;
|
||||
ready = poll (&poll_fd, 1, -1);
|
||||
if (ready < 0)
|
||||
break;
|
||||
if (ready > 0)
|
||||
{
|
||||
len = sizeof (value);
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/select.h>
|
||||
|
||||
#include "../../core/weechat.h"
|
||||
#include "../../core/wee-command.h"
|
||||
@@ -383,10 +382,6 @@ void
|
||||
gui_main_loop ()
|
||||
{
|
||||
struct t_hook *hook_fd_keyboard;
|
||||
struct timeval tv_timeout;
|
||||
fd_set read_fds, write_fds, except_fds;
|
||||
int max_fd;
|
||||
int ready;
|
||||
|
||||
/* catch SIGWINCH signal: redraw screen */
|
||||
util_catch_signal (SIGWINCH, &gui_main_signal_sigwinch);
|
||||
@@ -399,7 +394,7 @@ gui_main_loop ()
|
||||
|
||||
while (!weechat_quit)
|
||||
{
|
||||
/* execute hook timers */
|
||||
/* execute timer hooks */
|
||||
hook_timer_exec ();
|
||||
|
||||
/* auto reset of color pairs */
|
||||
@@ -424,18 +419,8 @@ gui_main_loop ()
|
||||
|
||||
gui_color_pairs_auto_reset_pending = 0;
|
||||
|
||||
/* wait for keyboard or network activity */
|
||||
FD_ZERO (&read_fds);
|
||||
FD_ZERO (&write_fds);
|
||||
FD_ZERO (&except_fds);
|
||||
max_fd = hook_fd_set (&read_fds, &write_fds, &except_fds);
|
||||
hook_timer_time_to_next (&tv_timeout);
|
||||
ready = select (max_fd + 1, &read_fds, &write_fds, &except_fds,
|
||||
&tv_timeout);
|
||||
if (ready > 0)
|
||||
{
|
||||
hook_fd_exec (&read_fds, &write_fds, &except_fds);
|
||||
}
|
||||
/* execute fd hooks */
|
||||
hook_fd_exec ();
|
||||
}
|
||||
|
||||
/* remove keyboard hook */
|
||||
|
||||
Reference in New Issue
Block a user