diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-06-01 17:08:49 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-06-01 17:08:49 +0000 |
commit | 1ac9ef013b0e9c737d6909ab41a38b45a3d36e43 (patch) | |
tree | a989b4b6a8dc71c9352a7f5c6265ccf764260970 /src/util/disk.c | |
parent | 1be4eb49815a40fd5de052b2f7ceef7b99c4e08d (diff) | |
download | gnunet-1ac9ef013b0e9c737d6909ab41a38b45a3d36e43.tar.gz gnunet-1ac9ef013b0e9c737d6909ab41a38b45a3d36e43.zip |
fix #4545: create directory for log file if it does not exist
Diffstat (limited to 'src/util/disk.c')
-rw-r--r-- | src/util/disk.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/util/disk.c b/src/util/disk.c index 91ce02b05..4624df7c1 100644 --- a/src/util/disk.c +++ b/src/util/disk.c | |||
@@ -814,23 +814,30 @@ GNUNET_DISK_directory_create_for_file (const char *filename) | |||
814 | char *rdir; | 814 | char *rdir; |
815 | size_t len; | 815 | size_t len; |
816 | int ret; | 816 | int ret; |
817 | int eno; | ||
817 | 818 | ||
818 | rdir = GNUNET_STRINGS_filename_expand (filename); | 819 | rdir = GNUNET_STRINGS_filename_expand (filename); |
819 | if (rdir == NULL) | 820 | if (NULL == rdir) |
821 | { | ||
822 | errno = EINVAL; | ||
820 | return GNUNET_SYSERR; | 823 | return GNUNET_SYSERR; |
824 | } | ||
821 | len = strlen (rdir); | 825 | len = strlen (rdir); |
822 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) | 826 | while ((len > 0) && (rdir[len] != DIR_SEPARATOR)) |
823 | len--; | 827 | len--; |
824 | rdir[len] = '\0'; | 828 | rdir[len] = '\0'; |
825 | /* The empty path is invalid and in this case refers to / */ | 829 | /* The empty path is invalid and in this case refers to / */ |
826 | if (0 == len) { | 830 | if (0 == len) |
831 | { | ||
827 | GNUNET_free (rdir); | 832 | GNUNET_free (rdir); |
828 | rdir = GNUNET_strdup ("/"); | 833 | rdir = GNUNET_strdup ("/"); |
829 | } | 834 | } |
830 | ret = GNUNET_DISK_directory_create (rdir); | 835 | ret = GNUNET_DISK_directory_create (rdir); |
831 | if ((ret == GNUNET_OK) && (0 != ACCESS (rdir, W_OK))) | 836 | if ((GNUNET_OK == ret) && (0 != ACCESS (rdir, W_OK))) |
832 | ret = GNUNET_NO; | 837 | ret = GNUNET_NO; |
838 | eno = errno; | ||
833 | GNUNET_free (rdir); | 839 | GNUNET_free (rdir); |
840 | errno = eno; | ||
834 | return ret; | 841 | return ret; |
835 | } | 842 | } |
836 | 843 | ||