ia64/xen-unstable

changeset 15344:fd0103b55504

[IA64] Add error checking to nvram store mkdir

Signed-off-by: Alex Williamson <alex.williamson@hp.com>
author Alex Williamson <alex.williamson@hp.com>
date Fri Jun 15 11:34:34 2007 -0600 (2007-06-15)
parents 33cc64dcaead
children 65956e1d1aec
files tools/libxc/ia64/xc_ia64_hvm_build.c
line diff
     1.1 --- a/tools/libxc/ia64/xc_ia64_hvm_build.c	Fri Jun 15 09:25:09 2007 -0600
     1.2 +++ b/tools/libxc/ia64/xc_ia64_hvm_build.c	Fri Jun 15 11:34:34 2007 -0600
     1.3 @@ -578,7 +578,7 @@ static uint64_t
     1.4  nvram_init(const char *nvram_path)
     1.5  {
     1.6      uint64_t fd = 0;
     1.7 -    fd = open(nvram_path, O_CREAT|O_RDWR, 0666);
     1.8 +    fd = open(nvram_path, O_CREAT|O_RDWR, 0644);
     1.9  
    1.10      if ( fd < 0 )
    1.11      {
    1.12 @@ -736,12 +736,34 @@ int xc_ia64_save_to_nvram(int xc_handle,
    1.13  }
    1.14  
    1.15  #define NVRAM_DIR       "/usr/lib/xen/boot/"
    1.16 -#define NVRAM_FILE_PATH	"/usr/lib/xen/boot/nvram_"
    1.17 +#define NVRAM_FILE_PATH "/usr/lib/xen/boot/nvram_"
    1.18 +
    1.19  int xc_ia64_nvram_init(int xc_handle, char *dom_name, uint32_t dom)
    1.20  {
    1.21      int file_path_len = strlen(NVRAM_FILE_PATH);
    1.22      uint64_t nvram_fd = 0;
    1.23      char nvram_path[100] = {0};
    1.24 +    struct stat stat_buf;
    1.25 +
    1.26 +    if ( stat(NVRAM_DIR, &stat_buf) == -1 ) {
    1.27 +        if ( errno != ENOENT )
    1.28 +        {
    1.29 +            PERROR("Error stat'ing NVRAM dir %s.", NVRAM_DIR);
    1.30 +            return -1;
    1.31 +        }
    1.32 +        if ( mkdir(NVRAM_DIR, 0755) == -1 )
    1.33 +        {
    1.34 +            PERROR("Unable to create NVRAM store directory %s.", NVRAM_DIR);
    1.35 +            return -1;
    1.36 +        }
    1.37 +    }
    1.38 +
    1.39 +    if ( !(stat_buf.st_mode & S_IRUSR) || !(stat_buf.st_mode & S_IWUSR) )
    1.40 +    {
    1.41 +        errno = EACCES;
    1.42 +        PERROR("No R/W permission to NVRAM store directory %s.", NVRAM_DIR);
    1.43 +        return -1;
    1.44 +    }
    1.45  
    1.46      strncpy(nvram_path, NVRAM_FILE_PATH, file_path_len);
    1.47      if ( file_path_len + strlen(dom_name) + 1 > sizeof(nvram_path) )
    1.48 @@ -750,7 +772,6 @@ int xc_ia64_nvram_init(int xc_handle, ch
    1.49          return -1;
    1.50      }
    1.51      strcpy(nvram_path + file_path_len, dom_name);
    1.52 -    mkdir(NVRAM_DIR, 0765);
    1.53  
    1.54      nvram_fd = nvram_init(nvram_path);
    1.55      if ( nvram_fd == (uint64_t)(-1) )