1 /*
2  *  Copyright 2018 Google, Inc
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16 
17 #ifndef _LIBLMKD_UTILS_H_
18 #define _LIBLMKD_UTILS_H_
19 
20 #include <sys/cdefs.h>
21 #include <sys/types.h>
22 
23 #include <lmkd.h>
24 
25 __BEGIN_DECLS
26 
27 /*
28  * Connects to lmkd process and returns socket handle.
29  * On success returns socket handle.
30  * On error, -1 is returned, and errno is set appropriately.
31  */
32 int lmkd_connect();
33 
34 /*
35  * Registers a process with lmkd and sets its oomadj score.
36  * On success returns 0.
37  * On error, -1 is returned.
38  * In the case of error errno is set appropriately.
39  */
40 int lmkd_register_proc(int sock, struct lmk_procprio *params);
41 
42 /*
43  * Unregisters a process previously registered with lmkd.
44  * On success returns 0.
45  * On error, -1 is returned.
46  * In the case of error errno is set appropriately.
47  */
48 int lmkd_unregister_proc(int sock, struct lmk_procremove *params);
49 
50 enum update_props_result {
51     UPDATE_PROPS_SUCCESS,
52     UPDATE_PROPS_FAIL,
53     UPDATE_PROPS_SEND_ERR,
54     UPDATE_PROPS_RECV_ERR,
55     UPDATE_PROPS_FORMAT_ERR,
56 };
57 
58 /*
59  * Updates lmkd properties.
60  * In the case of ERR_SEND or ERR_RECV errno is set appropriately.
61  */
62 enum update_props_result lmkd_update_props(int sock);
63 
64 /*
65  * Creates memcg directory for given process.
66  * On success returns 0.
67  * -1 is returned if path creation failed.
68  * -2 is returned if tasks file open operation failed.
69  * -3 is returned if tasks file write operation failed.
70  * In the case of error errno is set appropriately.
71  */
72 int create_memcg(uid_t uid, pid_t pid);
73 
74 __END_DECLS
75 
76 #endif /* _LIBLMKD_UTILS_H_ */
77