yash-env 0.14.0

Yash shell execution environment interface
Documentation
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
// This file is part of yash, an extended POSIX shell.
// Copyright (C) 2021 WATANABE Yuki
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.

//! Items related to the `tcsetpgrp` operation

use super::Pid;
use crate::io::Fd;
use crate::signal;
#[cfg(doc)]
use crate::system::Concurrent;
use crate::system::{
    Disposition, Result, Sigaction, Sigmask, SigmaskOp, Signals, Sigset as _, TcSetPgrp,
};

/// A trait to run a function with a signal blocked
///
/// This trait represents the capability required by [`tcsetpgrp_with_block`] to
/// run a function with a signal blocked. It is automatically implemented for
/// any type that implements [`Sigmask`].
///
/// This trait defines a higher-level interface to temporarily modify the signal
/// mask. Typical implementations of this trait will internally depend on
/// [`Sigmask`] to perform the actual signal mask modification, but the trait
/// itself does not require this as a supertrait. Using this trait as the public
/// capability leaves room for types such as [`Concurrent`] to stop exposing
/// `Sigmask` directly in a future release while still providing the behavior
/// required by callers.
pub trait RunBlocking: Signals {
    /// Runs the given function with the specified signal blocked.
    ///
    /// This function blocks the given signal, runs the given function, and then
    /// restores the original signal mask. If all operations succeed, the result
    /// of the function is returned. If any operation fails, an error is
    /// returned.
    ///
    /// This function restores the original signal mask even if the given
    /// function returns an error, in which case any error restoring the signal
    /// mask is discarded. If the signal cannot be blocked, this function
    /// returns an error without running the function.
    fn run_blocking<F, T>(
        &self,
        signal: signal::Number,
        f: F,
    ) -> impl Future<Output = Result<T>> + use<'_, Self, F, T>
    where
        F: AsyncFnOnce() -> Result<T>;
}

impl<S> RunBlocking for S
where
    S: Sigmask + ?Sized,
{
    async fn run_blocking<F, T>(&self, signal: signal::Number, f: F) -> Result<T>
    where
        F: AsyncFnOnce() -> Result<T>,
    {
        let mut old_mask = S::Sigset::new();
        self.sigmask(
            Some((SigmaskOp::Add, &S::Sigset::from_signals([signal])?)),
            Some(&mut old_mask),
        )
        .await?;

        let main_result = f().await;

        let restore_result = self.sigmask(Some((SigmaskOp::Set, &old_mask)), None).await;
        if main_result.is_ok() {
            restore_result?;
        }

        main_result
    }
}

/// Switches the foreground process group with SIGTTOU blocked.
///
/// This is a convenience function to change the foreground process group
/// safely. If you call [`TcSetPgrp::tcsetpgrp`] from a background process, the
/// process is stopped by SIGTTOU by default. To prevent this effect, SIGTTOU
/// must be blocked or ignored when `tcsetpgrp` is called. This function uses
/// [`RunBlocking::run_blocking`] to block SIGTTOU while calling `tcsetpgrp`,
/// which ensures that the shell is not suspended even if it is not in the
/// foreground.
///
/// Use [`tcsetpgrp_without_block`] if you need to make sure the shell is in the
/// foreground before changing the foreground job.
pub async fn tcsetpgrp_with_block<S>(system: &S, fd: Fd, pgid: Pid) -> Result<()>
where
    S: RunBlocking + TcSetPgrp + ?Sized,
{
    system
        .run_blocking(S::SIGTTOU, || system.tcsetpgrp(fd, pgid))
        .await
}

/// A trait to run a function with a signal unblocked and the default disposition
///
/// This trait represents the capability required by [`tcsetpgrp_without_block`]
/// to run a function with a signal unblocked and the default disposition. It is
/// automatically implemented for any type that implements [`Sigmask`] and
/// [`Sigaction`].
///
/// This trait defines a higher-level interface to temporarily modify the signal
/// mask and disposition. Typical implementations of this trait will internally
/// depend on [`Sigmask`] and [`Sigaction`] to perform the actual signal mask
/// and disposition modification, but the trait itself does not require them as
/// supertraits. Using this trait as the public capability leaves room for types
/// such as [`Concurrent`] to stop exposing `Sigmask` directly in a future
/// release while still providing the behavior required by callers.
pub trait RunUnblocking: Signals {
    /// Runs the given function with the specified signal unblocked and the
    /// default disposition.
    ///
    /// For most signals, this function restores the default disposition for the
    /// given signal, unblocks it, runs the given function, and then restores
    /// the original signal mask and disposition. If all operations succeed, the
    /// result of the function is returned. If any operation fails, an error is
    /// returned.
    ///
    /// This function restores the original signal mask and disposition even if
    /// the given function returns an error, in which case any error restoring
    /// the signal mask or disposition is discarded. If the signal cannot be
    /// unblocked or the disposition cannot be changed, this function returns an
    /// error without running the function.
    ///
    /// For signals whose mask or disposition cannot be changed (i.e., [SIGKILL]
    /// and [SIGSTOP]), this function does not try to unblock the signal or
    /// restore its default disposition and instead simply runs the given
    /// function.
    ///
    /// [SIGKILL]: crate::system::Signals::SIGKILL
    /// [SIGSTOP]: crate::system::Signals::SIGSTOP
    fn run_unblocking<F, T>(
        &self,
        signal: signal::Number,
        f: F,
    ) -> impl Future<Output = Result<T>> + use<'_, Self, F, T>
    where
        F: AsyncFnOnce() -> Result<T>;
}

impl<S> RunUnblocking for S
where
    S: Sigmask + Sigaction + ?Sized,
{
    async fn run_unblocking<F, T>(&self, signal: signal::Number, f: F) -> Result<T>
    where
        F: AsyncFnOnce() -> Result<T>,
    {
        if signal == S::SIGKILL || signal == S::SIGSTOP {
            // These signals cannot be ignored or blocked, so we just run the function.
            return f().await;
        }

        let sigset = S::Sigset::from_signals([signal])?;

        let old_handling = self.sigaction(signal, Disposition::Default)?;

        let mut old_mask = S::Sigset::new();
        let unblock_result = self
            .sigmask(Some((SigmaskOp::Remove, &sigset)), Some(&mut old_mask))
            .await;
        if let Err(e) = unblock_result {
            _ = self.sigaction(signal, old_handling);
            return Err(e);
        }

        let main_result = f().await;

        let restore_mask_result = self.sigmask(Some((SigmaskOp::Set, &old_mask)), None).await;
        let restore_action_result = self.sigaction(signal, old_handling);

        if main_result.is_ok() {
            restore_mask_result?;
            restore_action_result?;
        }
        main_result
    }
}

/// Switches the foreground process group with the default SIGTTOU settings.
///
/// This is a convenience function to ensure the shell has been in the
/// foreground and optionally change the foreground process group. If you call
/// [`TcSetPgrp::tcsetpgrp`] from a background process that has not ignored or
/// blocked SIGTTOU, the process is stopped by SIGTTOU. This behavior can be
/// used to ensure the shell is in the foreground before starting job control
/// operations.
///
/// This function temporarily restores the default disposition for SIGTTOU and
/// unblocks it while calling `tcsetpgrp`, which ensures that the shell is
/// suspended if it is not in the foreground. The suspended shell must be
/// resumed by another job-controlling process, after which this function
/// continues. If the shell is already in the foreground, this function behaves
/// the same as usual `tcsetpgrp`.
///
/// To simply make sure the shell is in the foreground without changing the
/// foreground job, you can call this function with `pgid` set to the process
/// group ID of the current process.
///
/// Use [`tcsetpgrp_with_block`] to change the job even if the current shell is
/// not in the foreground.
pub async fn tcsetpgrp_without_block<S>(system: &S, fd: Fd, pgid: Pid) -> Result<()>
where
    S: RunUnblocking + TcSetPgrp + ?Sized,
{
    system
        .run_unblocking(S::SIGTTOU, || system.tcsetpgrp(fd, pgid))
        .await
}

#[cfg(test)]
mod tests {
    use super::*;
    use crate::signal;
    use crate::system::r#virtual::{
        SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGIOT,
        SIGKILL, SIGPIPE, SIGPROF, SIGQUIT, SIGSEGV, SIGSTOP, SIGSYS, SIGTERM, SIGTRAP, SIGTSTP,
        SIGTTIN, SIGTTOU, SIGURG, SIGUSR1, SIGUSR2, SIGVTALRM, SIGWINCH, SIGXCPU, SIGXFSZ,
    };
    use crate::system::{Errno, GetSigaction};
    use futures_util::FutureExt as _;
    use std::cell::{Cell, RefCell};
    use std::collections::{BTreeMap, BTreeSet};
    use std::ops::RangeInclusive;

    #[derive(Clone, Debug, Default, Eq, PartialEq)]
    struct TestSigset(BTreeSet<signal::Number>);

    impl crate::system::Sigset for TestSigset {
        fn full() -> Self {
            unimplemented!("not needed for tests")
        }

        fn insert(&mut self, signal: signal::Number) -> Result<()> {
            self.0.insert(signal);
            Ok(())
        }

        fn remove(&mut self, signal: signal::Number) -> Result<()> {
            self.0.remove(&signal);
            Ok(())
        }

        fn contains(&self, signal: signal::Number) -> Result<bool> {
            Ok(self.0.contains(&signal))
        }
    }

    #[derive(Default)]
    struct MockSystem {
        mask: RefCell<TestSigset>,
        dispositions: RefCell<BTreeMap<signal::Number, Disposition>>,
        sigmask_errors: RefCell<BTreeMap<usize, Errno>>,
        sigaction_errors: RefCell<BTreeMap<usize, Errno>>,
        sigmask_call_count: Cell<usize>,
        sigaction_call_count: Cell<usize>,
    }

    impl MockSystem {
        fn set_mask(&self, mask: TestSigset) {
            self.mask.replace(mask);
        }

        fn set_disposition(&self, signal: signal::Number, disposition: Disposition) {
            self.dispositions.borrow_mut().insert(signal, disposition);
        }

        fn disposition_of(&self, signal: signal::Number) -> Disposition {
            self.dispositions
                .borrow()
                .get(&signal)
                .copied()
                .unwrap_or_default()
        }

        fn is_blocked(&self, signal: signal::Number) -> bool {
            self.mask
                .borrow()
                .contains(signal)
                .expect("signals in tests are always valid")
        }

        fn set_sigmask_error_on_call(&self, call: usize, error: Errno) {
            self.sigmask_errors.borrow_mut().insert(call, error);
        }

        fn set_sigaction_error_on_call(&self, call: usize, error: Errno) {
            self.sigaction_errors.borrow_mut().insert(call, error);
        }
    }

    impl Signals for MockSystem {
        const SIGABRT: signal::Number = SIGABRT;
        const SIGALRM: signal::Number = SIGALRM;
        const SIGBUS: signal::Number = SIGBUS;
        const SIGCHLD: signal::Number = SIGCHLD;
        const SIGCLD: Option<signal::Number> = None;
        const SIGCONT: signal::Number = SIGCONT;
        const SIGEMT: Option<signal::Number> = None;
        const SIGFPE: signal::Number = SIGFPE;
        const SIGHUP: signal::Number = SIGHUP;
        const SIGILL: signal::Number = SIGILL;
        const SIGINFO: Option<signal::Number> = None;
        const SIGINT: signal::Number = SIGINT;
        const SIGIO: Option<signal::Number> = None;
        const SIGIOT: signal::Number = SIGIOT;
        const SIGKILL: signal::Number = SIGKILL;
        const SIGLOST: Option<signal::Number> = None;
        const SIGPIPE: signal::Number = SIGPIPE;
        const SIGPOLL: Option<signal::Number> = None;
        const SIGPROF: signal::Number = SIGPROF;
        const SIGPWR: Option<signal::Number> = None;
        const SIGQUIT: signal::Number = SIGQUIT;
        const SIGSEGV: signal::Number = SIGSEGV;
        const SIGSTKFLT: Option<signal::Number> = None;
        const SIGSTOP: signal::Number = SIGSTOP;
        const SIGSYS: signal::Number = SIGSYS;
        const SIGTERM: signal::Number = SIGTERM;
        const SIGTHR: Option<signal::Number> = None;
        const SIGTRAP: signal::Number = SIGTRAP;
        const SIGTSTP: signal::Number = SIGTSTP;
        const SIGTTIN: signal::Number = SIGTTIN;
        const SIGTTOU: signal::Number = SIGTTOU;
        const SIGURG: signal::Number = SIGURG;
        const SIGUSR1: signal::Number = SIGUSR1;
        const SIGUSR2: signal::Number = SIGUSR2;
        const SIGVTALRM: signal::Number = SIGVTALRM;
        const SIGWINCH: signal::Number = SIGWINCH;
        const SIGXCPU: signal::Number = SIGXCPU;
        const SIGXFSZ: signal::Number = SIGXFSZ;

        fn sigrt_range(&self) -> Option<RangeInclusive<signal::Number>> {
            None
        }
    }

    impl Sigmask for MockSystem {
        type Sigset = TestSigset;

        fn sigmask(
            &self,
            op: Option<(SigmaskOp, &Self::Sigset)>,
            old_mask: Option<&mut Self::Sigset>,
        ) -> impl Future<Output = Result<()>> + use<> {
            let call_count = self.sigmask_call_count.get() + 1;
            self.sigmask_call_count.set(call_count);

            if let Some(error) = self.sigmask_errors.borrow_mut().remove(&call_count) {
                return std::future::ready(Err(error));
            }

            let result = {
                let mut mask = self.mask.borrow_mut();
                if let Some(old_mask) = old_mask {
                    old_mask.clone_from(&mask);
                }

                if let Some((op, signals)) = op {
                    match op {
                        SigmaskOp::Add => {
                            for &signal in &signals.0 {
                                mask.insert(signal).unwrap();
                            }
                        }
                        SigmaskOp::Remove => {
                            for &signal in &signals.0 {
                                mask.remove(signal).unwrap();
                            }
                        }
                        SigmaskOp::Set => {
                            *mask = signals.clone();
                        }
                    }
                }

                Ok(())
            };

            std::future::ready(result)
        }
    }

    impl GetSigaction for MockSystem {
        fn get_sigaction(&self, signal: signal::Number) -> Result<Disposition> {
            Ok(self.disposition_of(signal))
        }
    }

    impl Sigaction for MockSystem {
        fn sigaction(&self, signal: signal::Number, action: Disposition) -> Result<Disposition> {
            let call_count = self.sigaction_call_count.get() + 1;
            self.sigaction_call_count.set(call_count);

            if let Some(error) = self.sigaction_errors.borrow_mut().remove(&call_count) {
                return Err(error);
            }

            Ok(self
                .dispositions
                .borrow_mut()
                .insert(signal, action)
                .unwrap_or_default())
        }
    }

    #[test]
    fn run_blocking_blocks_signal_and_restores_mask_on_success() {
        let system = MockSystem::default();
        let called = Cell::new(false);

        let result = system
            .run_blocking(MockSystem::SIGTTOU, async || {
                called.set(true);
                assert!(system.is_blocked(MockSystem::SIGTTOU));
                Ok(())
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Ok(()));
        assert!(called.get());
        assert!(!system.is_blocked(MockSystem::SIGTTOU));
    }

    #[test]
    fn run_blocking_does_not_run_function_when_initial_sigmask_fails() {
        let system = MockSystem::default();
        system.set_sigmask_error_on_call(1, Errno::EINVAL);

        let result = system
            .run_blocking(MockSystem::SIGTTOU, async || -> Result<()> {
                unreachable!("closure should not be called")
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINVAL));
    }

    #[test]
    fn run_blocking_discards_restore_error_when_function_returns_error() {
        let system = MockSystem::default();
        system.set_sigmask_error_on_call(2, Errno::EPERM);

        let result = system
            .run_blocking(MockSystem::SIGTTOU, async || Err::<(), _>(Errno::EINTR))
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINTR));
    }

    #[test]
    fn run_blocking_propagates_restore_error_when_function_succeeds() {
        let system = MockSystem::default();
        system.set_sigmask_error_on_call(2, Errno::EPERM);

        let result = system
            .run_blocking(MockSystem::SIGTTOU, async || Ok(()))
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EPERM));
    }

    #[test]
    fn run_unblocking_for_sigkill_runs_function_without_sigaction_or_sigmask() {
        let system = MockSystem::default();
        let called = Cell::new(false);

        let result = system
            .run_unblocking(MockSystem::SIGKILL, async || {
                called.set(true);
                Err::<(), _>(Errno::EINTR)
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINTR));
        assert!(called.get());
        assert_eq!(system.sigmask_call_count.get(), 0);
        assert_eq!(system.sigaction_call_count.get(), 0);
    }

    #[test]
    fn run_unblocking_for_sigstop_runs_function_without_sigaction_or_sigmask() {
        let system = MockSystem::default();
        let called = Cell::new(false);

        let result = system
            .run_unblocking(MockSystem::SIGSTOP, async || {
                called.set(true);
                Err::<(), _>(Errno::EINTR)
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINTR));
        assert!(called.get());
        assert_eq!(system.sigmask_call_count.get(), 0);
        assert_eq!(system.sigaction_call_count.get(), 0);
    }

    #[test]
    fn run_unblocking_sets_default_unblocks_and_restores_on_success() {
        let system = MockSystem::default();
        let called = Cell::new(false);
        let mut initial_mask = TestSigset::new();
        initial_mask.insert(MockSystem::SIGTTOU).unwrap();
        system.set_mask(initial_mask.clone());
        system.set_disposition(MockSystem::SIGTTOU, Disposition::Ignore);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || {
                called.set(true);
                assert_eq!(
                    system.disposition_of(MockSystem::SIGTTOU),
                    Disposition::Default
                );
                assert!(!system.is_blocked(MockSystem::SIGTTOU));
                Ok(())
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Ok(()));
        assert!(called.get());
        assert!(system.is_blocked(MockSystem::SIGTTOU));
        assert_eq!(
            system.disposition_of(MockSystem::SIGTTOU),
            Disposition::Ignore
        );
    }

    #[test]
    fn run_unblocking_returns_error_when_unblock_sigmask_fails_and_restores_disposition() {
        let system = MockSystem::default();
        system.set_disposition(MockSystem::SIGTTOU, Disposition::Ignore);
        system.set_sigmask_error_on_call(1, Errno::EPERM);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || -> Result<()> {
                unreachable!("closure should not be called")
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EPERM));
        assert_eq!(
            system.disposition_of(MockSystem::SIGTTOU),
            Disposition::Ignore
        );
    }

    #[test]
    fn run_unblocking_discards_restore_errors_when_function_returns_error() {
        let system = MockSystem::default();
        let called = Cell::new(false);
        system.set_sigmask_error_on_call(2, Errno::EPERM);
        system.set_sigaction_error_on_call(2, Errno::EINVAL);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || {
                called.set(true);
                Err::<(), _>(Errno::EINTR)
            })
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINTR));
        assert!(called.get());
    }

    #[test]
    fn run_unblocking_propagates_restore_mask_error_when_function_succeeds() {
        let system = MockSystem::default();
        system.set_sigmask_error_on_call(2, Errno::EPERM);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || Ok(()))
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EPERM));
    }

    #[test]
    fn run_unblocking_restores_sigaction_on_sigmask_restoration_error() {
        let system = MockSystem::default();
        system.set_disposition(MockSystem::SIGTTOU, Disposition::Ignore);
        system.set_sigmask_error_on_call(2, Errno::EPERM);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || Ok(()))
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EPERM));
        assert_eq!(
            system.disposition_of(MockSystem::SIGTTOU),
            Disposition::Ignore
        );
    }

    #[test]
    fn run_unblocking_propagates_restore_action_error_when_function_succeeds() {
        let system = MockSystem::default();
        system.set_sigaction_error_on_call(2, Errno::EINVAL);

        let result = system
            .run_unblocking(MockSystem::SIGTTOU, async || Ok(()))
            .now_or_never()
            .unwrap();

        assert_eq!(result, Err(Errno::EINVAL));
    }
}