2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
23 #include <sys/types.h>
29 #define LOG_TAG "Netd"
31 #include "cutils/log.h"
33 #include "CommandListener.h"
34 #include "NetlinkManager.h"
35 #include "DnsProxyListener.h"
37 static void coldboot(const char *path);
38 static void sigchld_handler(int sig);
44 DnsProxyListener *dpl;
46 LOGI("Netd 1.0 starting");
48 // signal(SIGCHLD, sigchld_handler);
50 if (!(nm = NetlinkManager::Instance())) {
51 LOGE("Unable to create NetlinkManager");
56 cl = new CommandListener();
57 nm->setBroadcaster((SocketListener *) cl);
60 LOGE("Unable to start NetlinkManager (%s)", strerror(errno));
64 // Set local DNS mode, to prevent bionic from proxying
65 // back to this service, recursively.
66 setenv("ANDROID_DNS_MODE", "local", 1);
67 dpl = new DnsProxyListener();
68 if (dpl->startListener()) {
69 LOGE("Unable to start DnsProxyListener (%s)", strerror(errno));
74 * Now that we're up, we can respond to commands
76 if (cl->startListener()) {
77 LOGE("Unable to start CommandListener (%s)", strerror(errno));
81 // Eventually we'll become the monitoring thread
90 static void do_coldboot(DIR *d, int lvl)
97 fd = openat(dfd, "uevent", O_WRONLY);
99 write(fd, "add\n", 4);
103 while((de = readdir(d))) {
106 if (de->d_name[0] == '.')
109 if (de->d_type != DT_DIR && lvl > 0)
112 fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
120 do_coldboot(d2, lvl + 1);
126 static void coldboot(const char *path)
128 DIR *d = opendir(path);
135 static void sigchld_handler(int sig) {
136 pid_t pid = wait(NULL);
137 LOGD("Child process %d exited", pid);