-
Notifications
You must be signed in to change notification settings - Fork 202
/
libos_ipc_child.c
71 lines (59 loc) · 2.54 KB
/
libos_ipc_child.c
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
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/* Copyright (C) 2020 Intel Corporation
* Borys Popławski <[email protected]>
* Copyright (C) 2021 Intel Corporation
* Borys Popławski <[email protected]>
*/
#include "api.h"
#include "libos_ipc.h"
#include "libos_process.h"
void ipc_child_disconnect_callback(IDTYPE vmid) {
/*
* NOTE: IPC port may be closed by the host OS because the child process exited on the host OS
* (and so the host OS closed all its sockets). This may happen before arrival of the expected
* IPC_MSG_CHILDEXIT message from child process. In such case report that the child process was
* killed by SIGPWR (we've picked this signal hoping that nothing really uses it, as this case
* is not distinguishable from a genuine signal).
*/
if (mark_child_exited_by_vmid(vmid, /*uid=*/0, /*exit_code=*/0, SIGPWR)) {
log_error("Child process (vmid: 0x%x) got disconnected", vmid);
} else {
log_debug("Unknown process (vmid: 0x%x) disconnected", vmid);
}
}
int ipc_cld_exit_send(unsigned int exitcode, unsigned int term_signal) {
if (!g_process.ppid) {
/* We have no parent inside Gramine, so no one to notify. */
return 0;
}
struct libos_thread* self = get_cur_thread();
lock(&self->lock);
IDTYPE uid = self->uid;
unlock(&self->lock);
struct libos_ipc_cld_exit msgin = {
.ppid = g_process.ppid,
.pid = g_process.pid,
.exitcode = exitcode,
.term_signal = term_signal,
.uid = uid,
};
size_t total_msg_size = get_ipc_msg_size(sizeof(msgin));
struct libos_ipc_msg* msg = __alloca(total_msg_size);
init_ipc_msg(msg, IPC_MSG_CHILDEXIT, total_msg_size);
memcpy(msg->data, &msgin, sizeof(msgin));
return ipc_send_message(g_process_ipc_ids.parent_vmid, msg);
}
int ipc_cld_exit_callback(IDTYPE src, void* data, uint64_t seq) {
__UNUSED(seq);
struct libos_ipc_cld_exit* msgin = (struct libos_ipc_cld_exit*)data;
log_debug("IPC callback from %u: IPC_MSG_CHILDEXIT(%u, %u, %d, %u)", src, msgin->ppid,
msgin->pid, msgin->exitcode, msgin->term_signal);
if (mark_child_exited_by_pid(msgin->pid, msgin->uid, msgin->exitcode, msgin->term_signal)) {
log_debug("Child process (pid: %u) died", msgin->pid);
} else {
log_error("Unknown process sent a child-death notification: pid: %d, vmid: %u",
msgin->pid, src);
return -EINVAL;
}
return 0;
}