Skip to content
Browse files

Send notification only once per DISPLAY.

  • Loading branch information...
1 parent 5fd7904 commit a4a44cf4621df824981d781d865c14919e5d7eb5 @mgorny committed Aug 19, 2011
Showing with 39 additions and 2 deletions.
  1. +1 −1 configure.ac
  2. +38 −1 sw-notify-send.c
View
2 configure.ac
@@ -7,7 +7,7 @@ AC_PROG_CC_C89
AC_USE_SYSTEM_EXTENSIONS
AC_CHECK_FUNCS([chroot])
-AC_CHECK_FUNCS([setresuid],,
+AC_CHECK_FUNCS([setresuid strdup],,
[AC_MSG_ERROR([One of required system library functions was not found!])])
AC_CHECK_HEADERS([sysexits.h])
AC_CHECK_LIB([proc], [readproc],,
View
39 sw-notify-send.c
@@ -86,6 +86,24 @@ const char* getroot(int pid) {
return NULL;
}
+struct used_bus {
+ char *display;
+
+ struct used_bus *next;
+};
+
+struct used_bus *used_buses = NULL;
+
+void free_used_buses(void) {
+ struct used_bus *ub, *next_ub;
+
+ for (ub = used_buses; ub; ub = next_ub) {
+ next_ub = ub->next;
+ free(ub->display);
+ free(ub);
+ }
+}
+
#define FINDENV(p, key) _findenv(p, key "=")
#define CANFAIL(expr) if (expr) perror(#expr " failed (ignoring)")
#define CANTFAIL(expr) if (expr) { perror(#expr " failed (aborting)"); exit(1); }
@@ -95,6 +113,12 @@ int send_notify(char* const display, char* const xauth,
uid_t uid, const char* const root, NotifySession s, Notification n) {
int ret = 0;
uid_t old_ruid, old_euid, old_suid;
+ struct used_bus *ub;
+
+ for (ub = used_buses; ub; ub = ub->next) {
+ if (!strcmp(ub->display, display))
+ return EX_OK;
+ }
CANTFAIL(getresuid(&old_ruid, &old_euid, &old_suid));
@@ -108,8 +132,19 @@ int send_notify(char* const display, char* const xauth,
CANTFAIL(putenv(xauth));
notify_session_disconnect(s); /* ensure to get new connection */
- if (!notification_send(n, s))
+ if (!notification_send(n, s)) {
+ ub = malloc(sizeof(*ub));
+ if (ub) {
+ ub->display = strdup(display);
+ if (!ub->display)
+ free(ub);
+ else {
+ ub->next = used_buses;
+ used_buses = ub;
+ }
+ }
ret = 1;
+ }
CANTFAIL(setresuid(old_ruid, old_euid, old_suid));
#ifdef HAVE_CHROOT
@@ -173,6 +208,8 @@ int main(int argc, char* argv[]) {
}
}
+ free_used_buses();
+
notify_session_free(s);
closeproc(proc);
notification_free(n);

0 comments on commit a4a44cf

Please sign in to comment.
Something went wrong with that request. Please try again.