Exemple #1
0
void free_header_list(flist_t * list, int method)
{
	flist_node_t   *node = flist_head(list), *node2;
	while (node) {
		struct headers_data *data = flist_data(node);
		node2 = flist_next(node);

		if (method == FLIST_FREE_DATA) {
			free(data->header);
			free(data);
		}

		free(node);
		node = node2;
	}
}
Exemple #2
0
static void mapid_shutdown(int data) {
	flist_node_t *cur;
	struct client *cl;
	mapidrv *drv = drvlist;

	/* espenb TODO: use lock mechanisms instead 
	 * each thread receives signals, only one thread must execute
	 * shutdown, only one shutdown necessary
	 */
	if (running_shutdown != 0)
		return;
	running_shutdown = 1;

	//we don't want funny things to happen while freeing memory
	signal(SIGTERM, SIG_IGN);
	signal(SIGQUIT, SIG_IGN);
	signal(SIGINT, SIG_IGN);

	printf("Closing operations\n");
	//Unload drivers
	while (drv) {
		drvlist = drvlist->next;
		mapidrv_delete_device = get_drv_funct(drv->handle,
				"mapidrv_delete_device");
		if (mapidrv_delete_device)
			mapidrv_delete_device(drv->devid);

		/* if we close, we lose the symbol information associated with drivers 
		 * when running valgrind.
		 */
#ifndef VALGRIND
		printf("!!dlclose\n");
		dlclose(drv->handle);
#endif
		free(drv->device);
		if (drv->description!=NULL)
			free(drv->description);
		if (drv->name)
			free(drv->name);
		//if(drv->alias != NULL)
		//free(drv->alias);
		free(drv);
		drv = drvlist;
	}

	//Remove flowlist
	flist_destroy(flowlist);
	free(flowlist);

	//Remove clientlist
	cur = flist_head(clientlist);
	while (cur) {
		cl = flist_data(cur);
		flist_destroy(cl->flowlist);
		free(cl->flowlist);
		cur = flist_next(cur);
	}
	flist_destroy(clientlist);
	free(clientlist);

	free(gflist->fflist);
	free(gflist);
	free(mapidsocket);
	free(mapid_conf);

	if (log_to_file) {
		daemon_terminated(log_fd_info, "MAPID", daemonize, 0);
		daemon_terminated(log_fd_debug, "MAPID", daemonize, 0);
	}

	if (log_to_syslog) {
		log_message("MAPID was terminated %s%s",
				daemonize ? " ( was running as daemon )" : "");
		closelog(); // closes the descriptor being used to write to the system logger
	}
	//release socket resources
	unlink(mapidsocket);
	close(listenerfd);
	close(newfd);

	running_shutdown = 2;
	printf("mapid terminated\n");
	exit((data == 0) ? EXIT_FAILURE : EXIT_SUCCESS);
}