@ -41,22 +41,23 @@
# include <assert.h>
# include <assert.h>
# include <wayland-client.h>
# include <wayland-client.h>
# include "window.h"
# include "shared/cairo-util.h"
# include <libweston/config-parser.h>
# include <libweston/config-parser.h>
# include <libweston/zalloc.h>
# include "shared/helpers.h"
# include "shared/helpers.h"
# include "shared/xalloc.h"
# include "shared/xalloc.h"
# include <libweston/zalloc.h>
# include "shared/cairo-util.h"
# include "shared/file-util.h"
# include "shared/file-util.h"
# include "shared/process-util.h"
# include "shared/timespec-util.h"
# include "shared/timespec-util.h"
# include "window.h"
# include "weston-desktop-shell-client-protocol.h"
# include "weston-desktop-shell-client-protocol.h"
# define DEFAULT_CLOCK_FORMAT CLOCK_FORMAT_MINUTES
# define DEFAULT_CLOCK_FORMAT CLOCK_FORMAT_MINUTES
# define DEFAULT_SPACING 10
# define DEFAULT_SPACING 10
extern char * * environ ; /* defined by libc */
enum clock_format {
enum clock_format {
CLOCK_FORMAT_MINUTES ,
CLOCK_FORMAT_MINUTES ,
CLOCK_FORMAT_SECONDS ,
CLOCK_FORMAT_SECONDS ,
@ -144,8 +145,9 @@ struct panel_launcher {
char * path ;
char * path ;
char * displayname ;
char * displayname ;
struct wl_list link ;
struct wl_list link ;
struct wl_array envp ;
struct custom_env env ;
struct wl_array argv ;
char * const * argp ;
char * const * envp ;
} ;
} ;
struct panel_clock {
struct panel_clock {
@ -212,7 +214,6 @@ check_desktop_ready(struct window *window)
static void
static void
panel_launcher_activate ( struct panel_launcher * widget )
panel_launcher_activate ( struct panel_launcher * widget )
{
{
char * * argv ;
pid_t pid ;
pid_t pid ;
pid = fork ( ) ;
pid = fork ( ) ;
@ -224,13 +225,11 @@ panel_launcher_activate(struct panel_launcher *widget)
if ( pid )
if ( pid )
return ;
return ;
argv = widget - > argv . data ;
if ( setsid ( ) = = - 1 )
if ( setsid ( ) = = - 1 )
exit ( EXIT_FAILURE ) ;
exit ( EXIT_FAILURE ) ;
if ( execve ( argv [ 0 ] , argv , widget - > envp . data ) < 0 ) {
if ( execve ( widget - > argp [ 0 ] , widget - > argp , widget - > envp ) < 0 ) {
fprintf ( stderr , " execl '%s' failed: %s \n " , argv [ 0 ] ,
fprintf ( stderr , " execl '%s' failed: %s \n " , widget - > argp [ 0 ] ,
strerror ( errno ) ) ;
strerror ( errno ) ) ;
exit ( 1 ) ;
exit ( 1 ) ;
}
}
@ -576,8 +575,7 @@ panel_configure(void *data,
static void
static void
panel_destroy_launcher ( struct panel_launcher * launcher )
panel_destroy_launcher ( struct panel_launcher * launcher )
{
{
wl_array_release ( & launcher - > argv ) ;
custom_env_fini ( & launcher - > env ) ;
wl_array_release ( & launcher - > envp ) ;
free ( launcher - > path ) ;
free ( launcher - > path ) ;
free ( launcher - > displayname ) ;
free ( launcher - > displayname ) ;
@ -683,56 +681,16 @@ static void
panel_add_launcher ( struct panel * panel , const char * icon , const char * path , const char * displayname )
panel_add_launcher ( struct panel * panel , const char * icon , const char * path , const char * displayname )
{
{
struct panel_launcher * launcher ;
struct panel_launcher * launcher ;
char * start , * p , * eq , * * ps ;
int i , j , k ;
launcher = xzalloc ( sizeof * launcher ) ;
launcher = xzalloc ( sizeof * launcher ) ;
launcher - > icon = load_icon_or_fallback ( icon ) ;
launcher - > icon = load_icon_or_fallback ( icon ) ;
launcher - > path = xstrdup ( path ) ;
launcher - > path = xstrdup ( path ) ;
launcher - > displayname = xstrdup ( displayname ) ;
launcher - > displayname = xstrdup ( displayname ) ;
wl_array_init ( & launcher - > envp ) ;
custom_env_init_from_environ ( & launcher - > env ) ;
wl_array_init ( & launcher - > argv ) ;
custom_env_add_from_exec_string ( & launcher - > env , launcher - > path ) ;
for ( i = 0 ; environ [ i ] ; i + + ) {
launcher - > envp = custom_env_get_envp ( & launcher - > env ) ;
ps = wl_array_add ( & launcher - > envp , sizeof * ps ) ;
launcher - > argp = custom_env_get_argp ( & launcher - > env ) ;
* 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 ;
launcher - > panel = panel ;
launcher - > panel = panel ;
wl_list_insert ( panel - > launcher_list . prev , & launcher - > link ) ;
wl_list_insert ( panel - > launcher_list . prev , & launcher - > link ) ;