test programs use func my_daemon_init

multi_ipaddr
YuQing 2019-10-15 09:49:44 +08:00
parent 58be6d0a3a
commit 72ca728d67
6 changed files with 35 additions and 58 deletions

View File

@ -1,6 +1,6 @@
ENABLE_STATIC_LIB=0 ENABLE_STATIC_LIB=0
ENABLE_SHARED_LIB=1 ENABLE_SHARED_LIB=1
DESTDIR=/usr/local DESTDIR=/usr
TARGET_PREFIX=$DESTDIR TARGET_PREFIX=$DESTDIR
TARGET_CONF_PATH=$DESTDIR/etc/fdfs TARGET_CONF_PATH=$DESTDIR/etc/fdfs
TARGET_INIT_PATH=$DESTDIR/etc/init.d TARGET_INIT_PATH=$DESTDIR/etc/init.d

View File

@ -6,56 +6,31 @@
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include "fastcommon/shared_func.h"
#include "fastcommon/logger.h"
#include "common_func.h" #include "common_func.h"
int getFileContent(const char *filename, char **buff, int64_t *file_size) int my_daemon_init()
{ {
int fd; char cwd[256];
if (getcwd(cwd, sizeof(cwd)) == NULL)
fd = open(filename, O_RDONLY); {
if (fd < 0) 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; logError("file: "__FILE__", line: %d, "
*file_size = 0; "chdir to %s fail, errno: %d, error info: %s",
return errno != 0 ? errno : ENOENT; __LINE__, cwd, errno, STRERROR(errno));
return errno != 0 ? errno : EPERM;
} }
if ((*file_size=lseek(fd, 0, SEEK_END)) < 0) return 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;
} }

View File

@ -7,7 +7,7 @@
extern "C" { extern "C" {
#endif #endif
int getFileContent(const char *filename, char **buff, int64_t *file_size); int my_daemon_init();
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -119,9 +119,10 @@ int main(int argc, char **argv)
return result; return result;
} }
#ifndef WIN32 if ((result=my_daemon_init()) != 0)
daemon_init(false); {
#endif return result;
}
/* /*
printf("file_count = %d\n", file_count); printf("file_count = %d\n", file_count);

View File

@ -127,9 +127,10 @@ int main(int argc, char **argv)
return result; return result;
} }
#ifndef WIN32 if ((result=my_daemon_init()) != 0)
daemon_init(false); {
#endif return result;
}
/* /*
printf("file_count = %d\n", file_count); printf("file_count = %d\n", file_count);

View File

@ -9,7 +9,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/mman.h> #include <sys/mman.h>
#include "fastcommon/common_define.h" #include "fastcommon/common_define.h"
#include "fastcommon/shared_func.h"
#include "fastcommon/logger.h" #include "fastcommon/logger.h"
#include "test_types.h" #include "test_types.h"
#include "common_func.h" #include "common_func.h"
@ -121,9 +120,10 @@ int main(int argc, char **argv)
return result; return result;
} }
#ifndef WIN32 if ((result=my_daemon_init()) != 0)
daemon_init(false); {
#endif return result;
}
memset(&storages, 0, sizeof(storages)); memset(&storages, 0, sizeof(storages));
upload_count = 0; upload_count = 0;