diff options
author | Dominique Leuenberger <dimstar@opensuse.org> | 2020-06-02 14:55:03 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-02 14:55:03 +0200 |
commit | dde4cdb5af1d65d0610f1860c5289289685bb62f (patch) | |
tree | f055a871584c0d9ce793c584d5e2c18788f4955d | |
parent | de6c40741562406f0ed2dbd490f4c5c23728531f (diff) | |
parent | 6a3df54f90444d1819d9bd83404ab7ce9e44dc34 (diff) | |
download | libproxy-git-dde4cdb5af1d65d0610f1860c5289289685bb62f.tar.gz |
Merge pull request #117 from smcv/gsettings-wait-for-initial
Fix race conditions in GSettings backend
-rw-r--r-- | libproxy/modules/config_gnome3.cpp | 16 | ||||
-rw-r--r-- | libproxy/modules/pxgsettings.cpp | 3 |
2 files changed, 14 insertions, 5 deletions
diff --git a/libproxy/modules/config_gnome3.cpp b/libproxy/modules/config_gnome3.cpp index 34fead5..6a5d50b 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() { @@ -190,7 +191,7 @@ public: FD_ZERO(&rfds); FD_SET(fileno(this->read), &rfds); - if (select(fileno(this->read)+1, &rfds, NULL, NULL, &timeout) > 0) + while (select(fileno(this->read)+1, &rfds, NULL, NULL, &timeout) > 0) this->read_data(); // Mode is wpad:// or pac+http://... @@ -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 |