Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Send notification only once per DISPLAY.

  • Loading branch information...
commit a4a44cf4621df824981d781d865c14919e5d7eb5 1 parent 5fd7904
Michał Górny authored

Showing 2 changed files with 39 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 1  configure.ac
  2. +38 1 sw-notify-send.c
2  configure.ac
@@ -7,7 +7,7 @@ AC_PROG_CC_C89
7 7 AC_USE_SYSTEM_EXTENSIONS
8 8
9 9 AC_CHECK_FUNCS([chroot])
10   -AC_CHECK_FUNCS([setresuid],,
  10 +AC_CHECK_FUNCS([setresuid strdup],,
11 11 [AC_MSG_ERROR([One of required system library functions was not found!])])
12 12 AC_CHECK_HEADERS([sysexits.h])
13 13 AC_CHECK_LIB([proc], [readproc],,
39 sw-notify-send.c
@@ -86,6 +86,24 @@ const char* getroot(int pid) {
86 86 return NULL;
87 87 }
88 88
  89 +struct used_bus {
  90 + char *display;
  91 +
  92 + struct used_bus *next;
  93 +};
  94 +
  95 +struct used_bus *used_buses = NULL;
  96 +
  97 +void free_used_buses(void) {
  98 + struct used_bus *ub, *next_ub;
  99 +
  100 + for (ub = used_buses; ub; ub = next_ub) {
  101 + next_ub = ub->next;
  102 + free(ub->display);
  103 + free(ub);
  104 + }
  105 +}
  106 +
89 107 #define FINDENV(p, key) _findenv(p, key "=")
90 108 #define CANFAIL(expr) if (expr) perror(#expr " failed (ignoring)")
91 109 #define CANTFAIL(expr) if (expr) { perror(#expr " failed (aborting)"); exit(1); }
@@ -95,6 +113,12 @@ int send_notify(char* const display, char* const xauth,
95 113 uid_t uid, const char* const root, NotifySession s, Notification n) {
96 114 int ret = 0;
97 115 uid_t old_ruid, old_euid, old_suid;
  116 + struct used_bus *ub;
  117 +
  118 + for (ub = used_buses; ub; ub = ub->next) {
  119 + if (!strcmp(ub->display, display))
  120 + return EX_OK;
  121 + }
98 122
99 123 CANTFAIL(getresuid(&old_ruid, &old_euid, &old_suid));
100 124
@@ -108,8 +132,19 @@ int send_notify(char* const display, char* const xauth,
108 132 CANTFAIL(putenv(xauth));
109 133
110 134 notify_session_disconnect(s); /* ensure to get new connection */
111   - if (!notification_send(n, s))
  135 + if (!notification_send(n, s)) {
  136 + ub = malloc(sizeof(*ub));
  137 + if (ub) {
  138 + ub->display = strdup(display);
  139 + if (!ub->display)
  140 + free(ub);
  141 + else {
  142 + ub->next = used_buses;
  143 + used_buses = ub;
  144 + }
  145 + }
112 146 ret = 1;
  147 + }
113 148
114 149 CANTFAIL(setresuid(old_ruid, old_euid, old_suid));
115 150 #ifdef HAVE_CHROOT
@@ -173,6 +208,8 @@ int main(int argc, char* argv[]) {
173 208 }
174 209 }
175 210
  211 + free_used_buses();
  212 +
176 213 notify_session_free(s);
177 214 closeproc(proc);
178 215 notification_free(n);

0 comments on commit a4a44cf

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