You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I want is:
when the daemon running, I modify the flagfile or some env flags, and send the
daemon SIGUSR1 to reload the flagfile.
the Code:
extern GFLAGS_DLL_DECL void ReloadNonCommandFlags();
static uint32 __ReloadNonCommandFlagsInternal(int* argc, char*** argv,
bool remove_flags, bool do_report) {
SetArgv(*argc, const_cast<const char**>(*argv)); // save it for later
FlagRegistry* const registry = FlagRegistry::GlobalRegistry();
CommandLineFlagParser parser(registry);
// When we parse the commandline flags, we'll handle --flagfile,
// --tryfromenv, etc. as we see them (since flag-evaluation order
// may be important). But sometimes apps set FLAGS_tryfromenv/etc.
// manually before calling ParseCommandLineFlags. We want to evaluate
// those too, as if they were the first flags on the commandline.
registry->Lock();
parser.ProcessFlagfileLocked(FLAGS_flagfile, SET_FLAGS_VALUE);
// Last arg here indicates whether flag-not-found is a fatal error or not
parser.ProcessFromenvLocked(FLAGS_fromenv, SET_FLAGS_VALUE, true);
parser.ProcessFromenvLocked(FLAGS_tryfromenv, SET_FLAGS_VALUE, false);
registry->Unlock();
if (do_report)
HandleCommandLineHelpFlags(); // may cause us to exit on --help, etc.
// See if any of the unset flags fail their validation checks
parser.ValidateAllFlags();
if (parser.ReportErrors()) // may cause us to exit on illegal flags
gflags_exitfunc(1);
return 0;
}
void ReloadNonCommandFlags()
{
// We make a copy of argc and argv to pass in
const vector<string>& argvs = GetArgvs();
int tmp_argc = static_cast<int>(argvs.size());
char** tmp_argv = new char* [tmp_argc + 1];
for (int i = 0; i < tmp_argc; ++i)
tmp_argv[i] = strdup(argvs[i].c_str()); // TODO(csilvers): don't dup
__ReloadNonCommandFlagsInternal(&tmp_argc, &tmp_argv, false, true);
for (int i = 0; i < tmp_argc; ++i)
free(tmp_argv[i]);
delete[] tmp_argv;
}
Original issue reported on code.google.com by [email protected] on 25 Nov 2014 at 2:19
The text was updated successfully, but these errors were encountered:
Interesting suggestion. Any reason for duplicating the
ParseCommandLineFlagsInternal function? Why not just call the existing function
from ReloadNonCommandLineFlags? Actually, this function is doing the exact same
as ReparseCommandLineNonHelpFlags, except that help flags are treated as well.
However, I cannot see the why you would want a daemon to read a help flag from
a flag file or an environment variable to print a help screen and then exit...
Please elaborate the use case a bit more and why what you need cannot be
achieved using ReparseCommandLineNonHelpFlags.
Original issue reported on code.google.com by
[email protected]
on 25 Nov 2014 at 2:19The text was updated successfully, but these errors were encountered: