From patchwork Fri May 10 06:12:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 163839 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1952467ilr; Thu, 9 May 2019 23:13:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqxlp6hpR3EyDRCna/5JSuFLacSXnt4vHK3zjyQ93CgPMQxZDPBa9+gw3uZ9BxWWyAgUd1Ai X-Received: by 2002:a62:5b81:: with SMTP id p123mr11902491pfb.158.1557468797825; Thu, 09 May 2019 23:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557468797; cv=none; d=google.com; s=arc-20160816; b=W1wYFpRFwJtdWKWCVl9f4tq+lXFPA+fGah2ii/sB/6UbswOsOmBqPyYuwEkOOoW43I KUws/rV437Q0/FRSZZai+ea4U5bopRq3uFXGumi5OwIa2KsXHJYO8Y5QzRFz+kVyDtiU gQ4e/V/ZMIuYQsOVYwvYj6sbCVgopYFDfjgFtVlpyEq32KoGmyFsiVtexO6y62t2maPn FFB88MEYiYNS0vry31dG+6vUOJyWvtqOq/PUw9M0P3Cse6WlPmVw5oeMqQGXAo2Bbgu1 ntUOXvL3vAk3J+7YUFKCz2LdFFIL9tjroStTeVupx7oYDsQC74lj+0VE28a2aIVRRajW 6x7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:dkim-filter; bh=sNTgF7wioKY7uXMPCcWRJTAZz6AxXXLPrOF4RQ9AV0A=; b=JrhaU5wqT2sQ0zPyJsE9iXQxCW5yBGOEb/tm+uS8WnmW5v3zM7fHSaTHv5yu7ASYpx Ayr/UXccdXj07oTZYln/LG01yKJzQt60zYFzQiHl+zRXt+//K4vcOV8AcM8O88DyJw9T Y4vho/ZoXDAwrvSwfq7ZfOHHf4ORCvgMxr3e3lNYMPvb2YrfyDIGev4TtDf7s5ojN3E1 N/EGVqEvhrUaXVOGsPYCZY8Ma9o89OROsqdH7/yFGDEeZCYqwitXNYiba2FfiRpooAjP hmyCQ16JQG1MamY1sjZJqnqz3ChzxrCHSPqIMsSgR2bJlX7Cq0ezXhdPfqnFVtr22sPJ 0jvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VOoTHFEM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si3408086plr.238.2019.05.09.23.13.17; Thu, 09 May 2019 23:13:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=VOoTHFEM; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfEJGNQ (ORCPT + 30 others); Fri, 10 May 2019 02:13:16 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:49769 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726952AbfEJGNP (ORCPT ); Fri, 10 May 2019 02:13:15 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id x4A6C8eT029885; Fri, 10 May 2019 15:12:08 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com x4A6C8eT029885 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1557468729; bh=sNTgF7wioKY7uXMPCcWRJTAZz6AxXXLPrOF4RQ9AV0A=; h=From:To:Cc:Subject:Date:From; b=VOoTHFEM/7QzPfn7u5aEBn8U6OEZs2aC+E3Vw6Zcz1AImB1T5umuxJusgoj1l2jkJ uYFHv9sQnqKwJNnBDRYajp+ELUeSyjN1sejUq3cDdFT6J4C1uEPI8o3/PiXKC/65t2 kaUpNSA3QL2ZynIob3L1sdBqKTYRVAq5kBVLd3Z4kAX4Vxf5qDhK4vhlf0JqSgsaHD qaYRhGsN6SYWgSMIM1C9lbAYdJL0c2T6rxsBFnb+fbNxEymNFuts6nxILm5qOWz/EZ wp5TM4ia0GQOHmtGCKTEwpdRifDUoVhkNdDt3HLhs0hCSHPXBF9jy/i9inrtzNkSSh KDrtDZVWECf5Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Andrew Morton , Greg KH , Ulf Magnusson , Linus Torvalds , Joel Fernandes , Masahiro Yamada , Nicolas Porcel , linux-kernel@vger.kernel.org Subject: [PATCH 1/2] kconfig: do not accept a directory for configuration output Date: Fri, 10 May 2019 15:12:04 +0900 Message-Id: <20190510061205.28753-1-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently, conf_write() can be called with a directory name instead of a file name. As far as I see, this can happen for menuconfig, nconfig, gconfig. If it is given with a directory path, conf_write() kindly appends getenv("KCONFIG_CONFIG"), but this ends up with hacky dir/basename handling, and screwed up with a corner-case like "what if KCONFIG_CONFIG is an absolute path?" as discussed before: https://patchwork.kernel.org/patch/9910037/ Since conf_write() is already messed up, I'd say "do not do it". Please pass a file path all the time. If a directory path is specified for the configuration output, conf_write() will simply error out. Signed-off-by: Masahiro Yamada Cc: Nicolas Porcel --- scripts/kconfig/confdata.c | 58 ++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 34 deletions(-) -- 2.17.1 diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 08ba146a83c5..9fd6430c93d2 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -817,40 +817,31 @@ int conf_write(const char *name) FILE *out; struct symbol *sym; struct menu *menu; - const char *basename; const char *str; - char dirname[PATH_MAX+1], tmpname[PATH_MAX+22], newname[PATH_MAX+8]; + char tmpname[PATH_MAX + 1], oldname[PATH_MAX + 1]; char *env; - dirname[0] = 0; - if (name && name[0]) { - char *slash; - - if (is_dir(name)) { - strcpy(dirname, name); - strcat(dirname, "/"); - basename = conf_get_configname(); - } else if ((slash = strrchr(name, '/'))) { - int size = slash - name + 1; - memcpy(dirname, name, size); - dirname[size] = 0; - if (slash[1]) - basename = slash + 1; - else - basename = conf_get_configname(); - } else - basename = name; - } else - basename = conf_get_configname(); - - sprintf(newname, "%s%s", dirname, basename); + if (!name) + name = conf_get_configname(); + + if (!*name) { + fprintf(stderr, "config name is empty\n"); + return -1; + } + + if (is_dir(name)) { + fprintf(stderr, "%s: Is a directory\n", name); + return -1; + } + env = getenv("KCONFIG_OVERWRITECONFIG"); - if (!env || !*env) { - sprintf(tmpname, "%s.tmpconfig.%d", dirname, (int)getpid()); - out = fopen(tmpname, "w"); - } else { + if (env && *env) { *tmpname = 0; - out = fopen(newname, "w"); + out = fopen(name, "w"); + } else { + snprintf(tmpname, sizeof(tmpname), "%s.%d.tmp", + name, (int)getpid()); + out = fopen(tmpname, "w"); } if (!out) return 1; @@ -897,14 +888,13 @@ int conf_write(const char *name) fclose(out); if (*tmpname) { - strcat(dirname, basename); - strcat(dirname, ".old"); - rename(newname, dirname); - if (rename(tmpname, newname)) + snprintf(oldname, sizeof(oldname), "%s.old", name); + rename(name, oldname); + if (rename(tmpname, name)) return 1; } - conf_message("configuration written to %s", newname); + conf_message("configuration written to %s", name); sym_set_change_count(0); From patchwork Fri May 10 06:12:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 163840 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:142:0:0:0:0 with SMTP id j2csp1952520ilr; Thu, 9 May 2019 23:13:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzR0xKYPLblBS7GvV/Sek6TsVOOv2bemiW7xIvbWb/6VCZvOnWdIo+jnwgMkgv1hPyXBRI4 X-Received: by 2002:a62:62c3:: with SMTP id w186mr11252795pfb.73.1557468801214; Thu, 09 May 2019 23:13:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557468801; cv=none; d=google.com; s=arc-20160816; b=X/HEPPwSBgmnOJoWO7khlRdRNQSfzz91mGgQN3c77gTbdIGehrV6rdZWIntRsAp+ax 7zJ/eFABsU6lxFq3Q055x0M/KBh8y0w08YOMwvA2CWMiEXkIe0mRdxIKF7A9dTZ0Gq9o +6Z4PS7PinnxLNMVBZAhcpLGSx/uJ6vPKvVbfn4Oj0tCiTuBKeb+6DhnB429bM/H9mMt gU4b3fLzz8LoJAREmvbiNuwUn8qSpei1gRCSasfoulnvpe3XAAa6fzLwHYO38MgoscuJ Ab3RaVjwsm/Jsr6SQeF0KntDl7kh+vOdnvTAWiDutWxX0nBHNO8fRkrhh1gd5cCM4uTB Lh7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=Zz5IFdzVMzJDlwRPqiFlRYTAt3VGP5hkTJyDL3fFG1U=; b=tiX4hVBKhT2SvVN1Kqe6vFkUm4n4hwmVhBDtXYDwS4NHFU6y1/YxY79fOlF/qQpLyg C5AkEe4ZAIx9BzyA1LZHsgOk71hBGtWhQBqKTlKyaxPlZeQ2u6/Oqpqaq48fvz5Se+m6 lP4p6Atqkc46iBBn5a2GO8jr3i3QuKP8cSL9oVLdXNmX3g3B4mWmx7gCLcHQJijMpsin ypqwXnhYYLOwgw6+zvtTqgr4C96kyIM6AUX3edBMxa+evM2UZxxQBeEmln24hg+PZeL3 yh08SGdXLAXUdPb+jbwc5/v4P89bnQOKvwI2Gwm2L6BdwKvv9rRr/uGrq1TqE+UpwOX2 mxTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="taCcs/K6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q16si3408086plr.238.2019.05.09.23.13.20; Thu, 09 May 2019 23:13:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b="taCcs/K6"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727085AbfEJGNP (ORCPT + 30 others); Fri, 10 May 2019 02:13:15 -0400 Received: from conuserg-08.nifty.com ([210.131.2.75]:49735 "EHLO conuserg-08.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726923AbfEJGNP (ORCPT ); Fri, 10 May 2019 02:13:15 -0400 Received: from localhost.localdomain (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id x4A6C8eU029885; Fri, 10 May 2019 15:12:09 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com x4A6C8eU029885 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1557468730; bh=Zz5IFdzVMzJDlwRPqiFlRYTAt3VGP5hkTJyDL3fFG1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taCcs/K6j9GCIzR4TXiWlEwzuDBA7PJsUpoHNoSZW7DhpqNQ03j1oSrzmV3M10s8X Nn1f4EOsAI2/fFcX0yQruU5wcVLkIZ9Fc1Zn3Wl2icRv4QikUNAmLgdQNOpIHPTCnB pgIa8h7I3qOWU6zt9Trg3RktjLu7F2CSPsHUK1i4hZOPoy/GGh7bEJG9KgWa4eECRt RRonuBVrsJTx5yiRMNKawa8U2DsYVT6UD0EmpisLLr/ckaC3wP5Bmi5CEJC8v9BXgI b1+JFDEA8C0c8OlOBG21n8E8Ktty3799t1V+1S7mlYoTIXWf2V10Yr0LrMtvfSfKmD vI/fBduZV8A6A== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org Cc: Andrew Morton , Greg KH , Ulf Magnusson , Linus Torvalds , Joel Fernandes , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 2/2] kconfig: do not write .config if the content is the same Date: Fri, 10 May 2019 15:12:05 +0900 Message-Id: <20190510061205.28753-2-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190510061205.28753-1-yamada.masahiro@socionext.com> References: <20190510061205.28753-1-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Kconfig updates the .config when it exits even if its content is exactly the same as before. Since its timestamp becomes newer than that of other build artifacts, additional processing is invoked, which is annoying. - syncconfig is invoked to update include/config/auto.conf, etc. - kernel/config.o is recompiled if CONFIG_IKCONFIG is enabled, then vmlinux is relinked as well. If the .config is not changed at all, we do not have to even touch it. Just bail out showing "No change to .config". $ make allmodconfig scripts/kconfig/conf --allmodconfig Kconfig # # configuration written to .config # $ make allmodconfig scripts/kconfig/conf --allmodconfig Kconfig # # No change to .config # Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 54 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) -- 2.17.1 Reported-by: Linus Torvalds ? Reviewed-by: Greg Kroah-Hartman diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 9fd6430c93d2..399973e35533 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -3,6 +3,7 @@ * Copyright (C) 2002 Roman Zippel */ +#include #include #include #include @@ -36,6 +37,52 @@ static bool is_dir(const char *path) return S_ISDIR(st.st_mode); } +/* return true if the given two files are the same, false otherwise */ +static bool is_same(const char *file1, const char *file2) +{ + int fd1, fd2; + struct stat st1, st2; + void *map1, *map2; + bool ret = false; + + fd1 = open(file1, O_RDONLY); + if (fd1 < 0) + return ret; + + fd2 = open(file2, O_RDONLY); + if (fd2 < 0) + goto close1; + + ret = fstat(fd1, &st1); + if (ret) + goto close2; + ret = fstat(fd2, &st2); + if (ret) + goto close2; + + if (st1.st_size != st2.st_size) + goto close2; + + map1 = mmap(NULL, st1.st_size, PROT_READ, MAP_PRIVATE, fd1, 0); + if (map1 == MAP_FAILED) + goto close2; + + map2 = mmap(NULL, st2.st_size, PROT_READ, MAP_PRIVATE, fd2, 0); + if (map2 == MAP_FAILED) + goto close2; + + if (bcmp(map1, map2, st1.st_size)) + goto close2; + + ret = true; +close2: + close(fd2); +close1: + close(fd1); + + return ret; +} + /* * Create the parent directory of the given path. * @@ -888,6 +935,13 @@ int conf_write(const char *name) fclose(out); if (*tmpname) { + if (is_same(name, tmpname)) { + conf_message("No change to %s", name); + unlink(tmpname); + sym_set_change_count(0); + return 0; + } + snprintf(oldname, sizeof(oldname), "%s.old", name); rename(name, oldname); if (rename(tmpname, name))