mirror of
https://github.com/weechat/weechat.git
synced 2026-07-02 15:53:12 +02:00
core, plugins: abort upgrade immediately if any upgrade file fails to be written
Detail of changes: - the save of upgrade files in plugins is now done as soon as the "upgrade" signal is received, and not when the plugin is unloaded (it was too late to detect any problem and prevent the upgrade to happen) - if the write of an upgrade file fails, the signal callback in plugin now returns WEECHAT_RC_ERROR and WeeChat checks this code to stop the upgrade as soon as this return code is received - a new flag is added in plugin structure: unload_with_upgrade, it is set to 1 before unloading all plugins when upgrade will happen (all *.upgrade files are then already successfully written).
This commit is contained in:
@@ -199,7 +199,7 @@ irc_buffer_close_cb (const void *pointer, void *data,
|
||||
IRC_SERVER_OPTION_AUTOJOIN_DYNAMIC)
|
||||
&& ptr_server->is_connected
|
||||
&& !irc_signal_quit_received
|
||||
&& !irc_signal_upgrade_received)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_join_remove_channel_from_autojoin (ptr_server,
|
||||
ptr_channel->name);
|
||||
|
||||
@@ -452,7 +452,8 @@ irc_notify_free (struct t_irc_server *server, struct t_irc_notify *notify,
|
||||
if (notify->nick)
|
||||
{
|
||||
if ((server->monitor > 0) && remove_monitor
|
||||
&& (server->is_connected) && !irc_signal_upgrade_received)
|
||||
&& (server->is_connected)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
/* remove one monitored nick */
|
||||
irc_server_sendf (notify->server,
|
||||
@@ -491,7 +492,7 @@ irc_notify_free_all (struct t_irc_server *server)
|
||||
{
|
||||
/* remove all monitored nicks */
|
||||
if ((server->monitor > 0) && (server->is_connected)
|
||||
&& !irc_signal_upgrade_received)
|
||||
&& !weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_server_sendf (server, IRC_SERVER_SEND_OUTQ_PRIO_LOW, NULL,
|
||||
"MONITOR C");
|
||||
|
||||
@@ -2411,7 +2411,7 @@ irc_server_free (struct t_irc_server *server)
|
||||
* (only if we are not in a /upgrade, because during upgrade we want to
|
||||
* keep connections and closing server buffer would disconnect from server)
|
||||
*/
|
||||
if (server->buffer && !irc_signal_upgrade_received)
|
||||
if (server->buffer && !weechat_irc_plugin->unload_with_upgrade)
|
||||
weechat_buffer_close (server->buffer);
|
||||
|
||||
/* remove server from queue */
|
||||
|
||||
+18
-7
@@ -61,7 +61,6 @@ struct t_weechat_plugin *weechat_irc_plugin = NULL;
|
||||
struct t_hook *irc_hook_timer = NULL;
|
||||
|
||||
int irc_signal_quit_received = 0; /* signal "quit" received? */
|
||||
int irc_signal_upgrade_received = 0; /* signal "upgrade" received? */
|
||||
|
||||
|
||||
/*
|
||||
@@ -121,12 +120,17 @@ irc_signal_upgrade_cb (const void *pointer, void *data,
|
||||
* save session with a disconnected state in servers and a scheduled
|
||||
* reconnection
|
||||
*/
|
||||
irc_upgrade_save (1);
|
||||
if (!irc_upgrade_save (1))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
irc_signal_upgrade_received = 1;
|
||||
|
||||
quit = (signal_data && (strcmp (signal_data, "quit") == 0));
|
||||
|
||||
tls_disconnected = 0;
|
||||
@@ -178,6 +182,15 @@ irc_signal_upgrade_cb (const void *pointer, void *data,
|
||||
tls_disconnected);
|
||||
}
|
||||
|
||||
if (!irc_upgrade_save (0))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), IRC_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -194,7 +207,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
weechat_plugin = plugin;
|
||||
|
||||
irc_signal_quit_received = 0;
|
||||
irc_signal_upgrade_received = 0;
|
||||
|
||||
irc_color_init ();
|
||||
|
||||
@@ -323,10 +335,9 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
irc_hook_timer = NULL;
|
||||
}
|
||||
|
||||
if (irc_signal_upgrade_received)
|
||||
if (weechat_irc_plugin->unload_with_upgrade)
|
||||
{
|
||||
irc_config_write (1);
|
||||
irc_upgrade_save (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -28,6 +28,5 @@
|
||||
extern struct t_weechat_plugin *weechat_irc_plugin;
|
||||
|
||||
extern int irc_signal_quit_received;
|
||||
extern int irc_signal_upgrade_received;
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_IRC_H */
|
||||
|
||||
@@ -595,6 +595,7 @@ plugin_load (const char *filename, int init_plugin, int argc, char **argv)
|
||||
ptr_option = config_weechat_debug_get (name);
|
||||
new_plugin->debug = (ptr_option) ? CONFIG_INTEGER(ptr_option) : 0;
|
||||
new_plugin->upgrading = weechat_upgrading;
|
||||
new_plugin->unload_with_upgrade = 0;
|
||||
new_plugin->variables = hashtable_new (
|
||||
32,
|
||||
WEECHAT_HASHTABLE_STRING, WEECHAT_HASHTABLE_STRING,
|
||||
@@ -1461,6 +1462,7 @@ plugin_hdata_plugin_cb (const void *pointer, void *data,
|
||||
HDATA_VAR(struct t_weechat_plugin, initialized, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_weechat_plugin, debug, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_weechat_plugin, upgrading, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_weechat_plugin, unload_with_upgrade, INTEGER, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_weechat_plugin, variables, HASHTABLE, 0, NULL, NULL);
|
||||
HDATA_VAR(struct t_weechat_plugin, prev_plugin, POINTER, 0, NULL, hdata_name);
|
||||
HDATA_VAR(struct t_weechat_plugin, next_plugin, POINTER, 0, NULL, hdata_name);
|
||||
@@ -1521,6 +1523,8 @@ plugin_add_to_infolist (struct t_infolist *infolist,
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "upgrading", plugin->upgrading))
|
||||
return 0;
|
||||
if (!infolist_new_var_integer (ptr_item, "unload_with_upgrade", plugin->unload_with_upgrade))
|
||||
return 0;
|
||||
if (!hashtable_add_to_infolist (plugin->variables, ptr_item, "var"))
|
||||
return 0;
|
||||
|
||||
@@ -1553,6 +1557,7 @@ plugin_print_log ()
|
||||
log_printf (" initialized. . . . . . : %d", ptr_plugin->initialized);
|
||||
log_printf (" debug. . . . . . . . . : %d", ptr_plugin->debug);
|
||||
log_printf (" upgrading. . . . . . . : %d", ptr_plugin->upgrading);
|
||||
log_printf (" unload_with_upgrade. . : %d", ptr_plugin->unload_with_upgrade);
|
||||
hashtable_print_log (ptr_plugin->variables, "variables");
|
||||
log_printf (" prev_plugin. . . . . . : %p", ptr_plugin->prev_plugin);
|
||||
log_printf (" next_plugin. . . . . . : %p", ptr_plugin->next_plugin);
|
||||
|
||||
@@ -251,7 +251,7 @@ relay_server_close_socket (struct t_relay_server *server)
|
||||
server->sock = -1;
|
||||
if (server->unix_socket)
|
||||
unlink (server->path);
|
||||
if (!relay_signal_upgrade_received)
|
||||
if (!weechat_relay_plugin->unload_with_upgrade)
|
||||
{
|
||||
weechat_printf (NULL,
|
||||
_("%s: socket closed for %s (%s: %s)"),
|
||||
|
||||
+18
-10
@@ -73,8 +73,6 @@ struct t_hdata *relay_hdata_completion = NULL;
|
||||
struct t_hdata *relay_hdata_completion_word = NULL;
|
||||
struct t_hdata *relay_hdata_hotlist = NULL;
|
||||
|
||||
int relay_signal_upgrade_received = 0; /* signal "upgrade" received ? */
|
||||
|
||||
struct t_hook *relay_hook_timer = NULL;
|
||||
|
||||
|
||||
@@ -151,12 +149,17 @@ relay_signal_upgrade_cb (const void *pointer, void *data,
|
||||
if (signal_data && (strcmp (signal_data, "save") == 0))
|
||||
{
|
||||
/* save session with a disconnected state in clients */
|
||||
relay_upgrade_save (1);
|
||||
if (!relay_upgrade_save (1))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
relay_signal_upgrade_received = 1;
|
||||
|
||||
/* close socket for relay servers */
|
||||
for (ptr_server = relay_servers; ptr_server;
|
||||
ptr_server = ptr_server->next_server)
|
||||
@@ -203,6 +206,15 @@ relay_signal_upgrade_cb (const void *pointer, void *data,
|
||||
NG_("client", "clients", tls_disconnected));
|
||||
}
|
||||
|
||||
if (!relay_upgrade_save (0))
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), RELAY_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -284,8 +296,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
relay_hdata_completion_word = weechat_hdata_get ("completion_word");
|
||||
relay_hdata_hotlist = weechat_hdata_get ("hotlist");
|
||||
|
||||
relay_signal_upgrade_received = 0;
|
||||
|
||||
if (!relay_config_init ())
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
@@ -341,9 +351,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
|
||||
relay_config_write ();
|
||||
|
||||
if (relay_signal_upgrade_received)
|
||||
relay_upgrade_save (0);
|
||||
else
|
||||
if (!weechat_relay_plugin->unload_with_upgrade)
|
||||
relay_client_disconnect_all ();
|
||||
|
||||
relay_raw_message_free_all ();
|
||||
|
||||
@@ -37,8 +37,6 @@ extern struct t_hdata *relay_hdata_completion;
|
||||
extern struct t_hdata *relay_hdata_completion_word;
|
||||
extern struct t_hdata *relay_hdata_hotlist;
|
||||
|
||||
extern int relay_signal_upgrade_received;
|
||||
|
||||
/* relay protocol */
|
||||
|
||||
enum t_relay_protocol
|
||||
|
||||
@@ -74,7 +74,7 @@ struct t_weelist_item;
|
||||
* please change the date with current one; for a second change at same
|
||||
* date, increment the 01, otherwise please keep 01.
|
||||
*/
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20240727-01"
|
||||
#define WEECHAT_PLUGIN_API_VERSION "20241124-01"
|
||||
|
||||
/* macros for defining plugin infos */
|
||||
#define WEECHAT_PLUGIN_NAME(__name) \
|
||||
@@ -307,6 +307,8 @@ struct t_weechat_plugin
|
||||
int upgrading; /* 1 if the plugin must load upgrade */
|
||||
/* info on startup (if weechat is */
|
||||
/* run with --upgrade) */
|
||||
int unload_with_upgrade; /* 1 if the plugin is unloaded after */
|
||||
/* /upgrade command */
|
||||
struct t_hashtable *variables; /* plugin custom variables */
|
||||
struct t_weechat_plugin *prev_plugin; /* link to previous plugin */
|
||||
struct t_weechat_plugin *next_plugin; /* link to next plugin */
|
||||
|
||||
+17
-10
@@ -80,8 +80,6 @@ struct t_xfer *xfer_list = NULL; /* list of files/chats */
|
||||
struct t_xfer *last_xfer = NULL; /* last file/chat in list */
|
||||
int xfer_count = 0; /* number of xfer */
|
||||
|
||||
int xfer_signal_upgrade_received = 0; /* signal "upgrade" received ? */
|
||||
|
||||
void xfer_disconnect_all ();
|
||||
|
||||
|
||||
@@ -130,12 +128,17 @@ xfer_signal_upgrade_cb (const void *pointer, void *data,
|
||||
/* only save session and continue? */
|
||||
if (signal_data && (strcmp (signal_data, "save") == 0))
|
||||
{
|
||||
xfer_upgrade_save ();
|
||||
if (!xfer_upgrade_save ())
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), XFER_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
xfer_signal_upgrade_received = 1;
|
||||
|
||||
/*
|
||||
* TODO: do not disconnect here in case of upgrade when the save of xfers
|
||||
* in upgrade file will be implemented
|
||||
@@ -144,6 +147,15 @@ xfer_signal_upgrade_cb (const void *pointer, void *data,
|
||||
/*if (signal_data && (strcmp (signal_data, "quit") == 0))*/
|
||||
xfer_disconnect_all ();
|
||||
|
||||
if (!xfer_upgrade_save ())
|
||||
{
|
||||
weechat_printf (
|
||||
NULL,
|
||||
_("%s%s: failed to save upgrade data"),
|
||||
weechat_prefix ("error"), XFER_PLUGIN_NAME);
|
||||
return WEECHAT_RC_ERROR;
|
||||
}
|
||||
|
||||
return WEECHAT_RC_OK;
|
||||
}
|
||||
|
||||
@@ -1808,8 +1820,6 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[])
|
||||
|
||||
weechat_plugin = plugin;
|
||||
|
||||
xfer_signal_upgrade_received = 0;
|
||||
|
||||
if (!xfer_config_init ())
|
||||
return WEECHAT_RC_ERROR;
|
||||
|
||||
@@ -1861,9 +1871,6 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
|
||||
|
||||
xfer_config_write ();
|
||||
|
||||
if (xfer_signal_upgrade_received)
|
||||
xfer_upgrade_save ();
|
||||
|
||||
xfer_disconnect_all ();
|
||||
|
||||
xfer_free_all ();
|
||||
|
||||
Reference in New Issue
Block a user