-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.h
111 lines (101 loc) · 3.15 KB
/
loader.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* -*- Mode: C ; c-basic-offset: 2 -*- */
/*
* SPDX-FileCopyrightText: Copyright © 2009-2023 Nedko Arnaudov
* SPDX-License-Identifier: GPL-2.0-or-later */
/**
**************************************************************************
* @file loader.h
* @brief Interface to the code that starts programs (launcher module)
**************************************************************************/
#ifndef JPL_H__6D6AF97A_DA41_46D6_954B_A121B25E96CE__INCLUDED
#define JPL_H__6D6AF97A_DA41_46D6_954B_A121B25E96CE__INCLUDED
/** Handle to object describing child */
typedef struct jpl_child_tag
{
int unused; /**< opaque handle quazi-member */
} * jpl_child_handle;
/**
* @brief function type for callback called on child exit
*
* @param ctx context pointer with value as supplied by call to jpl_execute()
* @param exit_status Exit status of the child process
*/
typedef
void
(* jpl_on_child_exit)(
void * ctx,
int exit_status);
/**
* @brief function type for callback called on child exit
*
* @param ctx context pointer with value as supplied by call to jpl_execute()
* @param error whether line from stderr (true) is being logged or from stdout (false)
* @param format format string
* @param ... optional args, as specified by @c format parameter
*/
typedef
void
(* jpl_log_callback)(
void * ctx,
bool error,
const char * format,
...);
/**
* @brief initialize the launcher module
*
* @param on_child_exit function to call back when child exits
* @param log_callback function to call back child produces a line
*/
void
jpl_init(
jpl_on_child_exit on_child_exit,
jpl_log_callback log_callback);
/**
* @brief run child program in a subprocess
*
* @param ctx context pointer that will be passed as parameter when functions,
* previously specified int the jpl_init() call, are called.
* @param working_dir working dir where the program is started
* @param run_in_terminal whether to run the child program in a new terminal
* @param commandline command-line to use for starting the child process
* @param env_vars optional (can be NULL) array of strings for
* environment variables to be set in the child process
* the array is terminated by empty string element.
* @param ldpreload optional (can be NULL) array of strings for LD_PRELOAD-ed libraries.
* the array is terminated by empty string element.
* @param pid_ptr pointer to variable where, upon successful return,
* the child process identifier value will be stored.
* @param child_handle_ptr pointer to variable where, upon successful return,
* child handle is stored.
*
* @return success status
*/
bool
jpl_execute(
void * ctx,
const char * working_dir,
bool run_in_terminal,
const char * commandline,
const char * const * env_vars,
const char * const * ldpreload,
pid_t * pid_ptr,
jpl_child_handle * child_handle_ptr);
/**
* @brief Read subprocess output and call the callbacks
*/
void
jpl_run(
void);
/**
* @brief uninitialize the launcher module
*/
void
jpl_uninit(
void);
/**
* @brief get number of child processes
*/
unsigned int
jpl_get_app_count(
void);
#endif /* #ifndef JPL_H__6D6AF97A_DA41_46D6_954B_A121B25E96CE__INCLUDED */