Skip to content

Commit 38599bd

Browse files
committed
status_file_path clear code.
1 parent efeede6 commit 38599bd

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/android.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@
4747
#include "ssrutils.h"
4848
#include "utils.h"
4949

50-
int
51-
protect_socket(int fd)
52-
{
50+
int protect_socket(int fd) {
5351
int sock;
5452
struct sockaddr_un addr;
5553

@@ -94,12 +92,22 @@ protect_socket(int fd)
9492
return ret;
9593
}
9694

97-
extern char *stat_path;
95+
static char status_file_path[512] = { 0 };
96+
97+
void set_traffic_status_file_path(const char *path) {
98+
if (path) {
99+
strncpy(status_file_path, path, sizeof(status_file_path));
100+
}
101+
}
102+
103+
const char * get_traffic_status_file_path(void) {
104+
return status_file_path;
105+
}
98106

99107
int
100108
send_traffic_stat(uint64_t tx, uint64_t rx)
101109
{
102-
if (!stat_path) return 0;
110+
if (strlen(get_traffic_status_file_path()) == 0) return 0;
103111
int sock;
104112
struct sockaddr_un addr;
105113

@@ -117,7 +125,7 @@ send_traffic_stat(uint64_t tx, uint64_t rx)
117125

118126
memset(&addr, 0, sizeof(addr));
119127
addr.sun_family = AF_UNIX;
120-
strncpy(addr.sun_path, stat_path, sizeof(addr.sun_path) - 1);
128+
strncpy(addr.sun_path, get_traffic_status_file_path(), sizeof(addr.sun_path) - 1);
121129

122130
if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
123131
LOGE("[android] connect() failed for stat_path: %s (socket fd = %d)\n",

src/client/main.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ int log_tx_rx = 0;
4343
uint64_t tx = 0;
4444
uint64_t rx = 0;
4545
uint64_t last = 0;
46-
char *stat_path = NULL;
4746

4847
#include "ssrutils.h"
4948
static void dump_info_callback(int dump_level, const char* info, void* p) {
@@ -172,7 +171,7 @@ int main(int argc, char * const argv[]) {
172171

173172
#if ANDROID
174173
log_tx_rx = cmds->log_tx_rx;
175-
stat_path = cmds->stat_path;
174+
set_traffic_status_file_path(cmds->stat_path);
176175
#endif
177176

178177
print_remote_info(config);

src/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ extern int log_tx_rx;
6161
extern uint64_t tx;
6262
extern uint64_t rx;
6363
extern uint64_t last;
64-
extern char *stat_path;
64+
void set_traffic_status_file_path(const char *path);
6565

6666
#endif
6767

0 commit comments

Comments
 (0)