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 B632827F12 for ; Mon, 5 Aug 2024 08:56:44 +0200 (CEST) Received: (qmail 1189 invoked by uid 550); 5 Aug 2024 06:56:21 -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 32688 invoked from network); 5 Aug 2024 06:56:21 -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=Ceu/nRXvOPd42X ZPDoycH+nM/Riy9norpMFaOU/UcyU=; b=mY5Z21lA2YwFaKmimh0IzUAa6FHbRV nAEr4POn2EpQDDThZ8sIg3scUOqvqiDsrJP0Tu2zVNO8VkLSjeMIWz2+aRap7bIw M5F3XX+37PdO5Nz1GcyE7QpHrTIYRvbTXVhfrpiHUsGPTUC31DmVLfDUlfajpzJn /O1QReRO438xXqG7XD8AFjOq+33WRr8UkZw0iVMrqEviFYumT1M4kYBFFI4Fro8N XK0W5CIVWTOsuT+T3/FZsHX3A0ATynKm4yDtapff+Jf9VjRG2lGB3LhCNNWgRhzI zZhtZDdE6Q/5eBCo+6xnSeTVg0JzxleIVw/LGVUec7fXZdatUL+W9pSB5WQvQXzn Su4QTLoZmqhY3H0U3NDiMbCPipibosV7cIVUTzg7FNjf8OeAbpWpgNPHUS5xTF+y HnX6s5xq27pNZW+Mk5MOrvnrkgMms/aH6uL6V27UjonNosjcyrKiGQpNcfE9HyUp hgeoAtMYc7r+Dr6MRmLbJlRaGtzHhwkY2Ns66cIN8AbI7hS1AoUqwnc9AZS6/dnB e4ms4Mecty4/ejsmrLyz0tju3Wqi0mhk7vYdEBNMgfAkn5wr/c/PTN1tUNKWyLq9 iZPY6WpA49aRVwvfJ+imxsOtLqKO2yB4Gcttx/tneOsVEVXZxYwtMNSfnYfg8RzC TBZAZPKzEOuGw= 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=ohBg/bOl jsfV6/aBDORy0L9JcBrtNkRYG3dc9037lBLjzp8xtj17sAKZxKWCKGG5N08jS860 rC54ucIxql9uHKKlJvBMdSYwS58ArGnaB/+q4dXZX2eKQuRaCwOTWAQRsUSsccDo g1rz5e4WU2rjD2D9g5HJ1i/PgJwnb5PuWv0pwXoNOd6hjPquJ7t5hINS4Tvh9MHj V4RJH8ZlkIqMwsOejPcH7AiQRiLCrBPJtPSMNvrg4NePPJBfQr6AoFEtm/HDQQTv CdgAqzquKDory11YjbCQv9yA391Bo2uflX+Wfajowdd4bfHRsWa24+nCwL0GNzPS m6VVm+hfQ5UkcAVi/+g4Ac7aMdygNTtV1CZOEYGZZYYwtFrwtkh24iQVj0/WCQxb wfFIftWJdDP9E4sn0N+ceXkAexGljqqo0g7TNZrqyZ+sOSP3/5OdvvMTp8L7ugIU oZ68raTUuLxPF4iEowWk/Y4tGi9/tvN30a2idq6Gfam3Bv6B9guWd51ciVocnQir accwL2PXzC0v0dIqH1IX7XUrAJvMu17dyH2s8DCfIw/DjS01hOPIsodC75s5a0kO 2hBIbvgwIc0S9+9SG5Ni7rPbGHvXKPZdIsOxhJyaaZ+Y/fpZXOSlMSVSWsp/Toyn i/CsNZEmPI3dsGMLeWgD2HbkD6dl7mENS08= From: contact@hacktivis.me To: musl@lists.openwall.com Cc: "Haelwenn (lanodan) Monnier" Date: Mon, 5 Aug 2024 08:56:07 +0200 Message-ID: <20240805065607.22897-3-contact@hacktivis.me> X-Mailer: git-send-email 2.44.2 In-Reply-To: <20240805065607.22897-1-contact@hacktivis.me> References: <20240805065607.22897-1-contact@hacktivis.me> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v2 3/3] signal: add str2sig(3) from POSIX.1-2024 From: "Haelwenn (lanodan) Monnier" --- include/signal.h | 1 + src/signal/str2sig.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 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..b6a4fc23 --- /dev/null +++ b/src/signal/str2sig.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include + +int str2sig(const char *restrict str, int *restrict pnum) +{ + if (str[0] == '\0') return -1; + + errno = 0; + long signum = strtol(str, NULL, 10); + if (errno == 0 && signum < _NSIG) return (*pnum = signum, 0); + + if (strnlen(str, sizeof *__sys_signame) <= sizeof *__sys_signame) + for (int i = 0; i < sizeof __sys_signame/sizeof *__sys_signame; i++) + if (strncmp(str, __sys_signame[i], sizeof *__sys_signame) == 0) + return (*pnum = i, 0); + + // signal aliases + if (strcmp(str, "IOT") == 0) + return (*pnum = SIGIOT, 0); + if (strcmp(str, "UNUSED") == 0) + return (*pnum = SIGUNUSED, 0); +#if SIGPOLL != SIGIO + if (strcmp(str, "POLL") == 0) + return (*pnum = SIGPOLL, 0); +#endif + + if (strcmp(str, "RTMIN") == 0) + return (*pnum = SIGRTMIN, 0); + if (strcmp(str, "RTMAX") == 0) + return (*pnum = SIGRTMAX, 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; + } + + return -1; +} -- 2.44.2