void init() { mutex_init(&mutex_cli); mutex_init(&mutex_srv); mutex_init(&mutex_pool); cv_init(&cv_cli); cv_init(&cv_srv); msg_queue_init(&queue_pool); msg_queue_init(&queue_cli); msg_queue_init(&queue_srv); msg_init(&msg_pool); msg_queue_add(&mutex_pool, &queue_pool, &msg_pool); }
/* Create a new presentity but do not update database. * If pres_id not set it generates new one, but only if db_mode set. */ static inline int new_presentity_no_wb(struct pdomain *pdomain, str* _uri, str *uid, xcap_query_params_t *xcap_params, str *pres_id, presentity_t** _p) { presentity_t* presentity; int size = 0; dbid_t id; int id_len = 0; char *xcap_param_buffer; if ((!_uri) || (!_p) || (!uid)) { paerrno = PA_INTERNAL_ERROR; ERR("Invalid parameter value\n"); return -1; } if (pres_id) size += pres_id->len; else { if (use_db) { /* do not generate IDs if not using DB */ generate_dbid(id); id_len = dbid_strlen(id); size += id_len; } else id_len = 0; } if (xcap_params) size += get_inline_xcap_buf_len(xcap_params); size += sizeof(presentity_t) + _uri->len + uid->len; presentity = (presentity_t*)mem_alloc(size); /* TRACE("allocating presentity: %d\n", size); */ if (!presentity) { paerrno = PA_NO_MEMORY; LOG(L_ERR, "No memory left: size=%d\n", size); *_p = NULL; return -1; } /* fill whole structure with zeros */ memset(presentity, 0, sizeof(presentity_t)); msg_queue_init(&presentity->mq); presentity->data.uri.s = ((char*)presentity) + sizeof(presentity_t); str_cpy(&presentity->data.uri, _uri); presentity->uuid.s = presentity->data.uri.s + presentity->data.uri.len; str_cpy(&presentity->uuid, uid); presentity->pres_id.s = presentity->uuid.s + presentity->uuid.len; if (pres_id) str_cpy(&presentity->pres_id, pres_id); else { if (use_db) dbid_strcpy(&presentity->pres_id, id, id_len); else presentity->pres_id.len = 0; } xcap_param_buffer = after_str_ptr(&presentity->pres_id); presentity->pdomain = pdomain; if (pa_auth_params.type == auth_xcap) { /* store XCAP parameters for async XCAP queries and refreshing * (FIXME: rewrite - use table of a few of existing XCAP parameter * sets instead of always duplicating because it will be mostly * the same!) */ if (dup_xcap_params_inline(&presentity->xcap_params, xcap_params, xcap_param_buffer) < 0) { ERR("can't duplicate XCAP parameters\n"); shm_free(presentity); *_p = NULL; return -1; } } if (ask_auth_rules(presentity) < 0) { /* try it from timer again if fails here */ presentity->auth_rules_refresh_time = act_time; } else presentity->auth_rules_refresh_time = act_time + auth_rules_refresh_time; *_p = presentity; /* add presentity into domain */ add_presentity(pdomain, *_p); return 0; }
int main(int argc, char *argv[]) { int tmp; /* set progname */ progname = (const char *)strrchr(argv[0], '/'); progname = progname ? (progname + 1) : argv[0]; /* read command line */ cmdline(&argc, &argv); /* set default cfgfile */ if (*cfgfile == '\0') strncpy(cfgfile , DAEMON_CFGFILE, strlen(DAEMON_CFGFILE)); /* read config file */ if (cfg_file_read(cfgfile, cfg, cfglen) == -1) fprintf(stderr, "can't open cfgfile: %s ==> " \ "build in settings will be used\n", cfgfile); /* set unset configuration */ set_unset(); /* print configuration */ if (settings == YES) cfg_print(cfg, cfglen); /* set ebus configuration */ eb_set_nodevicecheck(nodevicecheck); eb_set_rawdump(rawdump); eb_set_showraw(showraw); tmp = (eb_htoi(&address[0])) * 16 + (eb_htoi(&address[1])); eb_set_qq((unsigned char) tmp); eb_set_get_retry(get_retry); eb_set_skip_ack(skip_ack); eb_set_max_wait(max_wait); eb_set_send_retry(send_retry); eb_set_print_size(print_size); /* open log */ log_level(loglevel); log_open(logfile, foreground); /* to be daemon */ if (foreground == NO) { log_print(L_ALL, DAEMON_NAME " " DAEMON_VERSION " started"); syslog(LOG_INFO, DAEMON_NAME " " DAEMON_VERSION " started"); daemonize(); } /* read ebus command configuration files */ if (eb_cmd_dir_read(cfgdir, extension) == -1) log_print(L_WAR, "error during read command file"); /* open raw file */ if (rawdump == YES) { if (eb_raw_file_open(rawfile) == -1) { log_print(L_ALL, "can't open rawfile: %s", rawfile); cleanup(EXIT_FAILURE); } else { log_print(L_INF, "%s opened", rawfile); } } /* open serial device */ if (eb_serial_open(device, &serialfd) == -1) { log_print(L_ALL, "can't open device: %s", device); cleanup(EXIT_FAILURE); } else { log_print(L_INF, "%s opened", device); } /* open listing tcp socket */ if (sock_open(&socketfd, port, localhost) == -1) { log_print(L_ALL, "can't open port: %d", port); cleanup(EXIT_FAILURE); } else { log_print(L_INF, "port %d opened", port); } /* init msg queue */ if (msg_queue_init() == -1) { log_print(L_ALL, "can't initialize msg queue"); cleanup(EXIT_FAILURE); } else { msg_queue_on = YES; log_print(L_INF, "msg queue initialized"); } /* enter main loop */ main_loop(); cleanup(EXIT_SUCCESS); return 0; }
act_t * act_register(reg_frame_t *frame, queue_t *queue, const char *name, status_e create_in_status, act_control_t *parent, size_t base) { (void)parent; KERNEL_TRACE("act", "Registering activation %s", name); if(kernel_next_act >= MAX_ACTIVATIONS) { kernel_panic("no act slot"); } act_t * act = kernel_acts + kernel_next_act; act->image_base = base; //TODO bit of a hack. the kernel needs to know what namespace service to use if(kernel_next_act == namespace_num_namespace) { KERNEL_TRACE("act", "found namespace"); ns_ref = act_create_sealed_ref(act); } #ifndef __LITE__ /* set name */ kernel_assert(ACT_NAME_MAX_LEN > 0); int name_len = 0; if(VCAP(name, 1, VCAP_R)) { name_len = imin(cheri_getlen(name), ACT_NAME_MAX_LEN-1); } for(int i = 0; i < name_len; i++) { char c = name[i]; act->name[i] = c; /* todo: sanitize the name if we do not trust it */ } act->name[name_len] = '\0'; #endif /* set status */ act->status = create_in_status; /*Some "documentation" for the interface between the kernel and activation start * * These fields are setup by the caller of act_register * * * * a0 : user GP argument (goes to main) * * c3 : user Cap argument (goes to main) * * * * These fields are setup by act_register itself. Although the queue is an argument to the function * * * * c21 : self control reference * * c23 : namespace reference (may be null for init and namespace) * * c24 : kernel interface table * * c25 : queue */ /* set namespace */ frame->cf_c21 = (capability)act_create_sealed_ctrl_ref(act); frame->cf_c23 = (capability)ns_ref; frame->cf_c24 = (capability)get_if(); frame->cf_c25 = (capability)queue; /* set queue */ msg_queue_init(act, queue); /* set expected sequence to not expecting */ act->sync_state.sync_token = 0; act->sync_state.sync_condition = 0; /* set scheduling status */ sched_create(act); /*update next_act */ kernel_next_act++; KERNEL_TRACE("register", "image base of %s is %lx", act->name, act->image_base); KERNEL_TRACE("act", "%s OK! ", __func__); return act; }