From patchwork Fri Aug 6 19:17:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cristian_Rodr=C3=ADguez?= X-Patchwork-Id: 1514457 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhFcr3Gf0z9sPf for ; Sat, 7 Aug 2021 05:18:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8BAD938618FC for ; Fri, 6 Aug 2021 19:18:17 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by sourceware.org (Postfix) with ESMTPS id BB9BF38618FC for ; Fri, 6 Aug 2021 19:18:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB9BF38618FC Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=opensuse.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f174.google.com with SMTP id u16so8392110ple.2 for ; Fri, 06 Aug 2021 12:18:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=fGoY9q+v2VGUOFDzQ09cMHiBC6SisUMp0qSMZVeR24I=; b=GBo3smrnbubdX1oPhB9se47b6pLu5oOmjMtf+wYAKn8NFKrGl8NTDsoxmmPwkZJhCo rI/dF2s0AwzFqNOp5zyTArZKq/l7FxxDaLztdxq8LR4ul9MKk1U4juP6v9hk68aWr88I dwLnzAAduaF1v8n8Y57S8Cdk+CWuMhJHW9ACkcxQ070gB1Vo380h3/t/Y4Lka9raUr8e leTLw+GnUxYdZu/QD3ZmMi56sIj6Lbj6p+3l/Pwyzx+dJt2TCuDF44RO8uq5Sy4bga7Z dlMs4myYZeiL1N1EGLv33WDT9+J7fTPGhibBfcON2QmanFIyFN51j69c4JTT+g5sUaM6 R+DQ== X-Gm-Message-State: AOAM533SCmCInwDPqNhyI/xkmrcB6LmNmE1JRm2U5CjYOI3bUQsz4ZRx 0xzhb+sMfWeS3vJd1CFV3GVu/8bl3CETug== X-Google-Smtp-Source: ABdhPJw5WzSBLwWKZz7ugLsyk09mIA1H7HTLN6MM37oPEr/YCj5vfO492adNCQxcNm/Y89RbiS7+1Q== X-Received: by 2002:a17:90a:d686:: with SMTP id x6mr13509759pju.8.1628277487445; Fri, 06 Aug 2021 12:18:07 -0700 (PDT) Received: from tumbleweedvm.. (181-162-17-236.baf.movistar.cl. [181.162.17.236]) by smtp.gmail.com with ESMTPSA id u17sm11304078pfh.184.2021.08.06.12.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 12:18:07 -0700 (PDT) From: =?utf-8?q?Cristian_Rodr=C3=ADguez?= To: libc-alpha@sourceware.org Subject: [PATCH 1/2] Linux: implement getloadavg(3) using sysinfo(2) Date: Fri, 6 Aug 2021 15:17:48 -0400 Message-Id: <20210806191749.4620-1-crrodriguez@opensuse.org> X-Mailer: git-send-email 2.32.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" Signed-off-by: Cristian Rodríguez Reviewed-by: Adhemerval Zanella --- sysdeps/unix/sysv/linux/getloadavg.c | 50 ++++++++-------------------- 1 file changed, 14 insertions(+), 36 deletions(-) diff --git a/sysdeps/unix/sysv/linux/getloadavg.c b/sysdeps/unix/sysv/linux/getloadavg.c index e50cc396e7..3ea7fd02b7 100644 --- a/sysdeps/unix/sysv/linux/getloadavg.c +++ b/sysdeps/unix/sysv/linux/getloadavg.c @@ -1,4 +1,4 @@ -/* Get system load averages. Linux (/proc/loadavg) version. +/* Get system load averages. Linux version. Copyright (C) 1999-2021 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -16,53 +16,31 @@ License along with the GNU C Library; if not, see . */ -#include -#include -#include -#include -#include -#include +#include +#include +#include /* 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 3, but may be less than NELEM), or -1 if an error occurred. */ +#define CLAMP(v, lo, hi) MIN (MAX (v, lo), hi) + +#define SYSINFO_LOADS_SCALE (1 << SI_LOAD_SHIFT) + int getloadavg (double loadavg[], int nelem) { - int fd; + struct sysinfo info = {}; - fd = __open_nocancel ("/proc/loadavg", O_RDONLY); - if (fd < 0) + if (__sysinfo (&info) != 0) return -1; - else - { - char buf[65], *p; - ssize_t nread; - int i; - nread = __read_nocancel (fd, buf, sizeof buf - 1); - __close_nocancel_nostatus (fd); - if (nread <= 0) - return -1; - buf[nread - 1] = '\0'; + nelem = CLAMP (nelem, 0, (int)array_length (info.loads)); - if (nelem > 3) - nelem = 3; - p = buf; - for (i = 0; i < nelem; ++i) - { - char *endp; - loadavg[i] = __strtod_l (p, &endp, _nl_C_locobj_ptr); - if (endp == p) - /* This should not happen. The format of /proc/loadavg - must have changed. Don't return with what we have, - signal an error. */ - return -1; - p = endp; - } + for (int i = 0; i < nelem; i++) + loadavg[i] = (double)info.loads[i] / SYSINFO_LOADS_SCALE; - return i; - } + return nelem; } From patchwork Fri Aug 6 19:17:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Cristian_Rodr=C3=ADguez?= X-Patchwork-Id: 1514458 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GhFdH2XMwz9sPf for ; Sat, 7 Aug 2021 05:18:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B810839ACC48 for ; Fri, 6 Aug 2021 19:18:40 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by sourceware.org (Postfix) with ESMTPS id 15F6D39ACC53 for ; Fri, 6 Aug 2021 19:18:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 15F6D39ACC53 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=opensuse.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-f52.google.com with SMTP id u13-20020a17090abb0db0290177e1d9b3f7so24206697pjr.1 for ; Fri, 06 Aug 2021 12:18:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HjakCvEfI956FWjzJ5PsU29o4BgU30cCY2Y6/0Aqpno=; b=iX7dEytHdqbdP2A264+gI4h/g3QCiEyyz+sU9NKqiQQLLaldoiOnh+5SCUW0AwsQew 1IB/m+OfehtaDnEgm4P2RznCYl+VD9Gj1ZHco6Lbzcxubdx22Q3hlZY8Q3YKVLWtffc0 ziqp0TFm/Zbso0KWCROVbFN0smEovnWmEDiMsWdAIfslmxG44lfUcLMTP3zbW0Y77g/t 9lMDRY6Ghaf7RvpQz1vY+2LxxWav9aCuukrejD1/BOSVWW56oBnO8GktM2CG02Dq2LpE nM4jWZOLPdN777LNQjM3bo4mZd44drjMKFJg0tjOKIEThNGc8J/uZEQthM+QOcM/nKdE 7+PA== X-Gm-Message-State: AOAM532yJCQgxaEgpj3dBF80FIhseMGpE3oBitjWUXKrJf74YqUxNoGp u94zZxLbpb+X9wa4ceFeA/hLz1cwxsKZjg== X-Google-Smtp-Source: ABdhPJw21M+UsXCFjvlwXIsipj7lk0m/JoustvACi13ALm2lyZf3J7la/Rlwx751yFmRFZ1g207Dug== X-Received: by 2002:a62:ea1a:0:b029:329:a95a:fab with SMTP id t26-20020a62ea1a0000b0290329a95a0fabmr6531841pfh.31.1628277495876; Fri, 06 Aug 2021 12:18:15 -0700 (PDT) Received: from tumbleweedvm.. (181-162-17-236.baf.movistar.cl. [181.162.17.236]) by smtp.gmail.com with ESMTPSA id u17sm11304078pfh.184.2021.08.06.12.18.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Aug 2021 12:18:15 -0700 (PDT) From: =?utf-8?q?Cristian_Rodr=C3=ADguez?= To: libc-alpha@sourceware.org Subject: [PATCH 2/2] resolv: make res_randomid use random_bits() Date: Fri, 6 Aug 2021 15:17:49 -0400 Message-Id: <20210806191749.4620-2-crrodriguez@opensuse.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210806191749.4620-1-crrodriguez@opensuse.org> References: <20210806191749.4620-1-crrodriguez@opensuse.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" It is at least "more random" than 0xffff & __getpid (); Signed-off-by: Cristian Rodríguez --- resolv/res_randomid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/resolv/res_randomid.c b/resolv/res_randomid.c index 546daf4c8b..08a52a111a 100644 --- a/resolv/res_randomid.c +++ b/resolv/res_randomid.c @@ -84,9 +84,10 @@ #include #include +#include unsigned int res_randomid (void) { - return 0xffff & __getpid (); + return random_bits(); } libc_hidden_def (__res_randomid)