Fix missing path concatination
This commit is contained in:
		
							parent
							
								
									0c13c03a73
								
							
						
					
					
						commit
						ce59bb364f
					
				
					 1 changed files with 19 additions and 5 deletions
				
			
		
							
								
								
									
										24
									
								
								src/config.c
									
										
									
									
									
								
							
							
						
						
									
										24
									
								
								src/config.c
									
										
									
									
									
								
							| 
						 | 
					@ -348,20 +348,34 @@ config_load_directory(config_t *config, const char *directory_name)
 | 
				
			||||||
        exit(1);
 | 
					        exit(1);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Process each entry.
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    while((directory_entry = readdir(directory)) != NULL)
 | 
					    while((directory_entry = readdir(directory)) != NULL)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        struct stat sb;
 | 
					        struct stat sb;
 | 
				
			||||||
        const char *entry_name = directory_entry->d_name;
 | 
					        const char *entry_name = directory_entry->d_name;
 | 
				
			||||||
        if(stat(entry_name, &sb))
 | 
					
 | 
				
			||||||
 | 
					        size_t copied = 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // Add 2 for '/' and '\0'.
 | 
				
			||||||
 | 
					        size_t path_size = strlen(directory_name) + strlen(entry_name) + 2;
 | 
				
			||||||
 | 
					        char *path = malloc(sizeof(char) * path_size);
 | 
				
			||||||
 | 
					        path[0] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        copied += strlcat(path + copied, directory_name, path_size - copied);
 | 
				
			||||||
 | 
					        if(path[copied - 1] != '/')
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            LOGGER_WARNING("failed to get info for '%s': %s\n", entry_name, strerror(errno));
 | 
					            copied += strlcat(path + copied, "/", path_size - copied);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        copied += strlcat(path + copied, entry_name, path_size - copied);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(stat(path, &sb))
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            LOGGER_WARNING("failed to get info for '%s': %s\n", path, strerror(errno));
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        if(S_ISREG(sb.st_mode))
 | 
					        if(S_ISREG(sb.st_mode))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            config_load_file(config, entry_name);
 | 
					            config_load_file(config, path);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					        free(path);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Close directory and exit.
 | 
					    // Close directory and exit.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue