void TreeSocket::SendListModes(Channel* chan) { FModeBuilder fmode(chan); const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i) { ListModeBase* mh = *i; ListModeBase::ModeList* list = mh->GetList(chan); if (!list) continue; // Add all items on the list to the FMODE, send it whenever it becomes too long const char modeletter = mh->GetModeChar(); for (ListModeBase::ModeList::const_iterator j = list->begin(); j != list->end(); ++j) { const std::string& mask = j->mask; if (!fmode.has_room(mask)) { // No room for this mask, send the current line as-is then add the mask to a // new, empty FMODE message this->WriteLine(fmode.finalize()); fmode.clear(); } fmode.push_mode(modeletter, mask); } } if (!fmode.empty()) this->WriteLine(fmode.finalize()); }
int run_parts(char *dir, char *cmd) { struct dirent **e; int i, num; num = scandir(dir, &e, NULL, alphasort); if (num < 0) { _d("No files found in %s, skipping ...", dir); return -1; } for (i = 0; i < num; i++) { int j = 0; pid_t pid = 0; mode_t mode; char *args[NUM_ARGS]; char *name = e[i]->d_name; char path[CMD_SIZE]; snprintf(path, sizeof(path), "%s/%s", dir, name); mode = fmode(path); if (!S_ISEXEC(mode) || S_ISDIR(mode)) { _d("Skipping %s ...", path); continue; } /* Fill in args[], starting with full path to executable */ args[j++] = path; /* If the callee didn't supply a run_parts() argument */ if (!cmd) { /* Check if S<NUM>service or K<NUM>service notation is used */ _d("Checking if %s is a sysvinit startstop script ...", name); if (name[0] == 'S' && isdigit(name[1])) { args[j++] = "start"; } else if (name[0] == 'K' && isdigit(name[1])) { args[j++] = "stop"; } } else { args[j++] = cmd; } args[j++] = NULL; pid = fork(); if (!pid) { _d("Calling %s ...", path); sig_unblock(); execv(path, args); exit(0); } complete(path, pid); } while (num--) free(e[num]); free(e); return 0; }