www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10364] New: Mac OS 10.8 program crash

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364

           Summary: Mac OS 10.8 program crash
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Mac OS X
            Status: NEW
          Severity: critical
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: spam kalekold.net



---
Created an attachment (id=1226)
Sample crash log

The following code produces a program crash on Mac OS 10.8. Nothing is output
to the opened file and a crash is reported to /etc/log/system.log.

import core.sys.posix.unistd;
import std.c.stdlib;
import std.process;
import std.stdio;
import std.string;

int main(string[] args)
{
    pid_t pid = fork();
    if (pid < 0)
    {
        exit(EXIT_FAILURE);
    }

    if (pid > 0)
    {
        exit(EXIT_SUCCESS);
    }

    auto logFile = File("/Users/gary/Desktop/test.log", "a");
    logFile.writeln("Opened file");

    string command = format("logger -t %s %s", "hello", "This is a test");
    executeShell(command);

    logFile.writeln("Done");

    return 0;
}

See attached for sample crash log.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364




---
Another example of maybe the same bug? This also crashes but does so silently
with no system.log entry or crash dump.

import core.sys.posix.sys.stat;
import core.sys.posix.unistd;
import std.c.stdio;
import std.c.stdlib;
import std.process;
import std.stdio;
import std.string;
import std.file;
import std.datetime;

class Logger
{
     private File _logFile;

     public this(string logFile)
     {
         this._logFile = File(logFile, "a");
     }

     public void info(string, A...)(string text, A args)
     {
         this._logFile.writefln(format(text, args));
     }
}

int main(string[] args)
{
     pid_t pid, sid;

     pid = fork();
     if (pid < 0)
     {
         exit(EXIT_FAILURE);
     }

     if (pid > 0)
     {
         exit(EXIT_SUCCESS);
     }

     umask(0);

     sid = setsid();
     if (sid < 0)
     {
         exit(EXIT_FAILURE);
     }

     if ((core.sys.posix.unistd.chdir("/")) < 0)
     {
         exit(EXIT_FAILURE);
     }

     close(STDIN_FILENO);
     close(STDOUT_FILENO);
     close(STDERR_FILENO);

     auto logger = new Logger("/Users/gary/Desktop/test.log");

     // Crash!
     logger.info("Reading file");

     string configFileContents = readText("/etc/hosts");

     // Never executes!
     logger.info(configFileContents);

     return 0;
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 15 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla kyllingen.net



08:11:16 PDT ---
I can not reproduce this on Linux.  It would be great to get confirmation from
someone else on OSX, to verify that it isn't a local issue.

One thing I've noticed is that you call exit() in the parent process after a
successful fork().  You should call _exit() instead, to avoid double-flushing
buffers etc.  This probably won't fix your problem, but it's worth a try.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|nobody puremagic.com        |bugzilla kyllingen.net


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 28 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364




---

 I can not reproduce this on Linux.  It would be great to get confirmation from
 someone else on OSX, to verify that it isn't a local issue.
 
 One thing I've noticed is that you call exit() in the parent process after a
 successful fork().  You should call _exit() instead, to avoid double-flushing
 buffers etc.  This probably won't fix your problem, but it's worth a try.
I've reduced it to this: import std.stdio; import std.string; import std.process; extern (C) { int daemon(int nochdir, int noclose); } void main(string[] args) { daemon(0, 0); auto logFile = File("/Users/gary/Desktop/test.log", "a"); logFile.writeln("Opened file"); string command = format("logger -t %s %s", "Hello", "This is a test."); executeShell(command); // Crash dump logged at /var/log/system.log logFile.writeln("Done!"); // Never executes. } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jul 28 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10364


Lars T. Kyllingstad <bugzilla kyllingen.net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|critical                    |major


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 06 2013