Answer the question
In order to leave comments, you need to log in
How disgusting is this code?
Hello. How disgusting is this code? I have not yet tested it for performance, I just would like to know your opinion.
bool update_uwsgi_config() {
const char *source = fmt::format("/tmp/{}.ini", unid).c_str();
const char *on_restart = "service uwsgi restart";
const char *dest = "/etc/uwsgi/apps-available/www.ini";
const char *on_update = fmt::format("lxc file push {} {} {}", source,contname,dest).c_str();
system(on_update);
system(on_restart);
remove(dest);
return true;
}
Answer the question
In order to leave comments, you need to log in
The main problem.
The fmt::format object will immediately disappear and source will hang.
Will have to write...
fmt::format fmSource("/tmp/{}.ini", unid);
const char *source = fmSource.c_str();
- Not cross-platform (although it is hardly needed here if lxc is used)
- if contname or unid are accepted from the user, then this is a serious vulnerability
- why an extra dependency if formatting is in std::?
- it is better to put constants in the config, it is more convenient to edit them later
Yes, and this is usually written in python / bash, unless of course it is part of a project that is already in C ++
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question