summaryrefslogtreecommitdiff
path: root/clients
diff options
context:
space:
mode:
authorDaniel Stone <daniels@collabora.com>2022-07-12 16:58:12 +0100
committerPekka Paalanen <pq@iki.fi>2022-07-19 14:12:37 +0000
commit965d90cbaaa8f4e3e2b472bb08043a6381978181 (patch)
treec8ad139ffbd4cdae094437cdcabdb94899cb1944 /clients
parent2cdb473690a4414b0bcafbb3878e468fce6e89e2 (diff)
downloadweston-965d90cbaaa8f4e3e2b472bb08043a6381978181.tar.gz
desktop-shell: Use custom_env to launch panel clients
Rather than open-coding our own implementation of parsing a string to construct an envp and an argp, just use custom_env's implementation. Signed-off-by: Daniel Stone <daniels@collabora.com>
Diffstat (limited to 'clients')
-rw-r--r--clients/desktop-shell.c74
1 files changed, 16 insertions, 58 deletions
diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c
index 02c1ae5c..b450a010 100644
--- a/clients/desktop-shell.c
+++ b/clients/desktop-shell.c
@@ -41,22 +41,23 @@
#include <assert.h>
#include <wayland-client.h>
-#include "window.h"
-#include "shared/cairo-util.h"
+
#include <libweston/config-parser.h>
+#include <libweston/zalloc.h>
#include "shared/helpers.h"
#include "shared/xalloc.h"
-#include <libweston/zalloc.h>
+#include "shared/cairo-util.h"
#include "shared/file-util.h"
+#include "shared/process-util.h"
#include "shared/timespec-util.h"
+#include "window.h"
+
#include "weston-desktop-shell-client-protocol.h"
#define DEFAULT_CLOCK_FORMAT CLOCK_FORMAT_MINUTES
#define DEFAULT_SPACING 10
-extern char **environ; /* defined by libc */
-
enum clock_format {
CLOCK_FORMAT_MINUTES,
CLOCK_FORMAT_SECONDS,
@@ -144,8 +145,9 @@ struct panel_launcher {
char *path;
char *displayname;
struct wl_list link;
- struct wl_array envp;
- struct wl_array argv;
+ struct custom_env env;
+ char * const *argp;
+ char * const *envp;
};
struct panel_clock {
@@ -212,7 +214,6 @@ check_desktop_ready(struct window *window)
static void
panel_launcher_activate(struct panel_launcher *widget)
{
- char **argv;
pid_t pid;
pid = fork();
@@ -224,13 +225,11 @@ panel_launcher_activate(struct panel_launcher *widget)
if (pid)
return;
- argv = widget->argv.data;
-
if (setsid() == -1)
exit(EXIT_FAILURE);
- if (execve(argv[0], argv, widget->envp.data) < 0) {
- fprintf(stderr, "execl '%s' failed: %s\n", argv[0],
+ if (execve(widget->argp[0], widget->argp, widget->envp) < 0) {
+ fprintf(stderr, "execl '%s' failed: %s\n", widget->argp[0],
strerror(errno));
exit(1);
}
@@ -576,8 +575,7 @@ panel_configure(void *data,
static void
panel_destroy_launcher(struct panel_launcher *launcher)
{
- wl_array_release(&launcher->argv);
- wl_array_release(&launcher->envp);
+ custom_env_fini(&launcher->env);
free(launcher->path);
free(launcher->displayname);
@@ -683,56 +681,16 @@ static void
panel_add_launcher(struct panel *panel, const char *icon, const char *path, const char *displayname)
{
struct panel_launcher *launcher;
- char *start, *p, *eq, **ps;
- int i, j, k;
launcher = xzalloc(sizeof *launcher);
launcher->icon = load_icon_or_fallback(icon);
launcher->path = xstrdup(path);
launcher->displayname = xstrdup(displayname);
- wl_array_init(&launcher->envp);
- wl_array_init(&launcher->argv);
- for (i = 0; environ[i]; i++) {
- ps = wl_array_add(&launcher->envp, sizeof *ps);
- *ps = environ[i];
- }
- j = 0;
-
- start = launcher->path;
- while (*start) {
- for (p = start, eq = NULL; *p && !isspace(*p); p++)
- if (*p == '=')
- eq = p;
-
- if (eq && j == 0) {
- ps = launcher->envp.data;
- for (k = 0; k < i; k++)
- if (strncmp(ps[k], start, eq - start) == 0) {
- ps[k] = start;
- break;
- }
- if (k == i) {
- ps = wl_array_add(&launcher->envp, sizeof *ps);
- *ps = start;
- i++;
- }
- } else {
- ps = wl_array_add(&launcher->argv, sizeof *ps);
- *ps = start;
- j++;
- }
-
- while (*p && isspace(*p))
- *p++ = '\0';
-
- start = p;
- }
-
- ps = wl_array_add(&launcher->envp, sizeof *ps);
- *ps = NULL;
- ps = wl_array_add(&launcher->argv, sizeof *ps);
- *ps = NULL;
+ custom_env_init_from_environ(&launcher->env);
+ custom_env_add_from_exec_string(&launcher->env, launcher->path);
+ launcher->envp = custom_env_get_envp(&launcher->env);
+ launcher->argp = custom_env_get_argp(&launcher->env);
launcher->panel = panel;
wl_list_insert(panel->launcher_list.prev, &launcher->link);