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"
36 #include "MDnsSdListener.h"
37 #include "UidMarkMap.h"
39 static void coldboot(const char *path);
40 static void sigchld_handler(int sig);
41 static void blockSigpipe();
47 DnsProxyListener *dpl;
48 MDnsSdListener *mdnsl;
50 ALOGI("Netd 1.0 starting");
52 // signal(SIGCHLD, sigchld_handler);
55 if (!(nm = NetlinkManager::Instance())) {
56 ALOGE("Unable to create NetlinkManager");
60 UidMarkMap *rangeMap = new UidMarkMap();
62 cl = new CommandListener(rangeMap);
63 nm->setBroadcaster((SocketListener *) cl);
66 ALOGE("Unable to start NetlinkManager (%s)", strerror(errno));
70 // Set local DNS mode, to prevent bionic from proxying
71 // back to this service, recursively.
72 setenv("ANDROID_DNS_MODE", "local", 1);
73 dpl = new DnsProxyListener(rangeMap);
74 if (dpl->startListener()) {
75 ALOGE("Unable to start DnsProxyListener (%s)", strerror(errno));
79 mdnsl = new MDnsSdListener();
80 if (mdnsl->startListener()) {
81 ALOGE("Unable to start MDnsSdListener (%s)", strerror(errno));
85 * Now that we're up, we can respond to commands
87 if (cl->startListener()) {
88 ALOGE("Unable to start CommandListener (%s)", strerror(errno));
92 // Eventually we'll become the monitoring thread
97 ALOGI("Netd exiting");
101 static void do_coldboot(DIR *d, int lvl)
108 fd = openat(dfd, "uevent", O_WRONLY);
110 write(fd, "add\n", 4);
114 while((de = readdir(d))) {
117 if (de->d_name[0] == '.')
120 if (de->d_type != DT_DIR && lvl > 0)
123 fd = openat(dfd, de->d_name, O_RDONLY | O_DIRECTORY);
131 do_coldboot(d2, lvl + 1);
137 static void coldboot(const char *path)
139 DIR *d = opendir(path);
146 static void sigchld_handler(int sig) {
147 pid_t pid = wait(NULL);
148 ALOGD("Child process %d exited", pid);
151 static void blockSigpipe()
156 sigaddset(&mask, SIGPIPE);
157 if (sigprocmask(SIG_BLOCK, &mask, NULL) != 0)
158 ALOGW("WARNING: SIGPIPE not blocked\n");