summaryrefslogtreecommitdiff
path: root/nix/nix-daemon
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2012-12-16 18:28:00 +0100
committerLudovic Courtès <ludo@gnu.org>2012-12-16 18:28:00 +0100
commit868fce7c4ae92d533ec6936c8077cd4845aebd19 (patch)
treea0c36d90dbbca7a1de8e2e4abda1b0ef9df8fbd1 /nix/nix-daemon
parente2332e8aa7240451fd596140d242dc062c93230b (diff)
downloadgnu-guix-868fce7c4ae92d533ec6936c8077cd4845aebd19.tar
gnu-guix-868fce7c4ae92d533ec6936c8077cd4845aebd19.tar.gz
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.
Diffstat (limited to 'nix/nix-daemon')
-rw-r--r--nix/nix-daemon/guix-daemon.cc32
1 files changed, 22 insertions, 10 deletions
diff --git a/nix/nix-daemon/guix-daemon.cc b/nix/nix-daemon/guix-daemon.cc
index 459c794f5d..6ffc8f04ad 100644
--- a/nix/nix-daemon/guix-daemon.cc
+++ b/nix/nix-daemon/guix-daemon.cc
@@ -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 */
}