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_SHARED_LIB=1
DESTDIR=/usr/local
DESTDIR=/usr
TARGET_PREFIX=$DESTDIR
TARGET_CONF_PATH=$DESTDIR/etc/fdfs
TARGET_INIT_PATH=$DESTDIR/etc/init.d

View File

@ -6,56 +6,31 @@
#include <unistd.h>
#include <sys/stat.h>
#include <fcntl.h>
#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;
}

View File

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

View File

@ -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);

View File

@ -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);

View File

@ -9,7 +9,6 @@
#include <sys/stat.h>
#include <sys/mman.h>
#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;