ErrorStack EnginePimpl::uninitialize_once() { LOG(INFO) << "================================================================================"; LOG(INFO) << "=================== FOEDUS ENGINE (" << describe_short() << ") EXITTING...... ================"; LOG(INFO) << "================================================================================"; if (is_master() && soc_manager_.is_initialized()) { soc_manager_.get_shared_memory_repo()->change_master_status( soc::MasterEngineStatus::kWaitingForChildTerminate); } ErrorStackBatch batch; // uninit in reverse order of initialization auto modules = get_modules(); std::reverse(modules.begin(), modules.end()); for (ModulePtr& module : modules) { if (!module.ptr_->is_initialized()) { continue; } // During uninitialization, master waits for SOCs' uninitialization before its uninit. if (is_master()) { batch.emprace_back(soc_manager_.wait_for_children_module(false, module.type_)); } batch.emprace_back(module.ptr_->uninitialize()); on_module_uninitialized(module.type_); // Then SOCs wait for master before moving on to next module. if (!is_master()) { batch.emprace_back(soc_manager_.wait_for_master_module(false, module.type_)); } } // SOC manager is special. We must uninitialize it at last. batch.emprace_back(soc_manager_.uninitialize()); // after that, we can't even set status. shared memory has been detached. return SUMMARIZE_ERROR_BATCH(batch); }
static int step_before_quit(int status) { static int remaining = 20; remaining--; if(remaining == 15 && !is_master()) { set_token(getpid()); } if(remaining == 10 && !is_master()) { get_token(getpid()); } if(!remaining) fiber_quit(); return 0; }
static int async_db_get_hook(aroop_txt_t*bin, aroop_txt_t*output) { /** * The database is available only in the master process */ aroop_assert(is_master()); aroop_txt_t key = {}; // the key to set int srcpid = 0; int cb_token = 0; aroop_txt_t cb_hook = {}; // 0 = srcpid, 1 = command, 2 = token, 3 = cb_hook, 4 = key, 5 = val binary_unpack_int(bin, 0, &srcpid); binary_unpack_int(bin, 2, &cb_token); binary_unpack_string(bin, 3, &cb_hook); // needs cleanup binary_unpack_string(bin, 4, &key); // needs cleanup DB_LOG(LOG_NOTICE, "[token%d]-get-doing ..--[dest:%d]-[key:%s]-[app:%s]", cb_token, srcpid, aroop_txt_to_string(&key), aroop_txt_to_string(&cb_hook)); //syslog(LOG_NOTICE, "[pid:%d]-getting:%s", getpid(), aroop_txt_to_string(&key)); aroop_txt_t*oldval = NULL; do { oldval = (aroop_txt_t*)opp_hash_table_get_no_ref(&global_db, &key); // no cleanup needed #if 0 if(destpid <= 0) { break; } #endif //syslog(LOG_NOTICE, "[pid:%d]-got:%s", getpid(), aroop_txt_to_string(oldval)); async_db_op_reply(srcpid, cb_token, &cb_hook, 1, &key, oldval); } while(0); // cleanup aroop_txt_destroy(&cb_hook); aroop_txt_destroy(&key); return 0; }
int LeaseManager::giveup(const int32_t who) { int ret = TFS_SUCCESS; DsRuntimeGlobalInformation& ds_info = DsRuntimeGlobalInformation::instance(); DsGiveupLeaseMessage req_msg; req_msg.set_ds_stat(ds_info.information_); if (is_master(who)) { BlockInfoV2* block_infos = req_msg.get_block_infos(); ArrayHelper<BlockInfoV2> blocks(MAX_WRITABLE_BLOCK_COUNT, block_infos); get_writable_block_manager().get_blocks(blocks, BLOCK_ANY); req_msg.set_size(blocks.get_array_index()); } tbnet::Packet* ret_msg = NULL; NewClient* new_client = NewClientManager::get_instance().create_client(); ret = (NULL != new_client) ? TFS_SUCCESS : EXIT_CLIENT_MANAGER_CREATE_CLIENT_ERROR; if (TFS_SUCCESS == ret) { // no need to process return message ret = send_msg_to_server(ns_ip_port_[who], new_client, &req_msg, ret_msg); NewClientManager::get_instance().destroy_client(new_client); } return ret; }
ErrorStack EnginePimpl::initialize_modules() { ASSERT_ND(soc_manager_.is_initialized()); for (ModulePtr& module : get_modules()) { // During initialization, SOCs wait for master's initialization before their init. if (!is_master()) { CHECK_ERROR(soc_manager_.wait_for_master_module(true, module.type_)); } CHECK_ERROR(module.ptr_->initialize()); on_module_initialized(module.type_); // Then master waits for SOCs before moving on to next module. if (is_master()) { CHECK_ERROR(soc_manager_.wait_for_children_module(true, module.type_)); } } return kRetOk; }
t_bool seek_master(t_player *player, t_cmds **cmds) { int i; int pos; char **split; i = -1; if ((split = get_broadcast(&pos, &player->msg)) == NULL) return (FALSE); is_master(player, pos, split); if (pos == 1) modify_cmd(ADV, -1, NULL, cmds); else if (pos == 3) modify_cmd(LEFT, -1, NULL, cmds); else if (pos == 5) { modify_cmd(LEFT, -1, NULL, cmds); modify_cmd(LEFT, -1, NULL, cmds); } else if (pos == 7) modify_cmd(RIGHT, -1, NULL, cmds); while (split[++i]) ft_strdel(&split[i]); free(split); return (TRUE); }
static int async_db_CAS_hook(aroop_txt_t*bin, aroop_txt_t*output) { /** * The database is available only in the master process */ aroop_assert(is_master()); aroop_txt_t key = {}; // the key to set aroop_txt_t expval = {}; // the val to compare with the oldval aroop_txt_t newval = {}; // the val to set int srcpid = 0; int cb_token = 0; aroop_txt_t cb_hook = {}; // 0 = srcpid, 1 = command, 2 = token, 3 = cb_hook, 4 = key, 5 = newval, 6 = oldval binary_unpack_int(bin, 0, &srcpid); binary_unpack_int(bin, 2, &cb_token); binary_unpack_string(bin, 3, &cb_hook); // needs cleanup binary_unpack_string(bin, 4, &key); // needs cleanup binary_unpack_string(bin, 5, &newval); // needs cleanup binary_unpack_string(bin, 6, &expval); // needs cleanup DB_LOG(LOG_NOTICE, "[token%d]-CAS-doing ..--[dest:%d]-[key:%s]-[app:%s]", cb_token, srcpid, aroop_txt_to_string(&key), aroop_txt_to_string(&cb_hook)); int success = 0; success = !async_db_op_helper(&key, &newval, &expval); #if 0 if(destpid > 0) { #endif async_db_op_reply(srcpid, cb_token, &cb_hook, success, &key, &newval); #if 0 } #endif // cleanup aroop_txt_destroy(&key); aroop_txt_destroy(&newval); aroop_txt_destroy(&expval); aroop_txt_destroy(&cb_hook); return 0; }
int room_master_module_deinit() { aroop_assert(is_master()); pm_unplug_bridge(0, default_room_fork_child_after_callback); pm_unplug_bridge(0, default_room_fork_parent_after_callback); pm_unplug_callback(0, on_async_room_call_master); return 0; }
int noasync_db_get(aroop_txt_t*key, aroop_txt_t*val) { aroop_assert(is_master()); aroop_txt_t*oldval = (aroop_txt_t*)opp_hash_table_get_no_ref(&global_db, key); // no cleanup needed if(oldval) aroop_txt_embeded_rebuild_copy_shallow(val, oldval); // needs cleanup return 0; }
void EnginePimpl::on_module_uninitialized(ModuleType module) { soc::SharedMemoryRepo* repo = soc_manager_.get_shared_memory_repo(); if (is_master()) { repo->get_global_memory_anchors()->master_status_memory_->change_uninit_atomic(module); } else { repo->get_node_memory_anchors(soc_id_)->child_status_memory_->change_uninit_atomic(module); } }
bool is_msm_hw3d_file(struct file *file) { struct hw3d_info *info = hw3d_info; if (MAJOR(file->f_dentry->d_inode->i_rdev) == MAJOR(info->devno) && (is_master(info, file) || is_client(info, file))) return 1; return 0; }
/** * check that the no interruption has been requested and return the current status * * Iff called by the master thread, it will check for R-user level interruption. * * @return true iff the computation is aborted */ bool check_abort() { if ( is_aborted() ) return true; if ( is_master() ) { check_user_interrupt_master(); // update_display(); } return is_aborted(); }
int async_db_master_deinit() { aroop_assert(is_master()); opp_hash_table_destroy(&global_db); pm_unplug_callback(0, async_db_CAS_hook); pm_unplug_callback(0, async_db_set_if_null_hook); pm_unplug_callback(0, async_db_unset_hook); pm_unplug_callback(0, async_db_get_hook); pm_unplug_callback(0, async_db_dump_hook); return 0; }
int BBSDirect::master_take_result(int pid) { assert(is_master()); assert(nrnmpi_numprocs_bbs > 1); for (;;) { int id = look_take_result(pid); if (id) { return id; } // wait for a message (no MPI_Iprobe) BBSDirectServer::handle_block(); } }
int room_master_module_init() { aroop_assert(is_master()); default_room_setup(); aroop_txt_t plugin_space = {}; aroop_txt_embeded_set_static_string(&plugin_space, ON_ASYNC_ROOM_CALL); pm_plug_callback(&plugin_space, on_async_room_call_master, on_asyncchat_rooms_desc); aroop_txt_embeded_set_static_string(&plugin_space, "fork/parent/after"); pm_plug_bridge(&plugin_space, default_room_fork_parent_after_callback, default_room_fork_callback_desc); aroop_txt_embeded_set_static_string(&plugin_space, "fork/child/after"); pm_plug_bridge(&plugin_space, default_room_fork_child_after_callback, default_room_fork_callback_desc); return 0; }
int tcp_listener_init() { if(!is_master()) // we only start it in the master return 0; memset(tcp_ports, 0, sizeof(tcp_ports)); protostack_get_ports_internal(tcp_ports); tcp_listener_start(); aroop_txt_t plugin_space = {}; aroop_txt_embeded_set_static_string(&plugin_space, "fork/child/after"); pm_plug_callback(&plugin_space, tcp_listener_stop, tcp_listener_stop_desc); aroop_txt_embeded_set_static_string(&plugin_space, "shake/softquitall"); pm_plug_callback(&plugin_space, tcp_listener_stop, tcp_listener_stop_desc); return 0; }
int async_db_master_init() { aroop_txt_embeded_set_static_string(&null_hook, "null"); aroop_assert(is_master()); opp_hash_table_create(&global_db, 16, 0, aroop_txt_get_hash_cb, aroop_txt_equals_cb); aroop_txt_t plugin_space = {}; aroop_txt_embeded_set_static_string(&plugin_space, "asyncdb/cas/request"); pm_plug_callback(&plugin_space, async_db_CAS_hook, async_db_hook_desc); aroop_txt_embeded_set_static_string(&plugin_space, "asyncdb/sin/request"); pm_plug_callback(&plugin_space, async_db_set_if_null_hook, async_db_hook_desc); aroop_txt_embeded_set_static_string(&plugin_space, "asyncdb/unset/request"); pm_plug_callback(&plugin_space, async_db_unset_hook, async_db_hook_desc); aroop_txt_embeded_set_static_string(&plugin_space, "asyncdb/get/request"); pm_plug_callback(&plugin_space, async_db_get_hook, async_db_hook_desc); aroop_txt_embeded_set_static_string(&plugin_space, "shake/dbdump"); pm_plug_callback(&plugin_space, async_db_dump_hook, async_db_dump_desc); return 0; }
/** Open the first DRM device matching the criteria */ int drm_open_matching(const char *pci_glob, int flags, int *vendor_id, int *device_id) { struct udev *udev; struct udev_enumerate *e; struct udev_device *device, *parent; struct udev_list_entry *entry; const char *pci_id, *path; char *tmp; int fd; *vendor_id = 0; *device_id = 0; udev = udev_new(); if (udev == NULL) { fprintf(stderr, "failed to initialize udev context\n"); return -1; //abort(); } fd = -1; e = udev_enumerate_new(udev); udev_enumerate_add_match_subsystem(e, "drm"); udev_enumerate_scan_devices(e); udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(e)) { path = udev_list_entry_get_name(entry); device = udev_device_new_from_syspath(udev, path); parent = udev_device_get_parent(device); /* Filter out KMS output devices. */ if (strcmp(udev_device_get_subsystem(parent), "pci") != 0) continue; pci_id = udev_device_get_property_value(parent, "PCI_ID"); if (fnmatch(pci_glob, pci_id, 0) != 0) continue; fd = open(udev_device_get_devnode(device), O_RDWR); if (fd < 0) continue; if ((flags & DRM_TEST_MASTER) && !is_master(fd)) { close(fd); fd = -1; continue; } break; }
static int default_room_setup() { if(!is_master()) // we only start it in the master return 0; aroop_txt_t roomstr = {}; aroop_txt_embeded_stackbuffer(&roomstr, sizeof(default_rooms)); int i = 0; int room_count = sizeof(default_rooms)/sizeof(*default_rooms); for(i=0;i<room_count;i++) { aroop_txt_concat_string(&roomstr, default_rooms[i]); aroop_txt_concat_char(&roomstr, ' '); // add space to separate words } aroop_txt_shift(&roomstr, -1);// trim the last space aroop_txt_zero_terminate(&roomstr); aroop_txt_t key = {}; aroop_txt_embeded_set_static_string(&key, ROOM_KEY); async_db_compare_and_swap(-1, NULL, &key, &roomstr, NULL); return 0; }
static long hw3d_wait_for_revoke(struct hw3d_info *info, struct file *filp) { struct hw3d_data *data = filp->private_data; int ret; if (is_master(info, filp)) { pr_err("%s: cannot revoke on master node\n", __func__); return -EPERM; } ret = wait_event_interruptible(info->revoke_wq, info->revoking || data->closing); if (ret == 0 && data->closing) ret = -EPIPE; if (ret < 0) return ret; return 0; }
int LeaseManager::renew(const int32_t timeout_ms, const int32_t who) { int ret = TFS_SUCCESS; DsRuntimeGlobalInformation& ds_info = DsRuntimeGlobalInformation::instance(); DsRenewLeaseMessage req_msg; req_msg.set_ds_stat(ds_info.information_); if (is_master(who)) { BlockInfoV2* block_infos = req_msg.get_block_infos(); ArrayHelper<BlockInfoV2> blocks(MAX_WRITABLE_BLOCK_COUNT, block_infos); get_writable_block_manager().get_blocks(blocks, BLOCK_WRITABLE); req_msg.set_size(blocks.get_array_index()); } tbnet::Packet* ret_msg = NULL; NewClient* new_client = NewClientManager::get_instance().create_client(); ret = (NULL != new_client) ? TFS_SUCCESS : EXIT_CLIENT_MANAGER_CREATE_CLIENT_ERROR; if (TFS_SUCCESS == ret) { ret = send_msg_to_server(ns_ip_port_[who], new_client, &req_msg, ret_msg, timeout_ms); if (TFS_SUCCESS == ret) { if (DS_RENEW_LEASE_RESPONSE_MESSAGE == ret_msg->getPCode()) { DsRenewLeaseResponseMessage* resp_msg = dynamic_cast<DsRenewLeaseResponseMessage* >(ret_msg); process_renew_response(resp_msg, who); } else if (STATUS_MESSAGE == ret_msg->getPCode()) { StatusMessage* resp_msg = dynamic_cast<StatusMessage*>(ret_msg); ret = resp_msg->get_status(); } else { ret = EXIT_UNKNOWN_MSGTYPE; } } NewClientManager::get_instance().destroy_client(new_client); } return ret; }
void mesos::add_tasks(mesos_framework& framework, const Json::Value& f_val) { if(is_master()) { Json::Value tasks = f_val["tasks"]; add_tasks_impl(framework, tasks); } else { Json::Value executors = f_val["executors"]; if(!executors.isNull()) { for(const auto& executor : executors) { Json::Value tasks = executor["tasks"]; add_tasks_impl(framework, tasks); } } } }
static int test_main() { int number_failed; /* initiate nginz */ setlogmask (LOG_UPTO (LOG_NOTICE)); openlog ("nginz_db_check", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); nginz_core_init(); /* initiate fibers */ register_fiber(step_before_quit); nginz_db_module_init_before_parallel_init(); nginz_parallel_init(); nginz_db_module_init_after_parallel_init(); /* cleanup nginz */ fiber_module_run(); nginz_db_module_deinit(); nginz_core_deinit(); closelog(); if(is_master()) { SRunner *sr = srunner_create(db_master_suite()); srunner_set_fork_status(sr, CK_NOFORK); srunner_run_all(sr, CK_NORMAL); number_failed = srunner_ntests_failed(sr); srunner_free(sr); status = ((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE); } else { //syslog(LOG_NOTICE, "[%d]is master\n", getpid()); SRunner *sr = srunner_create(db_child_suite()); srunner_set_fork_status(sr, CK_NOFORK); srunner_run_all(sr, CK_NORMAL); number_failed = srunner_ntests_failed(sr); srunner_free(sr); status = ((number_failed == 0) ? EXIT_SUCCESS : EXIT_FAILURE); } return 0; }
/* s = service the command was sent to u = user the command was sent from */ void ns_group(IRC_User *s, IRC_User *u) { u_int32_t source_snid; u_int32_t snid; char *cmd; char *gname; char *nick; int memberc = 0; u_int32_t master_sgid; u_int32_t sgid; CHECK_IF_IDENTIFIED_NICK cmd = strtok(NULL, " "); gname = strtok(NULL, " "); /* base syntax validation */ if(IsNull(cmd)) send_lang(u, s, NS_GROUP_SYNTAX); else if(strcasecmp(cmd,"CREATE") == 0) { char *master; char *gdesc; char *umodes = NULL; master = strtok(NULL, " "); gdesc = strtok(NULL, ""); if(gname) /* first check if the name contains umodes */ { char *pumodes; char *eumodes; pumodes = strchr(gname,'['); if(pumodes && pumodes[0]) { *(pumodes++) = '\0'; eumodes = strchr(pumodes,']'); if(eumodes) { *eumodes = '\0'; umodes = pumodes; } } } /* syntax validation */ if(IsNull(gname) || IsNull(master)) send_lang(u, s, NS_GROUP_CREATE_SYNTAX); /* permissions validation */ else if(!is_sroot(source_snid)) send_lang(u, s, NICK_NOT_ROOT); /* check requirements */ else if((master_sgid = find_group(master)) == 0) send_lang(u, s, NS_GROUP_MASTER_NOT_FOUND, master); /* avoid duplicates */ else if((sgid = find_group(gname)) != 0) send_lang(u, s, NS_GROUP_ALREADY_EXISTS, gname); /* execute operation */ else if(group_create(gname, master_sgid, gdesc, umodes) > 0) /* report operation status */ send_lang(u, s, NS_GROUP_CREATE_OK, gname); else send_lang(u, s, UPDATE_FAIL); } else if(strcasecmp(cmd,"ADD") == 0) { u_int32_t duration = 0; time_t master_expire = 0; u_int32_t is_master_sgid; char *duration_str; nick = strtok(NULL, " "); duration_str = strtok(NULL, " "); if(duration_str) duration = time_str(duration_str); /* syntax validation */ if(IsNull(gname) || IsNull(nick)) send_lang(u, s, NS_GROUP_ADD_SYNTAX); /* check requirements */ else if((snid = nick2snid(nick)) == 0) send_lang(u, s, NO_SUCH_NICK_X, nick); else if((sgid = find_group(gname)) == 0) send_lang(u, s, NO_SUCH_GROUP_X, gname); /* privileges validation */ else if(group_is_full(sgid)) send_lang(u, s, NS_GROUP_IS_FULL_X); else if(((is_master_sgid = is_master(source_snid, sgid))== 0) && !is_sroot(source_snid)) send_lang(u, s, NOT_MASTER_OF_X, gname); /* avoid duplicates */ else if(sql_singlequery("SELECT t_expire FROM ns_group_users " " WHERE sgid=%d AND snid=%d", is_master_sgid, source_snid) && (master_expire = sql_field_i(0)) && duration) send_lang(u, s, NS_GROUP_CANT_DEFINE_TIME_X, gname); else if(is_member_of(snid, sgid)) send_lang(u, s, NICK_X_ALREADY_ON_X, nick, gname); /* execute operation */ else { time_t t_expire = 0; if(master_expire) t_expire = master_expire; else if(duration) t_expire = irc_CurrentTime + duration; if(add_to_group(sgid, snid, t_expire) > 0) /* report operation status */ { char *server = strchr(gname, '@'); IRC_User *user = irc_FindUser(nick); send_lang(u, s, NICK_ADDED_X_X, nick, gname); if(server) /* we have a server rule to be validated */ ++server; if(user && (!server || (strcasecmp(server,u->server->sname) == 0))) { if(user->extra[ED_GROUPS] == NULL) { user->extra[ED_GROUPS] = malloc(sizeof(darray)); array_init(user->extra[ED_GROUPS], 1, DA_INT); } array_add_int(user->extra[ED_GROUPS], sgid); } } else send_lang(u, s, UPDATE_FAIL); } } else if(strcasecmp(cmd,"DEL") == 0) { nick = strtok(NULL, " "); /* syntax validation */ if(IsNull(gname) || IsNull(nick)) send_lang(u, s, NS_GROUP_DEL_SYNTAX); /* check requirements */ else if((sgid = find_group(gname)) == 0) send_lang(u, s, NO_SUCH_GROUP_X, gname); else if((snid = nick2snid(nick)) == 0) send_lang(u, s, NO_SUCH_NICK_X, nick); /* privileges validation */ else if(!is_sroot(source_snid) && !is_master(source_snid, sgid)) send_lang(u, s, NOT_MASTER_OF_X, gname); else if(!is_member_of(snid, sgid)) send_lang(u, s, NICK_X_NOT_ON_GROUP_X, nick, gname); /* execute operation */ else if(del_from_group(sgid, snid) > 0) /* report operation status */ { IRC_User *user = irc_FindUser(nick); send_lang(u, s, NICK_DEL_X_X, nick, gname); if(user) array_del_int(user->extra[ED_GROUPS], sgid); } else send_lang(u, s, UPDATE_FAIL); } else if(strcasecmp(cmd,"INFO") == 0) { /* syntax validation */ if(IsNull(gname)) send_lang(u, s, NS_GROUP_INFO_SYNTAX); /* check requirements */ else if((sgid = find_group(gname)) == 0) send_lang(u, s, NO_SUCH_GROUP_X, gname); /* check privileges */ else if(!is_master(source_snid, sgid) && !is_member_of(source_snid, sgid)) send_lang(u, s, NOT_MASTER_OR_MEMBER_X, gname); else if((sgid = find_group(gname))) /* we need to get the group description */ { /* execute operation */ MYSQL_RES* res; master_sgid = 0; sql_singlequery("SELECT gdesc, master_sgid FROM ns_group WHERE sgid=%d", sgid); send_lang(u, s, NS_GROUP_INFO_X, gname); if(sql_field(0)) send_lang(u, s, NS_GROUP_INFO_DESC_X, sql_field(0)); master_sgid = sql_field_i(1); if(master_sgid != 0) { if(sql_singlequery("SELECT name FROM ns_group WHERE sgid=%d", master_sgid) > 0) { send_lang(u, s, NS_GROUP_INFO_MASTER_X, sql_field(0)); } } res = sql_query("SELECT n.nick, gm.t_expire FROM " "nickserv n, ns_group_users gm WHERE gm.sgid=%d AND n.snid=gm.snid", sgid); if(sql_next_row(res) == NULL) send_lang(u, s, NS_GROUP_EMPTY); else { do { char buf[64]; struct tm *tm; time_t t_expire = sql_field_i(1); buf[0] = '\0'; if(t_expire) { tm = localtime(&t_expire); strftime(buf, sizeof(buf), format_str(u, DATE_FORMAT), tm); send_lang(u,s, NS_GROUP_ITEM_X_X, sql_field(0), buf); } else send_lang(u,s, NS_GROUP_ITEM_X, sql_field(0)); ++memberc; } while(sql_next_row(res)); send_lang(u, s, NS_GROUP_MEMBERS_TAIL_X, memberc); } sql_free(res); } } else if(strcasecmp(cmd,"DROP") == 0) { /* syntax validation */ if(IsNull(gname)) send_lang(u, s, NS_GROUP_DROP_SYNTAX); /* privileges validation */ else if(!is_sroot(source_snid)) send_lang(u, s, NICK_NOT_ROOT); /* check requirements */ else if((sgid = find_group(gname)) == 0) send_lang(u, s, NO_SUCH_GROUP_X, gname); /* NOTE: The following sql_field( depends on previous find_group( */ else if(!sql_field(2) || (master_sgid = atoi(sql_field(2))) == 0) send_lang(u, s, CANT_DROP_ROOT); /* execute operation */ else if(drop_group(sgid)>0) /* report operation status */ send_lang(u, s, NS_GROUP_DROPPED_X, gname); else send_lang(u, s, UPDATE_FAIL); } else if(strcasecmp(cmd,"LIST") == 0) /* List groups */ { MYSQL_RES* res; MYSQL_ROW row; /* privileges validation */ if(!is_sroot(source_snid)) send_lang(u, s, NICK_NOT_ROOT); else { res = sql_query("SELECT name, master_sgid, gdesc FROM ns_group"); send_lang(u, s, NS_GROUP_LIST_HEADER); while((row = sql_next_row(res))) { char* mname = ""; if(row[1] && sql_singlequery("SELECT name FROM ns_group WHERE sgid=%d", atoi(row[1])) > 0) mname = sql_field(0); send_lang(u, s, NS_GROUP_LIST_X_X_X, row[0], mname, row[2] ? row[2] : ""); } send_lang(u, s, NS_GROUP_LIST_TAIL); sql_free(res); } } else if(strcasecmp(cmd,"SHOW") == 0) /* Show groups we belong to */ { /* groups count */ int gc = array_count(u->extra[ED_GROUPS]); if(gc == 0) send_lang(u, s, NO_GROUPS); else { MYSQL_RES *res; MYSQL_ROW row; char buf[64]; struct tm *tm; time_t t_expire; #if 0 int i; u_int32_t* data = array_data_int(u->extra[ED_GROUPS]); #endif send_lang(u, s, NS_GROUP_SHOW_HEADER); #if 0 for(i = 0; i < gc; ++i) { if(sql_singlequery("SELECT name,gdesc FROM ns_group WHERE sgid=%d", data[i]) > 0 ) send_lang(u, s, NS_GROUP_SHOW_X_X, sql_field(0), sql_field(1) ? sql_field(1) : ""); } #endif res = sql_query("SELECT g.name, g.gdesc, gu.t_expire FROM ns_group g, ns_group_users gu" " WHERE gu.snid=%d AND g.sgid=gu.sgid ORDER BY g.master_sgid", source_snid); while((row = sql_next_row(res))) { t_expire = sql_field_i(2); buf[0] = '\0'; if(t_expire) { tm = localtime(&t_expire); strftime(buf, sizeof(buf), format_str(u, DATE_FORMAT), tm); send_lang(u,s, NS_GROUP_SHOW_X_X_X, row[0], row[1] ? row[1] : "", buf); } else send_lang(u, s, NS_GROUP_SHOW_X_X, row[0], row[1] ? row[1] : ""); } send_lang(u, s, NS_GROUP_SHOW_TAIL); sql_free(res); } } else if(strcasecmp(cmd,"SET") == 0) { char *option; char *value ; option = strtok(NULL, " "); value = strtok(NULL, " "); /* syntax validation */ if(IsNull(gname) || IsNull(option)) send_lang(u, s, NS_GROUP_SET_SYNTAX); /* privileges validation */ else if(!is_sroot(source_snid)) send_lang(u, s, NICK_NOT_ROOT); /* check requirements */ else if((sgid = find_group(gname)) == 0) send_lang(u, s, NO_SUCH_GROUP_X, gname); else { if(strcasecmp(option,"AUTOMODES") == 0) STRING_SET("autoumodes", AUTOMODES_X_UNSET, AUTOMODES_X_CHANGED_TO_X) else if(strcasecmp(option,"DESC") == 0) STRING_SET("gdesc", DESC_X_UNSET, DESC_X_CHANGED_TO_X) else if(strcasecmp(option, "MAXUSERS") == 0) INT_SET("maxusers", NS_GROUP_SET_MAXUSERS_SET_X_X) else send_lang(u, s, SET_INVALID_OPTION_X, option); } }
void hc_scheduler_start(hc_tree_opaque_t *services, int port, hc_sequence_callback_t start_cb, void *cookie) { int operation_performed; hc_error_t *error = NULL; hc_service_t *service = NULL; hc_sequence_t *sequence = NULL; hc_service_filter_t filter; _global_datas.running = 1; _global_datas.services = services; _global_datas.server_socket = -1; _global_datas.sequences = hc_list_allocate(NULL); if (!_global_datas.sequences) { cm_trace(CM_TRACE_LEVEL_ERROR, "hc_list_allocate failed. Couldn't create the list of sequences"); return; } _global_datas.errors = hc_list_allocate(NULL); if (!_global_datas.errors) { cm_trace(CM_TRACE_LEVEL_ERROR, "hc_list_allocate failed. Couldn't create a queue for errors"); hc_list_free(_global_datas.sequences, NULL); return; } /* Create the first sequence (starting the SYSTEM services) */ /* hc_monitor_enable_detection(1); */ filter = HC_FILTER_GROUP_SYSTEM | HC_FILTER_NODE_ANYNODE; if (is_master()) { filter |= HC_FILTER_NODE_MASTER; } hc_config_lock(NULL, HC_DOMAIN_ALL, filter, 0); _global_datas.allowed_groups = HC_FILTER_GROUP_SYSTEM; sequence = create_sequence_from_services(hc_scheduler_get_services(), HC_DOMAIN_ALL, filter, start_components_creator, HC_SEQUENCE_EXECUTION_NORMAL, start_cb, cookie, NULL); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the sequence to start the SYSTEM components"); } if (sequence) { hc_scheduler_add_sequence(sequence); sequence = create_sequence_from_services(hc_scheduler_get_services(), HC_DOMAIN_ALL, filter, state_change_creator, HC_SEQUENCE_EXECUTION_NORMAL, NULL, NULL, (void*)SRV_RUNNING); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the sequence to put the SYSTEM components RUNNING"); } else { hc_scheduler_add_sequence(sequence); } } /* Starting the request server */ _global_datas.server_socket = hc_server_start(port); if (_global_datas.server_socket == -1) { cm_trace(CM_TRACE_LEVEL_ERROR, "Failed to start the server"); hc_list_free(_global_datas.sequences, hc_sequence_simple_free); hc_list_free(_global_datas.errors, NULL); return; } cm_trace(CM_TRACE_LEVEL_NOTICE, "The scheduler has been started"); while (_global_datas.running) { operation_performed = 0; operation_performed += schedule_sequences(); if (operation_performed) { cm_trace(CM_TRACE_LEVEL_DEBUG, "Some action have been executed"); } hc_forker_check(_global_datas.errors); hc_monitor_services(_global_datas.errors); error = (hc_error_t*)hc_list_extract_first_element(_global_datas.errors); while (error) { service = (hc_service_t*)hc_tree_get_datas(error->service_node); switch (error->type) { case HC_ERROR_DISABLED_SERVICE: cm_trace(CM_TRACE_LEVEL_DEBUG, "A HC_ERROR_DISABLED_SERVICE has been received for service %s", service->start_cmd); if (service->nb_ongoing_operations == 0) { /* We increase operation_performed not to block at the * scheduler loop and to execute the RESTART sequence * as fast as possible */ operation_performed++; restart_service(error->service_node); } else { cm_trace(CM_TRACE_LEVEL_DEBUG, "Does not restart %s, since there is already an operation affecting it", service->start_cmd); } (int)update_mailbox(); break; default: cm_trace(CM_TRACE_LEVEL_ERROR, "Got an unexpected error report %d", error->type); } hc_error_free(error); error = (hc_error_t*)hc_list_extract_first_element(_global_datas.errors); } if (operation_performed) { cm_trace(CM_TRACE_LEVEL_DEBUG, "Polling server without waiting"); (int)update_mailbox(); hc_server_wait(_global_datas.server_socket, 0); } else { hc_server_wait(_global_datas.server_socket, 500); } } close(_global_datas.server_socket); _global_datas.server_socket = -1; hc_list_free(_global_datas.sequences, hc_sequence_simple_free); _global_datas.sequences = NULL; hc_list_free(_global_datas.errors, NULL); _global_datas.errors = NULL; cmm_dispose(); cm_trace(CM_TRACE_LEVEL_DEBUG, "The scheduler is exiting"); }
static void restart_service(hc_tree_opaque_t *service_node) { hc_service_t *service = (hc_service_t*)hc_tree_get_datas(service_node); hc_sequence_t *sequence = NULL; hc_service_filter_t filter; time_t now; service->restart_current++; if (service->restart_current == service->restart_nb) { service->restart_current = 0; } now = time(NULL); if ((service->restart_times[service->restart_current] == 0) || (now-service->restart_times[service->restart_current] > service->restart_window)) { /* We can restart */ service->restart_times[service->restart_current] = now; cm_trace(CM_TRACE_LEVEL_NOTICE, "Service %s is being restarted", service->start_cmd); filter = _global_datas.allowed_groups | HC_FILTER_NODE_ANYNODE; if (is_master()) { filter |= HC_FILTER_NODE_MASTER; } sequence = create_sequence_from_services(service_node, HC_DOMAIN_PROCESS, filter, stop_components_creator, HC_SEQUENCE_EXECUTION_BOTTOMUP, NULL, NULL, NULL); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the restart sequence"); return; } hc_scheduler_add_sequence(sequence); sequence = create_sequence_from_services(service_node, HC_DOMAIN_PROCESS, filter, start_components_creator, HC_SEQUENCE_EXECUTION_NORMAL, NULL, NULL, NULL); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the restart sequence"); return; } hc_scheduler_add_sequence(sequence); sequence = create_sequence_from_services(service_node, HC_DOMAIN_PROCESS, filter, state_change_creator, HC_SEQUENCE_EXECUTION_NORMAL, NULL, NULL, (void*)SRV_RUNNING); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the restart sequence"); return; } hc_scheduler_add_sequence(sequence); return; } /* We exhausted the restarts, simply stop the service */ cm_trace(CM_TRACE_LEVEL_NOTICE, "***** The service %s cannot be restarted anymore (too many restarts). *****", service->start_cmd); filter = HC_FILTER_GROUP_ALL | HC_FILTER_NODE_ANYNODE; if (is_master()) { filter |= HC_FILTER_NODE_MASTER; } hc_config_lock(service_node, HC_DOMAIN_CHILDREN, filter, 1); sequence = create_sequence_from_services(service_node, HC_DOMAIN_CHILDREN, filter, stop_components_creator, HC_SEQUENCE_EXECUTION_BOTTOMUP, NULL, NULL, NULL); if (!sequence) { cm_trace(CM_TRACE_LEVEL_ERROR, "Couldn't create the stop sequence"); return; } hc_scheduler_add_sequence(sequence); }
static void print(const char *msg, FILE *f) { print0(f, msg); if (is_master(rank)) print0(stderr, msg); }
void Trick::MonteCarlo::set_connection_device_port(int port_number) { // This port is passed to slave as an argument, do not override if (is_master()) { connection_device.port = port_number ; } }
ErrorStack EnginePimpl::initialize_once() { if (is_master()) { CHECK_ERROR(check_valid_options()); } // SOC manager is special. We must initialize it first. CHECK_ERROR(soc_manager_.initialize()); on_module_initialized(kSoc); ErrorStack module_initialize_error = initialize_modules(); if (module_initialize_error.is_error()) { LOG(ERROR) << "*******************************************************************************"; LOG(ERROR) << "*** ERROR while module initailization in " << describe_short() << ". " << module_initialize_error << ""; LOG(ERROR) << "*******************************************************************************"; soc_manager_.report_engine_fatal_error(); CHECK_ERROR(module_initialize_error); } // The following can assume SOC manager is already initialized if (is_master()) { soc::SharedMemoryRepo* repo = soc_manager_.get_shared_memory_repo(); repo->change_master_status(soc::MasterEngineStatus::kRunning); // wait for children's kRunning status // TASK(Hideaki) should be a function in soc manager uint16_t soc_count = engine_->get_options().thread_.group_count_; while (true) { std::this_thread::sleep_for(std::chrono::milliseconds(5)); assorted::memory_fence_acq_rel(); bool error_happened = false; bool remaining = false; for (uint16_t node = 0; node < soc_count; ++node) { soc::ChildEngineStatus* status = repo->get_node_memory_anchors(node)->child_status_memory_; if (status->status_code_ == soc::ChildEngineStatus::kFatalError) { error_happened = true; break; } if (status->status_code_ == soc::ChildEngineStatus::kRunning) { continue; // ok } remaining = true; } if (error_happened) { LOG(ERROR) << "[FOEDUS] ERROR! error while waiting child kRunning"; soc_manager_.report_engine_fatal_error(); return ERROR_STACK(kErrorCodeSocChildInitFailed); } else if (!remaining) { break; } } } LOG(INFO) << "================================================================================"; LOG(INFO) << "================== FOEDUS ENGINE (" << describe_short() << ") INITIALIZATION DONE ==========="; LOG(INFO) << "================================================================================"; // In a few places, we check if we are running under valgrind and, if so, turn off // optimizations valgrind can't handle (eg hugepages). bool running_on_valgrind = RUNNING_ON_VALGRIND; if (running_on_valgrind) { LOG(INFO) << "=============== ATTENTION: VALGRIND MODE! =================="; LOG(INFO) << "This Engine is running under valgrind, which disables several optimizations"; LOG(INFO) << "If you see this message while usual execution, something is wrong."; LOG(INFO) << "=============== ATTENTION: VALGRIND MODE! =================="; } return kRetOk; }
static int hw3d_mmap(struct file *file, struct vm_area_struct *vma) { struct hw3d_info *info = hw3d_info; struct hw3d_data *data = file->private_data; unsigned long vma_size = vma->vm_end - vma->vm_start; int ret = 0; int region = REGION_PAGE_ID(vma->vm_pgoff); if (region >= HW3D_NUM_REGIONS) { pr_err("%s: Trying to mmap unknown region %d\n", __func__, region); return -EINVAL; } else if (vma_size > info->regions[region].size) { pr_err("%s: VMA size %ld exceeds region %d size %ld\n", __func__, vma_size, region, info->regions[region].size); return -EINVAL; } else if (REGION_PAGE_OFFS(vma->vm_pgoff) != 0 || (vma_size & ~PAGE_MASK)) { pr_err("%s: Can't remap part of the region %d\n", __func__, region); return -EINVAL; } else if (!is_master(info, file) && current->group_leader != info->client_task) { pr_err("%s: current(%d) != client_task(%d)\n", __func__, current->group_leader->pid, info->client_task->pid); return -EPERM; } else if (!is_master(info, file) && (info->revoking || info->suspending)) { pr_err("%s: cannot mmap while revoking(%d) or suspending(%d)\n", __func__, info->revoking, info->suspending); return -EPERM; } mutex_lock(&data->mutex); if (data->vmas[region] != NULL) { pr_err("%s: Region %d already mapped (pid=%d tid=%d)\n", __func__, region, current->group_leader->pid, current->pid); ret = -EBUSY; goto done; } #ifdef pgprot_noncached vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); #endif ret = io_remap_pfn_range(vma, vma->vm_start, info->regions[region].pbase >> PAGE_SHIFT, vma_size, vma->vm_page_prot); if (ret) { pr_err("%s: Cannot remap page range for region %d!\n", __func__, region); ret = -EAGAIN; goto done; } if (region != HW3D_REGS) memset(info->regions[region].vbase, 0, info->regions[region].size); vma->vm_ops = &hw3d_vm_ops; data->vmas[region] = vma; done: mutex_unlock(&data->mutex); return ret; }