gpio_utils/commands/
gpio_unexportall.rs

1// Copyright (c) 2016, The gpio-utils Authors.
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/license/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option.  This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use config::GpioConfig;
10use export;
11use options::GpioUnexportAllOptions;
12use std::process::exit;
13
14pub fn main(config: &GpioConfig, opts: &GpioUnexportAllOptions) {
15    let symlink_root = match opts.symlink_root {
16        Some(slr) => slr,
17        None => config.get_symlink_root(),
18    };
19
20    for pin in config.get_pins().iter().filter(|p| p.export) {
21        if let Err(e) = export::unexport(pin, Some(symlink_root)) {
22            println!("Error occurred while exporting pin: {:?}", pin);
23            println!("{}", e);
24            exit(1);
25        }
26    }
27}