Exemplo n.º 1
0
/**
 * Malloc a new entry and add it to the list
 * associated to this table. The item identified by
 * the index parameter must not exist in this list.
 */
static struct swrun_entry *
swrun_entry_create(int32_t idx)
{
	struct swrun_entry *entry;

	if ((entry = malloc(sizeof(*entry))) == NULL) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		return (NULL);
	}
	memset(entry, 0, sizeof(*entry));
	entry->index = idx;

	INSERT_OBJECT_INT(entry, &swrun_tbl);
	return (entry);
}
Exemplo n.º 2
0
/**
 * Create entry into the printer table.
 */
static struct printer_entry *
printer_entry_create(const struct device_entry *devEntry)
{
	struct printer_entry *entry = NULL;

	assert(devEntry != NULL);
	if (devEntry == NULL)
		return (NULL);

	if ((entry = malloc(sizeof(*entry))) == NULL) {
		syslog(LOG_WARNING, "hrPrinterTable: %s: %m", __func__);
		return (NULL);
	}
	memset(entry, 0, sizeof(*entry));
	entry->index = devEntry->index;
	INSERT_OBJECT_INT(entry, &printer_tbl);
	return (entry);
}
Exemplo n.º 3
0
/**
 * Create an entry into the FS table and an entry in the map (if needed).
 */
static struct fs_entry *
fs_entry_create(const char *name)
{
	struct fs_entry	*entry;
	struct fs_map_entry *map;

	assert(name != NULL);
	assert(strlen(name) > 0);

	STAILQ_FOREACH(map, &fs_map, link)
		if (strcmp(map->a_name, name) == 0)
			break;

	if (map == NULL) {
		size_t mount_point_len;

		/* new object - get a new index */
		if (next_fs_index > INT_MAX) {
			/* Unrecoverable error - die clean and quicly*/
		        syslog(LOG_ERR, "%s: hrFSTable index wrap", __func__);
			errx(EX_SOFTWARE, "hrFSTable index wrap");
		}

		if ((map = malloc(sizeof(*map))) == NULL) {
			syslog(LOG_ERR, "%s: %m", __func__);
			return (NULL);
		}

		mount_point_len = strlen(name) + 1;
		if (mount_point_len > FS_MP_MLEN)
			mount_point_len = FS_MP_MLEN;

		if ((map->a_name = malloc(mount_point_len)) == NULL) {
			syslog(LOG_ERR, "%s: %m", __func__);
			free(map);
			return (NULL);
		}

		strlcpy(map->a_name, name, mount_point_len);

		map->hrIndex = next_fs_index++;
		map->entry = NULL;
		STAILQ_INSERT_TAIL(&fs_map, map, link);

		HRDBG("%s added into hrFSMap at index=%d", name, map->hrIndex);
	} else {
		HRDBG("%s exists in hrFSMap index=%d", name, map->hrIndex);
	}

	if ((entry = malloc(sizeof(*entry))) == NULL) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		return (NULL);
	}

	if ((entry->mountPoint = strdup(name)) == NULL) {
		syslog(LOG_ERR, "%s: %m", __func__);
		free(entry);
		return (NULL);
	}

	entry->index = map->hrIndex;
	map->entry = entry;

	INSERT_OBJECT_INT(entry, &fs_tbl);
	return (entry);
}
Exemplo n.º 4
0
/**
 * Create a new entry into the storage table and, if necessary, an
 * entry into the storage map.
 */
static struct storage_entry *
storage_entry_create(const char *name)
{
	struct storage_entry *entry;
	struct storage_map_entry *map;
	size_t name_len;

	assert(name != NULL);
	assert(strlen(name) > 0);

	STAILQ_FOREACH(map, &storage_map, link)
		if (strcmp(map->a_name, name) == 0)
			break;

	if (map == NULL) {
		/* new object - get a new index */
		if (next_storage_index > INT_MAX) {
		        syslog(LOG_ERR,
			    "%s: hrStorageTable index wrap", __func__);
			errx(EX_SOFTWARE, "hrStorageTable index wrap");
		}

		if ((map = malloc(sizeof(*map))) == NULL) {
			syslog(LOG_ERR, "hrStorageTable: %s: %m", __func__ );
			return (NULL);
		}

		name_len = strlen(name) + 1;
		if (name_len > SE_DESC_MLEN)
			name_len = SE_DESC_MLEN;

		if ((map->a_name = malloc(name_len)) == NULL) {
			free(map);
			return (NULL);
		}

		strlcpy(map->a_name, name, name_len);
		map->hrIndex = next_storage_index++;

		STAILQ_INSERT_TAIL(&storage_map, map, link);

		HRDBG("%s added into hrStorageMap at index=%d",
		    name, map->hrIndex);
	} else {
		HRDBG("%s exists in hrStorageMap index=%d\n",
		    name, map->hrIndex);
	}

	if ((entry = malloc(sizeof(*entry))) == NULL) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		return (NULL);
	}
        memset(entry, 0, sizeof(*entry));

	entry->index = map->hrIndex;

	if ((entry->descr = strdup(map->a_name)) == NULL) {
		free(entry);
		return (NULL);
	}

	map->entry = entry;

	INSERT_OBJECT_INT(entry, &storage_tbl);

	return (entry);
}
Exemplo n.º 5
0
/**
 * Create a new entry into the hrSWInstalledTable
 */
static struct swins_entry *
swins_entry_create(const char *name)
{
	struct swins_entry *entry;
	struct swins_map_entry *map;

	STAILQ_FOREACH(map, &swins_map, link)
		if (strcmp((const char *)map->name, name) == 0)
			break;

	if (map == NULL) {
		size_t name_len;
		/* new object - get a new index */
		if (next_swins_index > INT_MAX) {
		        syslog(LOG_ERR, "%s: hrSWInstalledTable index wrap",
			    __func__ );
			/* There isn't much we can do here.
			 * If the next_swins_index is consumed
			 * then we can't add entries to this table
			 * So it is better to exit - if the table is sparsed
			 * at the next agent run we can fill it fully.
			 */
			errx(EX_SOFTWARE, "hrSWInstalledTable index wrap");
		}

		if ((map = malloc(sizeof(*map))) == NULL) {
			syslog(LOG_ERR, "%s: %m", __func__ );
			return (NULL);
		}

		name_len = strlen(name) + 1;
		if (name_len > SW_NAME_MLEN)
			 name_len = SW_NAME_MLEN;

		if ((map->name = malloc(name_len)) == NULL) {
			syslog(LOG_WARNING, "%s: %m", __func__);
			free(map);
			return (NULL);
		}

		map->index = next_swins_index++;
		strlcpy((char *)map->name, name, name_len);

		STAILQ_INSERT_TAIL(&swins_map, map, link);

		HRDBG("%s added into hrSWInstalled at %d", name, map->index);
	}

	if ((entry = malloc(sizeof(*entry))) == NULL) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		return (NULL);
	}
	memset(entry, 0, sizeof(*entry));

	if ((entry->name = strdup(map->name)) == NULL) {
		syslog(LOG_WARNING, "%s: %m", __func__);
		free(entry);
		return (NULL);
	}

	entry->index = map->index;
	map->entry = entry;

	INSERT_OBJECT_INT(entry, &swins_tbl);

	return (entry);
}