From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S262754AbUCRQpR (ORCPT ); Thu, 18 Mar 2004 11:45:17 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S262755AbUCRQpR (ORCPT ); Thu, 18 Mar 2004 11:45:17 -0500 Received: from pub236.cambridge.redhat.com ([213.86.99.236]:11770 "EHLO warthog.cambridge.redhat.com") by vger.kernel.org with ESMTP id S262754AbUCRQpJ (ORCPT ); Thu, 18 Mar 2004 11:45:09 -0500 From: David Howells To: Andrew Morton , torvalds@osdl.org cc: linux-kernel@vger.kernel.org Subject: fcntl error User-Agent: EMH/1.14.1 SEMI/1.14.4 (Hosorogi) FLIM/1.14.5 (Demachiyanagi) APEL/10.6 Emacs/21.3 (i386-redhat-linux-gnu) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.4 - "Hosorogi") Content-Type: text/plain; charset=US-ASCII Date: Thu, 18 Mar 2004 16:44:57 +0000 Message-ID: <7051.1079628297@redhat.com> Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Hi Andrew, Linus, The attached patch fixes a minor problem with fcntl. get_close_on_exec() uses FD_ISSET() to determine the fd state. However, FD_ISSET() does not return 0 or 1 on all archs. On some it returns 0 or non-0, which is fine by POSIX. Also, the argument of set_close_on_exec() is being AND'ed with literal 1. This is incorrect - there's no requirement for FD_CLOEXEC to be 1. This is also wrong on 2.4 kernels. David --- fs/fcntl.c.orig 2004-03-18 16:29:57.000000000 +0000 +++ fs/fcntl.c 2004-03-18 16:30:27.000000000 +0000 @@ -293,11 +293,11 @@ err = dupfd(filp, arg); break; case F_GETFD: - err = get_close_on_exec(fd); + err = get_close_on_exec(fd) ? FD_CLOEXEC : 0; break; case F_SETFD: err = 0; - set_close_on_exec(fd, arg&1); + set_close_on_exec(fd, arg & FD_CLOEXEC); break; case F_GETFL: err = filp->f_flags;