diff options
author | Simon McVittie <smcv@debian.org> | 2020-05-01 10:35:47 +0100 |
---|---|---|
committer | Simon McVittie <smcv@debian.org> | 2020-05-01 11:13:24 +0100 |
commit | 16f690f89c317764bc8b911bcf374926ccce738c (patch) | |
tree | d39da6f8eba47f4c19e849e876e77928840e6c11 | |
parent | 68776320108215228552fe93f5b1a0b828a656b4 (diff) | |
download | libproxy-git-16f690f89c317764bc8b911bcf374926ccce738c.tar.gz |
gsettings: Always read at least the initial values of all keys
Previously, the gsettings (gnome3) module would wait until it had read
at least one key/value pair for each GSettings schema requested on the
command line. However, GSettings schemas often contain more than one
key. With a relatively elaborate proxy configuration, we don't
necessarily read all of them in one read() from the pipe, resulting in
the full configuration not being read until later - but for proxy(1),
"later" is too late, because it exits after the first query.
To resolve this, add a way for pxgsettings to signal that it has
written all the initial values (a blank line), and wait for that.
Fixes: #116
Signed-off-by: Simon McVittie <smcv@debian.org>
-rw-r--r-- | libproxy/modules/config_gnome3.cpp | 14 | ||||
-rw-r--r-- | libproxy/modules/pxgsettings.cpp | 3 |
2 files changed, 13 insertions, 4 deletions
diff --git a/libproxy/modules/config_gnome3.cpp b/libproxy/modules/config_gnome3.cpp index 34fead5..e56146d 100644 --- a/libproxy/modules/config_gnome3.cpp +++ b/libproxy/modules/config_gnome3.cpp @@ -127,7 +127,7 @@ static inline uint16_t get_port(const string &port) class gnome_config_extension : public config_extension { public: - gnome_config_extension() { + gnome_config_extension() : had_initial_values(false) { // Build the command int count; struct stat st; @@ -147,9 +147,6 @@ public: if (popen2(cmd.c_str(), &this->read, &this->write, &this->pid) != 0) throw runtime_error("Unable to run gconf helper!"); - // Read in our initial data - this->read_data(count); - // Set the read pipe to non-blocking if (fcntl(fileno(this->read), F_SETFL, O_NONBLOCK) == -1) { fclose(this->read); @@ -157,6 +154,10 @@ public: kill(this->pid, SIGTERM); throw runtime_error("Unable to set pipe to non-blocking!"); } + + // Read in our initial data + while (!this->had_initial_values) + this->read_data(); } ~gnome_config_extension() { @@ -257,6 +258,7 @@ private: FILE* write; pid_t pid; map<string, string> data; + bool had_initial_values; bool read_data(int num=-1) { if (num == 0) return true; @@ -265,6 +267,10 @@ private: for (char l[BUFFERSIZE] ; num != 0 && fgets(l, BUFFERSIZE, this->read) != NULL ; ) { string line = l; line = line.substr(0, line.rfind('\n')); + if (line == "") { + this->had_initial_values = true; + continue; + } string key = line.substr(0, line.find('\t')); string val = line.substr(line.find('\t')+1); this->data[key] = val; diff --git a/libproxy/modules/pxgsettings.cpp b/libproxy/modules/pxgsettings.cpp index 0db5a6a..2e693ad 100644 --- a/libproxy/modules/pxgsettings.cpp +++ b/libproxy/modules/pxgsettings.cpp @@ -163,6 +163,9 @@ int main(int argc, char **argv) { g_strfreev(keys); } + // A blank line indicates the end of the initial values + printf("\n"); + g_main_loop_run(loop); // Cleanup |