use func sf_parse_daemon_mode_and_action from libserverframe

use_libserverframe
YuQing 2022-09-11 09:51:52 +08:00
parent 2e342b6649
commit 1d7b15d1be
23 changed files with 148 additions and 146 deletions

5
.gitignore vendored
View File

@ -104,3 +104,8 @@ php_client/run-tests.php
# fastdfs runtime paths # fastdfs runtime paths
data/ data/
logs/ logs/
# others
*.pid
*.swp
*.swo

View File

@ -1,4 +1,7 @@
Version 6.09 2022-09-11
* use libfastcommon V1.60 and libserverframe 1.1.18
Version 6.08 2022-06-21 Version 6.08 2022-06-21
* use libfastcommon V1.56 * use libfastcommon V1.56
NOTE: you MUST upgrade libfastcommon to V1.56 or later NOTE: you MUST upgrade libfastcommon to V1.56 or later

25
INSTALL
View File

@ -11,28 +11,37 @@ Chinese language: http://www.fastken.com/
# command lines as: # command lines as:
git clone https://github.com/happyfish100/libfastcommon.git git clone https://github.com/happyfish100/libfastcommon.git
cd libfastcommon; git checkout V1.0.56 cd libfastcommon; git checkout V1.0.60
./make.sh clean && ./make.sh && ./make.sh install ./make.sh clean && ./make.sh && ./make.sh install
# step 2. download fastdfs source codes and install it, # step 2. download libserverframe source codes and install it,
# github address: https://github.com/happyfish100/libserverframe.git
# gitee address: https://gitee.com/fastdfs100/libserverframe.git
# command lines as:
git clone https://github.com/happyfish100/libserverframe.git
cd libserverframe; git checkout V1.1.18
./make.sh clean && ./make.sh && ./make.sh install
# step 3. download fastdfs source codes and install it,
# github address: https://github.com/happyfish100/fastdfs.git # github address: https://github.com/happyfish100/fastdfs.git
# gitee address: https://gitee.com/fastdfs100/fastdfs.git # gitee address: https://gitee.com/fastdfs100/fastdfs.git
# command lines as: # command lines as:
git clone https://github.com/happyfish100/fastdfs.git git clone https://github.com/happyfish100/fastdfs.git
cd fastdfs; git checkout V6.08 cd fastdfs; git checkout V6.09
./make.sh clean && ./make.sh && ./make.sh install ./make.sh clean && ./make.sh && ./make.sh install
# step 3. setup the config files # step 4. setup the config files
# the setup script does NOT overwrite existing config files, # the setup script does NOT overwrite existing config files,
# please feel free to execute this script (take easy :) # please feel free to execute this script (take easy :)
./setup.sh /etc/fdfs ./setup.sh /etc/fdfs
# step 4. edit or modify the config files of tracker, storage and client # step 5. edit or modify the config files of tracker, storage and client
such as: such as:
vi /etc/fdfs/tracker.conf vi /etc/fdfs/tracker.conf
vi /etc/fdfs/storage.conf vi /etc/fdfs/storage.conf
@ -41,7 +50,7 @@ such as:
and so on ... and so on ...
# step 5. run the server programs # step 6. run the server programs
# start the tracker server: # start the tracker server:
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf restart
@ -53,12 +62,12 @@ such as:
/sbin/service fdfs_storaged restart /sbin/service fdfs_storaged restart
# step 6. (optional) run monitor program # step 7. (optional) run monitor program
# such as: # such as:
/usr/bin/fdfs_monitor /etc/fdfs/client.conf /usr/bin/fdfs_monitor /etc/fdfs/client.conf
# step 7. (optional) run the test program # step 8. (optional) run the test program
# such as: # such as:
/usr/bin/fdfs_test <client_conf_filename> <operation> /usr/bin/fdfs_test <client_conf_filename> <operation>
/usr/bin/fdfs_test1 <client_conf_filename> <operation> /usr/bin/fdfs_test1 <client_conf_filename> <operation>

View File

@ -4,7 +4,7 @@ COMPILE = $(CC) $(CFLAGS)
ENABLE_STATIC_LIB = $(ENABLE_STATIC_LIB) ENABLE_STATIC_LIB = $(ENABLE_STATIC_LIB)
ENABLE_SHARED_LIB = $(ENABLE_SHARED_LIB) ENABLE_SHARED_LIB = $(ENABLE_SHARED_LIB)
INC_PATH = -I../common -I../tracker -I/usr/include/fastcommon INC_PATH = -I../common -I../tracker -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon LIB_PATH = $(LIBS) -lfastcommon -lserverframe
TARGET_PATH = $(TARGET_PREFIX)/bin TARGET_PATH = $(TARGET_PREFIX)/bin
TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION) TARGET_LIB = $(TARGET_PREFIX)/$(LIB_VERSION)
TARGET_INC = $(TARGET_PREFIX)/include TARGET_INC = $(TARGET_PREFIX)/include

View File

@ -270,25 +270,25 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
pBasePath = iniGetStrValue(NULL, "base_path", iniContext); pBasePath = iniGetStrValue(NULL, "base_path", iniContext);
if (pBasePath == NULL) if (pBasePath == NULL)
{ {
strcpy(g_fdfs_base_path, "/tmp"); strcpy(SF_G_BASE_PATH_STR, "/tmp");
} }
else else
{ {
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR),
"%s", pBasePath); "%s", pBasePath);
chopPath(g_fdfs_base_path); chopPath(SF_G_BASE_PATH_STR);
if (!fileExists(g_fdfs_base_path)) if (!fileExists(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"\"%s\" can't be accessed, error info: %s", \ "\"%s\" can't be accessed, error info: %s", \
__LINE__, g_fdfs_base_path, STRERROR(errno)); __LINE__, SF_G_BASE_PATH_STR, STRERROR(errno));
return errno != 0 ? errno : ENOENT; return errno != 0 ? errno : ENOENT;
} }
if (!isDir(g_fdfs_base_path)) if (!isDir(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"\"%s\" is not a directory!", \ "\"%s\" is not a directory!", \
__LINE__, g_fdfs_base_path); __LINE__, SF_G_BASE_PATH_STR);
return ENOTDIR; return ENOTDIR;
} }
} }
@ -376,7 +376,7 @@ static int fdfs_client_do_init_ex(TrackerServerGroup *pTrackerGroup, \
"use_connection_pool=%d, " \ "use_connection_pool=%d, " \
"g_connection_pool_max_idle_time=%ds, " \ "g_connection_pool_max_idle_time=%ds, " \
"use_storage_id=%d, storage server id count: %d\n", \ "use_storage_id=%d, storage server id count: %d\n", \
g_fdfs_base_path, g_fdfs_connect_timeout, \ SF_G_BASE_PATH_STR, g_fdfs_connect_timeout, \
g_fdfs_network_timeout, pTrackerGroup->server_count, \ g_fdfs_network_timeout, pTrackerGroup->server_count, \
g_anti_steal_token, g_anti_steal_secret_key.length, \ g_anti_steal_token, g_anti_steal_secret_key.length, \
g_use_connection_pool, g_connection_pool_max_idle_time, \ g_use_connection_pool, g_connection_pool_max_idle_time, \

View File

@ -22,7 +22,6 @@
int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT; int g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT;
int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT; int g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT;
char g_fdfs_base_path[MAX_PATH_SIZE] = {'/', 't', 'm', 'p', '\0'};
Version g_fdfs_version = {6, 8}; Version g_fdfs_version = {6, 8};
bool g_use_connection_pool = false; bool g_use_connection_pool = false;
ConnectionPool g_connection_pool; ConnectionPool g_connection_pool;

View File

@ -12,6 +12,7 @@
#define _FDFS_GLOBAL_H #define _FDFS_GLOBAL_H
#include "fastcommon/common_define.h" #include "fastcommon/common_define.h"
#include "sf/sf_global.h"
#include "fdfs_define.h" #include "fdfs_define.h"
#include "fastcommon/connection_pool.h" #include "fastcommon/connection_pool.h"
@ -23,7 +24,6 @@ extern "C" {
extern int g_fdfs_connect_timeout; extern int g_fdfs_connect_timeout;
extern int g_fdfs_network_timeout; extern int g_fdfs_network_timeout;
extern char g_fdfs_base_path[MAX_PATH_SIZE];
extern Version g_fdfs_version; extern Version g_fdfs_version;
extern bool g_use_connection_pool; extern bool g_use_connection_pool;
extern ConnectionPool g_connection_pool; extern ConnectionPool g_connection_pool;

View File

@ -7541,28 +7541,28 @@ static int load_config_files()
if (zend_get_configuration_directive_wrapper(ITEM_NAME_BASE_PATH, \ if (zend_get_configuration_directive_wrapper(ITEM_NAME_BASE_PATH, \
sizeof(ITEM_NAME_BASE_PATH), &base_path) != SUCCESS) sizeof(ITEM_NAME_BASE_PATH), &base_path) != SUCCESS)
{ {
strcpy(g_fdfs_base_path, "/tmp"); strcpy(SF_G_BASE_PATH_STR, "/tmp");
fprintf(stderr, "file: "__FILE__", line: %d, " \ fprintf(stderr, "file: "__FILE__", line: %d, " \
"fastdfs_client.ini does not have item " \ "fastdfs_client.ini does not have item " \
"\"%s\", set to %s!", __LINE__, "\"%s\", set to %s!", __LINE__,
ITEM_NAME_BASE_PATH, g_fdfs_base_path); ITEM_NAME_BASE_PATH, SF_G_BASE_PATH_STR);
} }
else else
{ {
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", \ snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", \
Z_STRVAL_P(base_path)); Z_STRVAL_P(base_path));
chopPath(g_fdfs_base_path); chopPath(SF_G_BASE_PATH_STR);
} }
if (!fileExists(g_fdfs_base_path)) if (!fileExists(SF_G_BASE_PATH_STR))
{ {
logError("\"%s\" can't be accessed, error info: %s", \ logError("\"%s\" can't be accessed, error info: %s", \
g_fdfs_base_path, STRERROR(errno)); SF_G_BASE_PATH_STR, STRERROR(errno));
return errno != 0 ? errno : ENOENT; return errno != 0 ? errno : ENOENT;
} }
if (!isDir(g_fdfs_base_path)) if (!isDir(SF_G_BASE_PATH_STR))
{ {
logError("\"%s\" is not a directory!", g_fdfs_base_path); logError("\"%s\" is not a directory!", SF_G_BASE_PATH_STR);
return ENOTDIR; return ENOTDIR;
} }
@ -7737,7 +7737,7 @@ static int load_config_files()
"anti_steal_secret_key length=%d, " \ "anti_steal_secret_key length=%d, " \
"tracker_group_count=%d, first tracker group server_count=%d, "\ "tracker_group_count=%d, first tracker group server_count=%d, "\
"use_connection_pool=%d, connection_pool_max_idle_time: %d", \ "use_connection_pool=%d, connection_pool_max_idle_time: %d", \
g_fdfs_base_path, g_fdfs_connect_timeout, \ SF_G_BASE_PATH_STR, g_fdfs_connect_timeout, \
g_fdfs_network_timeout, (int)strlen(pAntiStealSecretKey), \ g_fdfs_network_timeout, (int)strlen(pAntiStealSecretKey), \
config_count, g_tracker_group.server_count, \ config_count, g_tracker_group.server_count, \
g_use_connection_pool, g_connection_pool_max_idle_time); g_use_connection_pool, g_connection_pool_max_idle_time);

View File

@ -2,7 +2,7 @@
COMPILE = $(CC) $(CFLAGS) COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon INC_PATH = -I. -Itrunk_mgr -I../common -I../tracker -I../client -Ifdht_client -I/usr/include/fastcommon
LIB_PATH = $(LIBS) -lfastcommon LIB_PATH = $(LIBS) -lfastcommon -lserverframe
TARGET_PATH = $(TARGET_PREFIX)/bin TARGET_PATH = $(TARGET_PREFIX)/bin
CONFIG_PATH = $(TARGET_CONF_PATH) CONFIG_PATH = $(TARGET_CONF_PATH)

View File

@ -28,6 +28,8 @@
#include "fdfs_global.h" #include "fdfs_global.h"
#include "fastcommon/ini_file_reader.h" #include "fastcommon/ini_file_reader.h"
#include "fastcommon/sockopt.h" #include "fastcommon/sockopt.h"
#include "sf/sf_service.h"
#include "sf/sf_util.h"
#include "tracker_types.h" #include "tracker_types.h"
#include "tracker_proto.h" #include "tracker_proto.h"
#include "tracker_client_thread.h" #include "tracker_client_thread.h"
@ -53,6 +55,7 @@
#define ACCEPT_STAGE_DOING 1 #define ACCEPT_STAGE_DOING 1
#define ACCEPT_STAGE_DONE 2 #define ACCEPT_STAGE_DONE 2
static bool daemon_mode = true;
static bool bTerminateFlag = false; static bool bTerminateFlag = false;
static char accept_stage = ACCEPT_STAGE_NONE; static char accept_stage = ACCEPT_STAGE_NONE;
@ -75,17 +78,9 @@ static void sigSegvHandler(int signum, siginfo_t *info, void *ptr);
static void sigDumpHandler(int sig); static void sigDumpHandler(int sig);
#endif #endif
static void usage(const char *program)
{
fprintf(stderr, "FastDFS server v%d.%02d\n"
"Usage: %s <config_file> [start | stop | restart]\n",
g_fdfs_version.major, g_fdfs_version.minor,
program);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *conf_filename; const char *conf_filename;
char *action; char *action;
int result; int result;
int sock; int sock;
@ -96,13 +91,19 @@ int main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
{ {
usage(argv[0]); sf_usage(argv[0]);
return 1; return 1;
} }
conf_filename = sf_parse_daemon_mode_and_action(argc, argv,
&g_fdfs_version, &daemon_mode, &action);
if (conf_filename == NULL)
{
return 0;
}
g_current_time = time(NULL); g_current_time = time(NULL);
g_up_time = g_current_time; g_up_time = g_current_time;
log_init2(); log_init2();
if ((result=trunk_shared_init()) != 0) if ((result=trunk_shared_init()) != 0)
{ {
@ -110,17 +111,7 @@ int main(int argc, char *argv[])
return result; return result;
} }
conf_filename = argv[1]; if ((result=sf_get_base_path_from_conf_file(conf_filename)) != 0)
if (!fileExists(conf_filename))
{
if (starts_with(conf_filename, "-"))
{
usage(argv[0]);
return 0;
}
}
if ((result=get_base_path_from_conf_file(conf_filename,
g_fdfs_base_path, sizeof(g_fdfs_base_path))) != 0)
{ {
log_destroy(); log_destroy();
return result; return result;
@ -131,14 +122,14 @@ int main(int argc, char *argv[])
log_destroy(); log_destroy();
return result; return result;
} }
snprintf(pidFilename, sizeof(pidFilename), snprintf(pidFilename, sizeof(pidFilename),
"%s/data/fdfs_storaged.pid", g_fdfs_base_path); "%s/data/fdfs_storaged.pid", SF_G_BASE_PATH_STR);
action = argc >= 3 ? argv[2] : "start";
if ((result=process_action(pidFilename, action, &stop)) != 0) if ((result=process_action(pidFilename, action, &stop)) != 0)
{ {
if (result == EINVAL) if (result == EINVAL)
{ {
usage(argv[0]); sf_usage(argv[0]);
} }
log_destroy(); log_destroy();
return result; return result;
@ -159,7 +150,9 @@ int main(int argc, char *argv[])
} }
#endif #endif
daemon_init(false); if (daemon_mode) {
daemon_init(false);
}
umask(0); umask(0);
if ((result=write_to_pid_file(pidFilename)) != 0) if ((result=write_to_pid_file(pidFilename)) != 0)
@ -429,7 +422,7 @@ static void sigDumpHandler(int sig)
bDumpFlag = true; bDumpFlag = true;
snprintf(filename, sizeof(filename), snprintf(filename, sizeof(filename),
"%s/logs/storage_dump.log", g_fdfs_base_path); "%s/logs/storage_dump.log", SF_G_BASE_PATH_STR);
fdfs_dump_storage_global_vars_to_file(filename); fdfs_dump_storage_global_vars_to_file(filename);
bDumpFlag = false; bDumpFlag = false;

View File

@ -44,7 +44,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
total_len = snprintf(buff, buffSize, total_len = snprintf(buff, buffSize,
"g_fdfs_connect_timeout=%ds\n" "g_fdfs_connect_timeout=%ds\n"
"g_fdfs_network_timeout=%ds\n" "g_fdfs_network_timeout=%ds\n"
"g_fdfs_base_path=%s\n" "SF_G_BASE_PATH_STR=%s\n"
"g_fdfs_version=%d.%02d\n" "g_fdfs_version=%d.%02d\n"
"g_continue_flag=%d\n" "g_continue_flag=%d\n"
"g_schedule_flag=%d\n" "g_schedule_flag=%d\n"
@ -138,7 +138,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
#endif #endif
, g_fdfs_connect_timeout , g_fdfs_connect_timeout
, g_fdfs_network_timeout , g_fdfs_network_timeout
, g_fdfs_base_path , SF_G_BASE_PATH_STR
, g_fdfs_version.major, g_fdfs_version.minor , g_fdfs_version.major, g_fdfs_version.minor
, g_continue_flag , g_continue_flag
, g_schedule_flag , g_schedule_flag

View File

@ -285,7 +285,7 @@ static char *get_storage_stat_filename(const void *pArg, char *full_filename)
} }
snprintf(full_filename, MAX_PATH_SIZE, \ snprintf(full_filename, MAX_PATH_SIZE, \
"%s/data/%s", g_fdfs_base_path, STORAGE_STAT_FILENAME); "%s/data/%s", SF_G_BASE_PATH_STR, STORAGE_STAT_FILENAME);
return full_filename; return full_filename;
} }
@ -648,7 +648,7 @@ int storage_write_to_sync_ini_file()
int i; int i;
snprintf(full_filename, sizeof(full_filename), snprintf(full_filename, sizeof(full_filename),
"%s/data/%s", g_fdfs_base_path, DATA_DIR_INITED_FILENAME); "%s/data/%s", SF_G_BASE_PATH_STR, DATA_DIR_INITED_FILENAME);
fdfs_multi_ips_to_string(&g_tracker_client_ip, fdfs_multi_ips_to_string(&g_tracker_client_ip,
ip_str, sizeof(ip_str)); ip_str, sizeof(ip_str));
@ -702,7 +702,7 @@ int storage_check_and_make_global_data_path()
{ {
char data_path[MAX_PATH_SIZE]; char data_path[MAX_PATH_SIZE];
snprintf(data_path, sizeof(data_path), "%s/data", snprintf(data_path, sizeof(data_path), "%s/data",
g_fdfs_base_path); SF_G_BASE_PATH_STR);
if (!fileExists(data_path)) if (!fileExists(data_path))
{ {
if (mkdir(data_path, 0755) != 0) if (mkdir(data_path, 0755) != 0)
@ -982,7 +982,7 @@ static int storage_check_and_make_data_dirs()
bool pathCreated; bool pathCreated;
snprintf(data_path, sizeof(data_path), "%s/data", snprintf(data_path, sizeof(data_path), "%s/data",
g_fdfs_base_path); SF_G_BASE_PATH_STR);
snprintf(full_filename, sizeof(full_filename), "%s/%s", snprintf(full_filename, sizeof(full_filename), "%s/%s",
data_path, DATA_DIR_INITED_FILENAME); data_path, DATA_DIR_INITED_FILENAME);
if (fileExists(full_filename)) if (fileExists(full_filename))
@ -1460,7 +1460,7 @@ int storage_func_init(const char *filename, \
} }
load_log_level(&iniContext); load_log_level(&iniContext);
if ((result=log_set_prefix(g_fdfs_base_path, \ if ((result=log_set_prefix(SF_G_BASE_PATH_STR, \
STORAGE_ERROR_LOG_FILENAME)) != 0) STORAGE_ERROR_LOG_FILENAME)) != 0)
{ {
break; break;
@ -1926,7 +1926,7 @@ int storage_func_init(const char *filename, \
STORAGE_FILE_SIGNATURE_METHOD_HASH; STORAGE_FILE_SIGNATURE_METHOD_HASH;
} }
strcpy(g_fdht_base_path, g_fdfs_base_path); strcpy(g_fdht_base_path, SF_G_BASE_PATH_STR);
g_fdht_connect_timeout = g_fdfs_connect_timeout; g_fdht_connect_timeout = g_fdfs_connect_timeout;
g_fdht_network_timeout = g_fdfs_network_timeout; g_fdht_network_timeout = g_fdfs_network_timeout;
@ -1996,7 +1996,7 @@ int storage_func_init(const char *filename, \
LOG_TIME_PRECISION_MSECOND); LOG_TIME_PRECISION_MSECOND);
log_set_cache_ex(&g_access_log_context, true); log_set_cache_ex(&g_access_log_context, true);
result = log_set_prefix_ex(&g_access_log_context, \ result = log_set_prefix_ex(&g_access_log_context, \
g_fdfs_base_path, "storage_access"); SF_G_BASE_PATH_STR, "storage_access");
if (result != 0) if (result != 0)
{ {
break; break;
@ -2185,7 +2185,7 @@ int storage_func_init(const char *filename, \
"compress_binlog_time=%02d:%02d, " \ "compress_binlog_time=%02d:%02d, " \
"check_store_path_mark=%d", \ "check_store_path_mark=%d", \
g_fdfs_version.major, g_fdfs_version.minor, \ g_fdfs_version.major, g_fdfs_version.minor, \
g_fdfs_base_path, g_fdfs_store_paths.count, \ SF_G_BASE_PATH_STR, g_fdfs_store_paths.count, \
g_subdir_count_per_path, \ g_subdir_count_per_path, \
g_group_name, g_run_by_group, g_run_by_user, \ g_group_name, g_run_by_group, g_run_by_user, \
g_fdfs_connect_timeout, g_fdfs_network_timeout, \ g_fdfs_connect_timeout, g_fdfs_network_timeout, \

View File

@ -1216,7 +1216,7 @@ static int write_to_binlog_index(const int binlog_index)
int len; int len;
snprintf(full_filename, sizeof(full_filename), snprintf(full_filename, sizeof(full_filename),
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
SYNC_BINLOG_INDEX_FILENAME); SYNC_BINLOG_INDEX_FILENAME);
if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
{ {
@ -1258,7 +1258,7 @@ static int get_binlog_index_from_file_old()
int bytes; int bytes;
snprintf(full_filename, sizeof(full_filename), snprintf(full_filename, sizeof(full_filename),
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
SYNC_BINLOG_INDEX_FILENAME_OLD); SYNC_BINLOG_INDEX_FILENAME_OLD);
if ((fd=open(full_filename, O_RDONLY)) >= 0) if ((fd=open(full_filename, O_RDONLY)) >= 0)
{ {
@ -1297,7 +1297,7 @@ static int get_binlog_index_from_file()
int result; int result;
snprintf(full_filename, sizeof(full_filename), snprintf(full_filename, sizeof(full_filename),
"%s/data/"SYNC_DIR_NAME"/%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s", SF_G_BASE_PATH_STR,
SYNC_BINLOG_INDEX_FILENAME); SYNC_BINLOG_INDEX_FILENAME);
if (access(full_filename, F_OK) != 0) if (access(full_filename, F_OK) != 0)
{ {
@ -1348,7 +1348,7 @@ static char *get_writable_binlog_filename(char *full_filename)
snprintf(full_filename, MAX_PATH_SIZE, \ snprintf(full_filename, MAX_PATH_SIZE, \
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \ "%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \
SYNC_BINLOG_FILE_EXT_FMT, \ SYNC_BINLOG_FILE_EXT_FMT, \
g_fdfs_base_path, g_binlog_index); SF_G_BASE_PATH_STR, g_binlog_index);
return full_filename; return full_filename;
} }
@ -1358,7 +1358,7 @@ static char *get_writable_binlog_filename1(char *full_filename, \
snprintf(full_filename, MAX_PATH_SIZE, \ snprintf(full_filename, MAX_PATH_SIZE, \
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \ "%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" \
SYNC_BINLOG_FILE_EXT_FMT, \ SYNC_BINLOG_FILE_EXT_FMT, \
g_fdfs_base_path, binlog_index); SF_G_BASE_PATH_STR, binlog_index);
return full_filename; return full_filename;
} }
@ -1413,7 +1413,7 @@ int storage_sync_init()
char full_filename[MAX_PATH_SIZE]; char full_filename[MAX_PATH_SIZE];
int result; int result;
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path); snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
if (!fileExists(data_path)) if (!fileExists(data_path))
{ {
if (mkdir(data_path, 0755) != 0) if (mkdir(data_path, 0755) != 0)
@ -1720,7 +1720,7 @@ static char *get_binlog_readable_filename_ex(
snprintf(full_filename, MAX_PATH_SIZE, snprintf(full_filename, MAX_PATH_SIZE,
"%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX"" "%s/data/"SYNC_DIR_NAME"/"SYNC_BINLOG_FILE_PREFIX""
SYNC_BINLOG_FILE_EXT_FMT, SYNC_BINLOG_FILE_EXT_FMT,
g_fdfs_base_path, binlog_index); SF_G_BASE_PATH_STR, binlog_index);
return full_filename; return full_filename;
} }
@ -1952,13 +1952,13 @@ static char *get_mark_filename_by_id_and_port(const char *storage_id,
if (g_use_storage_id) if (g_use_storage_id)
{ {
snprintf(full_filename, filename_size, snprintf(full_filename, filename_size,
"%s/data/"SYNC_DIR_NAME"/%s%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s%s", SF_G_BASE_PATH_STR,
storage_id, SYNC_MARK_FILE_EXT); storage_id, SYNC_MARK_FILE_EXT);
} }
else else
{ {
snprintf(full_filename, filename_size, snprintf(full_filename, filename_size,
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR,
storage_id, port, SYNC_MARK_FILE_EXT); storage_id, port, SYNC_MARK_FILE_EXT);
} }
return full_filename; return full_filename;
@ -1968,7 +1968,7 @@ static char *get_mark_filename_by_ip_and_port(const char *ip_addr,
const int port, char *full_filename, const int filename_size) const int port, char *full_filename, const int filename_size)
{ {
snprintf(full_filename, filename_size, snprintf(full_filename, filename_size,
"%s/data/"SYNC_DIR_NAME"/%s_%d%s", g_fdfs_base_path, "%s/data/"SYNC_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR,
ip_addr, port, SYNC_MARK_FILE_EXT); ip_addr, port, SYNC_MARK_FILE_EXT);
return full_filename; return full_filename;
} }

View File

@ -150,7 +150,7 @@ static int storage_trunk_node_compare_offset(void *p1, void *p2)
char *storage_trunk_get_data_filename(char *full_filename) char *storage_trunk_get_data_filename(char *full_filename)
{ {
snprintf(full_filename, MAX_PATH_SIZE, "%s/data/%s", snprintf(full_filename, MAX_PATH_SIZE, "%s/data/%s",
g_fdfs_base_path, STORAGE_TRUNK_DATA_FILENAME); SF_G_BASE_PATH_STR, STORAGE_TRUNK_DATA_FILENAME);
return full_filename; return full_filename;
} }
@ -269,7 +269,7 @@ int storage_trunk_init()
/* /*
{ {
char filename[MAX_PATH_SIZE]; char filename[MAX_PATH_SIZE];
sprintf(filename, "%s/logs/tttt.dat", g_fdfs_base_path); sprintf(filename, "%s/logs/tttt.dat", SF_G_BASE_PATH_STR);
trunk_free_block_tree_print(filename); trunk_free_block_tree_print(filename);
} }
*/ */
@ -727,7 +727,7 @@ static int trunk_open_file_writers(struct walk_callback_args *pCallbackArgs)
memset(pCallbackArgs, 0, sizeof(*pCallbackArgs)); memset(pCallbackArgs, 0, sizeof(*pCallbackArgs));
snprintf(temp_trunk_filename, MAX_PATH_SIZE, "%s/data/.%s.tmp", snprintf(temp_trunk_filename, MAX_PATH_SIZE, "%s/data/.%s.tmp",
g_fdfs_base_path, STORAGE_TRUNK_DATA_FILENAME); SF_G_BASE_PATH_STR, STORAGE_TRUNK_DATA_FILENAME);
if ((result=buffered_file_writer_open(&pCallbackArgs->data_writer, if ((result=buffered_file_writer_open(&pCallbackArgs->data_writer,
temp_trunk_filename)) != 0) temp_trunk_filename)) != 0)
{ {

View File

@ -92,7 +92,7 @@ FDFSStorePathInfo *storage_load_paths_from_conf_file_ex(
return NULL; return NULL;
} }
pPath = g_fdfs_base_path; pPath = SF_G_BASE_PATH_STR;
} }
store_paths[0].path_len = strlen(pPath); store_paths[0].path_len = strlen(pPath);
@ -185,20 +185,20 @@ int storage_load_paths_from_conf_file(IniContext *pItemContext)
return ENOENT; return ENOENT;
} }
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", pPath); snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", pPath);
chopPath(g_fdfs_base_path); chopPath(SF_G_BASE_PATH_STR);
if (!fileExists(g_fdfs_base_path)) if (!fileExists(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
"\"%s\" can't be accessed, error info: %s", "\"%s\" can't be accessed, error info: %s",
__LINE__, STRERROR(errno), g_fdfs_base_path); __LINE__, STRERROR(errno), SF_G_BASE_PATH_STR);
return errno != 0 ? errno : ENOENT; return errno != 0 ? errno : ENOENT;
} }
if (!isDir(g_fdfs_base_path)) if (!isDir(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " logError("file: "__FILE__", line: %d, "
"\"%s\" is not a directory!", "\"%s\" is not a directory!",
__LINE__, g_fdfs_base_path); __LINE__, SF_G_BASE_PATH_STR);
return ENOTDIR; return ENOTDIR;
} }

View File

@ -84,7 +84,7 @@ char *get_trunk_binlog_filename(char *full_filename)
{ {
snprintf(full_filename, MAX_PATH_SIZE, \ snprintf(full_filename, MAX_PATH_SIZE, \
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR, \ "%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR, \
g_fdfs_base_path); SF_G_BASE_PATH_STR);
return full_filename; return full_filename;
} }
@ -171,7 +171,7 @@ int trunk_sync_init()
char binlog_filename[MAX_PATH_SIZE]; char binlog_filename[MAX_PATH_SIZE];
int result; int result;
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path); snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
if (!fileExists(data_path)) if (!fileExists(data_path))
{ {
if (mkdir(data_path, 0755) != 0) if (mkdir(data_path, 0755) != 0)
@ -487,7 +487,7 @@ static int trunk_binlog_delete_overflow_backups()
TrunkBinlogBackupFileArray file_array; TrunkBinlogBackupFileArray file_array;
snprintf(file_path, sizeof(file_path), snprintf(file_path, sizeof(file_path),
"%s/data/%s", g_fdfs_base_path, TRUNK_DIR_NAME); "%s/data/%s", SF_G_BASE_PATH_STR, TRUNK_DIR_NAME);
if ((dir=opendir(file_path)) == NULL) if ((dir=opendir(file_path)) == NULL)
{ {
result = errno != 0 ? errno : EPERM; result = errno != 0 ? errno : EPERM;
@ -1435,7 +1435,7 @@ static char *get_binlog_readable_filename(const void *pArg,
snprintf(full_filename, MAX_PATH_SIZE, snprintf(full_filename, MAX_PATH_SIZE,
"%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR, "%s/data/"TRUNK_DIR_NAME"/"TRUNK_SYNC_BINLOG_FILENAME_STR,
g_fdfs_base_path); SF_G_BASE_PATH_STR);
return full_filename; return full_filename;
} }
@ -1505,13 +1505,13 @@ static char *trunk_get_mark_filename_by_id_and_port(const char *storage_id, \
if (g_use_storage_id) if (g_use_storage_id)
{ {
snprintf(full_filename, filename_size, \ snprintf(full_filename, filename_size, \
"%s/data/"TRUNK_DIR_NAME"/%s%s", g_fdfs_base_path, \ "%s/data/"TRUNK_DIR_NAME"/%s%s", SF_G_BASE_PATH_STR, \
storage_id, TRUNK_SYNC_MARK_FILE_EXT_STR); storage_id, TRUNK_SYNC_MARK_FILE_EXT_STR);
} }
else else
{ {
snprintf(full_filename, filename_size, \ snprintf(full_filename, filename_size, \
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", g_fdfs_base_path, \ "%s/data/"TRUNK_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR, \
storage_id, port, TRUNK_SYNC_MARK_FILE_EXT_STR); storage_id, port, TRUNK_SYNC_MARK_FILE_EXT_STR);
} }
@ -1522,7 +1522,7 @@ static char *trunk_get_mark_filename_by_ip_and_port(const char *ip_addr, \
const int port, char *full_filename, const int filename_size) const int port, char *full_filename, const int filename_size)
{ {
snprintf(full_filename, filename_size, \ snprintf(full_filename, filename_size, \
"%s/data/"TRUNK_DIR_NAME"/%s_%d%s", g_fdfs_base_path, \ "%s/data/"TRUNK_DIR_NAME"/%s_%d%s", SF_G_BASE_PATH_STR, \
ip_addr, port, TRUNK_SYNC_MARK_FILE_EXT_STR); ip_addr, port, TRUNK_SYNC_MARK_FILE_EXT_STR);
return full_filename; return full_filename;
@ -2486,7 +2486,7 @@ int trunk_unlink_all_mark_files()
localtime_r(&t, &tm); localtime_r(&t, &tm);
snprintf(file_path, sizeof(file_path), snprintf(file_path, sizeof(file_path),
"%s/data/%s", g_fdfs_base_path, TRUNK_DIR_NAME); "%s/data/%s", SF_G_BASE_PATH_STR, TRUNK_DIR_NAME);
if ((dir=opendir(file_path)) == NULL) if ((dir=opendir(file_path)) == NULL)
{ {

View File

@ -2,7 +2,7 @@
COMPILE = $(CC) $(CFLAGS) COMPILE = $(CC) $(CFLAGS)
INC_PATH = -I../common -I/usr/local/include INC_PATH = -I../common -I/usr/local/include
LIB_PATH = $(LIBS) -lfastcommon LIB_PATH = $(LIBS) -lfastcommon -lserverframe
TARGET_PATH = $(TARGET_PREFIX)/bin TARGET_PATH = $(TARGET_PREFIX)/bin
CONFIG_PATH = $(TARGET_CONF_PATH) CONFIG_PATH = $(TARGET_CONF_PATH)

View File

@ -28,6 +28,8 @@
#include "fastcommon/base64.h" #include "fastcommon/base64.h"
#include "fastcommon/sockopt.h" #include "fastcommon/sockopt.h"
#include "fastcommon/sched_thread.h" #include "fastcommon/sched_thread.h"
#include "sf/sf_service.h"
#include "sf/sf_util.h"
#include "tracker_types.h" #include "tracker_types.h"
#include "tracker_mem.h" #include "tracker_mem.h"
#include "tracker_service.h" #include "tracker_service.h"
@ -46,6 +48,7 @@
#include "tracker_dump.h" #include "tracker_dump.h"
#endif #endif
static bool daemon_mode = true;
static bool bTerminateFlag = false; static bool bTerminateFlag = false;
static bool bAcceptEndFlag = false; static bool bAcceptEndFlag = false;
@ -68,17 +71,9 @@ static void sigDumpHandler(int sig);
#define SCHEDULE_ENTRIES_COUNT 5 #define SCHEDULE_ENTRIES_COUNT 5
static void usage(const char *program)
{
fprintf(stderr, "FastDFS server v%d.%02d\n"
"Usage: %s <config_file> [start | stop | restart]\n",
g_fdfs_version.major, g_fdfs_version.minor,
program);
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
char *conf_filename; const char *conf_filename;
char *action; char *action;
int result; int result;
int wait_count; int wait_count;
@ -92,40 +87,35 @@ int main(int argc, char *argv[])
if (argc < 2) if (argc < 2)
{ {
usage(argv[0]); sf_usage(argv[0]);
return 1; return 1;
} }
conf_filename = sf_parse_daemon_mode_and_action(argc, argv,
&g_fdfs_version, &daemon_mode, &action);
if (conf_filename == NULL)
{
return 0;
}
g_current_time = time(NULL); g_current_time = time(NULL);
g_up_time = g_current_time; g_up_time = g_current_time;
srand(g_up_time); srand(g_up_time);
log_init2(); log_init2();
conf_filename = argv[1]; if ((result=sf_get_base_path_from_conf_file(conf_filename)) != 0)
if (!fileExists(conf_filename))
{
if (starts_with(conf_filename, "-"))
{
usage(argv[0]);
return 0;
}
}
if ((result=get_base_path_from_conf_file(conf_filename,
g_fdfs_base_path, sizeof(g_fdfs_base_path))) != 0)
{ {
log_destroy(); log_destroy();
return result; return result;
} }
snprintf(pidFilename, sizeof(pidFilename), snprintf(pidFilename, sizeof(pidFilename),
"%s/data/fdfs_trackerd.pid", g_fdfs_base_path); "%s/data/fdfs_trackerd.pid", SF_G_BASE_PATH_STR);
action = argc >= 3 ? argv[2] : "start";
if ((result=process_action(pidFilename, action, &stop)) != 0) if ((result=process_action(pidFilename, action, &stop)) != 0)
{ {
if (result == EINVAL) if (result == EINVAL)
{ {
usage(argv[0]); sf_usage(argv[0]);
} }
log_destroy(); log_destroy();
return result; return result;
@ -192,7 +182,10 @@ int main(int argc, char *argv[])
return result; return result;
} }
daemon_init(false); if (daemon_mode)
{
daemon_init(false);
}
umask(0); umask(0);
if ((result=write_to_pid_file(pidFilename)) != 0) if ((result=write_to_pid_file(pidFilename)) != 0)
@ -441,7 +434,7 @@ static void sigDumpHandler(int sig)
bDumpFlag = true; bDumpFlag = true;
snprintf(filename, sizeof(filename), snprintf(filename, sizeof(filename),
"%s/logs/tracker_dump.log", g_fdfs_base_path); "%s/logs/tracker_dump.log", SF_G_BASE_PATH_STR);
fdfs_dump_tracker_global_vars_to_file(filename); fdfs_dump_tracker_global_vars_to_file(filename);
bDumpFlag = false; bDumpFlag = false;

View File

@ -293,7 +293,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
total_len = snprintf(buff, buffSize, total_len = snprintf(buff, buffSize,
"g_fdfs_connect_timeout=%ds\n" "g_fdfs_connect_timeout=%ds\n"
"g_fdfs_network_timeout=%ds\n" "g_fdfs_network_timeout=%ds\n"
"g_fdfs_base_path=%s\n" "SF_G_BASE_PATH_STR=%s\n"
"g_fdfs_version=%d.%02d\n" "g_fdfs_version=%d.%02d\n"
"g_continue_flag=%d\n" "g_continue_flag=%d\n"
"g_schedule_flag=%d\n" "g_schedule_flag=%d\n"
@ -347,7 +347,7 @@ static int fdfs_dump_global_vars(char *buff, const int buffSize)
#endif #endif
, g_fdfs_connect_timeout , g_fdfs_connect_timeout
, g_fdfs_network_timeout , g_fdfs_network_timeout
, g_fdfs_base_path , SF_G_BASE_PATH_STR
, g_fdfs_version.major, g_fdfs_version.minor , g_fdfs_version.major, g_fdfs_version.minor
, g_continue_flag , g_continue_flag
, g_schedule_flag , g_schedule_flag

View File

@ -188,27 +188,27 @@ int tracker_load_from_conf_file(const char *filename, \
break; break;
} }
snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", pBasePath); snprintf(SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), "%s", pBasePath);
chopPath(g_fdfs_base_path); chopPath(SF_G_BASE_PATH_STR);
if (!fileExists(g_fdfs_base_path)) if (!fileExists(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"\"%s\" can't be accessed, error info: %s", \ "\"%s\" can't be accessed, error info: %s", \
__LINE__, g_fdfs_base_path, STRERROR(errno)); __LINE__, SF_G_BASE_PATH_STR, STRERROR(errno));
result = errno != 0 ? errno : ENOENT; result = errno != 0 ? errno : ENOENT;
break; break;
} }
if (!isDir(g_fdfs_base_path)) if (!isDir(SF_G_BASE_PATH_STR))
{ {
logError("file: "__FILE__", line: %d, " \ logError("file: "__FILE__", line: %d, " \
"\"%s\" is not a directory!", \ "\"%s\" is not a directory!", \
__LINE__, g_fdfs_base_path); __LINE__, SF_G_BASE_PATH_STR);
result = ENOTDIR; result = ENOTDIR;
break; break;
} }
load_log_level(&iniContext); load_log_level(&iniContext);
if ((result=log_set_prefix(g_fdfs_base_path, \ if ((result=log_set_prefix(SF_G_BASE_PATH_STR, \
TRACKER_ERROR_LOG_FILENAME)) != 0) TRACKER_ERROR_LOG_FILENAME)) != 0)
{ {
break; break;
@ -800,7 +800,7 @@ int tracker_load_from_conf_file(const char *filename, \
"use_connection_pool=%d, " "use_connection_pool=%d, "
"g_connection_pool_max_idle_time=%ds", "g_connection_pool_max_idle_time=%ds",
g_fdfs_version.major, g_fdfs_version.minor, g_fdfs_version.major, g_fdfs_version.minor,
g_fdfs_base_path, g_run_by_group, g_run_by_user, SF_G_BASE_PATH_STR, g_run_by_group, g_run_by_user,
g_fdfs_connect_timeout, g_fdfs_connect_timeout,
g_fdfs_network_timeout, g_server_port, bind_addr, g_fdfs_network_timeout, g_server_port, bind_addr,
g_max_connections, g_accept_threads, g_work_threads, g_max_connections, g_accept_threads, g_work_threads,

View File

@ -758,7 +758,7 @@ static int tracker_locate_group_trunk_servers(FDFSGroups *pGroups, \
{ {
snprintf(buff, sizeof(buff), \ snprintf(buff, sizeof(buff), \
"in the file \"%s/data/%s\", ", \ "in the file \"%s/data/%s\", ", \
g_fdfs_base_path, \ SF_G_BASE_PATH_STR, \
STORAGE_GROUPS_LIST_FILENAME_NEW); STORAGE_GROUPS_LIST_FILENAME_NEW);
} }
else else
@ -824,7 +824,7 @@ static int tracker_locate_storage_sync_server(FDFSGroups *pGroups, \
{ {
snprintf(buff, sizeof(buff), \ snprintf(buff, sizeof(buff), \
"in the file \"%s/data/%s\", ", \ "in the file \"%s/data/%s\", ", \
g_fdfs_base_path, \ SF_G_BASE_PATH_STR, \
STORAGE_SERVERS_LIST_FILENAME_NEW); STORAGE_SERVERS_LIST_FILENAME_NEW);
} }
else else
@ -1600,7 +1600,7 @@ static int tracker_load_data(FDFSGroups *pGroups)
FDFSStorageSync *pTrunkServers; FDFSStorageSync *pTrunkServers;
int nTrunkServerCount; int nTrunkServerCount;
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path); snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
if (!fileExists(data_path)) if (!fileExists(data_path))
{ {
if (mkdir(data_path, 0755) != 0) if (mkdir(data_path, 0755) != 0)
@ -1681,7 +1681,7 @@ int tracker_save_groups()
tracker_mem_file_lock(); tracker_mem_file_lock();
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \ snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
g_fdfs_base_path, STORAGE_GROUPS_LIST_FILENAME_NEW); SF_G_BASE_PATH_STR, STORAGE_GROUPS_LIST_FILENAME_NEW);
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename); snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
{ {
@ -1820,7 +1820,7 @@ int tracker_save_storages()
tracker_mem_file_lock(); tracker_mem_file_lock();
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \ snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
g_fdfs_base_path, STORAGE_SERVERS_LIST_FILENAME_NEW); SF_G_BASE_PATH_STR, STORAGE_SERVERS_LIST_FILENAME_NEW);
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename); snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
{ {
@ -2108,7 +2108,7 @@ int tracker_save_sync_timestamps()
tracker_mem_file_lock(); tracker_mem_file_lock();
snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \ snprintf(trueFilename, sizeof(trueFilename), "%s/data/%s", \
g_fdfs_base_path, STORAGE_SYNC_TIMESTAMP_FILENAME); SF_G_BASE_PATH_STR, STORAGE_SYNC_TIMESTAMP_FILENAME);
snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename); snprintf(tmpFilename, sizeof(tmpFilename), "%s.tmp", trueFilename);
if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) if ((fd=open(tmpFilename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0)
{ {
@ -2232,7 +2232,7 @@ static int tracker_open_changlog_file()
char data_path[MAX_PATH_SIZE]; char data_path[MAX_PATH_SIZE];
char filename[MAX_PATH_SIZE]; char filename[MAX_PATH_SIZE];
snprintf(data_path, sizeof(data_path), "%s/data", g_fdfs_base_path); snprintf(data_path, sizeof(data_path), "%s/data", SF_G_BASE_PATH_STR);
if (!fileExists(data_path)) if (!fileExists(data_path))
{ {
if (mkdir(data_path, 0755) != 0) if (mkdir(data_path, 0755) != 0)
@ -2247,7 +2247,7 @@ static int tracker_open_changlog_file()
} }
snprintf(filename, sizeof(filename), "%s/data/%s", \ snprintf(filename, sizeof(filename), "%s/data/%s", \
g_fdfs_base_path, STORAGE_SERVERS_CHANGELOG_FILENAME); SF_G_BASE_PATH_STR, STORAGE_SERVERS_CHANGELOG_FILENAME);
changelog_fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644); changelog_fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, 0644);
if (changelog_fd < 0) if (changelog_fd < 0)
{ {
@ -3934,7 +3934,7 @@ static int tracker_mem_get_one_sys_file(ConnectionInfo *pTrackerServer, \
int64_t file_size; int64_t file_size;
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
g_fdfs_base_path, g_tracker_sys_filenames[file_index]); SF_G_BASE_PATH_STR, g_tracker_sys_filenames[file_index]);
fd = open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644); fd = open(full_filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
if (fd < 0) if (fd < 0)
{ {
@ -5094,7 +5094,7 @@ static int tracker_write_to_trunk_change_log(FDFSGroupInfo *pGroup, \
tracker_mem_file_lock(); tracker_mem_file_lock();
snprintf(full_filename, sizeof(full_filename), "%s/logs/%s", \ snprintf(full_filename, sizeof(full_filename), "%s/logs/%s", \
g_fdfs_base_path, TRUNK_SERVER_CHANGELOG_FILENAME); SF_G_BASE_PATH_STR, TRUNK_SERVER_CHANGELOG_FILENAME);
if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0) if ((fd=open(full_filename, O_WRONLY | O_CREAT | O_APPEND, 0644)) < 0)
{ {
tracker_mem_file_unlock(); tracker_mem_file_unlock();

View File

@ -486,7 +486,7 @@ static int tracker_changelog_response(struct fast_task_info *pTask, \
chg_len = TRACKER_MAX_PACKAGE_SIZE - sizeof(TrackerHeader); chg_len = TRACKER_MAX_PACKAGE_SIZE - sizeof(TrackerHeader);
} }
snprintf(filename, sizeof(filename), "%s/data/%s", g_fdfs_base_path,\ snprintf(filename, sizeof(filename), "%s/data/%s", SF_G_BASE_PATH_STR,\
STORAGE_SERVERS_CHANGELOG_FILENAME); STORAGE_SERVERS_CHANGELOG_FILENAME);
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if (fd < 0) if (fd < 0)
@ -2098,7 +2098,7 @@ static int tracker_deal_get_one_sys_file(struct fast_task_info *pTask)
} }
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
g_fdfs_base_path, g_tracker_sys_filenames[index]); SF_G_BASE_PATH_STR, g_tracker_sys_filenames[index]);
if (stat(full_filename, &file_stat) != 0) if (stat(full_filename, &file_stat) != 0)
{ {
result = errno != 0 ? errno : ENOENT; result = errno != 0 ? errno : ENOENT;

View File

@ -38,7 +38,7 @@ int tracker_write_status_to_file(void *args)
int len; int len;
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
g_fdfs_base_path, TRACKER_STATUS_FILENAME); SF_G_BASE_PATH_STR, TRACKER_STATUS_FILENAME);
len = sprintf(buff, "%s=%d\n" \ len = sprintf(buff, "%s=%d\n" \
"%s=%d\n", "%s=%d\n",
@ -56,7 +56,7 @@ int tracker_load_status_from_file(TrackerStatus *pStatus)
int result; int result;
snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \ snprintf(full_filename, sizeof(full_filename), "%s/data/%s", \
g_fdfs_base_path, TRACKER_STATUS_FILENAME); SF_G_BASE_PATH_STR, TRACKER_STATUS_FILENAME);
if (!fileExists(full_filename)) if (!fileExists(full_filename))
{ {
return 0; return 0;