github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/configstate/configcore/backlight.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package configcore 21 22 import ( 23 "fmt" 24 25 "github.com/snapcore/snapd/dirs" 26 "github.com/snapcore/snapd/overlord/configstate/config" 27 "github.com/snapcore/snapd/systemd" 28 ) 29 30 func init() { 31 // add supported configuration of this module 32 supportedConfigurations["core.system.disable-backlight-service"] = true 33 } 34 35 func validateBacklightServiceSettings(tr config.ConfGetter) error { 36 return validateBoolFlag(tr, "system.disable-backlight-service") 37 } 38 39 type backlightSysdLogger struct{} 40 41 func (l *backlightSysdLogger) Notify(status string) { 42 fmt.Fprintf(Stderr, "sysd: %s\n", status) 43 } 44 45 // systemd-backlight service has no installation config. It's started when needed via udev. 46 // So, systemctl enable/disable/start/stop are invalid commands. After masking/unmasking 47 // the service, rebooting is required for making new setting work 48 func handleBacklightServiceConfiguration(tr config.ConfGetter, opts *fsOnlyContext) error { 49 var sysd systemd.Systemd 50 const serviceName = "systemd-backlight@.service" 51 if opts != nil { 52 sysd = systemd.NewEmulationMode(opts.RootDir) 53 } else { 54 sysd = systemd.New(dirs.GlobalRootDir, systemd.SystemMode, &backlightSysdLogger{}) 55 } 56 output, err := coreCfg(tr, "system.disable-backlight-service") 57 if err != nil { 58 return nil 59 } 60 if output != "" { 61 switch output { 62 case "true": 63 return sysd.Mask(serviceName) 64 case "false": 65 return sysd.Unmask(serviceName) 66 default: 67 return fmt.Errorf("unsupported disable-backlight-service option: %q", output) 68 } 69 } 70 return nil 71 }