diff --git a/make.sh b/make.sh index 86f93182..da084ce3 100755 --- a/make.sh +++ b/make.sh @@ -1,6 +1,6 @@ ENABLE_STATIC_LIB=0 ENABLE_SHARED_LIB=1 -DESTDIR=/usr/local +DESTDIR=/usr TARGET_PREFIX=$DESTDIR TARGET_CONF_PATH=$DESTDIR/etc/fdfs TARGET_INIT_PATH=$DESTDIR/etc/init.d diff --git a/test/common_func.c b/test/common_func.c index 6899a73d..9faec204 100644 --- a/test/common_func.c +++ b/test/common_func.c @@ -6,56 +6,31 @@ #include #include #include +#include "fastcommon/shared_func.h" +#include "fastcommon/logger.h" #include "common_func.h" -int getFileContent(const char *filename, char **buff, int64_t *file_size) +int my_daemon_init() { - int fd; - - fd = open(filename, O_RDONLY); - if (fd < 0) + char cwd[256]; + if (getcwd(cwd, sizeof(cwd)) == NULL) + { + logError("file: "__FILE__", line: %d, " + "getcwd fail, errno: %d, error info: %s", + __LINE__, errno, STRERROR(errno)); + return errno != 0 ? errno : EPERM; + } +#ifndef WIN32 + daemon_init(false); +#endif + + if (chdir(cwd) != 0) { - *buff = NULL; - *file_size = 0; - return errno != 0 ? errno : ENOENT; + logError("file: "__FILE__", line: %d, " + "chdir to %s fail, errno: %d, error info: %s", + __LINE__, cwd, errno, STRERROR(errno)); + return errno != 0 ? errno : EPERM; } - if ((*file_size=lseek(fd, 0, SEEK_END)) < 0) - { - *buff = NULL; - *file_size = 0; - close(fd); - return errno != 0 ? errno : EIO; - } - - *buff = (char *)malloc(*file_size + 1); - if (*buff == NULL) - { - *file_size = 0; - close(fd); - - return errno != 0 ? errno : ENOMEM; - } - - if (lseek(fd, 0, SEEK_SET) < 0) - { - *buff = NULL; - *file_size = 0; - close(fd); - return errno != 0 ? errno : EIO; - } - if (read(fd, *buff, *file_size) != *file_size) - { - free(*buff); - *buff = NULL; - *file_size = 0; - close(fd); - return errno != 0 ? errno : EIO; - } - - (*buff)[*file_size] = '\0'; - close(fd); - - return 0; + return 0; } - diff --git a/test/common_func.h b/test/common_func.h index bf6386a3..8b90adf4 100644 --- a/test/common_func.h +++ b/test/common_func.h @@ -7,7 +7,7 @@ extern "C" { #endif -int getFileContent(const char *filename, char **buff, int64_t *file_size); +int my_daemon_init(); #ifdef __cplusplus } diff --git a/test/test_delete.c b/test/test_delete.c index f08d120d..d34b1e17 100644 --- a/test/test_delete.c +++ b/test/test_delete.c @@ -119,9 +119,10 @@ int main(int argc, char **argv) return result; } -#ifndef WIN32 - daemon_init(false); -#endif + if ((result=my_daemon_init()) != 0) + { + return result; + } /* printf("file_count = %d\n", file_count); diff --git a/test/test_download.c b/test/test_download.c index da3a0427..63365aa4 100644 --- a/test/test_download.c +++ b/test/test_download.c @@ -127,9 +127,10 @@ int main(int argc, char **argv) return result; } -#ifndef WIN32 - daemon_init(false); -#endif + if ((result=my_daemon_init()) != 0) + { + return result; + } /* printf("file_count = %d\n", file_count); diff --git a/test/test_upload.c b/test/test_upload.c index a54f6c32..c73a4f45 100644 --- a/test/test_upload.c +++ b/test/test_upload.c @@ -9,7 +9,6 @@ #include #include #include "fastcommon/common_define.h" -#include "fastcommon/shared_func.h" #include "fastcommon/logger.h" #include "test_types.h" #include "common_func.h" @@ -121,9 +120,10 @@ int main(int argc, char **argv) return result; } -#ifndef WIN32 - daemon_init(false); -#endif + if ((result=my_daemon_init()) != 0) + { + return result; + } memset(&storages, 0, sizeof(storages)); upload_count = 0;