~ruther/guix-local

868fce7c4ae92d533ec6936c8077cd4845aebd19 — Ludovic Courtès 13 years ago e2332e8
daemon: Gracefully handle Nix errors.

* nix/nix-daemon/guix-daemon.cc (main): Run Nix code in an exception
  handler; gracefully print error messages, and exit with EXIT_FAILURE.
1 files changed, 22 insertions(+), 10 deletions(-)

M nix/nix-daemon/guix-daemon.cc
M nix/nix-daemon/guix-daemon.cc => nix/nix-daemon/guix-daemon.cc +22 -10
@@ 27,6 27,7 @@
#include <argp.h>
#include <unistd.h>
#include <sys/types.h>
#include <exception>

/* Variables used by `nix-daemon.cc'.  */
volatile ::sig_atomic_t blockInt;


@@ 170,18 171,29 @@ main (int argc, char *argv[])
  settings.useChroot = false;
#endif

  settings.processEnvironment ();
  argvSaved = argv;

  try
    {
      settings.processEnvironment ();

  /* FIXME: Disable substitutes until we have something that works.  */
  settings.useSubstitutes = false;
  settings.substituters.clear ();
      /* FIXME: Disable substitutes until we have something that works.  */
      settings.useSubstitutes = false;
      settings.substituters.clear ();

  argp_parse (&argp, argc, argv, 0, 0, 0);
      argp_parse (&argp, argc, argv, 0, 0, 0);

  if (geteuid () == 0 && settings.buildUsersGroup.empty ())
    fprintf (stderr, "warning: running as root is highly recommended, "
	     "unless `--build-users-group' is used\n");
      if (geteuid () == 0 && settings.buildUsersGroup.empty ())
	fprintf (stderr, "warning: running as root is highly recommended, "
		 "unless `--build-users-group' is used\n");

  argvSaved = argv;
  run (nothing);
      run (nothing);
    }
  catch (std::exception &e)
    {
      fprintf (stderr, "error: %s\n", e.what ());
      return EXIT_FAILURE;
    }

  return EXIT_SUCCESS;				  /* never reached */
}