Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp6685461ybi; Wed, 29 May 2019 11:27:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1X6BR8yAEDc55qQuhqF5rp1soFP+o749N8oqTT19Czo3DCyT07QtCvh9zTM1T5R6chrrx X-Received: by 2002:a17:902:6bc4:: with SMTP id m4mr67465779plt.266.1559154456529; Wed, 29 May 2019 11:27:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559154456; cv=none; d=google.com; s=arc-20160816; b=a2O3hA+MhUCNFSsc9XiJ7DUo/4LsbCO4Xh7eFTR1ERfOF1M5SbAIL7a8FS9w6R3T2m nWyoeVw4KZPmpRaECoqDhb220gDB/YTNaxjjjG/Xz0ZAXWpJ7n4jKWuALDNu8UDUYBxt ZaErSuNoVxxwG3kfmhL0DOrPDUxi7yMzn3K4U29MXfkAWmRW+/KUsuH2+fY4QEDxLPZe goHIpRo9WLPAEEnWl6qSGxhNv0x+QYXFRzOeUbr/Y5X0+ytVL5evTIJPR2xpaZhsmPHe 2ZXUPTrNdoXFhbwRl/XQAF6vt+mdNCi78MYGxSicKwWB0SoHwzTXJJLBSumj5FD4BL14 U8Yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=TPw4eflGaKI/OKKxvlJQ22C2ftNP7pXq0GeN7f/mbOQ=; b=yfiDwedAtTby83h2wyoRre1W2XIXb/NQz0UyWG6U01nW6Mxb+7Subx4vz3dtIwsIOb ZNdQ+0s02mIYrXaEmB+3UK6U20OAzafFjfZMKDZTg6d1dHxtbrn90JTVidgZ9oaagd/d y0VbW4PPUOVYVOQfPeTM8D7gMJiMAL3sasKGeB6aU3R+9UDE8P3YF0vg7d/nl9/XfGy5 fGdyXmIO1MgP7wVoAMvJE8viFxfI2o5Rps8FgG9QzQtr9knSFYCSbU1b8ix4UrKxyJHE E1mMh5GDp1innBj8ADej7RFXF5uxJvfaZxGLwBNzoTp1VYB7GxUNsz7emnAQ5nWRLPuA /lzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="AH62/ckY"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si343378pfd.258.2019.05.29.11.27.20; Wed, 29 May 2019 11:27:36 -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=@gmail.com header.s=20161025 header.b="AH62/ckY"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727524AbfE2S0O (ORCPT + 99 others); Wed, 29 May 2019 14:26:14 -0400 Received: from mail-it1-f194.google.com ([209.85.166.194]:38460 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725917AbfE2S0O (ORCPT ); Wed, 29 May 2019 14:26:14 -0400 Received: by mail-it1-f194.google.com with SMTP id i63so898763ita.3; Wed, 29 May 2019 11:26:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=TPw4eflGaKI/OKKxvlJQ22C2ftNP7pXq0GeN7f/mbOQ=; b=AH62/ckYQ4jBdFzIhVm6Y9tX+W+XJ8LN+DSBwBYxk7Bm9tdpsUtfMOXWZrdZa23+N1 u52GCBTu11nt5boSjHA+BOio3ozjlwTYumDqAnoM/cr8AxTxvzxvvaCvKnYlSH8h8uvt 8Wmn/eEVEosthorZkMwvgqH5oelyyuwoLIc/9mKcqnd5MNYls7F3IPlPdwh3pD0gysxe Kfu1ovDYlRu6LKMs6HeAy3oIlVcwzFFzgd1N7lHIWyNfomtNweNbdWNwSgiR1z9qSHjp Y+8edTj7EW2rS1Bksua0OTS9fhE4BuUGvgAcC7WLnFps5AMZCypbpRQ29+6AvMSnBbPl +Trg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=TPw4eflGaKI/OKKxvlJQ22C2ftNP7pXq0GeN7f/mbOQ=; b=lHhSgSNkcQ49bkv0GZujWBxlBiWn4QRkrCnSkAAdl04PjgifrmcADqlYKc2K9hHGim Ydabg82Pfgi+NV8zih0UU4700i45kC3NsyQqWDIceSLPKiEd3HhAcb/t638WO/EH5LJp Ii8eiybUCu4Pp0ejJkJjqCvMQ4WYlSSp4QwPLu7GsDC0IMBHpxYkefpNhScUti4G3GRm Kur6sEuU6GRrkYVYp4VmsyHkCrjlkOURndaDFv15boog71C+mJ+EBGqu/NwcArKlkviW 314eJVnuELAbfrClBsYR5H4xJPcqZvBbnOC3ucVnVU7p1jPmfALd0lq9JpUajeaZEyT7 yQBw== X-Gm-Message-State: APjAAAXZaCxNBfQEOUbTo5dQ0nN4JbRDbFvhWWdZAmZPQfAHFtg+xHw2 vE9Lk/mUkSwfuoSiFPQZmfIz+ti4+4eNTpwefMc= X-Received: by 2002:a02:bb83:: with SMTP id g3mr11149521jan.139.1559154373608; Wed, 29 May 2019 11:26:13 -0700 (PDT) MIME-Version: 1.0 References: <20190522032144.10995-1-deepa.kernel@gmail.com> <20190529161157.GA27659@redhat.com> In-Reply-To: <20190529161157.GA27659@redhat.com> From: Deepa Dinamani Date: Wed, 29 May 2019 11:26:02 -0700 Message-ID: Subject: Re: pselect/etc semantics (Was: [PATCH v2] signal: Adjust error codes according to restore_user_sigmask()) To: Oleg Nesterov Cc: Al Viro , "Eric W. Biederman" , Linus Torvalds , Linux Kernel Mailing List , Andrew Morton , Arnd Bergmann , dbueso@suse.de, axboe@kernel.dk, Davidlohr Bueso , Eric Wong , Jason Baron , Linux FS-devel Mailing List , linux-aio , Omar Kilani , Thomas Gleixner , stable@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, May 29, 2019 at 9:12 AM Oleg Nesterov wrote: > > Al, Linus, Eric, please help. > > The previous discussion was very confusing, we simply can not understand each > other. > > To me everything looks very simple and clear, but perhaps I missed something > obvious? Please correct me. > > I think that the following code is correct > > int interrupted = 0; > > void sigint_handler(int sig) > { > interrupted = 1; > } > > int main(void) > { > sigset_t sigint, empty; > > sigemptyset(&sigint); > sigaddset(&sigint, SIGINT); > sigprocmask(SIG_BLOCK, &sigint, NULL); > > signal(SIGINT, sigint_handler); > > sigemptyset(&empty); // so pselect() unblocks SIGINT > > ret = pselect(..., &empty); > > if (ret >= 0) // sucess or timeout > assert(!interrupted); > > if (interrupted) > assert(ret == -EINTR); > } > > IOW, if pselect(sigmask) temporary unblocks SIGINT according to sigmask, this > signal should not be delivered if a ready fd was found or timeout. The signal > handle should only run if ret == -EINTR. I do not think we discussed this part earlier. But, if this is true then this is what is wrong as part of 854a6ed56839a. I missed that before. > (pselect() can be interrupted by any other signal which has a handler. In this > case the handler can be called even if ret >= 0. This is correct, I fail to > understand why some people think this is wrong, and in any case we simply can't > avoid this). This patch is wrong because I did not know that it was ok to deliver a signal and not set the errno before. I also admitted to this. And proposed another way to revert the patch.: https://lore.kernel.org/lkml/CABeXuvouBzZuNarmNcd9JgZgvonL1N_p21gat=O_x0-1hMx=6A@mail.gmail.com/ -Deepa