priod: initialize properly
This commit is contained in:
		
							parent
							
								
									1fa6f95135
								
							
						
					
					
						commit
						f26e6eeba5
					
				
							
								
								
									
										27
									
								
								priod.c
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								priod.c
									
									
									
									
									
								
							| @ -319,6 +319,27 @@ on_exec (struct app_context *ctx, int pid) | |||||||
| 	str_free (&cmdline); | 	str_free (&cmdline); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | static void | ||||||
|  | preapply_rules (struct app_context *ctx) | ||||||
|  | { | ||||||
|  | 	DIR *dir = opendir ("/proc"); | ||||||
|  | 	if (!dir) | ||||||
|  | 	{ | ||||||
|  | 		print_error ("opendir: %s: %s", "/proc", strerror (errno)); | ||||||
|  | 		return; | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
|  | 	// We don't care about processes deleted or created during this loop
 | ||||||
|  | 	struct dirent *iter; | ||||||
|  | 	while ((errno = 0, iter = readdir (dir))) | ||||||
|  | 	{ | ||||||
|  | 		int pid = atoi (iter->d_name); | ||||||
|  | 		if (pid && (iter->d_type == DT_UNKNOWN || iter->d_type == DT_DIR)) | ||||||
|  | 			on_exec (ctx, pid); | ||||||
|  | 	} | ||||||
|  | 	closedir (dir); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| static void | static void | ||||||
| on_netlink_message (struct app_context *ctx, struct nlmsghdr *mh) | on_netlink_message (struct app_context *ctx, struct nlmsghdr *mh) | ||||||
| { | { | ||||||
| @ -522,7 +543,11 @@ main (int argc, char *argv[]) | |||||||
| 	ctx.proc_event.user_data = &ctx; | 	ctx.proc_event.user_data = &ctx; | ||||||
| 	poller_fd_set (&ctx.proc_event, POLLIN); | 	poller_fd_set (&ctx.proc_event, POLLIN); | ||||||
| 
 | 
 | ||||||
| 	// TODO: iterate through current /proc processes and apply politics
 | 	// While new events are being queued, we can apply rules to already
 | ||||||
|  | 	// existing processes, so that we don't miss anything except for obvious
 | ||||||
|  | 	// cases when a process re-execs to something else after a match.
 | ||||||
|  | 	// It would inherit the same values anyway, so it seems to be mostly okay.
 | ||||||
|  | 	preapply_rules (&ctx); | ||||||
| 
 | 
 | ||||||
| 	ctx.polling = true; | 	ctx.polling = true; | ||||||
| 	while (ctx.polling) | 	while (ctx.polling) | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user