Skip to content

Commit

Permalink
core: add command /sys to show resource limits and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
flashcode committed Aug 28, 2023
1 parent d328d7f commit 5ecb1ad
Show file tree
Hide file tree
Showing 17 changed files with 519 additions and 204 deletions.
1 change: 1 addition & 0 deletions ChangeLog.adoc
Expand Up @@ -15,6 +15,7 @@ For a list of important changes that require manual actions, please look at rele

New features::

* core: add command `/sys` to show resource limits and usage
* core: ignore key bindings with empty command
* core: add support of quotes in commands `/key bind` and `/key bindctxt`
* core: evaluate command given to `/repeat` with contextual variables (issue #2007)
Expand Down
2 changes: 2 additions & 0 deletions doc/en/weechat_dev.en.adoc
Expand Up @@ -146,6 +146,7 @@ WeeChat "core" is located in following directories:
|    wee-utf8.c | UTF-8 functions.
|    wee-util.c | Some other functions.
|    wee-version.c | Functions for WeeChat version.
|    wee-sys.c | System functions.
|    weechat.c | Main functions: command line options, startup.
|    hook/ | Hook functions.
|       wee-hook-command-run.c | Hook "command_run".
Expand Down Expand Up @@ -420,6 +421,7 @@ WeeChat "core" is located in following directories:
|          test-core-url.cpp | Tests: URLs.
|          test-core-utf8.cpp | Tests: UTF-8.
|          test-core-util.cpp | Tests: utility functions.
|          test-core-sys.cpp | Tests: system functions.
|       gui/ | Root of unit tests for interfaces.
|          test-gui-bar-window.cpp | Tests: bar window functions.
|          test-gui-buffer.cpp | Tests: buffer functions.
Expand Down
2 changes: 2 additions & 0 deletions doc/fr/weechat_dev.fr.adoc
Expand Up @@ -148,6 +148,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|    wee-utf8.c | Fonctions UTF-8.
|    wee-util.c | Quelques autres fonctions utilitaires.
|    wee-version.c | Fonctions pour la version de WeeChat.
|    wee-sys.c | Fonctions système.
|    weechat.c | Fonctions principales : options de ligne de commande, démarrage.
|    hook/ | Hook functions.
|       wee-hook-command-run.c | Hook "command_run".
Expand Down Expand Up @@ -422,6 +423,7 @@ Le cœur de WeeChat est situé dans les répertoires suivants :
|          test-core-url.cpp | Tests : URLs.
|          test-core-utf8.cpp | Tests : UTF-8.
|          test-core-util.cpp | Tests : fonctions utiles.
|          test-core-sys.cpp | Tests : fonctions système.
|       gui/ | Racine des tests unitaires pour les interfaces.
|          test-gui-bar-window.cpp | Tests : fonctions de fenêtres de barre.
|          test-gui-buffer.cpp | Tests : fonctions de tampons.
Expand Down
4 changes: 4 additions & 0 deletions doc/ja/weechat_dev.ja.adoc
Expand Up @@ -158,6 +158,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
|    wee-utf8.c | UTF-8 関数
|    wee-util.c | その他の関数
|    wee-version.c | WeeChat バージョンについての関数
// TRANSLATION MISSING
|    wee-sys.c | System functions.
|    weechat.c | 主要関数: コマンドラインオプション、起動
|    hook/ | フック関数
|       wee-hook-command-run.c | "command_run" フック
Expand Down Expand Up @@ -452,6 +454,8 @@ WeeChat "core" は以下のディレクトリに配置されています:
|          test-core-url.cpp | テスト: URL
|          test-core-utf8.cpp | テスト: UTF-8
|          test-core-util.cpp | テスト: ユーティリティ関数
// TRANSLATION MISSING
|          test-core-sys.cpp | Tests: system functions.
|       gui/ | インターフェースの単体テストを収める最上位ディレクトリ
// TRANSLATION MISSING
|          test-gui-bar-window.cpp | Tests: bar window functions.
Expand Down
4 changes: 4 additions & 0 deletions doc/sr/weechat_dev.sr.adoc
Expand Up @@ -148,6 +148,8 @@ WeeChat „језгро” се налази у следећим директо
|    wee-utf8.c | UTF-8 фунцкије.
|    wee-util.c | Неке друге функције.
|    wee-version.c | Функције за WeeChat верзију.
// TRANSLATION MISSING
|    wee-sys.c | System functions.
|    weechat.c | Основне функције: опције командне линије, покретање.
|    hook/ | Функције кука.
|       wee-hook-command-run.c | Кука "command_run".
Expand Down Expand Up @@ -422,6 +424,8 @@ WeeChat „језгро” се налази у следећим директо
|          test-core-url.cpp | Тестови: URL адресе.
|          test-core-utf8.cpp | Тестови: UTF-8.
|          test-core-util.cpp | Тестови: помоћне функције.
// TRANSLATION MISSING
|          test-core-sys.cpp | Tests: system functions.
|       gui/ | Корен unit тестова интерфејса.
|          test-gui-bar-window.cpp | Тестови: функције прозора траке.
|          test-gui-buffer.cpp | Тестови: бафер функције.
Expand Down
2 changes: 2 additions & 0 deletions po/srcfiles.cmake
Expand Up @@ -101,6 +101,8 @@ SET(WEECHAT_SOURCES
./src/core/wee-util.h
./src/core/wee-version.c
./src/core/wee-version.h
./src/core/wee-sys.c
./src/core/wee-sys.h
./src/gui/curses/gui-curses-bar-window.c
./src/gui/curses/gui-curses-bar-window.h
./src/gui/curses/gui-curses-chat.c
Expand Down
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Expand Up @@ -53,6 +53,7 @@ set(LIB_CORE_SRC
wee-utf8.c wee-utf8.h
wee-util.c wee-util.h
wee-version.c wee-version.h
wee-sys.c wee-sys.h
hook/wee-hook-command-run.c hook/wee-hook-command-run.h
hook/wee-hook-command.c hook/wee-hook-command.h
hook/wee-hook-completion.c hook/wee-hook-completion.h
Expand Down
40 changes: 40 additions & 0 deletions src/core/wee-command.c
Expand Up @@ -64,6 +64,7 @@
#include "wee-utf8.h"
#include "wee-util.h"
#include "wee-version.h"
#include "wee-sys.h"
#include "../gui/gui-bar.h"
#include "../gui/gui-bar-item.h"
#include "../gui/gui-bar-item-custom.h"
Expand Down Expand Up @@ -7774,6 +7775,35 @@ COMMAND_CALLBACK(window)
COMMAND_ERROR;
}

/*
* Callback for command "/sys": system actions.
*/

COMMAND_CALLBACK(sys)
{
/* make C compiler happy */
(void) pointer;
(void) data;
(void) buffer;

COMMAND_MIN_ARGS(2, "");

if (string_strcmp (argv[1], "get") == 0)
{
COMMAND_MIN_ARGS(2, "get");

if (string_strcmp (argv[2], "rlimit") == 0)
sys_display_rlimit ();
else if (string_strcmp (argv[2], "rusage") == 0)
sys_display_rusage ();
else
COMMAND_ERROR;
return WEECHAT_RC_OK;
}

COMMAND_ERROR;
}

/*
* Hooks WeeChat core commands.
*/
Expand Down Expand Up @@ -9456,6 +9486,16 @@ command_init ()
" || bare"
" || %(windows_numbers)",
&command_window, NULL, NULL);
hook_command (
NULL, "sys",
N_("system actions"),
N_("get rlimit|rusage"),
N_(" get: display system info\n"
"rlimit: display resource limits "
"(see /help weechat.startup.sys_rlimit and man getrlimit)\n"
"rusage: display resource usage (see man getrusage)"),
"get rlimit|rusage",
&command_sys, NULL, NULL);
}

/*
Expand Down
6 changes: 3 additions & 3 deletions src/core/wee-config.c
Expand Up @@ -44,11 +44,11 @@
#include "wee-log.h"
#include "wee-network.h"
#include "wee-utf8.h"
#include "wee-util.h"
#include "wee-list.h"
#include "wee-proxy.h"
#include "wee-string.h"
#include "wee-version.h"
#include "wee-sys.h"
#include "../gui/gui-bar.h"
#include "../gui/gui-bar-item.h"
#include "../gui/gui-bar-item-custom.h"
Expand Down Expand Up @@ -382,7 +382,7 @@ config_change_sys_rlimit (const void *pointer, void *data,
(void) option;

if (gui_init_ok)
util_setrlimit ();
sys_setrlimit ();
}

/*
Expand Down Expand Up @@ -1482,7 +1482,7 @@ config_weechat_init_after_read ()
{
int context;

util_setrlimit ();
sys_setrlimit ();

gui_buffer_notify_set_all ();

Expand Down

0 comments on commit 5ecb1ad

Please sign in to comment.