Project

General

Profile

Actions

Bug #5341

closed

gcore fails with "no such file or directory" if write fails ... error is misleading

Added by Robert Mustacchi almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Category:
cmd - userland programs
Start date:
2014-11-14
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

This is reproducible as long as the process you're taking a core file of is larger than the amount of free space in the ramdisk. trussing it shows:

pread(256, "02\\0\\0\\0 X05FAFE N %FDFE".., 4096, 0xFEFFB000) = 4096
pwrite(3, "02\\0\\0\\0 X05FAFE N %FDFE".., 4096, 0x0162483C) = 1988
pwrite(3, "02\\0\\0\\0", 4, 0x0162483C)        = 4
fcntl(3, F_FREESP, 0xFFFFFD7FFFDFE360)        = 0
pwrite(3, "01\\0\\0\\0\\0\\0\\0\\0\\0B0FFFE".., 32, 4756) = 32
pread(256, "\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0".., 4096, 0xFEFFD000) = 4096
pwrite(3, "\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0".., 4096, 0x01624844) = 1980
pwrite(3, "02\\0\\0\\0", 4, 0x01624844)        = 4
fcntl(3, F_FREESP, 0xFFFFFD7FFFDFE360)        = 0
pwrite(3, "01\\0\\0\\0\\0\\0\\0\\0\\0D0FFFE".., 32, 4788) = 32
pwrite(3, "\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0".., 677712, 0x0162484C) = 1972
fcntl(3, F_FREESP, 0xFFFFFD7FFFDFE4E0)        = 0
close(3)                    = 0
unlink("core.85530")                = 0
fstat(2, 0xFFFFFD7FFFDFDF40)            = 0
gcorewrite(2, " g c o r e", 5)            = 5
: write(2, " :  ", 2)                = 2
core.85530write(2, " c o r e . 8 5 5 3 0", 10)        = 10
 dump failed: write(2, "   d u m p   f a i l e d".., 14)    = 14
No such file or directorywrite(2, " N o   s u c h   f i l e".., 25)    = 25

If the pwrite64() call in dump_sections() doesn't return indicating that all bytes were written, dump_sections() returns -1. That gets propagated back up to Pgcore() in libproc, then gcore() in gcore(1), which prints the error message using "strerror(errno)". The problem is that errno was never set because no system call failed here: pwrite() just returned less than the full byte count. Even if an errno had been set by pwrite(), we make several system calls between that call and the return from Pgcore(), and any of them could clobber errno.

Actions #1

Updated by Electric Monk almost 7 years ago

  • Status changed from New to Closed

git commit 64e4e50ab4bc3670a29e5691e3dd935c94f0a5d7

commit  64e4e50ab4bc3670a29e5691e3dd935c94f0a5d7
Author: Keith M Wesolowski <wesolows@foobazco.org>
Date:   2014-11-25T16:07:17.000Z

    5341 gcore fails with "no such file or directory" if write fails ... error is misleading
    Reviewed by: Adam Leventhal <ahl@delphix.com>
    Reviewed by: Garrett D'Amore <garrett@damore.org>
    Approved by: Richard Lowe <richlowe@richlowe.net>

Actions

Also available in: Atom PDF