Path: blob/main/crypto/krb5/src/util/ss/list_rqs.c
34889 views
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */1/*2* Copyright 1987, 1988 by MIT Student Information Processing Board3*4* For copyright information, see copyright.h.5*/6#include "copyright.h"7#include "ss_internal.h"8#include <signal.h>9#include <setjmp.h>10#include <sys/wait.h>1112#ifdef lint /* "lint returns a value which is sometimes ignored" */13#define DONT_USE(x) x=x;14#else /* !lint */15#define DONT_USE(x) ;16#endif /* lint */1718static char const twentyfive_spaces[26] =19" ";20static char const NL[2] = "\n";2122void23ss_list_requests(int argc, const char * const *argv, int sci_idx,24void *info_ptr)25{26ss_request_entry *entry;27char const *const *name;28int spacing;29ss_request_table **table;3031char buffer[BUFSIZ];32FILE *output;33int fd;34#ifdef POSIX_SIGNALS35struct sigaction nsig, osig;36sigset_t nmask, omask;37#else38int mask;39void (*func)();40#endif41#ifndef WAIT_USES_INT42union wait waitb;43#else44int waitb;45#endif4647DONT_USE(argc);48DONT_USE(argv);4950#ifdef POSIX_SIGNALS51sigemptyset(&nmask);52sigaddset(&nmask, SIGINT);53sigprocmask(SIG_BLOCK, &nmask, &omask);5455nsig.sa_handler = SIG_IGN;56sigemptyset(&nsig.sa_mask);57nsig.sa_flags = 0;58sigaction(SIGINT, &nsig, &osig);59#else60mask = sigblock(sigmask(SIGINT));61func = signal(SIGINT, SIG_IGN);62#endif6364fd = ss_pager_create(); /* FD_CLOEXEC set */65output = fdopen(fd, "w");6667#ifdef POSIX_SIGNALS68sigprocmask(SIG_SETMASK, &omask, (sigset_t *)0);69#else70sigsetmask(mask);71#endif7273fprintf (output, "Available %s requests:\n\n",74ss_info (sci_idx) -> subsystem_name);7576for (table = ss_info(sci_idx)->rqt_tables; *table; table++) {77entry = (*table)->requests;78for (; entry->command_names; entry++) {79spacing = -2;80buffer[0] = '\0';81if (entry->flags & SS_OPT_DONT_LIST)82continue;83buffer[sizeof(buffer) - 1] = '\0';84for (name = entry->command_names; *name; name++) {85int len = strlen(*name);86strncat(buffer, *name, sizeof(buffer) - 1 - strlen(buffer));87spacing += len + 2;88if (name[1]) {89strncat(buffer, ", ", sizeof(buffer) - 1 - strlen(buffer));90}91}92if (spacing > 23) {93strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));94fputs(buffer, output);95spacing = 0;96buffer[0] = '\0';97}98strncat(buffer, twentyfive_spaces, sizeof(buffer) - 1 - (25-spacing));99strncpy(buffer + 25, entry->info_string, sizeof(buffer) - 1 - 25);100strncat(buffer, NL, sizeof(buffer) - 1 - strlen(buffer));101fputs(buffer, output);102}103}104fclose(output);105#ifndef NO_FORK106wait(&waitb);107#endif108#ifdef POSIX_SIGNALS109sigaction(SIGINT, &osig, (struct sigaction *)0);110#else111(void) signal(SIGINT, func);112#endif113}114115116