From 793d69e13d29fedc6b400545def5e61cacba0648 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 15 Jun 2020 16:39:12 +0200 Subject: [PATCH 1/6] version bump --- debian/changelog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/changelog b/debian/changelog index f098a16..6596d44 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,3 @@ -sigstoped (1:0.73-1) unstable; urgency=medium +sigstoped (1:1.0.2-1) unstable; urgency=medium Inital version -- Uvos Mon, 10 Jun 2020 15:00:00 +0100 From a579aa411c71ec52d9672af1f1f94654268d8325 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 15 Jun 2020 18:09:47 +0200 Subject: [PATCH 2/6] remove dpms header --- debian/changelog | 2 +- main.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6596d44..7a7aaee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,3 @@ -sigstoped (1:1.0.2-1) unstable; urgency=medium +sigstoped (1.0.2) unstable; urgency=medium Inital version -- Uvos Mon, 10 Jun 2020 15:00:00 +0100 diff --git a/main.cpp b/main.cpp index 67f82c6..ff8a5f2 100644 --- a/main.cpp +++ b/main.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include From d94633b7b4e479b63566a643c31f33652102a275 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 15 Jun 2020 23:18:29 +0200 Subject: [PATCH 3/6] Fix broken dependancy --- argpopt.h | 2 +- debian/control | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/argpopt.h b/argpopt.h index 8452a31..0e924ad 100644 --- a/argpopt.h +++ b/argpopt.h @@ -25,7 +25,7 @@ struct Config bool ignoreClientMachine = false; }; -const char *argp_program_version = "1.0.1"; +const char *argp_program_version = "1.0.2"; const char *argp_program_bug_address = ""; static char doc[] = "Deamon that stops programms via SIGSTOP when their X11 windows lose focus."; static char args_doc[] = ""; diff --git a/debian/control b/debian/control index 82253fb..50d271f 100755 --- a/debian/control +++ b/debian/control @@ -12,6 +12,6 @@ Package: sigstoped Architecture: any Multi-arch: same Depends: - libx11, + libx11-6, Description: A deamon that stops programms via SIGSTOP when their X11 windows lose focus. From e1253286e40a79e6890d5a149830b05f739d8598 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 15 Jun 2020 23:43:56 +0200 Subject: [PATCH 4/6] Ignore BadWindow errors caused by faulty __NET_ACTIVE_WINDOW events --- xinstance.cpp | 27 ++++++++++++++++++++++++--- xinstance.h | 2 ++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/xinstance.cpp b/xinstance.cpp index c9701e0..836eb64 100644 --- a/xinstance.cpp +++ b/xinstance.cpp @@ -124,6 +124,7 @@ void XInstance::flush() pid_t XInstance::getPid(Window wid) { + defaultHandler = XSetErrorHandler(ignoreErrorHandler); XTextProperty xWidHostNameTextProperty; bool ret; ret = XGetTextProperty(display, wid, &xWidHostNameTextProperty, atoms.wmClientMachine); @@ -132,7 +133,11 @@ pid_t XInstance::getPid(Window wid) char errorString[1024]; XGetErrorText(display, ret, errorString, 1024); debug("XGetWMClientMachine failed! " + std::string(errorString)); - if(!ignoreClientMachine) return -1; + if(!ignoreClientMachine) + { + XSetErrorHandler(defaultHandler); + return -1; + } } char** xWidHostNameStringList = nullptr; int nStrings; @@ -142,13 +147,21 @@ pid_t XInstance::getPid(Window wid) char errorString[1024]; XGetErrorText(display, ret, errorString, 1024); debug("XTextPropertyToStringList failed! " + std::string(errorString)); - if(!ignoreClientMachine) return -1; + if(!ignoreClientMachine) + { + XSetErrorHandler(defaultHandler); + return -1; + } } char hostName[HOST_NAME_MAX+1]={0}; if(gethostname(hostName, HOST_NAME_MAX) != 0) { debug("Can't get host name"); - if(!ignoreClientMachine) return -1; + if(!ignoreClientMachine) + { + XSetErrorHandler(defaultHandler); + return -1; + } } pid_t pid = -1; if(ignoreClientMachine || strcmp(hostName, xWidHostNameStringList[0]) == 0 ) @@ -165,9 +178,17 @@ pid_t XInstance::getPid(Window wid) debug("Window "+std::to_string(wid)+" is a remote window"); } if(xWidHostNameStringList) XFreeStringList(xWidHostNameStringList); + XSetErrorHandler(defaultHandler); return pid; } +int XInstance::ignoreErrorHandler(Display* display, XErrorEvent* xerror) +{ + std::cerr<<"Ignoring: error code"<error_code<<" request code "<request_code<<'\n' + <<"this error most likely occured because of a bug in your WM\n"; + return 0; +} + XInstance::~XInstance() { if(display) XCloseDisplay(display); diff --git a/xinstance.h b/xinstance.h index 5bced7f..dc69403 100644 --- a/xinstance.h +++ b/xinstance.h @@ -34,6 +34,7 @@ class XInstance public: + inline static XErrorHandler defaultHandler; static constexpr unsigned long MAX_BYTES = 1048576; inline static bool ignoreClientMachine = false; @@ -46,6 +47,7 @@ private: unsigned long readProparty(Window wid, Atom atom, unsigned char** prop, int* format); Atom getAtom(const std::string& atomName); + static int ignoreErrorHandler(Display* display, XErrorEvent* xerror); public: From bdcd27eb953bc71ec30b1ff67e769da2c76512a6 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Mon, 15 Jun 2020 23:49:00 +0200 Subject: [PATCH 5/6] version bump --- argpopt.h | 2 +- debian/changelog | 4 ++++ main.cpp | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/argpopt.h b/argpopt.h index 0e924ad..9be6d2c 100644 --- a/argpopt.h +++ b/argpopt.h @@ -25,7 +25,7 @@ struct Config bool ignoreClientMachine = false; }; -const char *argp_program_version = "1.0.2"; +const char *argp_program_version = "1.0.3"; const char *argp_program_bug_address = ""; static char doc[] = "Deamon that stops programms via SIGSTOP when their X11 windows lose focus."; static char args_doc[] = ""; diff --git a/debian/changelog b/debian/changelog index 7a7aaee..80f8af4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,7 @@ +sigstoped (1.0.3) unstable; urgency=medium + Ignore BadWindow errors caused by faulty __NET_ACTIVE_WINDOW events + -- Uvos Mon, 15 Jun 2020 23:47:00 +0100 + sigstoped (1.0.2) unstable; urgency=medium Inital version -- Uvos Mon, 10 Jun 2020 15:00:00 +0100 diff --git a/main.cpp b/main.cpp index ff8a5f2..a14b2ef 100644 --- a/main.cpp +++ b/main.cpp @@ -159,7 +159,7 @@ int main(int argc, char* argv[]) std::string confDir = getConfdir(); if(confDir.size() == 0) return 1; - if(!createPidFile(confDir+"pidfile")); + if(!createPidFile(confDir+"pidfile")) return 1; std::vector applicationNames = getApplicationlist(confDir+"blacklist"); From 8c69a02e5d4c0624e7c4c4d45441e469ae999c21 Mon Sep 17 00:00:00 2001 From: Carl Klemm Date: Tue, 16 Jun 2020 09:54:22 +0200 Subject: [PATCH 6/6] Fix memory leak in XInstance::getTopLevelWindows --- argpopt.h | 2 +- debian/changelog | 4 ++++ xinstance.cpp | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/argpopt.h b/argpopt.h index 9be6d2c..4ab2569 100644 --- a/argpopt.h +++ b/argpopt.h @@ -25,7 +25,7 @@ struct Config bool ignoreClientMachine = false; }; -const char *argp_program_version = "1.0.3"; +const char *argp_program_version = "1.0.4"; const char *argp_program_bug_address = ""; static char doc[] = "Deamon that stops programms via SIGSTOP when their X11 windows lose focus."; static char args_doc[] = ""; diff --git a/debian/changelog b/debian/changelog index 80f8af4..c9fa8bc 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,7 @@ +sigstoped (1.0.4) unstable; urgency=medium + Fix memory leak in XInstance::getTopLevelWindows() + -- Uvos Mon, 16 Jun 2020 09:47:00 +0100 + sigstoped (1.0.3) unstable; urgency=medium Ignore BadWindow errors caused by faulty __NET_ACTIVE_WINDOW events -- Uvos Mon, 15 Jun 2020 23:47:00 +0100 diff --git a/xinstance.cpp b/xinstance.cpp index 836eb64..c785a97 100644 --- a/xinstance.cpp +++ b/xinstance.cpp @@ -107,13 +107,13 @@ std::vector XInstance::getTopLevelWindows() Window* windows = nullptr; unsigned int nwindows; XQueryTree(display, RootWindow(display, screen), &root_return, &parent_return, &windows, &nwindows); - std::vector out; out.reserve(nwindows); - for(unsigned int i; i < nwindows; ++i) + for(unsigned int i = 0; i < nwindows; ++i) { out.push_back(windows[i]); } + if(windows != nullptr) XFree(windows); return out; }