static void services_changed(GVariant *params) { connman_service_t *prev = NULL, *cs; GVariant *del = g_variant_get_child_value(params, 1); for(int i = 0, n = g_variant_n_children(del); i < n; i++) { GVariant *v = g_variant_get_child_value(del, i); if(g_variant_type_equal(g_variant_get_type(v), G_VARIANT_TYPE_OBJECT_PATH)) { const char *name = g_variant_get_string(v, NULL); TRACE(TRACE_DEBUG, "CONNMAN", "Deleted network %s", name); if((cs = connman_service_find(name)) != NULL) connman_service_destroy(cs); } } GVariant *add = g_variant_get_child_value(params, 0); for(int i = 0, n = g_variant_n_children(add); i < n; i++) { GVariant *v = g_variant_get_child_value(add, i); const char *id = g_variant_get_string(g_variant_get_child_value(v, 0), NULL); cs = update_service(g_variant_get_child_value(v, 1), id, prev); if(cs != NULL) prev = cs; } }
static gboolean on_delayed_unit_new_timeout (gpointer user_data) { DelayedUnitNewData *data = user_data; update_service (data->services, data->object_path); g_hash_table_remove (data->services->delayed_unit_news, data->object_path); return FALSE; }
void MessageQueueService::handle_CimServicePause(CimServicePause *req) { // set the paused bit and update _capabilities |= module_capabilities::paused; update_service(_capabilities, _mask); _make_response(req, async_results::CIM_PAUSED); // now tell the meta dispatcher we are stopped }
void MessageQueueService::handle_CimServiceResume(CimServiceResume *req) { // clear the paused bit and update _capabilities &= (~(module_capabilities::paused)); update_service(_capabilities, _mask); _make_response(req, async_results::OK); // now tell the meta dispatcher we are stopped }
void MessageQueueService::handle_CimServiceStop(CimServiceStop *req) { #ifdef MESSAGEQUEUESERVICE_DEBUG PEGASUS_STD(cout) << getQueueName() << "received STOP" << PEGASUS_STD(endl); #endif // set the stopeed bit and update _capabilities |= module_capabilities::stopped; _make_response(req, async_results::CIM_STOPPED); // now tell the meta dispatcher we are stopped update_service(_capabilities, _mask); }
/****************************************************************************** * * * Function: process_check * * * * Purpose: check if service is avaiable and update database * * * * Parameters: service - service info * * * * Return value: * * * * Author: Eugene Grigorjev * * * * Comments: * * * ******************************************************************************/ static void process_check(DB_DRULE *rule, DB_DCHECK *check, char *ip) { int port, first, last; char *curr_range = NULL, *next_range = NULL, *last_port = NULL; assert(rule); assert(check); assert(ip); zabbix_log(LOG_LEVEL_DEBUG, "In process_check(ip:%s, ports:%s, type:%d)", ip, check->ports, check->type); for ( curr_range = check->ports; curr_range; curr_range = next_range ) { /* split by ',' */ if ( (next_range = strchr(curr_range, ',')) ) { *next_range = '\0'; } if ( (last_port = strchr(curr_range, '-')) ) { /* split by '-' */ *last_port = '\0'; first = atoi(curr_range); last = atoi(last_port); *last_port = '-'; } else { first = last = atoi(curr_range); } if ( next_range ) { *next_range = ','; next_range++; } for ( port = first; port <= last; port++) { check->status = discover_service(check,ip,port); update_service(rule, check, ip, port); } } zabbix_log(LOG_LEVEL_DEBUG, "End process_check()"); }
void MessageQueueService::handle_CimServiceStart(CimServiceStart *req) { #ifdef MESSAGEQUEUESERVICE_DEBUG PEGASUS_STD(cout) << getQueueName() << "received START" << PEGASUS_STD(endl); #endif // clear the stoped bit and update _capabilities &= (~(module_capabilities::stopped)); _make_response(req, async_results::OK); // now tell the meta dispatcher we are stopped update_service(_capabilities, _mask); }
static void on_systemd_properties_changed (GDBusConnection *connection, const gchar *sender_name, const gchar *object_path, const gchar *interface_name, const gchar *signal_name, GVariant *parameters, gpointer user_data) { Services *services = user_data; const gchar *prop_interface; g_variant_get (parameters, "(&sa{sv}as)", &prop_interface, NULL, NULL); if (strcmp (prop_interface, "org.freedesktop.systemd1.Unit") == 0) update_service (services, object_path); }
static void manager_property_changed(DBusGProxy *proxy, const char *property, GValue *value, gpointer user_data) { if (property == NULL || value == NULL) return; if (g_str_equal(property, "Services") == TRUE) { gchar *path = NULL; dbus_g_type_collection_value_iterate(value, iterate_list, &path); update_service(proxy, path); g_free(path); } }
/*===========================================================================* * sef_cb_init_restart * *===========================================================================*/ static int sef_cb_init_restart(int type, sef_init_info_t *info) { /* Restart the reincarnation server. */ int r; struct rproc *old_rs_rp, *new_rs_rp; assert(info->endpoint == RS_PROC_NR); /* Perform default state transfer first. */ r = SEF_CB_INIT_RESTART_STATEFUL(type, info); if(r != OK) { printf("SEF_CB_INIT_RESTART_STATEFUL failed: %d\n", r); return r; } /* New RS takes over. */ old_rs_rp = rproc_ptr[_ENDPOINT_P(RS_PROC_NR)]; new_rs_rp = rproc_ptr[_ENDPOINT_P(info->old_endpoint)]; if(rs_verbose) printf("RS: %s is the new RS after restart\n", srv_to_string(new_rs_rp)); /* If an update was in progress, end it. */ if(SRV_IS_UPDATING(old_rs_rp)) { end_update(ERESTART, RS_REPLY); } /* Update the service into the replica. */ r = update_service(&old_rs_rp, &new_rs_rp, RS_DONTSWAP, 0); if(r != OK) { printf("update_service failed: %d\n", r); return r; } /* Initialize the new RS instance. */ r = init_service(new_rs_rp, SEF_INIT_RESTART, 0); if(r != OK) { printf("init_service failed: %d\n", r); return r; } /* Reschedule a synchronous alarm for the next period. */ if (OK != (r=sys_setalarm(RS_DELTA_T, 0))) panic("couldn't set alarm: %d", r); return OK; }
/*===========================================================================* * sef_cb_init_lu * *===========================================================================*/ static int sef_cb_init_lu(int type, sef_init_info_t *info) { /* Start a new version of the reincarnation server. */ int r; struct rproc *old_rs_rp, *new_rs_rp; assert(info->endpoint == RS_PROC_NR); /* Perform default state transfer first. */ sef_setcb_init_restart(SEF_CB_INIT_RESTART_STATEFUL); r = SEF_CB_INIT_LU_DEFAULT(type, info); if(r != OK) { printf("SEF_CB_INIT_LU_DEFAULT failed: %d\n", r); return r; } /* New RS takes over. */ old_rs_rp = rproc_ptr[_ENDPOINT_P(RS_PROC_NR)]; new_rs_rp = rproc_ptr[_ENDPOINT_P(info->old_endpoint)]; if(rs_verbose) printf("RS: %s is the new RS after live update\n", srv_to_string(new_rs_rp)); /* Update the service into the replica. */ r = update_service(&old_rs_rp, &new_rs_rp, RS_DONTSWAP, 0); if(r != OK) { printf("update_service failed: %d\n", r); return r; } /* Check if everything is as expected. */ assert(RUPDATE_IS_UPDATING()); assert(RUPDATE_IS_INITIALIZING()); assert(rupdate.num_rpupds > 0); assert(rupdate.num_init_ready_pending > 0); return OK; }
static void connman_getservices(GDBusProxy *connman) { GError *err = NULL; GVariant *v = g_dbus_proxy_call_sync(connman, "GetServices", NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &err); if(v == NULL) { TRACE(TRACE_ERROR, "CONNMAN", "Unable to GetServices -- %s", err->message); g_error_free(err); return; } GVariant *list = g_variant_get_child_value(v, 0); connman_service_t *prev = NULL, *cs; if(list != NULL) { prop_destroy_childs(service_nodes); int num_services = g_variant_n_children(list); for(int i = 0; i < num_services; i++) { GVariant *svc = g_variant_get_child_value(list, i); const char *path = g_variant_get_string(g_variant_get_child_value(svc, 0), NULL); cs = update_service(g_variant_get_child_value(svc, 1), path, prev); if(cs != NULL) prev = cs; } } g_variant_unref(v); }
/*===========================================================================* * sef_cb_init_fresh * *===========================================================================*/ PRIVATE int sef_cb_init_fresh(int type, sef_init_info_t *info) { /* Initialize the reincarnation server. */ struct boot_image *ip; int s,i; int nr_image_srvs, nr_image_priv_srvs, nr_uncaught_init_srvs; struct rproc *rp; struct rproc *replica_rp; struct rprocpub *rpub; struct boot_image image[NR_BOOT_PROCS]; struct boot_image_priv *boot_image_priv; struct boot_image_sys *boot_image_sys; struct boot_image_dev *boot_image_dev; int pid, replica_pid; endpoint_t replica_endpoint; int ipc_to; int *calls; int all_c[] = { ALL_C, NULL_C }; int no_c[] = { NULL_C }; /* See if we run in verbose mode. */ env_parse("rs_verbose", "d", 0, &rs_verbose, 0, 1); if ((s = sys_getinfo(GET_HZ, &system_hz, sizeof(system_hz), 0, 0)) != OK) panic("Cannot get system timer frequency\n"); /* Initialize the global init descriptor. */ rinit.rproctab_gid = cpf_grant_direct(ANY, (vir_bytes) rprocpub, sizeof(rprocpub), CPF_READ); if(!GRANT_VALID(rinit.rproctab_gid)) { panic("unable to create rprocpub table grant: %d", rinit.rproctab_gid); } /* Initialize some global variables. */ rupdate.flags = 0; shutting_down = FALSE; /* Get a copy of the boot image table. */ if ((s = sys_getimage(image)) != OK) { panic("unable to get copy of boot image table: %d", s); } /* Determine the number of system services in the boot image table. */ nr_image_srvs = 0; for(i=0;i<NR_BOOT_PROCS;i++) { ip = &image[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(ip->endpoint))) { continue; } nr_image_srvs++; } /* Determine the number of entries in the boot image priv table and make sure * it matches the number of system services in the boot image table. */ nr_image_priv_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } nr_image_priv_srvs++; } if(nr_image_srvs != nr_image_priv_srvs) { panic("boot image table and boot image priv table mismatch"); } /* Reset the system process table. */ for (rp=BEG_RPROC_ADDR; rp<END_RPROC_ADDR; rp++) { rp->r_flags = 0; rp->r_pub = &rprocpub[rp - rproc]; rp->r_pub->in_use = FALSE; } /* Initialize the system process table in 4 steps, each of them following * the appearance of system services in the boot image priv table. * - Step 1: set priviliges, sys properties, and dev properties (if any) * for every system service. */ for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding entries in other tables. */ boot_image_info_lookup(boot_image_priv->endpoint, image, &ip, NULL, &boot_image_sys, &boot_image_dev); rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* * Set privileges. */ /* Get label. */ strcpy(rpub->label, boot_image_priv->label); /* Force a static priv id for system services in the boot image. */ rp->r_priv.s_id = static_priv_id( _ENDPOINT_P(boot_image_priv->endpoint)); /* Initialize privilege bitmaps and signal manager. */ rp->r_priv.s_flags = boot_image_priv->flags; /* priv flags */ rp->r_priv.s_trap_mask= SRV_OR_USR(rp, SRV_T, USR_T); /* traps */ ipc_to = SRV_OR_USR(rp, SRV_M, USR_M); /* targets */ fill_send_mask(&rp->r_priv.s_ipc_to, ipc_to == ALL_M); rp->r_priv.s_sig_mgr= SRV_OR_USR(rp, SRV_SM, USR_SM); /* sig mgr */ rp->r_priv.s_bak_sig_mgr = NONE; /* backup sig mgr */ /* Initialize kernel call mask bitmap. */ calls = SRV_OR_USR(rp, SRV_KC, USR_KC) == ALL_C ? all_c : no_c; fill_call_mask(calls, NR_SYS_CALLS, rp->r_priv.s_k_call_mask, KERNEL_CALL, TRUE); /* Set the privilege structure. */ if(boot_image_priv->endpoint != RS_PROC_NR) { if ((s = sys_privctl(ip->endpoint, SYS_PRIV_SET_SYS, &(rp->r_priv))) != OK) { panic("unable to set privilege structure: %d", s); } } /* Synch the privilege structure with the kernel. */ if ((s = sys_getpriv(&(rp->r_priv), ip->endpoint)) != OK) { panic("unable to synch privilege structure: %d", s); } /* * Set sys properties. */ rpub->sys_flags = boot_image_sys->flags; /* sys flags */ /* * Set dev properties. */ rpub->dev_flags = boot_image_dev->flags; /* device flags */ rpub->dev_nr = boot_image_dev->dev_nr; /* major device number */ rpub->dev_style = boot_image_dev->dev_style; /* device style */ rpub->dev_style2 = boot_image_dev->dev_style2; /* device style 2 */ /* Get process name. */ strcpy(rpub->proc_name, ip->proc_name); /* Build command settings. */ rp->r_cmd[0]= '\0'; rp->r_script[0]= '\0'; build_cmd_dep(rp); /* Initialize vm call mask bitmap. */ calls = SRV_OR_USR(rp, SRV_VC, USR_VC) == ALL_C ? all_c : no_c; fill_call_mask(calls, NR_VM_CALLS, rpub->vm_call_mask, VM_RQ_BASE, TRUE); /* Scheduling parameters. */ rp->r_scheduler = SRV_OR_USR(rp, SRV_SCH, USR_SCH); rp->r_priority = SRV_OR_USR(rp, SRV_Q, USR_Q); rp->r_quantum = SRV_OR_USR(rp, SRV_QT, USR_QT); /* Get some settings from the boot image table. */ rpub->endpoint = ip->endpoint; /* Set some defaults. */ rp->r_old_rp = NULL; /* no old version yet */ rp->r_new_rp = NULL; /* no new version yet */ rp->r_prev_rp = NULL; /* no prev replica yet */ rp->r_next_rp = NULL; /* no next replica yet */ rp->r_uid = 0; /* root */ rp->r_check_tm = 0; /* not checked yet */ getuptime(&rp->r_alive_tm); /* currently alive */ rp->r_stop_tm = 0; /* not exiting yet */ rp->r_restarts = 0; /* no restarts so far */ rp->r_period = 0; /* no period yet */ rp->r_exec = NULL; /* no in-memory copy yet */ rp->r_exec_len = 0; /* Mark as in use and active. */ rp->r_flags = RS_IN_USE | RS_ACTIVE; rproc_ptr[_ENDPOINT_P(rpub->endpoint)]= rp; rpub->in_use = TRUE; } /* - Step 2: allow every system service in the boot image to run. */ nr_uncaught_init_srvs = 0; for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* RS is already running as we speak. */ if(boot_image_priv->endpoint == RS_PROC_NR) { if ((s = init_service(rp, SEF_INIT_FRESH)) != OK) { panic("unable to initialize RS: %d", s); } continue; } /* Allow the service to run. */ if ((s = sched_init_proc(rp)) != OK) { panic("unable to initialize scheduling: %d", s); } if ((s = sys_privctl(rpub->endpoint, SYS_PRIV_ALLOW, NULL)) != OK) { panic("unable to initialize privileges: %d", s); } /* Initialize service. We assume every service will always get * back to us here at boot time. */ if(boot_image_priv->flags & SYS_PROC) { if ((s = init_service(rp, SEF_INIT_FRESH)) != OK) { panic("unable to initialize service: %d", s); } if(rpub->sys_flags & SF_SYNCH_BOOT) { /* Catch init ready message now to synchronize. */ catch_boot_init_ready(rpub->endpoint); } else { /* Catch init ready message later. */ nr_uncaught_init_srvs++; } } } /* - Step 3: let every system service complete initialization by * catching all the init ready messages left. */ while(nr_uncaught_init_srvs) { catch_boot_init_ready(ANY); nr_uncaught_init_srvs--; } /* - Step 4: all the system services in the boot image are now running. * Complete the initialization of the system process table in collaboration * with other system services. */ for (i=0; boot_image_priv_table[i].endpoint != NULL_BOOT_NR; i++) { boot_image_priv = &boot_image_priv_table[i]; /* System services only. */ if(iskerneln(_ENDPOINT_P(boot_image_priv->endpoint))) { continue; } /* Lookup the corresponding slot in the system process table. */ rp = &rproc[boot_image_priv - boot_image_priv_table]; rpub = rp->r_pub; /* Get pid from PM. */ rp->r_pid = getnpid(rpub->endpoint); if(rp->r_pid == -1) { panic("unable to get pid"); } } /* Set alarm to periodically check service status. */ if (OK != (s=sys_setalarm(RS_DELTA_T, 0))) panic("couldn't set alarm: %d", s); /* Now create a new RS instance with a private page table and let the current * instance live update into the replica. Clone RS' own slot first. */ rp = rproc_ptr[_ENDPOINT_P(RS_PROC_NR)]; if((s = clone_slot(rp, &replica_rp)) != OK) { panic("unable to clone current RS instance: %d", s); } /* Fork a new RS instance. */ pid = srv_fork(); if(pid == -1) { panic("unable to fork a new RS instance"); } replica_pid = pid ? pid : getpid(); replica_endpoint = getnprocnr(replica_pid); replica_rp->r_pid = replica_pid; replica_rp->r_pub->endpoint = replica_endpoint; if(pid == 0) { /* New RS instance running. */ /* Live update the old instance into the new one. */ s = update_service(&rp, &replica_rp, RS_SWAP); if(s != OK) { panic("unable to live update RS: %d", s); } cpf_reload(); /* Clean up the old RS instance, the new instance will take over. */ cleanup_service(rp); /* Map out our own text and data. */ unmap_ok = 1; _minix_unmapzero(); /* Ask VM to pin memory for the new RS instance. */ if((s = vm_memctl(RS_PROC_NR, VM_RS_MEM_PIN)) != OK) { panic("unable to pin memory for the new RS instance: %d", s); } } else { /* Old RS instance running. */ /* Set up privileges for the new instance and let it run. */ s = sys_privctl(replica_endpoint, SYS_PRIV_SET_SYS, &(replica_rp->r_priv)); if(s != OK) { panic("unable to set privileges for the new RS instance: %d", s); } if ((s = sched_init_proc(replica_rp)) != OK) { panic("unable to initialize RS replica scheduling: %d", s); } s = sys_privctl(replica_endpoint, SYS_PRIV_YIELD, NULL); if(s != OK) { panic("unable to yield control to the new RS instance: %d", s); } NOT_REACHABLE; } return(OK); }