1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #include <cstdlib> 18 #include <string> 19 20 #include <base/at_exit.h> 21 #include <base/command_line.h> 22 #include <base/logging.h> 23 #include <base/memory/ref_counted.h> 24 #include <brillo/syslog_logging.h> 25 26 #include "shill/rpc_task.h" 27 #include "shill/shims/environment.h" 28 #include "shill/shims/task_proxy.h" 29 30 using shill::shims::Environment; 31 using std::map; 32 using std::string; 33 34 int main(int argc, char** argv) { 35 base::AtExitManager exit_manager; 36 base::CommandLine::Init(argc, argv); 37 brillo::InitLog(brillo::kLogToSyslog | brillo::kLogHeader); 38 39 Environment* environment = Environment::GetInstance(); 40 string service, path, reason; 41 if (!environment->GetVariable(shill::kRPCTaskServiceVariable, &service) || 42 !environment->GetVariable(shill::kRPCTaskPathVariable, &path) || 43 !environment->GetVariable("script_type", &reason)) { 44 LOG(ERROR) << "Environment variables not available."; 45 return EXIT_FAILURE; 46 } 47 48 scoped_refptr<dbus::Bus> bus; 49 dbus::Bus::Options options; 50 options.bus_type = dbus::Bus::SYSTEM; 51 bus = new dbus::Bus(options); 52 CHECK(bus->Connect()); 53 54 shill::shims::TaskProxy proxy(bus, path, service); 55 map<string, string> env = environment->AsMap(); 56 proxy.Notify(reason, env); 57 if (bus) { 58 bus->ShutdownAndBlock(); 59 } 60 return EXIT_SUCCESS; 61 } 62