blob: 8b103ee1d9fab0a9565a025862a54fd7ae366de2 [file] [log] [blame]
hj.shaofe9d0022025-06-11 20:22:48 -07001#include "gsw_sys_interface.h"
2
hj.shao0bbdedc2025-06-20 04:18:11 -07003#define LOG_LEVLE_CONFIG_FILE "/etc/telinit"
4
hj.shaofe9d0022025-06-11 20:22:48 -07005int gsw_sys_svr_ftp_start(const char *cfg)
6{
7 int ret = GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -07008 char command[128] = "vsftpd &";
9 if(NULL == cfg)
10 {
11 ret = system(command);
12 }
13 else
14 {
15 sprintf(command, "vsftpd %s &", cfg);
16 ret = system(command);
17 }
18
19 if(ret != 0) {
20 printf("command execution failed command:%s.\n", command);
hj.shaofe9d0022025-06-11 20:22:48 -070021 return GSW_HAL_NORMAL_FAIL;
hj.shao0bbdedc2025-06-20 04:18:11 -070022 }
hj.shaofe9d0022025-06-11 20:22:48 -070023
24 return GSW_HAL_SUCCESS;
25}
26
27int gsw_sys_svr_ftp_stop()
28{
29 int ret = GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -070030 char command[] = "killall -TERM vsftpd";
31
32 ret = system(command);
33 if(ret != 0)
34 {
35 printf("command execution failed command:%s.\n", command);
36 return GSW_HAL_NORMAL_FAIL;
37 }
38
39 return GSW_HAL_SUCCESS;
40
hj.shaofe9d0022025-06-11 20:22:48 -070041}
42
43int gsw_sys_svr_ssh_start(const char *cfg)
44{
45 int ret= GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -070046 char command[128] = "/usr/sbin/dropbear &";
47
48 if(NULL == cfg)
49 {
50 ret = system(command);
51 }
52 else
53 {
54 sprintf(command, "/usr/sbin/dropbear %s &", cfg);
55 ret = system(command);
56 }
57
hj.shaofe9d0022025-06-11 20:22:48 -070058 if(ret != 0)
hj.shao0bbdedc2025-06-20 04:18:11 -070059 {
60 printf("command execution failed command:%s.\n", command);
hj.shaofe9d0022025-06-11 20:22:48 -070061 return GSW_HAL_NORMAL_FAIL;
hj.shao0bbdedc2025-06-20 04:18:11 -070062
63 }
hj.shaofe9d0022025-06-11 20:22:48 -070064 return GSW_HAL_SUCCESS;
65}
66
67int gsw_sys_svr_ssh_stop()
68{
69 int ret = GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -070070 char command[] = "killall dropbear";
71
72 ret = system(command);
hj.shaofe9d0022025-06-11 20:22:48 -070073 if(ret != 0)
hj.shao0bbdedc2025-06-20 04:18:11 -070074 {
75 printf("command execution failed command:%s.\n", command);
hj.shaofe9d0022025-06-11 20:22:48 -070076 return GSW_HAL_NORMAL_FAIL;
hj.shao0bbdedc2025-06-20 04:18:11 -070077 }
hj.shaofe9d0022025-06-11 20:22:48 -070078
79 return GSW_HAL_SUCCESS;
80}
81
82int gsw_sys_svr_syslog_restart(const char *log_lvl)
83{
84 (void)log_lvl;
hj.shao0bbdedc2025-06-20 04:18:11 -070085 char command[256] = {0};
86
87 snprintf(command, sizeof(command),
88 "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE);
89
90 int exists = system(command);
91 if (exists != 0) {
92 printf("config option not exist.\n");
93 return GSW_HAL_NORMAL_FAIL;
94 }
95
96 if(1 == strlen(log_lvl))
97 {
98 snprintf(command, sizeof(command),
99 "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s",
100 log_lvl, LOG_LEVLE_CONFIG_FILE);
101
102 int result = system(command);
103 if (result != 0) {
104 printf("command execution failed.\n");
105 return GSW_HAL_SUCCESS;
106 }
107
108 }
109
hj.shaofe9d0022025-06-11 20:22:48 -0700110 return GSW_HAL_NORMAL_FAIL;
111}
112
113