1use crate::ffi::polkit_unix_process_set_gids;
6use crate::{Subject, ffi};
7use glib::{
8 ffi::{GArray, g_array_append_vals, g_array_new},
9 prelude::*,
10 signal::{SignalHandlerId, connect_raw},
11 translate::*,
12};
13use std::{boxed::Box as Box_, slice};
14
15glib::wrapper! {
16 #[doc(alias = "PolkitUnixProcess")]
17 pub struct UnixProcess(Object<ffi::PolkitUnixProcess, ffi::PolkitUnixProcessClass>) @implements Subject;
18
19 match fn {
20 type_ => || ffi::polkit_unix_process_get_type(),
21 }
22}
23
24impl UnixProcess {
25 #[doc(alias = "polkit_unix_process_get_gids")]
26 #[doc(alias = "get_gids")]
27 pub fn gids(&self) -> Vec<i32> {
28 unsafe {
29 let arrays_g = ffi::polkit_unix_process_get_gids(self.to_glib_none().0);
30 let arrays = (*arrays_g).data as *mut i32;
31 let len = (*arrays_g).len as usize;
32 slice::from_raw_parts(arrays, len).to_vec()
33 }
34 }
35
36 #[doc(alias = "polkit_unix_process_get_owner")]
37 #[doc(alias = "get_owner")]
38 pub fn owner(&self) -> Result<i32, glib::Error> {
39 unsafe {
40 let mut error = std::ptr::null_mut();
41 let ret = ffi::polkit_unix_process_get_owner(self.to_glib_none().0, &mut error);
42 if error.is_null() {
43 Ok(ret)
44 } else {
45 Err(from_glib_full(error))
46 }
47 }
48 }
49
50 #[doc(alias = "polkit_unix_process_get_pid")]
51 #[doc(alias = "get_pid")]
52 pub fn pid(&self) -> i32 {
53 unsafe { ffi::polkit_unix_process_get_pid(self.to_glib_none().0) }
54 }
55
56 #[doc(alias = "polkit_unix_process_get_pidfd")]
57 #[doc(alias = "get_pidfd")]
58 pub fn pidfd(&self) -> i32 {
59 unsafe { ffi::polkit_unix_process_get_pidfd(self.to_glib_none().0) }
60 }
61
62 #[doc(alias = "polkit_unix_process_get_pidfd_is_safe")]
63 #[doc(alias = "get_pidfd_is_safe")]
64 #[doc(alias = "pidfd-is-safe")]
65 pub fn is_pidfd_is_safe(&self) -> bool {
66 unsafe {
67 from_glib(ffi::polkit_unix_process_get_pidfd_is_safe(
68 self.to_glib_none().0,
69 ))
70 }
71 }
72
73 #[doc(alias = "polkit_unix_process_get_start_time")]
74 #[doc(alias = "get_start_time")]
75 #[doc(alias = "start-time")]
76 pub fn start_time(&self) -> u64 {
77 unsafe { ffi::polkit_unix_process_get_start_time(self.to_glib_none().0) }
78 }
79
80 #[doc(alias = "polkit_unix_process_get_uid")]
81 #[doc(alias = "get_uid")]
82 pub fn uid(&self) -> i32 {
83 unsafe { ffi::polkit_unix_process_get_uid(self.to_glib_none().0) }
84 }
85
86 #[doc(alias = "polkit_unix_process_set_gids")]
87 #[doc(alias = "gids")]
88 pub fn set_gids(&self, gids: Vec<usize>) {
89 unsafe {
90 let new_gids = g_array_new(0, 0, std::mem::size_of::<usize>() as u32);
91
92 g_array_append_vals(new_gids, gids.as_ptr() as *const _, gids.len() as u32);
93 ffi::polkit_unix_process_set_gids(self.to_glib_none().0, new_gids);
94 }
95 }
96
97 #[doc(alias = "polkit_unix_process_set_pid")]
98 #[doc(alias = "pid")]
99 pub fn set_pid(&self, pid: i32) {
100 unsafe {
101 ffi::polkit_unix_process_set_pid(self.to_glib_none().0, pid);
102 }
103 }
104
105 #[doc(alias = "polkit_unix_process_set_pidfd")]
106 #[doc(alias = "pidfd")]
107 pub fn set_pidfd(&self, pidfd: i32) {
108 unsafe {
109 ffi::polkit_unix_process_set_pidfd(self.to_glib_none().0, pidfd);
110 }
111 }
112
113 #[doc(alias = "polkit_unix_process_set_start_time")]
114 #[doc(alias = "start-time")]
115 pub fn set_start_time(&self, start_time: u64) {
116 unsafe {
117 ffi::polkit_unix_process_set_start_time(self.to_glib_none().0, start_time);
118 }
119 }
120
121 #[doc(alias = "polkit_unix_process_set_uid")]
122 #[doc(alias = "uid")]
123 pub fn set_uid(&self, uid: i32) {
124 unsafe {
125 ffi::polkit_unix_process_set_uid(self.to_glib_none().0, uid);
126 }
127 }
128
129 #[doc(alias = "polkit_unix_process_new")]
130 pub fn new(pid: i32) -> Self {
131 unsafe {
132 let subject: Subject = from_glib_full(ffi::polkit_unix_process_new(pid));
133 subject.unsafe_cast()
134 }
135 }
136
137 #[doc(alias = "polkit_unix_process_new_for_owner")]
138 pub fn new_for_owner(pid: i32, start_time: u64, uid: i32) -> Self {
139 unsafe {
140 let subject: Subject =
141 from_glib_full(ffi::polkit_unix_process_new_for_owner(pid, start_time, uid));
142 subject.unsafe_cast()
143 }
144 }
145
146 #[doc(alias = "polkit_unix_process_new_full")]
147 pub fn new_full(pid: i32, start_time: u64) -> Self {
148 unsafe {
149 let subject: Subject =
150 from_glib_full(ffi::polkit_unix_process_new_full(pid, start_time));
151 subject.unsafe_cast()
152 }
153 }
154
155 #[doc(alias = "polkit_unix_process_new_pidfd")]
156 pub fn new_pidfd(pidfd: i32, uid: i32, gids: Vec<usize>) -> Self {
157 unsafe {
158 let subject: Subject = {
159 let new_gids = g_array_new(0, 0, std::mem::size_of::<usize>() as u32);
160
161 g_array_append_vals(new_gids, gids.as_ptr() as *const _, gids.len() as u32);
162 from_glib_full(ffi::polkit_unix_process_new_pidfd(pidfd, uid, new_gids))
163 };
164 subject.unsafe_cast()
165 }
166 }
167
168 #[doc(alias = "gids")]
169 pub fn connect_gids_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
170 unsafe extern "C" fn notify_gids_trampoline<F: Fn(&UnixProcess) + 'static>(
171 this: *mut ffi::PolkitUnixProcess,
172 _param_spec: glib::ffi::gpointer,
173 f: glib::ffi::gpointer,
174 ) {
175 unsafe {
176 let f: &F = &*(f as *const F);
177 f(&from_glib_borrow(this))
178 }
179 }
180 unsafe {
181 let f: Box_<F> = Box_::new(f);
182 connect_raw(
183 self.as_ptr() as *mut _,
184 c"notify::gids".as_ptr() as *const _,
185 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
186 notify_gids_trampoline::<F> as *const (),
187 )),
188 Box_::into_raw(f),
189 )
190 }
191 }
192
193 #[doc(alias = "pid")]
194 pub fn connect_pid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
195 unsafe extern "C" fn notify_pid_trampoline<F: Fn(&UnixProcess) + 'static>(
196 this: *mut ffi::PolkitUnixProcess,
197 _param_spec: glib::ffi::gpointer,
198 f: glib::ffi::gpointer,
199 ) {
200 unsafe {
201 let f: &F = &*(f as *const F);
202 f(&from_glib_borrow(this))
203 }
204 }
205 unsafe {
206 let f: Box_<F> = Box_::new(f);
207 connect_raw(
208 self.as_ptr() as *mut _,
209 c"notify::pid".as_ptr() as *const _,
210 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
211 notify_pid_trampoline::<F> as *const (),
212 )),
213 Box_::into_raw(f),
214 )
215 }
216 }
217
218 #[doc(alias = "pidfd")]
219 pub fn connect_pidfd_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
220 unsafe extern "C" fn notify_pidfd_trampoline<F: Fn(&UnixProcess) + 'static>(
221 this: *mut ffi::PolkitUnixProcess,
222 _param_spec: glib::ffi::gpointer,
223 f: glib::ffi::gpointer,
224 ) {
225 unsafe {
226 let f: &F = &*(f as *const F);
227 f(&from_glib_borrow(this))
228 }
229 }
230 unsafe {
231 let f: Box_<F> = Box_::new(f);
232 connect_raw(
233 self.as_ptr() as *mut _,
234 c"notify::pidfd".as_ptr() as *const _,
235 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
236 notify_pidfd_trampoline::<F> as *const (),
237 )),
238 Box_::into_raw(f),
239 )
240 }
241 }
242
243 #[doc(alias = "pidfd-is-safe")]
244 pub fn connect_pidfd_is_safe_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
245 unsafe extern "C" fn notify_pidfd_is_safe_trampoline<F: Fn(&UnixProcess) + 'static>(
246 this: *mut ffi::PolkitUnixProcess,
247 _param_spec: glib::ffi::gpointer,
248 f: glib::ffi::gpointer,
249 ) {
250 unsafe {
251 let f: &F = &*(f as *const F);
252 f(&from_glib_borrow(this))
253 }
254 }
255 unsafe {
256 let f: Box_<F> = Box_::new(f);
257 connect_raw(
258 self.as_ptr() as *mut _,
259 c"notify::pidfd-is-safe".as_ptr() as *const _,
260 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
261 notify_pidfd_is_safe_trampoline::<F> as *const (),
262 )),
263 Box_::into_raw(f),
264 )
265 }
266 }
267
268 #[doc(alias = "start-time")]
269 pub fn connect_start_time_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
270 unsafe extern "C" fn notify_start_time_trampoline<F: Fn(&UnixProcess) + 'static>(
271 this: *mut ffi::PolkitUnixProcess,
272 _param_spec: glib::ffi::gpointer,
273 f: glib::ffi::gpointer,
274 ) {
275 unsafe {
276 let f: &F = &*(f as *const F);
277 f(&from_glib_borrow(this))
278 }
279 }
280 unsafe {
281 let f: Box_<F> = Box_::new(f);
282 connect_raw(
283 self.as_ptr() as *mut _,
284 c"notify::start-time".as_ptr() as *const _,
285 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
286 notify_start_time_trampoline::<F> as *const (),
287 )),
288 Box_::into_raw(f),
289 )
290 }
291 }
292
293 #[doc(alias = "uid")]
294 pub fn connect_uid_notify<F: Fn(&Self) + 'static>(&self, f: F) -> SignalHandlerId {
295 unsafe extern "C" fn notify_uid_trampoline<F: Fn(&UnixProcess) + 'static>(
296 this: *mut ffi::PolkitUnixProcess,
297 _param_spec: glib::ffi::gpointer,
298 f: glib::ffi::gpointer,
299 ) {
300 unsafe {
301 let f: &F = &*(f as *const F);
302 f(&from_glib_borrow(this))
303 }
304 }
305 unsafe {
306 let f: Box_<F> = Box_::new(f);
307 connect_raw(
308 self.as_ptr() as *mut _,
309 c"notify::uid".as_ptr() as *const _,
310 Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
311 notify_uid_trampoline::<F> as *const (),
312 )),
313 Box_::into_raw(f),
314 )
315 }
316 }
317}