commit: fa45f039974438d4262422dd1630634fc84c5dbd
Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Tue Nov 18 19:00:21 2025 +0000
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Tue Nov 18 19:00:21 2025 +0000
URL: https://gitweb.gentoo.org/proj/steve.git/commit/?id=fa45f039
Print status on SIGUSR1
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
steve.cxx | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/steve.cxx b/steve.cxx
index 713137f..a837a4a 100644
--- a/steve.cxx
+++ b/steve.cxx
@@ -307,6 +307,18 @@ static const struct cuse_lowlevel_ops steve_ops = {
.poll = steve_poll,
};
+static steve_state *steve_global_state;
+
+static void steve_handle_sigusr1(int, siginfo_t *, void *) {
+ steve_check_processes(steve_global_state);
+
+ printf("steve: currently %d tokens available out of %d\n",
+ steve_global_state->tokens, steve_global_state->jobs);
+ for (auto it : steve_global_state->processes) {
+ printf("PID %ld holds %d tokens\n", it.first,
it.second.tokens_held);
+ }
+}
+
int main(int argc, char **argv)
{
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
@@ -314,6 +326,7 @@ int main(int argc, char **argv)
const char *dev_info_argv[] = { dev_name };
struct cuse_info ci = { 0 };
steve_state state = { 0 };
+ struct sigaction sigact = { 0 };
int ret;
if (fuse_opt_parse(&args, &state, steve_opts, steve_process_arg)) {
@@ -329,6 +342,11 @@ int main(int argc, char **argv)
if (state.jobs == 0)
state.jobs = sysconf(_SC_NPROCESSORS_ONLN);
+ steve_global_state = &state;
+ sigact.sa_flags = SA_SIGINFO;
+ sigact.sa_sigaction = steve_handle_sigusr1;
+ sigaction(SIGUSR1, &sigact, NULL);
+
ret = cuse_lowlevel_main(args.argc, args.argv, &ci, &steve_ops, &state);
fuse_opt_free_args(&args);
return ret;