ujail: remove "#include log.h" from elf.h
[project/procd.git] / jail / elf.c
index c19859987b8093de05fd3ba3d6d76889b182ef40..5e22606478d1fedd521b0adfac93e2f4dbcff70d 100644 (file)
  */
 
 #define _GNU_SOURCE
-#include <sys/syscall.h>
 #include <sys/mman.h>
-#include <sys/utsname.h>
-#include <sys/types.h>
-#include <sys/wait.h>
 
 #include <stdlib.h>
 #include <unistd.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
-#include <sys/mount.h>
-#include <values.h>
-#include <errno.h>
-#include <stdio.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <syslog.h>
 #include <libgen.h>
 #include <glob.h>
 #include <elf.h>
 
-#include <libubox/avl.h>
-#include <libubox/avl-cmp.h>
 #include <libubox/utils.h>
-#include <libubox/list.h>
-#include <libubox/uloop.h>
 
 #include "elf.h"
+#include "log.h"
 
 struct avl_tree libraries;
 static LIST_HEAD(library_paths);
 
 void alloc_library_path(const char *path)
 {
+       struct stat s;
+       if (stat(path, &s))
+               return;
+
        struct library_path *p;
        char *_path;
 
@@ -79,7 +69,7 @@ static void alloc_library(const char *path, const char *name)
        DEBUG("adding library %s/%s\n", path, name);
 }
 
-static int elf_open(char **dir, char *file)
+static int elf_open(char **dir, const char *file)
 {
        struct library_path *p;
        char path[256];
@@ -105,7 +95,7 @@ static int elf_open(char **dir, char *file)
        return fd;
 }
 
-char* find_lib(char *file)
+const char* find_lib(const char *file)
 {
        struct library *l;
        static char path[256];
@@ -124,7 +114,7 @@ char* find_lib(char *file)
        return path;
 }
 
-static int elf64_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf64_find_section(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
 {
        Elf64_Ehdr *e;
        Elf64_Phdr *ph;
@@ -147,7 +137,7 @@ static int elf64_find_section(char *map, unsigned int type, unsigned int *offset
        return -1;
 }
 
-static int elf32_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf32_find_section(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
 {
        Elf32_Ehdr *e;
        Elf32_Phdr *ph;
@@ -170,7 +160,7 @@ static int elf32_find_section(char *map, unsigned int type, unsigned int *offset
        return -1;
 }
 
-static int elf_find_section(char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
+static int elf_find_section(const char *map, unsigned int type, unsigned int *offset, unsigned int *size, unsigned int *vaddr)
 {
        int clazz = map[EI_CLASS];
 
@@ -184,10 +174,10 @@ static int elf_find_section(char *map, unsigned int type, unsigned int *offset,
        return -1;
 }
 
-static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset)
+static int elf32_scan_dynamic(const char *map, int dyn_offset, int dyn_size, int load_offset)
 {
        Elf32_Dyn *dynamic = (Elf32_Dyn *) (map + dyn_offset);
-       char *strtab = NULL;
+       const char *strtab = NULL;
 
        while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
                Elf32_Dyn *curr = dynamic;
@@ -218,10 +208,10 @@ static int elf32_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_
        return 0;
 }
 
-static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_offset)
+static int elf64_scan_dynamic(const char *map, int dyn_offset, int dyn_size, int load_offset)
 {
        Elf64_Dyn *dynamic = (Elf64_Dyn *) (map + dyn_offset);
-       char *strtab = NULL;
+       const char *strtab = NULL;
 
        while ((void *) dynamic < (void *) (map + dyn_offset + dyn_size)) {
                Elf64_Dyn *curr = dynamic;
@@ -252,7 +242,7 @@ static int elf64_scan_dynamic(char *map, int dyn_offset, int dyn_size, int load_
        return 0;
 }
 
-int elf_load_deps(char *library)
+int elf_load_deps(const char *library)
 {
        unsigned int dyn_offset, dyn_size;
        unsigned int load_offset, load_vaddr;
@@ -298,10 +288,12 @@ int elf_load_deps(char *library)
        if (dir) {
                alloc_library(dir, library);
        } else {
-               char *elf = strdup(library);
+               char *elf1 = strdup(library);
+               char *elf2 = strdup(library);
 
-               alloc_library(dirname(elf), basename(library));
-               free(elf);
+               alloc_library(dirname(elf1), basename(elf2));
+               free(elf1);
+               free(elf2);
        }
        clazz = map[EI_CLASS];
 
@@ -357,10 +349,6 @@ void load_ldso_conf(const char *conf)
                                load_ldso_conf(gl.gl_pathv[i]);
                        globfree(&gl);
                } else {
-                       struct stat s;
-
-                       if (stat(line, &s))
-                               continue;
                        alloc_library_path(line);
                }
        }