liblmkd_utils: Adding get kill count interface

Add new API to fetch the current kill count from lmkd.

Test: m
Bug: 325525024
Change-Id: I9289be653444c8641cd5a698049835c3ac271b56
Signed-off-by: Carlos Galo <carlosgalo@google.com>
This commit is contained in:
Carlos Galo 2024-05-14 21:21:11 +00:00
parent 8b5a67d35a
commit 05e8c7bbda
2 changed files with 34 additions and 0 deletions

View File

@ -85,6 +85,19 @@ enum boot_completed_notification_result {
*/
enum boot_completed_notification_result lmkd_notify_boot_completed(int sock);
enum get_kill_count_err_result {
GET_KILL_COUNT_SEND_ERR = -1,
GET_KILL_COUNT_RECV_ERR = -2,
GET_KILL_COUNT_FORMAT_ERR = -3,
};
/*
* Get the number of kills LMKD has performed.
* On success returns number of kills.
* On error, get_kill_count_err_result integer value.
*/
int lmkd_get_kill_count(int sock, struct lmk_getkillcnt* params);
__END_DECLS
#endif /* _LIBLMKD_UTILS_H_ */

View File

@ -118,6 +118,27 @@ enum boot_completed_notification_result lmkd_notify_boot_completed(int sock) {
return res;
}
int lmkd_get_kill_count(int sock, struct lmk_getkillcnt* params) {
LMKD_CTRL_PACKET packet;
int size;
size = lmkd_pack_set_getkillcnt(packet, params);
if (TEMP_FAILURE_RETRY(write(sock, packet, size)) < 0) {
return (int)GET_KILL_COUNT_SEND_ERR;
}
size = TEMP_FAILURE_RETRY(read(sock, packet, CTRL_PACKET_MAX_SIZE));
if (size < 0) {
return (int)GET_KILL_COUNT_RECV_ERR;
}
if (size != 2 * sizeof(int) || lmkd_pack_get_cmd(packet) != LMK_GETKILLCNT) {
return (int)GET_KILL_COUNT_FORMAT_ERR;
}
return packet[1];
}
int create_memcg(uid_t uid, pid_t pid) {
return createProcessGroup(uid, pid, true) == 0 ? 0 : -1;
}