diff options
Diffstat (limited to 'rts/RtsFlags.c')
-rw-r--r-- | rts/RtsFlags.c | 44 |
1 files changed, 29 insertions, 15 deletions
diff --git a/rts/RtsFlags.c b/rts/RtsFlags.c index 1e541a0201..4f850b583c 100644 --- a/rts/RtsFlags.c +++ b/rts/RtsFlags.c @@ -61,7 +61,7 @@ wchar_t **win32_prog_argv = NULL; Static function decls -------------------------------------------------------------------------- */ -static void procRtsOpts (int rts_argc0, RtsOptsEnabledEnum enabled); +static void procRtsOpts (HsBool is_hs_main, int rts_argc0, RtsOptsEnabledEnum enabled); static void normaliseRtsOpts (void); @@ -85,6 +85,8 @@ static char * copyArg (char *arg); static char ** copyArgv (int argc, char *argv[]); static void freeArgv (int argc, char *argv[]); +static void errorRtsOptsDisabled(HsBool is_hs_main, const char *s); + /* ----------------------------------------------------------------------------- * Command-line option parsing routines. * ---------------------------------------------------------------------------*/ @@ -444,6 +446,17 @@ static void splitRtsFlags(const char *s) } while (*c1 != '\0'); } +static void +errorRtsOptsDisabled(HsBool is_hs_main, const char *s) { + char *advice; + if (is_hs_main) { + advice = "Link with -rtsopts to enable them."; + } else { + advice = "Use hs_init_with_rtsopts() to enable them."; + } + errorBelch(s, advice); +} + /* ----------------------------------------------------------------------------- Parse the command line arguments, collecting options for the RTS. @@ -463,7 +476,8 @@ static void splitRtsFlags(const char *s) void setupRtsFlags (int *argc, char *argv[], RtsOptsEnabledEnum rtsOptsEnabled, - const char *ghc_rts_opts) + const char *ghc_rts_opts, + HsBool is_hs_main) { nat mode; nat total_arg; @@ -488,7 +502,7 @@ void setupRtsFlags (int *argc, char *argv[], if (ghc_rts_opts != NULL) { splitRtsFlags(ghc_rts_opts); // opts from ghc_rts_opts are always enabled: - procRtsOpts(rts_argc0, RtsOptsAll); + procRtsOpts(is_hs_main, rts_argc0, RtsOptsAll); rts_argc0 = rts_argc; } } @@ -500,11 +514,11 @@ void setupRtsFlags (int *argc, char *argv[], if (ghc_rts != NULL) { if (rtsOptsEnabled == RtsOptsNone) { - errorBelch("Warning: Ignoring GHCRTS variable as RTS options are disabled.\n Link with -rtsopts to enable them."); + errorRtsOptsDisabled(is_hs_main, "Warning: Ignoring GHCRTS variable as RTS options are disabled.\n %s"); // We don't actually exit, just warn } else { splitRtsFlags(ghc_rts); - procRtsOpts(rts_argc0, rtsOptsEnabled); + procRtsOpts(is_hs_main, rts_argc0, rtsOptsEnabled); rts_argc0 = rts_argc; } } @@ -543,7 +557,7 @@ void setupRtsFlags (int *argc, char *argv[], } argv[*argc] = (char *) 0; - procRtsOpts(rts_argc0, rtsOptsEnabled); + procRtsOpts(is_hs_main, rts_argc0, rtsOptsEnabled); appendRtsArg((char *)0); rts_argc--; // appendRtsArg will have bumped it for the NULL (#7227) @@ -564,29 +578,29 @@ void setupRtsFlags (int *argc, char *argv[], * procRtsOpts: Process rts_argv between rts_argc0 and rts_argc. * -------------------------------------------------------------------------- */ -static void checkSuid(RtsOptsEnabledEnum enabled) +static void checkSuid(HsBool is_hs_main, RtsOptsEnabledEnum enabled) { if (enabled == RtsOptsSafeOnly) { #if defined(HAVE_UNISTD_H) && defined(HAVE_SYS_TYPES_H) && !defined(mingw32_HOST_OS) /* This doesn't cover linux/posix capabilities like CAP_DAC_OVERRIDE, we'd have to link with -lcap for that. */ if ((getuid() != geteuid()) || (getgid() != getegid())) { - errorBelch("RTS options are disabled for setuid binaries. Link with -rtsopts to enable them."); + errorRtsOptsDisabled(is_hs_main, "RTS options are disabled for setuid binaries. %s"); stg_exit(EXIT_FAILURE); } #endif } } -static void checkUnsafe(RtsOptsEnabledEnum enabled) +static void checkUnsafe(HsBool is_hs_main, RtsOptsEnabledEnum enabled) { if (enabled == RtsOptsSafeOnly) { - errorBelch("Most RTS options are disabled. Link with -rtsopts to enable them."); + errorRtsOptsDisabled(is_hs_main, "Most RTS options are disabled. %s"); stg_exit(EXIT_FAILURE); } } -static void procRtsOpts (int rts_argc0, RtsOptsEnabledEnum rtsOptsEnabled) +static void procRtsOpts (HsBool is_hs_main, int rts_argc0, RtsOptsEnabledEnum rtsOptsEnabled) { rtsBool error = rtsFalse; int arg; @@ -594,11 +608,11 @@ static void procRtsOpts (int rts_argc0, RtsOptsEnabledEnum rtsOptsEnabled) if (!(rts_argc0 < rts_argc)) return; if (rtsOptsEnabled == RtsOptsNone) { - errorBelch("RTS options are disabled. Link with -rtsopts to enable them."); + errorRtsOptsDisabled(is_hs_main, "RTS options are disabled. %s"); stg_exit(EXIT_FAILURE); } - checkSuid(rtsOptsEnabled); + checkSuid(is_hs_main, rtsOptsEnabled); // Process RTS (rts_argv) part: mainly to determine statsfile for (arg = rts_argc0; arg < rts_argc; arg++) { @@ -610,7 +624,7 @@ static void procRtsOpts (int rts_argc0, RtsOptsEnabledEnum rtsOptsEnabled) rtsBool option_checked = rtsFalse; #define OPTION_SAFE option_checked = rtsTrue; -#define OPTION_UNSAFE checkUnsafe(rtsOptsEnabled); option_checked = rtsTrue; +#define OPTION_UNSAFE checkUnsafe(is_hs_main, rtsOptsEnabled); option_checked = rtsTrue; if (rts_argv[arg][0] != '-') { fflush(stdout); @@ -1162,7 +1176,7 @@ error = rtsTrue; } if (rtsOptsEnabled == RtsOptsSafeOnly && nNodes > (int)getNumberOfProcessors()) { - errorBelch("Using large values for -N is not allowed by default. Link with -rtsopts to allow full control."); + errorRtsOptsDisabled(is_hs_main, "Using large values for -N is not allowed by default. %s"); stg_exit(EXIT_FAILURE); } RtsFlags.ParFlags.nNodes = (nat)nNodes; |