static mem_header_t * get_mem_from_pool (unsigned long nquantas) { unsigned long total_req_size; mem_header_t * h; if (nquantas < MIN_POOL_ALLOC_QUANTAS) nquantas = MIN_POOL_ALLOC_QUANTAS; total_req_size = nquantas * sizeof (mem_header_t); if (pool_free_pos + total_req_size <= POOL_SIZE) { h = (mem_header_t *)(pool + pool_free_pos); h->s.size = nquantas; s16mem_free ((void *)(h + 1)); pool_free_pos += total_req_size; } else { return 0; } return freep; }
void pt_destroy (process_tracker_t * pt) { for (pid_list_iterator it = pid_list_begin (pt->pids); it != NULL; pid_list_iterator_next (&it)) { pt_disregard_pid (pt, *it->val); free (it->val); } List_destroy (pt->pids); s16mem_free (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; }
void unit_deregister_pid (unit_t * unit, pid_t pid) { for (pid_list_iterator it = pid_list_begin (unit->pids); it != NULL; pid_list_iterator_next (&it)) { if (*it->val == pid) { pid_t * tofree = it->val; pid_list_del (unit->pids, it->val); pt_disregard_pid (Manager.ptrack, pid); s16mem_free (tofree); return; } } }
void pt_disregard_pid (process_tracker_t * pt, pid_t pid) { pid_list_iterator it; for (it = pid_list_begin (pt->pids); it != NULL; pid_list_iterator_next (&it)) { if (*it->val == pid) { s16mem_free (it->val); pid_list_del (pt->pids, it->val); break; } } return; }