open file with flag O_CLOEXEC

replication_quorum
YuQing 2022-06-24 18:56:28 +08:00
parent 56ccde45ba
commit 8824c35975
5 changed files with 13 additions and 6 deletions

View File

@ -11,6 +11,8 @@ TOP_HEADERS = sf_types.h sf_global.h sf_define.h sf_nio.h sf_service.h \
sf_binlog_index.h sf_file_writer.h sf_binlog_writer.h \
sf_ordered_writer.h sf_buffered_writer.h sf_iov.h
IDEMP_COMMON_HEADER = idempotency/common/idempotency_types.h
IDEMP_SERVER_HEADER = idempotency/server/server_types.h \
idempotency/server/server_channel.h \
idempotency/server/request_htable.h \
@ -55,11 +57,13 @@ libserverframe.so: $(SHARED_OBJS)
install:
mkdir -p $(TARGET_LIB)
mkdir -p $(TARGET_PREFIX)/lib
mkdir -p $(TARGET_PREFIX)/include/sf/idempotency/common
mkdir -p $(TARGET_PREFIX)/include/sf/idempotency/server
mkdir -p $(TARGET_PREFIX)/include/sf/idempotency/client
install -m 755 $(ALL_LIBS) $(TARGET_LIB)
cp -f $(TOP_HEADERS) $(TARGET_PREFIX)/include/sf
cp -f $(IDEMP_COMMON_HEADER) $(TARGET_PREFIX)/include/sf/idempotency/common
cp -f $(IDEMP_SERVER_HEADER) $(TARGET_PREFIX)/include/sf/idempotency/server
cp -f $(IDEMP_CLIENT_HEADER) $(TARGET_PREFIX)/include/sf/idempotency/client

View File

@ -175,7 +175,9 @@ static int save(SFBinlogIndexContext *ctx, const char *filename)
int i;
int result;
if ((fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644)) < 0) {
if ((fd=open(filename, O_WRONLY | O_CREAT | O_TRUNC |
O_CLOEXEC, 0644)) < 0)
{
result = errno != 0 ? errno : EIO;
logError("file: "__FILE__", line: %d, "
"open file %s fail, errno: %d, error info: %s",

View File

@ -43,7 +43,8 @@ extern "C" {
int result;
writer->filename = filename;
writer->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0644);
writer->fd = open(filename, O_WRONLY | O_CREAT |
O_TRUNC | O_CLOEXEC, 0644);
if (writer->fd < 0) {
result = errno != 0 ? errno : EIO;
logError("file: "__FILE__", line: %d, "

View File

@ -166,8 +166,8 @@ static int open_writable_binlog(SFFileWriterInfo *writer)
}
GET_BINLOG_FILENAME(writer);
writer->file.fd = open(writer->file.name,
O_WRONLY | O_CREAT | O_APPEND, 0644);
writer->file.fd = open(writer->file.name, O_WRONLY |
O_CREAT | O_APPEND | O_CLOEXEC, 0644);
if (writer->file.fd < 0) {
logError("file: "__FILE__", line: %d, "
"open file \"%s\" fail, "

View File

@ -332,11 +332,11 @@ static int _socket_server(const char *bind_addr, int port, int *sock)
return result;
}
if ((result=tcpsetserveropt(*sock, g_sf_global_vars.network_timeout)) != 0) {
if ((result=tcpsetserveropt(*sock, SF_G_NETWORK_TIMEOUT)) != 0) {
return result;
}
return 0;
return fd_set_cloexec(*sock);
}
int sf_socket_server_ex(SFContext *sf_context)