Monday, 5 February 2018

linux - C++ flag management

I have a design question about flag management.






CONTEXT



The system includes some shell script and then a C++ binary. Currently, the entry point of the system is the shell script, and then all flags are passed into the main function of the C++ binary and accessed via gflag mechanism.



This isn't super nice because the c++ binary has many submodules. To add a new flag, there are too much code change needed to pass the flag all the way down to the submodule that may be very deep in the pipe.




Therefore, I'm looking for a better way to manage flags.




Some more details:




  • Let's assume the num of flags is about 100 ~ 200.

  • On one machine, there can be multiple instances of this system running simultaneously. Each instance may be invoked with different flag values.

  • It's safe to assume each instance is in separate processes.

  • the shell part may be replaced by python implementation later.







SOLUTION CANDIDATES



I've got some suggestions, and want to discuss in this forum for any other possible ways and also evaluate pros and cons of the candidates.



A. environment variables. to export environment variables in the shell scripts. Then in the submodules, they can somehow access the corresponding env var that are relevant. (most likely through getenv())




B. config file. write flags and values to a file on disk, then do a file read in the submodules.






B is not preferred since it involves a file I/O. Performance is one key thing of the C++ system. So now I'm considering A. Is there other concern for env var? any performance concern?



The execution scenario would be multiple instances of the service running, but afaik env var are independent from each other, right?



Thanks for any thought and suggestion.

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...