summaryrefslogtreecommitdiffstats
path: root/lib/ss/list_rqs.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 15:49:25 +0000
commit464df1d5e5ab1322e2dd0a7796939fff1aeefa9a (patch)
tree6a403684e0978f0287d7f0ec0e5aab1fd31a59e1 /lib/ss/list_rqs.c
parentInitial commit. (diff)
downloade2fsprogs-upstream.tar.xz
e2fsprogs-upstream.zip
Adding upstream version 1.47.0.upstream/1.47.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'lib/ss/list_rqs.c')
-rw-r--r--lib/ss/list_rqs.c92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/ss/list_rqs.c b/lib/ss/list_rqs.c
new file mode 100644
index 0000000..89e37bb
--- /dev/null
+++ b/lib/ss/list_rqs.c
@@ -0,0 +1,92 @@
+/*
+ * Copyright 1987, 1988 by MIT Student Information Processing Board
+ *
+ * Permission to use, copy, modify, and distribute this software and
+ * its documentation for any purpose is hereby granted, provided that
+ * the names of M.I.T. and the M.I.T. S.I.P.B. not be used in
+ * advertising or publicity pertaining to distribution of the software
+ * without specific, written prior permission. M.I.T. and the
+ * M.I.T. S.I.P.B. make no representations about the suitability of
+ * this software for any purpose. It is provided "as is" without
+ * express or implied warranty.
+ */
+#include "config.h"
+#include "ss_internal.h"
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+#include <signal.h>
+#include <setjmp.h>
+#include <sys/wait.h>
+
+typedef void sigret_t;
+
+void ss_list_requests(int argc __SS_ATTR((unused)),
+ const char * const *argv __SS_ATTR((unused)),
+ int sci_idx, void *infop __SS_ATTR((unused)))
+{
+ ss_request_entry *entry;
+ char const * const *name;
+ int i, spacing;
+ ss_request_table **table;
+
+ FILE *output;
+ int fd;
+ sigset_t omask, igmask;
+ sigret_t (*func)(int);
+#ifndef NO_FORK
+ int waitb;
+#endif
+
+ sigemptyset(&igmask);
+ sigaddset(&igmask, SIGINT);
+ sigprocmask(SIG_BLOCK, &igmask, &omask);
+ func = signal(SIGINT, SIG_IGN);
+ fd = ss_pager_create();
+ if (fd < 0) {
+ perror("ss_pager_create");
+ (void) signal(SIGINT, func);
+ return;
+ }
+ output = fdopen(fd, "w");
+ if (!output) {
+ perror("fdopen");
+ close(fd);
+ (void) signal(SIGINT, func);
+ return;
+ }
+ sigprocmask(SIG_SETMASK, &omask, (sigset_t *) 0);
+
+ fprintf (output, "Available %s requests:\n\n",
+ ss_info (sci_idx) -> subsystem_name);
+
+ for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {
+ entry = (*table)->requests;
+ for (; entry->command_names; entry++) {
+ spacing = -2;
+ if (entry->flags & SS_OPT_DONT_LIST)
+ continue;
+ for (name = entry->command_names; *name; name++) {
+ int len = strlen(*name);
+ fputs(*name, output);
+ spacing += len + 2;
+ if (name[1]) {
+ fputs(", ", output);
+ }
+ }
+ if (spacing > 23) {
+ fputc('\n', output);
+ spacing = 0;
+ }
+ for (i = 0; i < 25 - spacing; i++)
+ fputc(' ', output);
+ fputs(entry->info_string, output);
+ fputc('\n', output);
+ }
+ }
+ fclose(output);
+#ifndef NO_FORK
+ wait(&waitb);
+#endif
+ (void) signal(SIGINT, func);
+}