| // Copyright 2021 Google LLC |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| package devicepolicy |
| |
| import ( |
| "fmt" |
| "time" |
| |
| "github.com/godbus/dbus" |
| "github.com/golang/glog" |
| ) |
| |
| const ( |
| sessionManagerObjectName = "org.chromium.SessionManager" |
| sessionManagerObjectPath = "/org/chromium/SessionManager" |
| propertyChangeSignal = "org.chromium.SessionManagerInterface.PropertyChangeComplete" |
| ) |
| |
| // signalPropertyChange sends PropertyChangeComplete signal over |
| // system D-Bus on the SessionManager object. |
| // |
| // Normally in ChromiumOS this object is owned by login manager which |
| // is responsible for device policy updates. But because there is no |
| // login manager in GCI we can simulate that object and emit the same |
| // signal. |
| func signalPropertyChange() error { |
| glog.V(1).Info("Sending PropertyChangeComplete signal...") |
| |
| conn, err := dbus.SystemBusPrivate() |
| if err != nil { |
| return err |
| } |
| defer conn.Close() |
| if err = conn.Auth(nil); err != nil { |
| return err |
| } |
| if err = conn.Hello(); err != nil { |
| return err |
| } |
| reply, err := conn.RequestName(sessionManagerObjectName, dbus.NameFlagDoNotQueue) |
| if err != nil { |
| return err |
| } |
| if reply != dbus.RequestNameReplyPrimaryOwner { |
| return fmt.Errorf("%s: name already taken", sessionManagerObjectName) |
| } |
| |
| err = conn.Emit(sessionManagerObjectPath, propertyChangeSignal, "success") |
| |
| // After updating device policy we send a signal notifying update engine. |
| // Due to a bug in dbus library that signal may be lost if the process |
| // exits. The fix for that bug (https://github.com/godbus/dbus/pull/31) |
| // has stalled, so we temporarily work around the bug by having this |
| // sleep :(. |
| time.Sleep(1 * time.Second) |
| |
| return err |
| } |