From debbugs-submit-bounces@debbugs.gnu.org Thu May 30 12:02:14 2019 Received: (at submit) by debbugs.gnu.org; 30 May 2019 16:02:14 +0000 Received: from localhost ([127.0.0.1]:33622 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWNVL-0007Xm-Qj for submit@debbugs.gnu.org; Thu, 30 May 2019 12:02:14 -0400 Received: from eggs.gnu.org ([209.51.188.92]:51754) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWN8j-0006tE-7Y for submit@debbugs.gnu.org; Thu, 30 May 2019 11:38:51 -0400 Received: from lists.gnu.org ([209.51.188.17]:41419) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hWN8e-0003Tc-3G for submit@debbugs.gnu.org; Thu, 30 May 2019 11:38:44 -0400 Received: from eggs.gnu.org ([209.51.188.92]:37899) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1hWN8b-00062C-DL for bug-coreutils@gnu.org; Thu, 30 May 2019 11:38:43 -0400 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_50, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,HTML_MESSAGE,URIBL_BLOCKED autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hWN8Y-0003PA-NC for bug-coreutils@gnu.org; Thu, 30 May 2019 11:38:41 -0400 Received: from mail-it1-x143.google.com ([2607:f8b0:4864:20::143]:53220) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hWN8W-0003G4-9u for bug-coreutils@gnu.org; Thu, 30 May 2019 11:38:36 -0400 Received: by mail-it1-x143.google.com with SMTP id t184so10607509itf.2 for ; Thu, 30 May 2019 08:38:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=RMy3/hSCmg20NGH0h3WMR4TZYmJEdjvxEN/KpSZsk2Y=; b=Y/fHPc3SWFhMPLvuBOrSXMNeldmj3O0NL+wZ2sPW7jdFEPfDJJYMO2Sg5jZu1MpmnY YMrMJewX7TPT9Vlb88lwSZswZK3gy8CmvfUybskuaugdD6Mr/wyum4rf+tBP8Po0IP+d KkuIKK/LwGdgKUC3tZXhjvtxLRiiq5PSlwcmI3ffEq7Z234hBuiDVk4df/eSnuChI7Ln 3zB9ivz15yReLCduV/FTmB61bEoZcBIWl5Yj//iRfJDGetBubjSysyRxzBVolcV2o/6e XiBZRbShfLZv3I/WTr5IKt7in1Rvh/yIvganP7BRGf3WjtPaCYXje7TqyfvciGprsvqo FfCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=RMy3/hSCmg20NGH0h3WMR4TZYmJEdjvxEN/KpSZsk2Y=; b=XYn6eofxnbNTZJKLwQlvZuIYUwXYGlxJGudvD4mNpOqKb+fJqyBNmUb9baGPChFkam U/nxT86yeoTBziQzY+X2oF0fnDBx96xZeZyiRYqtJeO7PQlkmEoG1ntyQK1RAWLIiTY6 0v8ZsKO0G0LLGpKIJjcwJnUGFEHMWglwYwrwuNn81/F1IIBbRt3wHt5BPTMFk16ENgkM LugH2BaWyn5AC8nXXxHwxistX+g0inlSXbYQqJDox7y/671C2LLSc2d9cV75iFRkYRTC oBi6h9VBXZiNiNSAkFSfF+dWmLsGMGlBEoI6nZ2LJi/WA7D/CFCZXmuL5/V9CqvqwZDi TgDw== X-Gm-Message-State: APjAAAXdBquVEnYXsXoUwqRgPdKaM1eVA2yxPEQbLEPiudHqLAL/r4Xx BDGy5ZnvRY5j4JUG2mZz+A7G48POiMf6lsil2waEqMfpB0Y= X-Google-Smtp-Source: APXvYqz0ct84XPUtKA6AJf4S6u/A9W2+1W1CBD19jMpLFT1BOcfO6ku5/fQh4CNO7oV421G55OY6ufAF3jEa5z/+i18= X-Received: by 2002:a24:9dc2:: with SMTP id f185mr3573339itd.151.1559230708266; Thu, 30 May 2019 08:38:28 -0700 (PDT) MIME-Version: 1.0 From: Hans Henrik Bergan Date: Thu, 30 May 2019 17:38:16 +0200 Message-ID: Subject: double close() of of=file if receiving SIGINT during fdatasync() To: bug-coreutils@gnu.org Content-Type: multipart/alternative; boundary="0000000000007d3dfd058a1cb08f" X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::143 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -1.1 (-) X-Debbugs-Envelope-To: submit X-Mailman-Approved-At: Thu, 30 May 2019 12:02:08 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.1 (--) --0000000000007d3dfd058a1cb08f Content-Type: text/plain; charset="UTF-8" i think there is a double-close() bug that causes dd to try to close input file twice if it receives a SIGINT during fdatasync(), it seems easy to reproduce on a slow block device (the issue was noticed on a 5400RPM harddrive), but i have not been able to reproduce it on a SSD (likely because fdatasync() finishes too fast, i didn't try very hard. like, i suppose i could have hooked fdatasync and made it slow on purpose, but i didn't spend that much time/energy on trying), anyway, the bug seems to boil down to somehow cleanup() is being called twice command issued: time strace dd if=/dev/zero of=/dev/sda4 bs=10M count=10 iflag=fullblock conv=fdatasync >stdout 2>stderr dd version: root@1:/dev# dd --version dd (coreutils) 8.30 Copyright (C) 2018 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later < https://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Paul Rubin, David MacKenzie, and Stuart Kemp. script log (corrupted when pasted, strictly speaking, but i don't think anything of value was lost. if you want an actual 100% intact log, i can send you a base64 copy if you want, but again i don't think anything of value was lost) Script started on 2019-05-30 09:39:45-04:00 [TERM="xterm" TTY="/dev/pts/1" COLUMNS="194" LINES="41"] root@1:/dev# exit pastebinit foo.log [C [C [C [C [C [C [C [C [C [C [C [C [C [5Pscript foo.log [3Prm foo.log [2@nano [C [C [C [C [C [C [C [C [C [1Pcat [C [C [C [C [C [C [C [C [C script foo.log ls [K cat stderr out time strace dd if=/dev/zero of=/dev/sda4 bs=10M count=10 iflag=fullblock conv=fdatasync >stdout 2>stderr execve("/usr/bin/dd", ["dd", "if=/dev/zero", "of=/dev/sda4", "bs=10M", "count=10", "iflag=fullblock", "conv=fdatasync"], 0x7fffffffe690 /* 18 vars */) = 0 brk(NULL) = 0x555555568000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=20223, ...}) = 0 mmap(NULL, 20223, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffff7fcb000 close(3) = 0 openat(AT_FDCWD, "/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260A\2\0\0\0\0\0"..., 832) = 832 fstat(3, {st_mode=S_IFREG|0755, st_size=1824496, ...}) = 0 mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffff7fc9000 mmap(NULL, 1837056, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7ffff7e08000 mprotect(0x7ffff7e2a000, 1658880, PROT_NONE) = 0 mmap(0x7ffff7e2a000, 1343488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x22000) = 0x7ffff7e2a000 mmap(0x7ffff7f72000, 311296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16a000) = 0x7ffff7f72000 mmap(0x7ffff7fbf000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) = 0x7ffff7fbf000 mmap(0x7ffff7fc5000, 14336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7ffff7fc5000 close(3) = 0 arch_prctl(ARCH_SET_FS, 0x7ffff7fca580) = 0 mprotect(0x7ffff7fbf000, 16384, PROT_READ) = 0 mprotect(0x555555566000, 4096, PROT_READ) = 0 mprotect(0x7ffff7ffc000, 4096, PROT_READ) = 0 munmap(0x7ffff7fcb000, 20223) = 0 rt_sigaction(SIGINT, NULL, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=0}, 8) = 0 rt_sigaction(SIGUSR1, {sa_handler=0x555555558430, sa_mask=[INT USR1], sa_flags=SA_RESTORER, sa_restorer=0x7ffff7e3f840}, NULL, 8) = 0 rt_sigaction(SIGINT, {sa_handler=0x555555558420, sa_mask=[INT USR1], sa_flags=SA_RESTORER|SA_NODEFER|SA_RESETHAND, sa_restorer=0x7ffff7e3f840}, NULL, 8) = 0 brk(NULL) = 0x555555568000 brk(0x555555589000) = 0x555555589000 openat(AT_FDCWD, "/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 fstat(3, {st_mode=S_IFREG|0644, st_size=3031616, ...}) = 0 mmap(NULL, 3031616, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffff7b23000 close(3) = 0 openat(AT_FDCWD, "/dev/zero", O_RDONLY) = 3 dup2(3, 0) = 0 close(3) = 0 lseek(0, 0, SEEK_CUR) = 0 openat(AT_FDCWD, "/dev/sda4", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3 dup2(3, 1) = 1 close(3) = 0 mmap(NULL, 10498048, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7ffff7120000 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = 10485760 fdatasync(1) = 0 --- SIGINT {si_signo=SIGINT, si_code=SI_USER, si_pid=1399, si_uid=0} --- rt_sigreturn({mask=[]}) = 0 close(0) = 0 close(1) = 0 openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 0 fstat(0, {st_mode=S_IFREG|0644, st_size=2995, ...}) = 0 read(0, "# Locale name alias data base.\n#"..., 4096) = 2995 read(0, "", 4096) = 0 close(0) = 0 openat(AT_FDCWD, "/usr/share/locale/en_CA/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, "10+0 records in\n10+0 records out"..., 3310+0 records in 10+0 records out ) = 33 write(2, "104857600 bytes (105 MB, 100 MiB"..., 62104857600 bytes (105 MB, 100 MiB) copied, 1.94798 s, 53.8 MB/s) = 62 write(2, "\n", 1 ) = 1 rt_sigprocmask(SIG_BLOCK, [INT USR1], [], 8) = 0 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0 close(0) = -1 EBADF (Bad file descriptor) write(2, "dd: ", 4dd: ) = 4 write(2, "closing input file '/dev/zero'", 30closing input file '/dev/zero') = 30 openat(AT_FDCWD, "/usr/share/locale/en_CA/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RDONLY) = -1 ENOENT (No such file or directory) write(2, ": Bad file descriptor", 21: Bad file descriptor) = 21 write(2, "\n", 1 ) = 1 close(2) = 0 exit_group(1) = ? +++ exited with 1 +++ real 0m1.955s user 0m0.001s sys 0m0.201s root@1:/dev# exit exit Script done on 2019-05-30 09:40:05-04:00 [COMMAND_EXIT_CODE="1"] --0000000000007d3dfd058a1cb08f Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
i think there is a double-close() bug that causes dd to tr= y to close input file twice if it receives a=C2=A0SIGINT during fdatasync()= ,=C2=A0

it seems easy to reproduce on a slow block devic= e (the issue was noticed on a 5400RPM harddrive), but i have not been able = to reproduce it on a SSD (likely because fdatasync() finishes too fast, i d= idn't try very hard. like, i suppose i could have hooked fdatasync and = made it slow on purpose, but i didn't spend that much time/energy on tr= ying),

anyway, the bug seems to boil down to someh= ow cleanup() is being called twice

command issued:

tim= e strace dd if=3D/dev/zero of=3D/dev/sda4 bs=3D10M count=3D10 iflag=3Dfullb= lock conv=3Dfdatasync >stdout 2>stderr=C2=A0=C2=A0

dd version:= =C2=A0
root@1:/dev# dd --version
dd (coreutils) 8.30
Copyri= ght (C) 2018 Free Software Foundation, Inc.
License GPLv3+: GNU GPL vers= ion 3 or later <https://gn= u.org/licenses/gpl.html>.
This is free software: you are free to = change and redistribute it.
There is NO WARRANTY, to the extent permitte= d by law.

Written by Paul Rubin, David MacKenzie, and Stuart Kemp.

script log (corrupted when pasted, strictly speaking, but i don&#= 39;t think anything of value was lost. if you want an actual 100% intact lo= g, i can send you a base64 copy if you want, but again i don't think an= ything of value was lost)

Script started on 2019-05-30 09:39:45-04:0= 0 [TERM=3D"xterm" TTY=3D"/dev/pts/1" COLUMNS=3D"19= 4" LINES=3D"41"]
root@1:/dev# exit pastebinit foo.log =
[C [C [C [C [C [C [C [C [C [C [C [C [C [5Pscript foo.log = [3Prm foo.log [2@nano [C [C [C [C [C [C [C [C [C = [1Pcat [C [C [C [C [C [C [C [C [C script foo.log ls= [K cat stderr out time strace dd if=3D/dev/zero of=3D/dev/sd= a4 bs=3D10M count=3D10 iflag=3Dfullblock conv=3Dfdatasync >stdout 2>s= tderr
execve("/usr/bin/dd", ["dd", "if=3D/dev/z= ero", "of=3D/dev/sda4", "bs=3D10M", "count=3D= 10", "iflag=3Dfullblock", "conv=3Dfdatasync"], 0x7= fffffffe690 /* 18 vars */) =3D 0
brk(NULL) =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =3D 0x555555568000
access("/etc/ld.so.preload", R_OK) =C2= =A0 =C2=A0 =C2=A0=3D -1 ENOENT (No such file or directory)
openat(AT_FDC= WD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) =3D 3
fstat(3, {st= _mode=3DS_IFREG|0644, st_size=3D20223, ...}) =3D 0
mmap(NULL, 20223, PRO= T_READ, MAP_PRIVATE, 3, 0) =3D 0x7ffff7fcb000
close(3) =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0=3D 0
openat(AT_FDCWD, "/lib/x86_64-linux-gnu/l= ibc.so.6", O_RDONLY|O_CLOEXEC) =3D 3
read(3, "\177ELF\2\1\1\3\= 0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260A\2\0\0\0\0\0"..., 832) =3D 832fstat(3, {st_mode=3DS_IFREG|0755, st_size=3D1824496, ...}) =3D 0
mmap(= NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) =3D 0x7= ffff7fc9000
mmap(NULL, 1837056, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3,= 0) =3D 0x7ffff7e08000
mprotect(0x7ffff7e2a000, 1658880, PROT_NONE) =3D = 0
mmap(0x7ffff7e2a000, 1343488, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIX= ED|MAP_DENYWRITE, 3, 0x22000) =3D 0x7ffff7e2a000
mmap(0x7ffff7f72000, 31= 1296, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x16a000) =3D 0x7f= fff7f72000
mmap(0x7ffff7fbf000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE= |MAP_FIXED|MAP_DENYWRITE, 3, 0x1b6000) =3D 0x7ffff7fbf000
mmap(0x7ffff7f= c5000, 14336, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1= , 0) =3D 0x7ffff7fc5000
close(3) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =3D 0
arch_prctl(ARCH_SET_FS, 0x7ffff7fca580) =3D 0
mprotect(0x7ffff7= fbf000, 16384, PROT_READ) =3D 0
mprotect(0x555555566000, 4096, PROT_READ= ) =3D 0
mprotect(0x7ffff7ffc000, 4096, PROT_READ) =3D 0
munmap(0x7fff= f7fcb000, 20223) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 0
rt_sigaction(S= IGINT, NULL, {sa_handler=3DSIG_DFL, sa_mask=3D[], sa_flags=3D0}, 8) =3D 0rt_sigaction(SIGUSR1, {sa_handler=3D0x555555558430, sa_mask=3D[INT USR1],= sa_flags=3DSA_RESTORER, sa_restorer=3D0x7ffff7e3f840}, NULL, 8) =3D 0
r= t_sigaction(SIGINT, {sa_handler=3D0x555555558420, sa_mask=3D[INT USR1], sa_= flags=3DSA_RESTORER|SA_NODEFER|SA_RESETHAND, sa_restorer=3D0x7ffff7e3f840},= NULL, 8) =3D 0
brk(NULL) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 0x555555568= 000
brk(0x555555589000) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =3D 0x555555589000
openat(AT_FDCWD, "/usr/lib= /locale/locale-archive", O_RDONLY|O_CLOEXEC) =3D 3
fstat(3, {st_mod= e=3DS_IFREG|0644, st_size=3D3031616, ...}) =3D 0
mmap(NULL, 3031616, PRO= T_READ, MAP_PRIVATE, 3, 0) =3D 0x7ffff7b23000
close(3) =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0=3D 0
openat(AT_FDCWD, "/dev/zero", O_RDON= LY) =3D 3
dup2(3, 0) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D 0
close(3) = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D 0
lseek(0, 0, SEEK_CUR) =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 0
openat(AT= _FDCWD, "/dev/sda4", O_WRONLY|O_CREAT|O_TRUNC, 0666) =3D 3
dup= 2(3, 1) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D 1
close(3) =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0=3D 0
mmap(NULL, 10498048, PROT_READ|PROT_WRITE, MAP= _PRIVATE|MAP_ANONYMOUS, -1, 0) =3D 0x7ffff7120000
read(0, "\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760= ) =3D 10485760
write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
read(0, "\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10= 485760) =3D 10485760
write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
read(0, &q= uot;\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0".= .., 10485760) =3D 10485760
write(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
read= (0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&= quot;..., 10485760) =3D 10485760
write(1, "\0\0\0\0\0\0\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0"..., 10485760) =3D 10485760
write(1, "\0\0\0\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 1048= 5760
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0\0\0\0"..., 10485760) =3D 10485760
write(1, "\0\0\0\0\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) = =3D 10485760
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
write(1, "\0\0= \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 1048= 5760) =3D 10485760
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
write(1, &quo= t;\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"...= , 10485760) =3D 10485760
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
write(1= , "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0&qu= ot;..., 10485760) =3D 10485760
read(0, "\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"..., 10485760) =3D 10485760
w= rite(1, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\= 0\0"..., 10485760) =3D 10485760
fdatasync(1) =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0=3D 0
--- SIGINT {si_signo=3DSIGINT, si_code=3DSI_USER, si_pid=3D1399= , si_uid=3D0} ---
rt_sigreturn({mask=3D[]}) =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 0
close(0) =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0=3D 0
close(1) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D 0
= openat(AT_FDCWD, "/usr/share/locale/locale.alias", O_RDONLY|O_CLO= EXEC) =3D 0
fstat(0, {st_mode=3DS_IFREG|0644, st_size=3D2995, ...}) =3D = 0
read(0, "# Locale name alias data base.\n#"..., 4096) =3D 29= 95
read(0, "", 4096) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 0
close(0) =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0=3D 0
openat(AT_FDCWD, "/usr/share/locale/en_CA/LC= _MESSAGES/coreutils.mo", O_RDONLY) =3D -1 ENOENT (No such file or dire= ctory)
openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/coreutils= .mo", O_RDONLY) =3D -1 ENOENT (No such file or directory)
write(2, = "10+0 records in\n10+0 records out"..., 3310+0 records in
10+0= records out
) =3D 33
write(2, "104857600 bytes (105 MB, 100 MiB= "..., 62104857600 bytes (105 MB, 100 MiB) copied, 1.94798 s, 53.8 MB/s= ) =3D 62
write(2, "\n", 1
) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 1
rt_sigprocmask(SIG_B= LOCK, [INT USR1], [], 8) =3D 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = =3D 0
close(0) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0=3D -1 EBADF (Bad fi= le descriptor)
write(2, "dd: ", 4dd: ) =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D 4
write(2, "cl= osing input file '/dev/zero'", 30closing input file '/dev/= zero') =3D 30
openat(AT_FDCWD, "/usr/share/locale/en_CA/LC_MESS= AGES/libc.mo", O_RDONLY) =3D -1 ENOENT (No such file or directory)
= openat(AT_FDCWD, "/usr/share/locale/en/LC_MESSAGES/libc.mo", O_RD= ONLY) =3D -1 ENOENT (No such file or directory)
write(2, ": Bad fil= e descriptor", 21: Bad file descriptor) =C2=A0 =3D 21
write(2, &quo= t;\n", 1
) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =3D 1
close(2) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0=3D 0
exit_group(1) =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =3D ?
+++ exited with 1 +++
real 0m1.955s
user 0m0.001s
sys 0m0.201s
root@1:/dev# exitexit

Script done on 2019-05-30 09:40:05-04:00 [COMMAND_EXIT_CODE=3D= "1"]
--0000000000007d3dfd058a1cb08f-- From debbugs-submit-bounces@debbugs.gnu.org Thu May 30 16:56:16 2019 Received: (at 36007-done) by debbugs.gnu.org; 30 May 2019 20:56:16 +0000 Received: from localhost ([127.0.0.1]:34055 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWS5w-0003GQ-BZ for submit@debbugs.gnu.org; Thu, 30 May 2019 16:56:16 -0400 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:45202) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWS5t-0003GA-SQ for 36007-done@debbugs.gnu.org; Thu, 30 May 2019 16:56:15 -0400 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 6999E160868; Thu, 30 May 2019 13:56:06 -0700 (PDT) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id Ey0J5HcgTxbe; Thu, 30 May 2019 13:56:05 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 2277C160863; Thu, 30 May 2019 13:56:05 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5Y_GBKpD6-Sp; Thu, 30 May 2019 13:56:05 -0700 (PDT) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 08B74160835; Thu, 30 May 2019 13:56:05 -0700 (PDT) Subject: Re: bug#36007: double close() of of=file if receiving SIGINT during fdatasync() To: Hans Henrik Bergan , 36007-done@debbugs.gnu.org References: From: Paul Eggert Openpgp: preference=signencrypt Autocrypt: addr=eggert@cs.ucla.edu; prefer-encrypt=mutual; keydata= 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 uNcby4U= Organization: UCLA Computer Science Department Message-ID: <8b6f188e-c3a1-50ec-a8fb-2214708e7981@cs.ucla.edu> Date: Thu, 30 May 2019 13:56:04 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/mixed; boundary="------------F9E475F550EF7567B6C5A81C" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 36007-done X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------F9E475F550EF7567B6C5A81C Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for reporting the bug. I installed the attached patch into the development version on Savannah, to fix the bug you reported along with a closely related bug that I found when looking into your problem. Please give this patch a try at your convenience. --------------F9E475F550EF7567B6C5A81C Content-Type: text/x-patch; name="0001-dd-be-more-careful-about-signal-handling.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-dd-be-more-careful-about-signal-handling.patch" >From 2c9f67e21aadbcf455ba8f9467202cc6ae8ad99d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Thu, 30 May 2019 13:53:54 -0700 Subject: [PATCH] dd: be more careful about signal handling Problem reported by Hans Henrik Bergan (Bug#36007). * NEWS: Mention this. * src/dd.c (iclose, ifdatasync, ifstat, ifsync): New functions, which are more careful about SIGINT. (cleanup): Use iclose instead of close. (finish_up): Process signals first. (skip, dd_copy, main): Use ifstat instead of fstat. (dd_copy): Use ifdatasync and ifsync instead of fdatasync and fsync. --- NEWS | 6 +++ src/dd.c | 113 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 96 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index 5db95b1c4..593c69b00 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,12 @@ GNU coreutils NEWS -*- outline -*- it is a character-special file whose minor device number is N. [bug introduced in fileutils-4.1.6] + dd conv=fdatasync no longer reports a "Bad file descriptor" error + when fdatasync is interrupted, and dd now retries interrupted calls + to close, fdatasync, fstat and fsync instead of incorrectly + reporting an "Interrupted system call" error. + [bugs introduced in coreutils-6.0] + df now correctly parses the /proc/self/mountinfo file for unusual entries like ones with '\r' in a field value ("mount -t tmpfs tmpfs /foo$'\r'bar"), when the source field is empty ('mount -t tmpfs "" /mnt'), and when the diff --git a/src/dd.c b/src/dd.c index ef0d07ac3..edb096a2f 100644 --- a/src/dd.c +++ b/src/dd.c @@ -529,7 +529,7 @@ maybe_close_stdout (void) _exit (EXIT_FAILURE); } -/* Like error() but handle any pending newline. */ +/* Like the 'error' function but handle any pending newline. */ static void _GL_ATTRIBUTE_FORMAT ((__printf__, 3, 4)) nl_error (int status, int errnum, const char *fmt, ...) @@ -914,8 +914,8 @@ install_signal_handlers (void) { act.sa_handler = siginfo_handler; /* Note we don't use SA_RESTART here and instead - handle EINTR explicitly in iftruncate() etc. - to avoid blocking on noncommitted read()/write() calls. */ + handle EINTR explicitly in iftruncate etc. + to avoid blocking on noncommitted read/write calls. */ act.sa_flags = 0; sigaction (SIGINFO, &act, NULL); } @@ -942,16 +942,33 @@ install_signal_handlers (void) #endif } +/* Close FD. Return 0 if successful, -1 (setting errno) otherwise. + If close fails with errno == EINTR, POSIX says the file descriptor + is in an unspecified state, so keep trying to close FD but do not + consider EBADF to be an error. Do not process signals. This all + differs somewhat from functions like ifdatasync and ifsync. */ +static int +iclose (int fd) +{ + if (close (fd) != 0) + do + if (errno != EINTR) + return -1; + while (close (fd) != 0 && errno != EBADF); + + return 0; +} + static void cleanup (void) { - if (close (STDIN_FILENO) < 0) + if (iclose (STDIN_FILENO) != 0) die (EXIT_FAILURE, errno, _("closing input file %s"), quoteaf (input_file)); /* Don't remove this call to close, even though close_stdout closes standard output. This close is necessary when cleanup - is called as part of a signal handler. */ - if (close (STDOUT_FILENO) < 0) + is called as a consequence of signal handling. */ + if (iclose (STDOUT_FILENO) != 0) die (EXIT_FAILURE, errno, _("closing output file %s"), quoteaf (output_file)); } @@ -992,9 +1009,10 @@ process_signals (void) static void finish_up (void) { + /* Process signals first, so that cleanup is called at most once. */ + process_signals (); cleanup (); print_stats (); - process_signals (); } static void ATTRIBUTE_NORETURN @@ -1192,7 +1210,7 @@ iwrite (int fd, char const *buf, size_t size) /* Since we have just turned off O_DIRECT for the final write, we try to preserve some of its semantics. */ - /* Call invalidate_cache() to setup the appropriate offsets + /* Call invalidate_cache to setup the appropriate offsets for subsequent calls. */ o_nocache_eof = true; invalidate_cache (STDOUT_FILENO, 0); @@ -1201,7 +1219,7 @@ iwrite (int fd, char const *buf, size_t size) to disk as quickly as possible. */ conversions_mask |= C_FSYNC; - /* After the subsequent fsync() we'll call invalidate_cache() + /* After the subsequent fsync we'll call invalidate_cache to attempt to clear all data from the page cache. */ } @@ -1271,7 +1289,24 @@ write_output (void) oc = 0; } -/* Restart on EINTR from fd_reopen(). */ +/* Restart on EINTR from fdatasync. */ + +static int +ifdatasync (int fd) +{ + int ret; + + do + { + process_signals (); + ret = fdatasync (fd); + } + while (ret < 0 && errno == EINTR); + + return ret; +} + +/* Restart on EINTR from fd_reopen. */ static int ifd_reopen (int desired_fd, char const *file, int flag, mode_t mode) @@ -1288,7 +1323,41 @@ ifd_reopen (int desired_fd, char const *file, int flag, mode_t mode) return ret; } -/* Restart on EINTR from ftruncate(). */ +/* Restart on EINTR from fstat. */ + +static int +ifstat (int fd, struct stat *st) +{ + int ret; + + do + { + process_signals (); + ret = fstat (fd, st); + } + while (ret < 0 && errno == EINTR); + + return ret; +} + +/* Restart on EINTR from fsync. */ + +static int +ifsync (int fd) +{ + int ret; + + do + { + process_signals (); + ret = fsync (fd); + } + while (ret < 0 && errno == EINTR); + + return ret; +} + +/* Restart on EINTR from ftruncate. */ static int iftruncate (int fd, off_t length) @@ -1780,7 +1849,7 @@ skip (int fdesc, char const *file, uintmax_t records, size_t blocksize, if (fdesc == STDIN_FILENO) { struct stat st; - if (fstat (STDIN_FILENO, &st) != 0) + if (ifstat (STDIN_FILENO, &st) != 0) die (EXIT_FAILURE, errno, _("cannot fstat %s"), quoteaf (file)); if (usable_st_size (&st) && st.st_size < input_offset + offset) { @@ -2036,7 +2105,7 @@ set_fd_flags (int fd, int add_flags, char const *name) /* NEW_FLAGS contains at least one file creation flag that requires some checking of the open file descriptor. */ struct stat st; - if (fstat (fd, &st) != 0) + if (ifstat (fd, &st) != 0) ok = false; else if ((new_flags & O_DIRECTORY) && ! S_ISDIR (st.st_mode)) { @@ -2327,7 +2396,7 @@ dd_copy (void) if (final_op_was_seek) { struct stat stdout_stat; - if (fstat (STDOUT_FILENO, &stdout_stat) != 0) + if (ifstat (STDOUT_FILENO, &stdout_stat) != 0) { error (0, errno, _("cannot fstat %s"), quoteaf (output_file)); return EXIT_FAILURE; @@ -2349,7 +2418,7 @@ dd_copy (void) } } - if ((conversions_mask & C_FDATASYNC) && fdatasync (STDOUT_FILENO) != 0) + if ((conversions_mask & C_FDATASYNC) && ifdatasync (STDOUT_FILENO) != 0) { if (errno != ENOSYS && errno != EINVAL) { @@ -2359,13 +2428,11 @@ dd_copy (void) conversions_mask |= C_FSYNC; } - if (conversions_mask & C_FSYNC) - while (fsync (STDOUT_FILENO) != 0) - if (errno != EINTR) - { - error (0, errno, _("fsync failed for %s"), quoteaf (output_file)); - return EXIT_FAILURE; - } + if ((conversions_mask & C_FSYNC) && ifsync (STDOUT_FILENO) != 0) + { + error (0, errno, _("fsync failed for %s"), quoteaf (output_file)); + return EXIT_FAILURE; + } return exit_status; } @@ -2465,7 +2532,7 @@ main (int argc, char **argv) fails on /dev/fd0. */ int ftruncate_errno = errno; struct stat stdout_stat; - if (fstat (STDOUT_FILENO, &stdout_stat) != 0) + if (ifstat (STDOUT_FILENO, &stdout_stat) != 0) die (EXIT_FAILURE, errno, _("cannot fstat %s"), quoteaf (output_file)); if (S_ISREG (stdout_stat.st_mode) -- 2.21.0 --------------F9E475F550EF7567B6C5A81C-- From debbugs-submit-bounces@debbugs.gnu.org Thu May 30 18:22:19 2019 Received: (at 36007-done) by debbugs.gnu.org; 30 May 2019 22:22:19 +0000 Received: from localhost ([127.0.0.1]:34260 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWTRC-0005jW-Oj for submit@debbugs.gnu.org; Thu, 30 May 2019 18:22:19 -0400 Received: from mail-it1-f181.google.com ([209.85.166.181]:34461) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1hWSwi-0004nW-73 for 36007-done@debbugs.gnu.org; Thu, 30 May 2019 17:50:48 -0400 Received: by mail-it1-f181.google.com with SMTP id g23so9238872iti.1 for <36007-done@debbugs.gnu.org>; Thu, 30 May 2019 14:50:48 -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=LUEOtxpPcI6eDi6cYHsCk9YRdqvW5OtnuRBgEcR4+Rc=; b=M2VDCaxld21LE/E2gEKrwibYL+88QpPSdg36ppSN7Za7aVsUF0Th9tJMgSFvCkQLjv tTnKAyP1eQ1JLuBjtM3fBW2ZD849IogKWeaE10FlCM6Eqgjsb4md90M0pxKsqfE/4wim dfPrAmplRb7a0B8ZhVdjqNNm4LZQiVBQdyjLCZAdES9LW4Pv3eMa3XMEJ2JenFK8Ta07 Q64msHthWCEeFnBHJb4stQVi4W5TKPFOA0Zht7KLnKlEi5AExNh8FrTEmwGl59Ol3k8s ++7Xvc1Vk1xL3/6yV7OSTQLv3RIY8GKf3cRwLPwqSk9/NoCfQHTTPtaHv/gUKOaYEFze BYBA== 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=LUEOtxpPcI6eDi6cYHsCk9YRdqvW5OtnuRBgEcR4+Rc=; b=NseeO3F3p5OfyGBD8QW+iHZjH/QmMdD/9JaYS/k/S0e9NzR5vZKL2z92g0kD0a4Cn7 NlbkKeWnF4brGMp3F9cxZtaRTkQQTaBlu/TCODm4HVETnFSexSa4vPpDQjqz355P2MQ9 LzsA5ul03BKgirIXJyWfQR4IaOuzVYSLVAP5CtJSc8RCol1SAM6i+iJ2LgFVGGSWbUWt dwocPfZUXrk9w2yACe7f5e+k4O9lBQY0WyHoVOoOL5BJYPThtuy4Z1h9GtM5ixPLFmDZ dph7KFnkOMKyd5qbf4VE+XPdecU5VbtbWpQGD1GeK9Dll1Y3dFpCbYdayb7WlB5Uysps sfRQ== X-Gm-Message-State: APjAAAX1ia/H5U8WD7RxvmsqWGr8V6oPHtssHF9Vo2b0N4meBFbpQ31L ziJahRsUt2GKw8/xH3fNI3VMM3bEPlS3i1BjeJU= X-Google-Smtp-Source: APXvYqz2kwU2fQ7OI4/uv3jhwNJA2L0MAP4wx9AeCxbThNHzprUvmOMCkjnZHM2gzRxS+9xSktUG1rGSCtLcnm9Id0I= X-Received: by 2002:a24:8342:: with SMTP id d63mr4535913ite.66.1559253042240; Thu, 30 May 2019 14:50:42 -0700 (PDT) MIME-Version: 1.0 References: <8b6f188e-c3a1-50ec-a8fb-2214708e7981@cs.ucla.edu> In-Reply-To: <8b6f188e-c3a1-50ec-a8fb-2214708e7981@cs.ucla.edu> From: Hans Henrik Bergan Date: Thu, 30 May 2019 23:50:30 +0200 Message-ID: Subject: Re: bug#36007: double close() of of=file if receiving SIGINT during fdatasync() To: Paul Eggert Content-Type: multipart/alternative; boundary="000000000000b2a0f9058a21e3c2" X-Spam-Score: -0.1 (/) X-Debbugs-Envelope-To: 36007-done X-Mailman-Approved-At: Thu, 30 May 2019 18:22:18 -0400 Cc: 36007-done@debbugs.gnu.org X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.1 (-) --000000000000b2a0f9058a21e3c2 Content-Type: text/plain; charset="UTF-8" the issue does not reproduce on a current git master build of dd ( commit 00d72e6122d37bbc32ef0e057c1e847fd8129133 ) , good job :) (dd is an old build, ./dd is a git master build) root@1:/temp/coreutils/src# dd if=/dev/zero of=/dev/sda4 bs=10M count=100 iflag=fullblock conv=fdatasync ^C100+0 records in 100+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 17.3542 s, 60.4 MB/s dd: closing input file '/dev/zero': Bad file descriptor root@1:/temp/coreutils/src# root@1:/temp/coreutils/src# root@1:/temp/coreutils/src# ./dd if=/dev/zero of=/dev/sda4 bs=10M count=100 iflag=fullblock conv=fdatasync ^C100+0 records in 100+0 records out 1048576000 bytes (1.0 GB, 1000 MiB) copied, 19.0614 s, 55.0 MB/s root@1:/temp/coreutils/src# On Thu, 30 May 2019 at 22:56, Paul Eggert wrote: > Thanks for reporting the bug. I installed the attached patch into the > development version on Savannah, to fix the bug you reported along with > a closely related bug that I found when looking into your problem. > Please give this patch a try at your convenience. > --000000000000b2a0f9058a21e3c2 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
the issue does not reproduce on a current git master build= of dd ( commit=C2=A000d72e6122d37bbc32ef0e057c1e847fd8129133 )
, good j= ob :)=C2=A0=C2=A0

(dd is an old build, ./dd is a git master build)root@1:/temp/coreutils/src# dd if=3D/dev/zero of=3D/dev/sda4 bs=3D10M cou= nt=3D100 iflag=3Dfullblock conv=3Dfdatasync
^C100+0 records in
100+0 = records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 17.3542 s, 60.4 = MB/s
dd: closing input file '/dev/zero': Bad file descriptor
= root@1:/temp/coreutils/src#
root@1:/temp/coreutils/src#
root@1:/temp/= coreutils/src# ./dd if=3D/dev/zero of=3D/dev/sda4 bs=3D10M count=3D100 ifla= g=3Dfullblock conv=3Dfdatasync
^C100+0 records in
100+0 records out1048576000 bytes (1.0 GB, 1000 MiB) copied, 19.0614 s, 55.0 MB/s
root@= 1:/temp/coreutils/src#



On Thu, 30 May 2019 at 22:56, Paul Eggert= <eggert@cs.ucla.edu> wrote= :
Thanks for rep= orting the bug. I installed the attached patch into the
development version on Savannah, to fix the bug you reported along with a closely related bug that I found when looking into your problem.
Please give this patch a try at your convenience.
--000000000000b2a0f9058a21e3c2-- From unknown Sat Jun 21 10:38:59 2025 Received: (at fakecontrol) by fakecontrolmessage; To: internal_control@debbugs.gnu.org From: Debbugs Internal Request Subject: Internal Control Message-Id: bug archived. Date: Fri, 28 Jun 2019 11:24:04 +0000 User-Agent: Fakemail v42.6.9 # This is a fake control message. # # The action: # bug archived. thanks # This fakemail brought to you by your local debbugs # administrator