[m-rev.] for review: don't abort if opening binary stdin/stdout fails

Julien Fischer juliensf at csse.unimelb.edu.au
Fri Feb 23 16:20:48 AEDT 2007


For review by anyone.

Estimated hours taken: 0.5
Branches: main

Remove an over-zealous sanity check in the standard library initialisation
code that causes Mercury programs that run in environments in which stdin or
stdout are not available to abort.  It also fixes a problem when running
Mercury programs under recent versions of GNU nohup.

library/io.m:
 	Don't abort if we cannot create binary stdin/stdout.

 	Fix some formatting.

Julien.

Index: library/io.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.372
diff -u -r1.372 io.m
--- library/io.m	13 Feb 2007 01:58:53 -0000	1.372
+++ library/io.m	22 Feb 2007 07:26:50 -0000
@@ -5668,15 +5668,24 @@
          defined(MR_HAVE_DUP)
      MR_file(mercury_stdin_binary) = fdopen(dup(fileno(stdin)), ""rb"");
      if (MR_file(mercury_stdin_binary) == NULL) {
-        MR_fatal_error(""error opening standard input stream in ""
-            ""binary mode:\\n\\tfdopen() failed: %s"",
-            strerror(errno));
+        /*
+        ** The call to fdopen() may fail if stdin is not available.
+        ** We don't abort since we still want Mercury programs to be runnable
+        ** in such a circumstance (aside from those that use stdin).
+        ** For the same reason we treat binary stdout identically below.
+        **
+        ** NOTE: some versions of nohup may also cause the above call to
+        **       fdopen() to fail because they redirect stdin to /dev/null
+        **       in *write* mode.  Setting binary stdin to stdin in such
+        **       a case also ensures that we work with those versions of
+        **       nohup.
+        */
+        MR_file(mercury_stdin_binary) = stdin;
      }
+
      MR_file(mercury_stdout_binary) = fdopen(dup(fileno(stdout)), ""wb"");
      if (MR_file(mercury_stdout_binary) == NULL) {
-        MR_fatal_error(""error opening standard output stream in ""
-            ""binary mode:\\n\\tfdopen() failed: %s"",
-            strerror(errno));
+        MR_file(mercury_stdout_binary) = stdout;
      }
  #else
      /*
@@ -8003,7 +8012,9 @@
  "{
      int i;

-    /* convert mercury_argv from a vector to a list */
+    /*
+    ** Convert mercury_argv from a vector to a list.
+    */
      i = mercury_argc;
      Args = MR_list_empty_msg(MR_PROC_LABEL);
      while (--i >= 0) {
@@ -8076,10 +8087,10 @@
  io.handle_system_command_exit_code(Status0::in) = (Status::out) :-
      % This is a fall-back for back-ends that don't support the C interface.
      ( (Status0 /\ 0xff) \= 0 ->
-        /* the process was killed by a signal */
+        % The process was killed by a signal.
          Status = -(Status0 /\ 0xff)
      ;
-        /* the process terminated normally */
+        % The process terminated normally.
          Status = (Status0 /\ 0xff00) >> 8
      ).


--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the reviews mailing list