@ -39,7 +39,7 @@
static int
static int
weston_xserver_handle_event ( int listen_fd , uint32_t mask , void * data )
weston_xserver_handle_event ( int listen_fd , uint32_t mask , void * data )
{
{
struct weston_xserver * m xs = data ;
struct weston_xserver * w xs = data ;
char display [ 8 ] , s [ 8 ] ;
char display [ 8 ] , s [ 8 ] ;
int sv [ 2 ] , client_fd ;
int sv [ 2 ] , client_fd ;
@ -48,8 +48,8 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
return 1 ;
return 1 ;
}
}
m xs- > process . pid = fork ( ) ;
w xs- > process . pid = fork ( ) ;
switch ( m xs- > process . pid ) {
switch ( w xs- > process . pid ) {
case 0 :
case 0 :
/* SOCK_CLOEXEC closes both ends, so we need to unset
/* SOCK_CLOEXEC closes both ends, so we need to unset
* the flag on the client fd . */
* the flag on the client fd . */
@ -60,7 +60,7 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
snprintf ( s , sizeof s , " %d " , client_fd ) ;
snprintf ( s , sizeof s , " %d " , client_fd ) ;
setenv ( " WAYLAND_SOCKET " , s , 1 ) ;
setenv ( " WAYLAND_SOCKET " , s , 1 ) ;
snprintf ( display , sizeof display , " :%d " , m xs- > display ) ;
snprintf ( display , sizeof display , " :%d " , w xs- > display ) ;
if ( execl ( XSERVER_PATH ,
if ( execl ( XSERVER_PATH ,
XSERVER_PATH ,
XSERVER_PATH ,
@ -75,15 +75,15 @@ weston_xserver_handle_event(int listen_fd, uint32_t mask, void *data)
exit ( - 1 ) ;
exit ( - 1 ) ;
default :
default :
weston_log ( " forked X server, pid %d \n " , m xs- > process . pid ) ;
weston_log ( " forked X server, pid %d \n " , w xs- > process . pid ) ;
close ( sv [ 1 ] ) ;
close ( sv [ 1 ] ) ;
m xs- > client = wl_client_create ( m xs- > wl_display , sv [ 0 ] ) ;
w xs- > client = wl_client_create ( w xs- > wl_display , sv [ 0 ] ) ;
weston_watch_process ( & m xs- > process ) ;
weston_watch_process ( & w xs- > process ) ;
wl_event_source_remove ( m xs- > abstract_source ) ;
wl_event_source_remove ( w xs- > abstract_source ) ;
wl_event_source_remove ( m xs- > unix_source ) ;
wl_event_source_remove ( w xs- > unix_source ) ;
break ;
break ;
case - 1 :
case - 1 :
@ -117,33 +117,33 @@ weston_xserver_shutdown(struct weston_xserver *wxs)
static void
static void
weston_xserver_cleanup ( struct weston_process * process , int status )
weston_xserver_cleanup ( struct weston_process * process , int status )
{
{
struct weston_xserver * m xs =
struct weston_xserver * w xs =
container_of ( process , struct weston_xserver , process ) ;
container_of ( process , struct weston_xserver , process ) ;
m xs- > process . pid = 0 ;
w xs- > process . pid = 0 ;
m xs- > client = NULL ;
w xs- > client = NULL ;
m xs- > resource = NULL ;
w xs- > resource = NULL ;
m xs- > abstract_source =
w xs- > abstract_source =
wl_event_loop_add_fd ( m xs- > loop , m xs- > abstract_fd ,
wl_event_loop_add_fd ( w xs- > loop , w xs- > abstract_fd ,
WL_EVENT_READABLE ,
WL_EVENT_READABLE ,
weston_xserver_handle_event , m xs) ;
weston_xserver_handle_event , w xs) ;
m xs- > unix_source =
w xs- > unix_source =
wl_event_loop_add_fd ( m xs- > loop , m xs- > unix_fd ,
wl_event_loop_add_fd ( w xs- > loop , w xs- > unix_fd ,
WL_EVENT_READABLE ,
WL_EVENT_READABLE ,
weston_xserver_handle_event , m xs) ;
weston_xserver_handle_event , w xs) ;
if ( m xs- > wm ) {
if ( w xs- > wm ) {
weston_log ( " xserver exited, code %d \n " , status ) ;
weston_log ( " xserver exited, code %d \n " , status ) ;
weston_wm_destroy ( m xs- > wm ) ;
weston_wm_destroy ( w xs- > wm ) ;
m xs- > wm = NULL ;
w xs- > wm = NULL ;
} else {
} else {
/* If the X server crashes before it binds to the
/* If the X server crashes before it binds to the
* xserver interface , shut down and don ' t try
* xserver interface , shut down and don ' t try
* again . */
* again . */
weston_log ( " xserver crashing too fast: %d \n " , status ) ;
weston_log ( " xserver crashing too fast: %d \n " , status ) ;
weston_xserver_shutdown ( m xs) ;
weston_xserver_shutdown ( w xs) ;
}
}
}
}
@ -315,64 +315,64 @@ WL_EXPORT int
module_init ( struct weston_compositor * compositor )
module_init ( struct weston_compositor * compositor )
{
{
struct wl_display * display = compositor - > wl_display ;
struct wl_display * display = compositor - > wl_display ;
struct weston_xserver * m xs;
struct weston_xserver * w xs;
char lockfile [ 256 ] , display_name [ 8 ] ;
char lockfile [ 256 ] , display_name [ 8 ] ;
m xs = malloc ( sizeof * m xs) ;
w xs = malloc ( sizeof * w xs) ;
memset ( m xs, 0 , sizeof * m xs) ;
memset ( w xs, 0 , sizeof * w xs) ;
m xs- > process . cleanup = weston_xserver_cleanup ;
w xs- > process . cleanup = weston_xserver_cleanup ;
m xs- > wl_display = display ;
w xs- > wl_display = display ;
m xs- > compositor = compositor ;
w xs- > compositor = compositor ;
m xs- > display = 0 ;
w xs- > display = 0 ;
retry :
retry :
if ( create_lockfile ( m xs- > display , lockfile , sizeof lockfile ) < 0 ) {
if ( create_lockfile ( w xs- > display , lockfile , sizeof lockfile ) < 0 ) {
if ( errno = = EAGAIN ) {
if ( errno = = EAGAIN ) {
goto retry ;
goto retry ;
} else if ( errno = = EEXIST ) {
} else if ( errno = = EEXIST ) {
m xs- > display + + ;
w xs- > display + + ;
goto retry ;
goto retry ;
} else {
} else {
free ( m xs) ;
free ( w xs) ;
return - 1 ;
return - 1 ;
}
}
}
}
m xs- > abstract_fd = bind_to_abstract_socket ( m xs- > display ) ;
w xs- > abstract_fd = bind_to_abstract_socket ( w xs- > display ) ;
if ( m xs- > abstract_fd < 0 & & errno = = EADDRINUSE ) {
if ( w xs- > abstract_fd < 0 & & errno = = EADDRINUSE ) {
m xs- > display + + ;
w xs- > display + + ;
unlink ( lockfile ) ;
unlink ( lockfile ) ;
goto retry ;
goto retry ;
}
}
m xs- > unix_fd = bind_to_unix_socket ( m xs- > display ) ;
w xs- > unix_fd = bind_to_unix_socket ( w xs- > display ) ;
if ( m xs- > unix_fd < 0 ) {
if ( w xs- > unix_fd < 0 ) {
unlink ( lockfile ) ;
unlink ( lockfile ) ;
close ( m xs- > abstract_fd ) ;
close ( w xs- > abstract_fd ) ;
free ( m xs) ;
free ( w xs) ;
return - 1 ;
return - 1 ;
}
}
snprintf ( display_name , sizeof display_name , " :%d " , m xs- > display ) ;
snprintf ( display_name , sizeof display_name , " :%d " , w xs- > display ) ;
weston_log ( " xserver listening on display %s \n " , display_name ) ;
weston_log ( " xserver listening on display %s \n " , display_name ) ;
setenv ( " DISPLAY " , display_name , 1 ) ;
setenv ( " DISPLAY " , display_name , 1 ) ;
m xs- > loop = wl_display_get_event_loop ( display ) ;
w xs- > loop = wl_display_get_event_loop ( display ) ;
m xs- > abstract_source =
w xs- > abstract_source =
wl_event_loop_add_fd ( m xs- > loop , m xs- > abstract_fd ,
wl_event_loop_add_fd ( w xs- > loop , w xs- > abstract_fd ,
WL_EVENT_READABLE ,
WL_EVENT_READABLE ,
weston_xserver_handle_event , m xs) ;
weston_xserver_handle_event , w xs) ;
m xs- > unix_source =
w xs- > unix_source =
wl_event_loop_add_fd ( m xs- > loop , m xs- > unix_fd ,
wl_event_loop_add_fd ( w xs- > loop , w xs- > unix_fd ,
WL_EVENT_READABLE ,
WL_EVENT_READABLE ,
weston_xserver_handle_event , m xs) ;
weston_xserver_handle_event , w xs) ;
wl_display_add_global ( display , & xserver_interface , m xs, bind_xserver ) ;
wl_display_add_global ( display , & xserver_interface , w xs, bind_xserver ) ;
m xs- > destroy_listener . notify = weston_xserver_destroy ;
w xs- > destroy_listener . notify = weston_xserver_destroy ;
wl_signal_add ( & compositor - > destroy_signal , & m xs- > destroy_listener ) ;
wl_signal_add ( & compositor - > destroy_signal , & w xs- > destroy_listener ) ;
return 0 ;
return 0 ;
}
}