dwlb

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 0872a9cbe4a8110972a4bb217bab319be49d3a01
parent 43747280ec1870d54a3be3212136251fcfa83a6c
Author: Janne Veteläinen <janne.vetelainen@elisanet.fi>
Date:   Sat, 13 Apr 2024 09:10:54 +0300

Get rid of readlink /proc/pid/self

Diffstat:
Mdwlb.c | 19++++++-------------
Mdwlbtray.c | 35+++--------------------------------
Mdwlbtray.h | 2--
3 files changed, 9 insertions(+), 47 deletions(-)

diff --git a/dwlb.c b/dwlb.c @@ -1963,18 +1963,11 @@ main(int argc, char **argv) /* Start tray program */ char tray_exe_path[PATH_MAX]; - char progname[PATH_MAX]; + char traypath_maybe[PATH_MAX]; char traybg_arg[64]; char height_arg[64]; char traymon_arg[64]; - ssize_t len = readlink("/proc/self/exe", progname, sizeof(progname)); - - if (len != -1) - progname[len] = '\0'; - else - exit(-1); - pixman_color_t *traybg_clr = &inactive_bg_color; snprintf(traybg_arg, sizeof(traybg_arg), @@ -1983,12 +1976,12 @@ main(int argc, char **argv) (int8_t)traybg_clr->green, (int8_t)traybg_clr->blue); - if (strncmp(progname, BUILD_DIR, strlen(BUILD_DIR)) == 0) { - strcpy(tray_exe_path, BUILD_DIR); - strcat(tray_exe_path, "dwlbtray"); - } else { + + snprintf(traypath_maybe, sizeof(traypath_maybe), "%stray", argv[0]); + if (access(traypath_maybe, X_OK) == 0) + strcpy(tray_exe_path, traypath_maybe); + else strcpy(tray_exe_path, "dwlbtray"); - } snprintf(height_arg, sizeof(height_arg), "--height=%u", height); snprintf(traymon_arg, sizeof(traymon_arg), "--traymon=%s", traymon); diff --git a/dwlbtray.c b/dwlbtray.c @@ -10,9 +10,6 @@ #include "dwlbtray.h" -const char *RESOURCE_PATH; - - static void activate(GtkApplication* app, StatusNotifierHost *snhost) { @@ -81,36 +78,9 @@ activate(GtkApplication* app, StatusNotifierHost *snhost) int main(int argc, char *argv[]) { - char progname[PATH_MAX]; - ssize_t len = readlink("/proc/self/exe", progname, sizeof(progname)); - - if (len != -1) { - progname[len] = '\0'; - } - else { - fprintf(stderr, "bad progname, exiting\n"); - exit(-1); - } - - if (strncmp(progname, BUILD_DIR, strlen(BUILD_DIR)) == 0) { - RESOURCE_PATH = g_strdup_printf("%s%s", BUILD_DIR, "Resources"); - } else { - const char * const *datadirs = g_get_system_data_dirs(); - int i; - - for (i = 0; datadirs[i]; i++) { - char *test = g_build_filename(datadirs[i], "dwlb", "boxbg.css", NULL); - if (g_file_test(test, G_FILE_TEST_EXISTS)) - RESOURCE_PATH = g_path_get_dirname(test); - } - } - - if (!RESOURCE_PATH) - RESOURCE_PATH = "/usr/local/dwlb"; - StatusNotifierHost *snhost = start_statusnotifierhost(); - const char *bgcolor; + char *bgcolor = NULL; int i = 1; for (; i < argc; i++) { char **strings = g_strsplit(argv[i], "=", 0); @@ -125,6 +95,7 @@ main(int argc, char *argv[]) } snhost->cssdata = g_strdup_printf("window{background-color:%s;}", bgcolor); + g_free(bgcolor); GtkApplication *app = gtk_application_new("com.vetu104.Gtktray", G_APPLICATION_DEFAULT_FLAGS); @@ -136,7 +107,7 @@ main(int argc, char *argv[]) * g_unix_signal_add(SIGTERM, (GSourceFunc)terminate_app, snhost); */ - char *argv_inner[] = { progname, NULL }; + char *argv_inner[] = { argv[0], NULL }; int status = g_application_run(G_APPLICATION(app), 1, argv_inner); g_object_unref(app); diff --git a/dwlbtray.h b/dwlbtray.h @@ -5,8 +5,6 @@ #include <gio/gio.h> #include <gtk/gtk.h> -extern const char *RESOURCE_PATH; - typedef struct { uint32_t id; GDBusProxy* proxy;