process_tracker_t * pt_new (int kq) { process_tracker_t * pt = s16mem_alloc (sizeof (process_tracker_t)); pt->kq = kq; pt->pids = List_new (); return pt; }
unit_t * unit_new (svc_t * svc, svc_instance_t * inst) { #define CompareType(typ) \ !strcasecmp (svc_object_get_property_string (svc, "Unit.Strategy"), typ) unit_t * unitnew = s16mem_alloc (sizeof (unit_t)); unitnew->name = inst_object_get_property_string (inst, "S16.FMRI"); unitnew->state = S_OFFLINE; unitnew->svc = svc; unitnew->inst = inst; unitnew->timer_id = 0; unitnew->main_pid = 0; unitnew->rtype = R_YES; unitnew->state = S_OFFLINE; unitnew->pids = List_new (); if (!unitnew->pids) { fprintf (stderr, "unit alloc! (%s pids)\n", inst_object_get_property_string (inst, "S16.FMRI")); return 0; } if (CompareType ("exec")) unitnew->type = T_EXEC; else if (CompareType ("forks")) unitnew->type = T_FORKS; else if (CompareType ("oneshot")) unitnew->type = T_ONESHOT; else { fprintf (stderr, "Unit <%s> lacks a known type\n", unitnew->name); List_destroy (unitnew->pids); s16mem_free (unitnew); return 0; } unitnew->method[M_PRESTART] = svc_object_get_property_string (svc, "Method.Prestart"); unitnew->method[M_START] = svc_object_get_property_string (svc, "Method.Start"); unitnew->method[M_POSTSTART] = svc_object_get_property_string (svc, "Method.Poststart"); unitnew->method[M_STOP] = svc_object_get_property_string (svc, "Method.Stop"); unitnew->timeout_secs = 12; fprintf (stderr, "[%s] new unit formed\n", unitnew->name); return unitnew; }
svc_instance_t * rpc_svc_instance_to_svc_instance (rpc_svc_instance_t * rinst) { RETURN_IF_NULL (rinst); svc_instance_t * newInst = s16mem_alloc (sizeof (svc_instance_t)); newInst->id = rinst->id; newInst->name = s16mem_strdup (rinst->name); newInst->svc_id = rinst->svc_id; newInst->properties = rpc_property_array_to_property_list ( rinst->properties.properties_val, rinst->properties.properties_len); return newInst; }
property_t * rpc_property_to_property (rpc_property_t * rprop) { RETURN_IF_NULL (rprop); property_t * newProp = s16mem_alloc (sizeof (property_t)); newProp->id = rprop->id; newProp->name = s16mem_strdup (rprop->name); newProp->value.type = rprop->value.type; if (rprop->value.type == STRING) newProp->value.pval_u.s = s16mem_strdup (rprop->value.pval_u.s); else newProp->value.pval_u.i = rprop->value.pval_u.i; return newProp; }
int i_config_subscribe_status (int p, svc_id_t id, svc_id_t i_id) { sub_config_sub_t * conf; subscriber_t * sub = i_subscriber_find_by_port (p); if (!sub) return 1; conf = s16mem_alloc (sizeof (sub_config_sub_t)); conf->id = id; conf->i_id = i_id; conf->status_only = 1; config_sub_list_add (sub->config_subs, conf); return 0; }
pt_info_t * pt_investigate_kevent (process_tracker_t * pt, struct kevent * ke) { pt_info_t * result; pt_info_t info; if (ke->filter != EVFILT_SIGNAL) return 0; if (ke->ident == SIGCHLD) { info.event = PT_EXIT; info.pid = waitpid ((pid_t) (-1), (int *)&info.flags, WNOHANG); info.ppid = 0; } else return 0; result = s16mem_alloc (sizeof (pt_info_t)); *result = info; return result; }
static pid_t * pid_new_p (pid_t val) { pid_t * res = s16mem_alloc (sizeof (pid_t)); *res = val; return res; }
char * s16mem_strdup (const char * str) { size_t len = strlen (str) + 1; void * ptr = s16mem_alloc (len); return (char *)memcpy (ptr, str, len); }
void * s16mem_calloc (size_t cnt, unsigned long nbytes) { void * ptr = s16mem_alloc (cnt * nbytes); return memset (ptr, '\0', cnt * nbytes); }
void unit_register_pid (unit_t * unit, pid_t pid) { pid_t * rpid = s16mem_alloc (sizeof (pid_t)); *rpid = pid; pid_list_add (unit->pids, rpid); }