bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Bug#290727: coreutils: dd: Please support /dev/stdin as argument to


From: Jim Meyering
Subject: Re: Bug#290727: coreutils: dd: Please support /dev/stdin as argument to if=
Date: Mon, 31 Mar 2008 08:55:11 +0200

Paul Eggert <address@hidden> wrote:
> How about this patch?  It fixes the bug that was reported.  It does have
> the downside of possibly failing with EMFILE when the current version would
> not fail, but that is a minor drawback.
>
> 2008-03-30  Paul Eggert  <address@hidden>
>
>       * lib/fd-reopen.c: Work even if FILE is "/dev/stdin".
>       Problem reported by Geoffrey Lee in <http://bugs.debian.org/290727>.
>       * tests/dd/misc: Check for this bug.

Thanks Paul!
And thanks to Michael for digging up and investigating
the 3-year-old old bug report.

> diff --git a/lib/fd-reopen.c b/lib/fd-reopen.c
> index 2ce4678..c12fef6 100644
> --- a/lib/fd-reopen.c
> +++ b/lib/fd-reopen.c
> @@ -1,6 +1,6 @@
>  /* Invoke open, but return either a desired file descriptor or -1.
>
> -   Copyright (C) 2005, 2006 Free Software Foundation, Inc.
> +   Copyright (C) 2005, 2006, 2008 Free Software Foundation, Inc.
>
>     This program is free software: you can redistribute it and/or modify
>     it under the terms of the GNU General Public License as published by
> @@ -31,15 +31,13 @@
>  int
>  fd_reopen (int desired_fd, char const *file, int flags, mode_t mode)
>  {
> -  int fd;
> +  int fd = open (file, flags, mode);
>
> -  close (desired_fd);
> -  fd = open (file, flags, mode);
>    if (fd == desired_fd || fd < 0)
>      return fd;
>    else
>      {
> -      int fd2 = fcntl (fd, F_DUPFD, desired_fd);
> +      int fd2 = dup2 (fd, desired_fd);
>        int saved_errno = errno;
>        close (fd);
>        errno = saved_errno;
> diff --git a/tests/dd/misc b/tests/dd/misc
> index 9172582..2b54cfb 100755
> --- a/tests/dd/misc
> +++ b/tests/dd/misc
> @@ -46,6 +46,13 @@ if dd oflag=append if=$tmp_in of=$tmp_out 2> /dev/null; 
> then
>    compare $tmp_in $tmp_out || fail=1
>  fi
>
> +case $(cat /dev/stdin <$tmp_in 2>/dev/null) in
> +(data)
> +  rm -f $tmp_out
> +  dd if=/dev/stdin of=$tmp_out <$tmp_in || fail=1
> +  compare $tmp_in $tmp_out || fail=1
> +esac
> +
>  if dd iflag=nofollow if=$tmp_in count=0 2> /dev/null; then
>    dd iflag=nofollow if=$tmp_sym count=0 2> /dev/null && fail=1
>  fi




reply via email to

[Prev in Thread] Current Thread [Next in Thread]