Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/openlaunchd
Path: blob/master/liblaunch/launch_internal.h
374 views
1
/*
2
* Copyright (c) 2007-2012 Apple Inc. All rights reserved.
3
*
4
* @APPLE_APACHE_LICENSE_HEADER_START@
5
*
6
* Licensed under the Apache License, Version 2.0 (the "License");
7
* you may not use this file except in compliance with the License.
8
* You may obtain a copy of the License at
9
*
10
* http://www.apache.org/licenses/LICENSE-2.0
11
*
12
* Unless required by applicable law or agreed to in writing, software
13
* distributed under the License is distributed on an "AS IS" BASIS,
14
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
* See the License for the specific language governing permissions and
16
* limitations under the License.
17
*
18
* @APPLE_APACHE_LICENSE_HEADER_END@
19
*/
20
21
#ifndef __LAUNCH_INTERNAL_H__
22
#define __LAUNCH_INTERNAL_H__
23
24
#include "vproc_priv.h"
25
26
#include <paths.h>
27
#include <dispatch/dispatch.h>
28
#include <pthread.h>
29
30
#if __has_include(<os/alloc_once_private.h>)
31
#include <os/alloc_once_private.h>
32
#if defined(OS_ALLOC_ONCE_KEY_LIBLAUNCH)
33
#define _LIBLAUNCH_HAS_ALLOC_ONCE 1
34
#endif
35
#endif
36
37
enum {
38
LAUNCHD_USE_CHECKIN_FD,
39
LAUNCHD_USE_OTHER_FD,
40
};
41
struct _launch {
42
void *sendbuf;
43
int *sendfds;
44
void *recvbuf;
45
int *recvfds;
46
size_t sendlen;
47
size_t sendfdcnt;
48
size_t recvlen;
49
size_t recvfdcnt;
50
int which;
51
int cifd;
52
int fd;
53
};
54
55
typedef struct _launch *launch_t;
56
57
struct launch_globals_s {
58
// liblaunch.c
59
pthread_once_t lc_once;
60
pthread_mutex_t lc_mtx;
61
launch_t l;
62
launch_data_t async_resp;
63
64
launch_t in_flight_msg_recv_client;
65
66
int64_t s_am_embedded_god;
67
68
// libvproc.c
69
dispatch_queue_t _vproc_gone2zero_queue;
70
_vproc_transaction_callout _vproc_gone2zero_callout;
71
void *_vproc_gone2zero_ctx;
72
73
dispatch_once_t _vproc_transaction_once;
74
uint64_t _vproc_transaction_enabled;
75
dispatch_queue_t _vproc_transaction_queue;
76
int64_t _vproc_transaction_cnt;
77
};
78
typedef struct launch_globals_s *launch_globals_t;
79
80
void _launch_init_globals(launch_globals_t globals);
81
82
#if !_LIBLAUNCH_HAS_ALLOC_ONCE
83
launch_globals_t _launch_globals_impl(void);
84
#endif
85
86
__attribute__((__pure__))
87
static inline launch_globals_t
88
_launch_globals(void) {
89
#if _LIBLAUNCH_HAS_ALLOC_ONCE
90
return (launch_globals_t)os_alloc_once(OS_ALLOC_ONCE_KEY_LIBLAUNCH,
91
sizeof(struct launch_globals_s),
92
(void*)&_launch_init_globals);
93
#else
94
return _launch_globals_impl();
95
#endif
96
}
97
98
#pragma GCC visibility push(default)
99
100
#define LAUNCHD_DB_PREFIX "/private/var/db/launchd.db"
101
#define LAUNCHD_LOG_PREFIX "/private/var/log"
102
103
#define LAUNCHD_JOB_DEFAULTS "Defaults"
104
#define LAUNCHD_JOB_DEFAULTS_CACHED "CachedDefaults"
105
106
launch_t launchd_fdopen(int, int);
107
int launchd_getfd(launch_t);
108
void launchd_close(launch_t, __typeof__(close) closefunc);
109
110
launch_data_t launch_data_new_errno(int);
111
bool launch_data_set_errno(launch_data_t, int);
112
113
int launchd_msg_send(launch_t, launch_data_t);
114
int launchd_msg_recv(launch_t, void (*)(launch_data_t, void *), void *);
115
116
size_t launch_data_pack(launch_data_t d, void *where, size_t len, int *fd_where, size_t *fdslotsleft);
117
launch_data_t launch_data_unpack(void *data, size_t data_size, int *fds, size_t fd_cnt, size_t *data_offset, size_t *fdoffset);
118
119
#pragma GCC visibility pop
120
121
#endif /* __LAUNCH_INTERNAL_H__*/
122
123