13 #define INCLUDE_KDENOTIFY 23 #define UNUSED(x) (void)(x) 26 # define MIN(a,b) (((a) < (b)) ? (a) : (b)) 29 int check(
const struct dirent *e);
32 static char *default_app =
"kde";
34 int check(
const struct dirent *e)
36 if(strcmp(e->d_name,
".") == 0 || strcmp(e->d_name,
"..") == 0)
38 if(e->d_type == DT_DIR)
45 const char *machine_id_file =
"/var/lib/dbus/machine-id";
46 const char *search_string =
"DBUS_SESSION_BUS_PID=";
47 const int search_string_len =
str_len(search_string);
53 char *machine_id = NULL;
55 FILE *fp = fopen(machine_id_file,
"r");
56 getline(&machine_id, &n, fp);
59 if(machine_id[
line_len(machine_id)] ==
'\n')
60 machine_id[
line_len(machine_id)] =
'\0';
63 struct dirent **dirs = NULL;
66 if((j = scandir(
"/home/", &dirs,
check, NULL)) != -1)
72 asprintf(&file,
"/home/%s/.dbus/session-bus/%s-0", dirs[k]->d_name, machine_id);
81 fp = fopen(file,
"r");
84 while((s = getline(&line, &n, fp)) != -1)
87 if(strncmp(line, search_string, search_string_len) == 0)
91 char *proc_dir = NULL;
93 asprintf(&proc_dir,
"/proc/%d/", pid);
103 if(stat(proc_dir, &st) != 0)
130 #ifdef INCLUDE_KDENOTIFY 131 GError *
error = NULL;
135 if(text == NULL || title == NULL)
138 unsigned int timeout = 5000;
146 debug(
_(
"change effective user id to %d for dbus call"), dbus_id);
151 GDBusProxy *proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SESSION, G_DBUS_PROXY_FLAGS_NONE, NULL,
"org.freedesktop.Notifications",
"/org/freedesktop/Notifications",
"org.freedesktop.Notifications", NULL, &
error);
154 error(
_(
"Error creating proxy: %s"),
error->message);
169 GVariant *data = g_variant_new(
"(susssasa{sv}i)", app, 0,
"", title, text, NULL, NULL, timeout);
170 GVariant *res = g_dbus_proxy_call_sync(proxy,
"org.freedesktop.Notifications.Notify", data, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &
error);
173 error(
_(
"Error issuing call: %s"),
error->message);
178 if(getuid() != geteuid())
180 debug(
_(
"change effective user id back to root"));
#define PATH_R
request read permission
uid_t find_dbus_user(void)
#define str_len(s)
Shorthand for counting '\0' terminating strings. See _len for more info.
#define check_file_exists(file, mode)
#define check_dir_exists(dir, mode)
#define UNUSED(x)
Used to indicate that a function does not use a certain parameter.
int check(const struct dirent *e)
#define line_len(s)
Shorthand for counting '\n' terminating strings. See _len for more info.
unsigned long long char_to_int(const char *s, int i, uint8_t base)
int kdenotify(char *app, char *title, char *text)