コード例 #1
0
int main() {

    VolumeManager *vm;
    CommandListener *cl;
    NetlinkManager *nm;

    SLOGI("Vold 2.1 (the revenge) firing up");

    mkdir("/dev/block/vold", 0755);

    /* Create our singleton managers */
    if (!(vm = VolumeManager::Instance())) {
        SLOGE("Unable to create VolumeManager");
        exit(1);
    };

    if (!(nm = NetlinkManager::Instance())) {
        SLOGE("Unable to create NetlinkManager");
        exit(1);
    };


    cl = new CommandListener();
    vm->setBroadcaster((SocketListener *) cl);
    nm->setBroadcaster((SocketListener *) cl);

    if (vm->start()) {
        SLOGE("Unable to start VolumeManager (%s)", strerror(errno));
        exit(1);
    }

    if (process_config(vm)) {
        SLOGE("Error reading configuration (%s)... continuing anyways", strerror(errno));
    }

    if (nm->start()) {
        SLOGE("Unable to start NetlinkManager (%s)", strerror(errno));
        exit(1);
    }

    coldboot("/sys/block");
//    coldboot("/sys/class/switch");

    /*
     * Now that we're up, we can respond to commands
     */
    if (cl->startListener()) {
        SLOGE("Unable to start CommandListener (%s)", strerror(errno));
        exit(1);
    }

    // Eventually we'll become the monitoring thread
    while(1) {
        sleep(1000);
    }

    SLOGI("Vold exiting");
    exit(0);
}
コード例 #2
0
ファイル: main.cpp プロジェクト: Andrewas/WonderMedia
int main() {
    pid_t pid, sid;
    
    pid = fork();
    if (pid < 0)
      exit(EXIT_FAILURE);
    
    if (pid > 0)
      exit(EXIT_SUCCESS);
    
    umask(0);
    sid = setsid();
    if (sid < 0)
      exit(EXIT_FAILURE);
    
    if ((chdir("/")) < 0)
      exit(EXIT_FAILURE);
    
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
    
    NetlinkManager *nm;

    if (!(nm = NetlinkManager::Instance())) {
        SLOGE("Unable to create NetlinkManager");
        exit(EXIT_FAILURE);
    };

    if (nm->start()) {
        SLOGE("Unable to start NetlinkManager (%s)", strerror(errno));
        exit(EXIT_FAILURE);
    }

    // Eventually we'll become the monitoring thread
    while(1) {
        sleep(1000);
    }

    SLOGI("DevListener exiting");
    exit(EXIT_SUCCESS);
}
コード例 #3
0
void NetlinkManager::netlinkRouteUpdated(
    struct nl_cache* /*cache*/,
    struct nl_object* obj,
    int nlOperation,
    void* data) {
  NetlinkManager* nlm = static_cast<NetlinkManager*>(data);
  std::string operation = nlm->nlOperationToStr(nlOperation);
  if (operation == "unknown") {
    VLOG(1) << "Ignoring an unknown route update";
    return;
  }

  VLOG(2) << "Received a " << operation << " netlink route update message";
  struct rtnl_route* route = (struct rtnl_route*)obj;

  if (rtnl_route_get_type(route) != RTN_UNICAST) {
    VLOG(1) << "Ignoring non-unicast route update";
    return;
  }

  struct nl_addr* nlDst = rtnl_route_get_dst(route);
  const uint8_t ipLen = nl_addr_get_prefixlen(nlDst);
  char strDst[ipLen];
  nl_addr2str(nlDst, strDst, ipLen);

  int numNexthops = rtnl_route_get_nnexthops(route);
  if (!numNexthops) {
    VLOG(0) << "Could not find next hop for route update for " << strDst;
    struct nl_dump_params dumpParams = initDumpParams();
    nl_object_dump((nl_object*)route, &dumpParams);
    return;
  }

  std::vector<BinaryAddress> nexthops;
  {
    std::lock_guard<std::mutex> lock(nlm->interfacesMutex_);
    nexthops = getNextHops(route, ipLen, nlm->monitoredInterfaces_);
  }

  if (nexthops.empty()) {
    VLOG(1) << operation << " Route update for " << strDst
            << " has no valid nexthop";
    return;
  }

  if (FLAGS_debug) {
    VLOG(1) << "Got " << operation << " route update for " << strDst;
    return;
  }

  switch (nlOperation) {
    case NL_ACT_NEW: {
      nlm->addRouteViaFbossThrift(nlDst, nexthops);
      break;
    }
    case NL_ACT_DEL: {
      nlm->deleteRouteViaFbossThrift(nlDst);
      break;
    }
    case NL_ACT_CHANGE: {
      VLOG(2) << "Not updating state due to unimplemented"
              << "NL_ACT_CHANGE netlink operation";
      break;
    }
    default: {
      VLOG(0) << "Not updating state due to unknown netlink operation "
              << std::to_string(nlOperation);
      break; /* NL_ACT_??? */
    }
  }
  return;
}