From patchwork Sat May 21 02:49:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lance Fredrickson X-Patchwork-Id: 1634161 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=TU39HPJU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=uclibc-ng.org (client-ip=89.238.66.15; helo=helium.openadk.org; envelope-from=devel-bounces@uclibc-ng.org; receiver=) Received: from helium.openadk.org (helium.openadk.org [89.238.66.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4L4p3d1wwNz9sG0 for ; Sat, 21 May 2022 12:50:03 +1000 (AEST) Received: from helium.openadk.org (localhost [IPv6:::1]) by helium.openadk.org (Postfix) with ESMTP id 033DC31E0734; Sat, 21 May 2022 04:49:58 +0200 (CEST) Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by helium.openadk.org (Postfix) with ESMTPS id 11C4631E0400 for ; Sat, 21 May 2022 04:49:53 +0200 (CEST) Received: by mail-pl1-f172.google.com with SMTP id m1so8741413plx.3 for ; Fri, 20 May 2022 19:49:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Tv6LHcsmlU/cLb9Kc5rk0xQm8FdueZpWxkOJ+qTDvmU=; b=TU39HPJUJ39iJUfFS3IpG1rTloeHt7TsmtsAwV2YC1e9DHqrhTE5krOG71l3hY76bK QvyjfzdtTwL+0tyiD63wbi9ZL9vPJSz+OS08wTbeDkhGSE9bUCULRuTE6tWX46a9t0nH 6UG5mvnKB3aOcCuY5ZN+Ze8+PgMbLDv4dqhGHVFN6mOeHDKH7gemyBbN3dPlPPdRSYWH 03Xr6B4CmWTJYRKuilZ7XEAU0RoGm5nYCRoWI3hLkw6YTQKG2ldcdgs3wVgIgV90pjyi hLayrAJiIUOZJ5U89JS3lXuavgLu5KfWAC8MVxyDKyPNVjlcLhYssmRjhJVr2zWAR2LS ZpGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Tv6LHcsmlU/cLb9Kc5rk0xQm8FdueZpWxkOJ+qTDvmU=; b=5O7NVvL9uPro7h7pBhi59szHXqnjZ/h2koxz9EUlHoIHYIk706cGTZ01hm++ES/GCH S9neq8eU5MAXH+jagsicpx+Ak5WPZMTtx/S5uR4fD/ZRFCwecb0ldrkkkRuTxOrCZgcO v8P13DhVexneqR9VaY5jotAPkv5kQeVSPaDchvCswmnGiurzdgdmIwZHsRERqDQu7zIG +KKDiFOGaQj5w49zaEnUX6wdC6eOd0ixTgZyiqKOQx2w7yGP2v28UxBTAOzJJ6nbQDoN o1YsntQqw9Fk8XDddnbaF6j1TYSPcANJ8TTXJs+k1NZD0WPaRamaBnEBLdPtjAdQELSD U/NA== X-Gm-Message-State: AOAM530FMLPj1mYys1KqpoFP+VWgW3qr6+aEaauw3j1sjkyz1X18OpUF xrqfZcKWUYnPi6LEt9gp9JWusJtDaUE= X-Google-Smtp-Source: ABdhPJy2Vwpnl7qbKnSMim6TNwjsvX5m77YKFenqN2MMFOm1Wn5DSxRM35Tau+uS2UZA/NZebn+2uw== X-Received: by 2002:a17:90b:380f:b0:1e0:9a0:4a99 with SMTP id mq15-20020a17090b380f00b001e009a04a99mr3637989pjb.158.1653101390233; Fri, 20 May 2022 19:49:50 -0700 (PDT) Received: from localhost.localdomain ([199.119.84.5]) by smtp.gmail.com with ESMTPSA id cp25-20020a056a00349900b0050dc76281c0sm2382410pfb.154.2022.05.20.19.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 19:49:49 -0700 (PDT) From: lancethepants To: devel@uclibc-ng.org Date: Fri, 20 May 2022 20:49:46 -0600 Message-Id: <20220521024946.16466-1-lancethepants@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Message-ID-Hash: C6EANDHVVDMCQTVWFDYANQL24I37Z7S5 X-Message-ID-Hash: C6EANDHVVDMCQTVWFDYANQL24I37Z7S5 X-MailFrom: lancethepants@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list Subject: [uclibc-ng-devel] [PATCH] libc/misc/getloadavg: Add getloadavg support to uClibc-ng List-Id: uClibc-ng Development Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: This borrows getloadavg.c from musl. getloadavg pops up often. Recently llvm and rust are dependent on it. glibc and musl have it and no-one actually checks if it's available in your libc. It's just become way easier to add it in uclibc-ng rather than patch everything else. Signed-off-by: Lance Fredrickson --- include/stdlib.h | 2 +- libc/misc/Makefile.in | 1 + libc/misc/getloadavg/Makefile | 13 +++++++++++ libc/misc/getloadavg/Makefile.in | 23 ++++++++++++++++++ libc/misc/getloadavg/getloadavg.c | 39 +++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 libc/misc/getloadavg/Makefile create mode 100644 libc/misc/getloadavg/Makefile.in create mode 100644 libc/misc/getloadavg/getloadavg.c diff --git a/include/stdlib.h b/include/stdlib.h index 6a253cc3f..987fe2223 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -979,7 +979,7 @@ extern int getpt (void); # endif #endif -#if 0 /* def __USE_BSD */ +#ifdef __USE_BSD /* Put the 1 minute, 5 minute and 15 minute load averages into the first NELEM elements of LOADAVG. Return the number written (never more than three, but may be less than NELEM), or -1 if an error occurred. */ diff --git a/libc/misc/Makefile.in b/libc/misc/Makefile.in index e45002e60..53bb6d6c8 100644 --- a/libc/misc/Makefile.in +++ b/libc/misc/Makefile.in @@ -14,6 +14,7 @@ include $(top_srcdir)libc/misc/file/Makefile.in include $(top_srcdir)libc/misc/fnmatch/Makefile.in include $(top_srcdir)libc/misc/ftw/Makefile.in include $(top_srcdir)libc/misc/fts/Makefile.in +include $(top_srcdir)libc/misc/getloadavg/Makefile.in include $(top_srcdir)libc/misc/glob/Makefile.in include $(top_srcdir)libc/misc/internals/Makefile.in include $(top_srcdir)libc/misc/locale/Makefile.in diff --git a/libc/misc/getloadavg/Makefile b/libc/misc/getloadavg/Makefile new file mode 100644 index 000000000..4a8f4a072 --- /dev/null +++ b/libc/misc/getloadavg/Makefile @@ -0,0 +1,13 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2005 Erik Andersen +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +top_srcdir=../../../ +top_builddir=../../../ +all: objs +include $(top_builddir)Rules.mak +include Makefile.in +include $(top_srcdir)Makerules diff --git a/libc/misc/getloadavg/Makefile.in b/libc/misc/getloadavg/Makefile.in new file mode 100644 index 000000000..3c8ca24f0 --- /dev/null +++ b/libc/misc/getloadavg/Makefile.in @@ -0,0 +1,23 @@ +# Makefile for uClibc +# +# Copyright (C) 2000-2008 Erik Andersen +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +subdirs += libc/misc/getloadavg + +CSRC-y := getloadavg.c + +MISC_GETLOADAVG_DIR := $(top_srcdir)libc/misc/getloadavg +MISC_GETLOADAVG_OUT := $(top_builddir)libc/misc/getloadavg + +MISC_GETLOADAVG_SRC := $(patsubst %.c,$(MISC_GETLOADAVG_DIR)/%.c,$(CSRC-y)) +MISC_GETLOADAVG_OBJ := $(patsubst %.c,$(MISC_GETLOADAVG_OUT)/%.o,$(CSRC-y)) + +libc-y += $(MISC_GETLOADAVG_OBJ) + +objclean-y += CLEAN_libc/misc/getloadavg + +CLEAN_libc/misc/getloadavg: + $(do_rm) $(addprefix $(MISC_GETLOADAVG_OUT)/*., o os) diff --git a/libc/misc/getloadavg/getloadavg.c b/libc/misc/getloadavg/getloadavg.c new file mode 100644 index 000000000..2aee565c0 --- /dev/null +++ b/libc/misc/getloadavg/getloadavg.c @@ -0,0 +1,39 @@ +/* + * Copyright © 2005-2020 Rich Felker, et al. + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + * Imported from musl C library + */ + +#define _GNU_SOURCE +#include +#include + +int getloadavg(double *a, int n) +{ + struct sysinfo si; + if (n <= 0) return n ? -1 : 0; + sysinfo(&si); + if (n > 3) n = 3; + for (int i=0; i