From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id 3DE52283CC for ; Sun, 4 Aug 2024 14:42:14 +0200 (CEST) Received: (qmail 1772 invoked by uid 550); 4 Aug 2024 12:41:57 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 1704 invoked from network); 4 Aug 2024 12:41:57 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed; d=hacktivis.me; h=from:to :cc:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; s=20240308_115322; bh=r9ihOCLQs8g659 RRY5EwztgzhXLAfMkDCb8Fu0v9L74=; b=Fiwyb4CgxMF1e4yVuSOqC+attIkkub 1vyYJjSFPgslzYZUtsR7I18zizUuX/eqyEbBnvMdUDmzqWuHXHtk4Nx+v9F0iWvr x9472ZS1rIPjdNVoAgO0fXqbdfRlWicdjxe++Esim/euKqBz2ibXLNWIWYEBcuw6 JgQHRxNMB3dY4J+mNZv1PNHA7CNmhhRxakwMX+k52ocG4v6qF1aSO0CKI7j2Yby4 3HB9cxNSvB1+HD6uZISIMSlwq2ArjZQLDLgJ5Ae9VCMCPQV+0dgzNYSIFwz/DyNc Nlk0qZ4W4XAuWtemHMVPA28LaRTt+fHLmlmThn6sxtV9MDxfXsx8OVr+WyqB+ca3 50ONgQOCqTBbwWuNImipnphhTgvIiCwkBhCZ/B9KlbRs/OsM4O37reiePxp65+lY FAtXxPVJ/rYHN2tl575vILv35Jq4B84FmCiF/ICgqZEUXzpGL0INeeamu6W71hju cQ+IbZgAd5+hu1xaDaE6LLDCaSmLpqsq+LtgGb1LB1d+EYT1non2kqHfhTq9ubHH cGloE3Q5AYba3hwrMl4fG2s+OLIZVLCrWbpalyjLKmzdWdC9mirYkuufxz2kyQ85 a5A1IUwGywtI5RXoqDzhmpObfQ/h76hjUF5Ln5QpIIqjU0ATXDaVxKow/8+Lio+T Qni8tdiOenk7c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=hacktivis.me; h=from:to:cc :date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; q=dns; s=20240308_115322; b=tV+/ezrS 9weoH+W1rojHJaf4nCJBic0L/aKZ+FXLuoI/CAKZBTu3tdIFEBE/irbXomQ5VuOx Ea9mzLGOIgHcxW1M7woE8HJ6uC3TtsbAXAHnm1eZcQs/IxTSM8T2Ypo6XoXowq9N dBdqcL2v3s3BRpPsixom7a11mNu8aJSb8wwobB/L53GvnNv0/24gNRejx7gPU6Va z0fVhSQgivujtwEqHIbZda9+OwgC6CeRBEIZz3gj9TbnidvgCnlIZ2mejFb6r/9c +GEXGOAuJ10XoeM1mDRMTLoo3rS9f5pPS1l7w8vJcx7lTyIjTNxK4Hm8P1tu72YL 6J+tSlXKbJmNQo4+eMuyyuMnzIxH31zu6bO04Ug1jzqzDQ7R7KdTbVGGYw+lxPNT 34MbXz5DLYALqS5xM7Db/YpeKTiJDmOtygHXvD0aVM18v8A3bmC/8QmnNmQ17O4k efxOnEXIxqAOGkEMs9nY3KFlnW+YjHYb++rbsdsMweoN76dG91ZMBrqfmHZsFes5 vX94Mk9lx/1BJP3c4gjeOcXdgCNMY2aVNzrA0RjFHkCiA1lmiE/JByPCvACcMlSm hhQCinel60sf6sNjPwlLNnOKowIS/i3LdwPSMKk4DohifYyteTvuZIAkZUy4G7OQ 5iVeIsFJ9h+djEw4sIuNbtylsPzB9LFZ8EE= From: contact@hacktivis.me To: musl@lists.openwall.com Cc: "Haelwenn (lanodan) Monnier" Date: Sun, 4 Aug 2024 14:41:45 +0200 Message-ID: <20240804124145.30659-2-contact@hacktivis.me> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240804124145.30659-1-contact@hacktivis.me> References: <20240804124145.30659-1-contact@hacktivis.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH 2/2] signal: add str2sig(3) from POSIX.1-2024 From: "Haelwenn (lanodan) Monnier" --- include/signal.h | 1 + src/signal/str2sig.c | 72 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 src/signal/str2sig.c diff --git a/include/signal.h b/include/signal.h index 217cfa08..fd486cd0 100644 --- a/include/signal.h +++ b/include/signal.h @@ -235,6 +235,7 @@ void psignal(int, const char *); #define SIG2STR_MAX sizeof("RTMIN+32") int sig2str(int signum, char *str); +int str2sig(const char *restrict str, int *restrict pnum); #endif diff --git a/src/signal/str2sig.c b/src/signal/str2sig.c new file mode 100644 index 00000000..6da2d4f4 --- /dev/null +++ b/src/signal/str2sig.c @@ -0,0 +1,72 @@ +#include +#include +#include +#include + +int str2sig(const char *restrict str, int *restrict pnum) +{ + errno = 0; + long signum = strtol(str, NULL, 10); + if(errno == 0 && signum < _NSIG) + { + *pnum = signum; + return 0; + } + + if ( + strncmp(str, "RTMIN+", 6) == 0 + || strncmp(str, "RTMAX-", 6) == 0 + ) + { + errno = 0; + long sigrt = strtol(str+6, NULL, 10); + if(errno != 0 || sigrt < 1 || sigrt > SIGRTMAX - SIGRTMIN) return -1; + + *pnum = str[5] == '+' ? SIGRTMIN + sigrt : SIGRTMAX - sigrt; + return 0; + } + + int ret = -1; + if(strcmp(str, "HUP") == 0) ret = SIGHUP; + if(strcmp(str, "INT") == 0) ret = SIGINT; + if(strcmp(str, "QUIT") == 0) ret = SIGQUIT; + if(strcmp(str, "ILL") == 0) ret = SIGILL; + if(strcmp(str, "TRAP") == 0) ret = SIGTRAP; + if(strcmp(str, "ABRT") == 0) ret = SIGABRT; + if(strcmp(str, "IOT") == 0) ret = SIGIOT; + if(strcmp(str, "BUS") == 0) ret = SIGBUS; + if(strcmp(str, "FPE") == 0) ret = SIGFPE; + if(strcmp(str, "KILL") == 0) ret = SIGKILL; + if(strcmp(str, "USR1") == 0) ret = SIGUSR1; + if(strcmp(str, "SEGV") == 0) ret = SIGSEGV; + if(strcmp(str, "USR2") == 0) ret = SIGUSR2; + if(strcmp(str, "PIPE") == 0) ret = SIGPIPE; + if(strcmp(str, "ALRM") == 0) ret = SIGALRM; + if(strcmp(str, "TERM") == 0) ret = SIGTERM; + if(strcmp(str, "STKFLT") == 0) ret = SIGSTKFLT; + if(strcmp(str, "CHLD") == 0) ret = SIGCHLD; + if(strcmp(str, "CONT") == 0) ret = SIGCONT; + if(strcmp(str, "STOP") == 0) ret = SIGSTOP; + if(strcmp(str, "TSTP") == 0) ret = SIGTSTP; + if(strcmp(str, "TTIN") == 0) ret = SIGTTIN; + if(strcmp(str, "TTOU") == 0) ret = SIGTTOU; + if(strcmp(str, "URG") == 0) ret = SIGURG; + if(strcmp(str, "XCPU") == 0) ret = SIGXCPU; + if(strcmp(str, "XFSZ") == 0) ret = SIGXFSZ; + if(strcmp(str, "VTALRM") == 0) ret = SIGVTALRM; + if(strcmp(str, "PROF") == 0) ret = SIGPROF; + if(strcmp(str, "WINCH") == 0) ret = SIGWINCH; + if(strcmp(str, "IO") == 0) ret = SIGIO; + if(strcmp(str, "POLL") == 0) ret = SIGPOLL; + if(strcmp(str, "PWR") == 0) ret = SIGPWR; + if(strcmp(str, "SYS") == 0) ret = SIGSYS; + if(strcmp(str, "UNUSED") == 0) ret = SIGUNUSED; + + if(strcmp(str, "RTMIN") == 0) ret = SIGRTMIN; + if(strcmp(str, "RTMAX") == 0) ret = SIGRTMAX; + + if(ret == -1) return -1; + + *pnum = ret; + return 0; +} -- 2.44.2