Example #1
0
// add interface to shm file
void bandwidth_shm_set(pid_t pid, const char *dev, int down, int up) {
	// create bandwidth directory & file in case they are not in the filesystem yet
	shm_create_firejail_dir();
	shm_create_bandwidth_file(pid);

	// create the new text entry
	char *txt;
	if (asprintf(&txt, "%s: RX %dKB/s, TX %dKB/s", dev, down, up) == -1)
		errExit("asprintf");
	
	// read bandwidth file
	shm_read_bandwidth_file(pid);

	// look for an existing entry and replace the text
	IFBW *ptr = ifbw_find(dev);
	if (ptr) {
		assert(ptr->txt);
		free(ptr->txt);
		ptr->txt = txt;
	}
	// ... or add a new entry
	else {
		IFBW *ifbw_new = malloc(sizeof(IFBW));
		if (!ifbw_new)
			errExit("malloc");
		memset(ifbw_new, 0, sizeof(IFBW));
		ifbw_new->txt = txt;
		
		// add it to the linked list
		ifbw_add(ifbw_new);
	}
	shm_write_bandwidth_file(pid) ;
}
Example #2
0
// remove interface from run file
void bandwidth_remove(pid_t pid, const char *dev) {
	bandwidth_create_run_file(pid);
	
	// read bandwidth file
	read_bandwidth_file(pid);
	
	// find the element and remove it
	IFBW *elem = ifbw_find(dev);
	if (elem) {
		ifbw_remove(elem);
		write_bandwidth_file(pid) ;
	}
	
	// remove the file if there are no entries in the list
	if (ifbw == NULL) {
		 bandwidth_del_run_file(pid);
	}
}
Example #3
0
// remove interface from shm file
void bandwidth_shm_remove(pid_t pid, const char *dev) {
	// create bandwidth directory & file in case they are not in the filesystem yet
	shm_create_firejail_dir();
	shm_create_bandwidth_file(pid);
	
	// read bandwidth file
	shm_read_bandwidth_file(pid);
	
	// find the element and remove it
	IFBW *elem = ifbw_find(dev);
	if (elem) {
		ifbw_remove(elem);
		shm_write_bandwidth_file(pid) ;
	}
	
	// remove the file if there are no entries in the list
	if (ifbw == NULL) {
		bandwidth_shm_del_file(pid);
	}
}