Another Mac OS crash

Gary Willoughby dev at kalekold.net
Thu Jun 13 11:16:10 PDT 2013


Another crash (Mac OS 10.8) here but this one doesn't seem to
raise a crash dump. Also it seems to work fine on Ubuntu 12.04

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;
}


More information about the Digitalmars-d-learn mailing list