]> git.sven.stormbind.net Git - sven/jattach.git/blob - src/posix/psutil.h
New upstream version 2.0
[sven/jattach.git] / src / posix / psutil.h
1 /*
2  * Copyright 2021 Andrei Pangin
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 _PSUTIL_H
18 #define _PSUTIL_H
19
20 #include <sys/types.h>
21
22
23 #define MAX_PATH 1024
24 extern char tmp_path[];
25
26 // Gets /tmp path of the specified process, as it can be accessed from the host.
27 // The obtained path is stored in the global tmp_path buffer.
28 void get_tmp_path(int pid);
29
30 // The reentrant version of get_tmp_path.
31 // Stores the process-specific temporary path into the provided buffer.
32 // Returns 0 on success, -1 on failure.
33 int get_tmp_path_r(int pid, char* buf, size_t bufsize);
34
35 // Gets the owner uid/gid of the target process, and also its pid inside the container.
36 // Returns 0 on success, -1 on failure.
37 int get_process_info(int pid, uid_t* uid, gid_t* gid, int* nspid);
38
39 // Tries to enter the namespace of the target process.
40 // type of the namespace can be "mnt", "net", "pid", etc.
41 // Returns 1, if the namespace has been successfully changed,
42 //         0, if the target process is in the same namespace as the host,
43 //        -1, if the attempt failed.
44 int enter_ns(int pid, const char* type);
45
46 #endif // _PSUTIL_H