[LLVMbugs] [Bug 22659] New: llvm::sys::ExecuteAndWait does not truncate redirected output

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Sat Feb 21 13:20:37 PST 2015


http://llvm.org/bugs/show_bug.cgi?id=22659

            Bug ID: 22659
           Summary: llvm::sys::ExecuteAndWait does not truncate redirected
                    output
           Product: libraries
           Version: 3.6
          Hardware: PC
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Support Libraries
          Assignee: unassignedbugs at nondot.org
          Reporter: pohilets at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

The following code snippet reproduces the problem:

#include <llvm/Support/Program.h>

int main(int argc, const char * argv[]) {
    if (argc == 1) {
        // Parent process
        char const * args[] = { argv[0], "foooooo", nullptr };
        llvm::StringRef out("test.txt");
        const llvm::StringRef* redirects[] = { nullptr, &out, nullptr };
        llvm::sys::ExecuteAndWait(argv[0], args, nullptr, redirects);
        args[1] = "xxx";
        llvm::sys::ExecuteAndWait(argv[0], args, nullptr, redirects);
    } else {
        // Child process
        printf("%s\n", argv[1]);
    }
    return 0;
}

Actual content of 'test.txt':
xxx
ooo
Expected content of 'test.txt':
xxx

LLVM is compiled with HAVE_POSIX_SPAWN - redirect is done in function
RedirectIO_PS.

Seems that this can be fixed by simply adding O_TRUNC to opening flags in
RedirectIO_PS() and RedirectIO().

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150221/5b975bc8/attachment.html>


More information about the llvm-bugs mailing list