wlmaker
Loading...
Searching...
No Matches
Classes | Functions
subprocess_monitor.c File Reference
#include "subprocess_monitor.h"
#include <inttypes.h>
#include <libbase/libbase.h>
#include <signal.h>
#include <stdbool.h>
#include <stdlib.h>
#include <wayland-server-core.h>
Include dependency graph for subprocess_monitor.c:

Classes

struct  _wlm_util_subprocess_monitor_t
 
struct  wlm_util_subprocess
 

Functions

static struct wlm_util_subprocesswlm_util_subprocess_handle_create (bs_subprocess_t *subprocess_ptr, struct wl_event_loop *wl_event_loop_ptr)
 
static void wlm_util_subprocess_handle_destroy (struct wlm_util_subprocess *sp_handle_ptr)
 
static int _wlm_util_subprocess_monitor_handle_read_stdout (int fd, uint32_t mask, void *data_ptr)
 
static int _wlm_util_subprocess_monitor_handle_read_stderr (int fd, uint32_t mask, void *data_ptr)
 
static int _wlm_util_subprocess_monitor_process_fd (struct wlm_util_subprocess *subprocess_handle_ptr, struct wl_event_source **wl_event_source_ptr_ptr, int fd, uint32_t mask, const char *fd_name_ptr, bs_dynbuf_t *dynbuf_ptr)
 
static int _wlm_util_subprocess_monitor_handle_sigchld (int signum, void *data_ptr)
 
wlm_util_subprocess_monitor_twlm_util_subprocess_monitor_create (struct wl_event_loop *wl_event_loop_ptr)
 
void wlm_util_subprocess_monitor_destroy (wlm_util_subprocess_monitor_t *monitor_ptr)
 
struct wlm_util_subprocesswlm_util_subprocess_monitor_entrust (wlm_util_subprocess_monitor_t *monitor_ptr, bs_subprocess_t *subprocess_ptr, wlm_util_subprocess_terminated_callback_t terminated_callback, void *userdata_ptr, bs_dynbuf_t *stdout_dynbuf_ptr)
 
void wlm_util_subprocess_monitor_cede (wlm_util_subprocess_monitor_t *monitor_ptr, struct wlm_util_subprocess *subprocess_handle_ptr)
 
bool wlm_util_subprocess_monitor_run (wlm_util_subprocess_monitor_t *monitor_ptr, bs_subprocess_t *subprocess_ptr)
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ _wlm_util_subprocess_monitor_handle_read_stderr()

int _wlm_util_subprocess_monitor_handle_read_stderr ( int  fd,
uint32_t  mask,
void *  data_ptr 
)
static

Handler for activity on stderr file descriptor, as prescribed by wl_event_loop_fd_func_t.

Parameters
fd
maskA bitmask of WL_EVENT_READABLE, WL_EVENT_HANGUP or WL_EVENT_ERROR.
data_ptrPoints to a wlm_util_subprocess.
Returns
0.

◆ _wlm_util_subprocess_monitor_handle_read_stdout()

int _wlm_util_subprocess_monitor_handle_read_stdout ( int  fd,
uint32_t  mask,
void *  data_ptr 
)
static

Handler for activity on stdout file descriptor, as prescribed by wl_event_loop_fd_func_t.

Parameters
fd
maskA bitmask of WL_EVENT_READABLE, WL_EVENT_HANGUP or WL_EVENT_ERROR.
data_ptrPoints ot a wlm_util_subprocess.
Returns
0.

◆ _wlm_util_subprocess_monitor_handle_sigchld()

int _wlm_util_subprocess_monitor_handle_sigchld ( int  signum,
void *  data_ptr 
)
static

Handles SIGCHLD. Callback for Wayland event loop.

Parameters
signum
data_ptrPoints to wlm_util_subprocess_monitor_t.

◆ _wlm_util_subprocess_monitor_process_fd()

int _wlm_util_subprocess_monitor_process_fd ( struct wlm_util_subprocess subprocess_handle_ptr,
struct wl_event_source **  wl_event_source_ptr_ptr,
int  fd,
uint32_t  mask,
const char *  fd_name_ptr,
bs_dynbuf_t *  dynbuf_ptr 
)
static

Processes activity on a file descriptor, matches wl_event_loop_fd_func_t.

Parameters
subprocess_handle_ptr
wl_event_source_ptr_ptr
fd
mask
fd_name_ptr
dynbuf_ptr
Returns
0.

◆ wlm_util_subprocess_handle_create()

struct wlm_util_subprocess * wlm_util_subprocess_handle_create ( bs_subprocess_t *  subprocess_ptr,
struct wl_event_loop *  wl_event_loop_ptr 
)
static

Creates a wlm_util_subprocess and connects to subprocess_ptr.

Parameters
subprocess_ptr
wl_event_loop_ptr
Returns
The subprocess handle or NULL on error.

◆ wlm_util_subprocess_handle_destroy()

void wlm_util_subprocess_handle_destroy ( struct wlm_util_subprocess sp_handle_ptr)
static

Destroys the subprocess handle and frees up associated resources.

Parameters
sp_handle_ptr

◆ wlm_util_subprocess_monitor_cede()

void wlm_util_subprocess_monitor_cede ( wlm_util_subprocess_monitor_t monitor_ptr,
struct wlm_util_subprocess subprocess_handle_ptr 
)

Releases the reference held on subprocess_handle_ptr. Once the subprocess terminates, all corresponding resources will be freed.

Parameters
monitor_ptr
subprocess_handle_ptr

◆ wlm_util_subprocess_monitor_create()

wlm_util_subprocess_monitor_t * wlm_util_subprocess_monitor_create ( struct wl_event_loop *  wl_event_loop_ptr)

Creates the subprocess monitor.

The subprocess monitor keeps references to all entrusted subprocesses, reads their output with appropriate logging, and issues a callback if and when the subprocess is terminated.

Parameters
wl_event_loop_ptr
Returns
Pointer to the subprocess monitor or NULL on error.

◆ wlm_util_subprocess_monitor_destroy()

void wlm_util_subprocess_monitor_destroy ( wlm_util_subprocess_monitor_t monitor_ptr)

Destroys the subprocess monitor.

Parameters
monitor_ptr

◆ wlm_util_subprocess_monitor_entrust()

struct wlm_util_subprocess * wlm_util_subprocess_monitor_entrust ( wlm_util_subprocess_monitor_t monitor_ptr,
bs_subprocess_t *  subprocess_ptr,
wlm_util_subprocess_terminated_callback_t  terminated_callback,
void *  userdata_ptr,
bs_dynbuf_t *  stdout_dynbuf_ptr 
)

Passes ownership of the started subprocess_ptr to monitor_ptr.

Also registers a set of callbacks that will be triggered. Permits to keep a central register of all started sub-processes, to monitor for termination, and to link up connecting clients with the sub-processes.

Parameters
monitor_ptr
subprocess_ptr
terminated_callback
userdata_ptr
stdout_dynbuf_ptr
Returns
A pointer to the created subprocess handle or NULL on error.

◆ wlm_util_subprocess_monitor_run()

bool wlm_util_subprocess_monitor_run ( wlm_util_subprocess_monitor_t monitor_ptr,
bs_subprocess_t *  subprocess_ptr 
)

Starts, entrust and cedes a subprocess to the monitor.

A convenience wrapper for bs_subprocess_start, wlm_util_subprocess_monitor_entrust and wlm_util_subprocess_monitor_cede.

Parameters
monitor_ptr
subprocess_ptrSubprocess. Ignored, if NULL. Takes ownership.
Returns
true on success.