1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
4 This file is part of systemd.
6 Copyright 2013 Lennart Poettering
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
26 #include "udev-util.h"
28 int main(int argc, char *argv[]) {
29 _cleanup_udev_unref_ struct udev *udev = NULL;
30 _cleanup_udev_device_unref_ struct udev_device *device = NULL;
31 _cleanup_free_ char *saved = NULL, *ss = NULL, *escaped_name = NULL;
32 const char *sysname, *name;
36 log_error("This program requires two arguments.");
40 log_set_target(LOG_TARGET_AUTO);
41 log_parse_environment();
46 r = mkdir_p("/var/lib/systemd/rfkill", 0755);
48 log_error("Failed to create rfkill directory: %s", strerror(-r));
58 sysname = strchr(argv[2], ':');
60 log_error("Requires pair of subsystem and sysname for specifying rfkill device.");
64 ss = strndup(argv[2], sysname - argv[2]);
72 if (!streq(ss, "rfkill")) {
73 log_error("Not a rfkill device: '%s:%s'", ss, sysname);
78 device = udev_device_new_from_subsystem_sysname(udev, ss, sysname);
81 log_error("Failed to get rfkill device '%s:%s': %m", ss, sysname);
88 name = udev_device_get_sysattr_value(device, "name");
90 log_error("rfkill device has no name?");
94 escaped_name = cescape(name);
100 saved = strjoin("/var/lib/systemd/rfkill/", escaped_name, NULL);
106 if (streq(argv[1], "load")) {
107 _cleanup_free_ char *value = NULL;
109 r = read_one_line_file(saved, &value);
115 log_error("Failed to read %s: %s", saved, strerror(-r));
119 r = udev_device_set_sysattr_value(device, "soft", value);
121 log_error("Failed to write system attribute: %s", strerror(-r));
125 } else if (streq(argv[1], "save")) {
128 value = udev_device_get_sysattr_value(device, "soft");
130 log_error("Failed to read system attribute: %s", strerror(-r));
134 r = write_string_file(saved, value);
136 log_error("Failed to write %s: %s", saved, strerror(-r));
141 log_error("Unknown verb %s.", argv[1]);