blob: 7aa27342b74989892abf43999f966edb36d69014 [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.shaoc85a46f2025-06-23 23:59:51 -070046 char command[128] = "/usr/sbin/sshd &";
hj.shao0bbdedc2025-06-20 04:18:11 -070047
48 if(NULL == cfg)
49 {
50 ret = system(command);
51 }
52 else
53 {
hj.shaoc85a46f2025-06-23 23:59:51 -070054 sprintf(command, "/usr/sbin/sshd %s &", cfg);
hj.shao0bbdedc2025-06-20 04:18:11 -070055 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.shaoc85a46f2025-06-23 23:59:51 -070070 char command[] = "killall sshd";
hj.shao0bbdedc2025-06-20 04:18:11 -070071
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};
hj.shaoc85a46f2025-06-23 23:59:51 -070086 int level = 0;
87 char *log_level_params[8] = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
88 char *log_level_values[8] = {"1", "2", "3", "4", "5", "6", "7", "8"};
hj.shao0bbdedc2025-06-20 04:18:11 -070089
90 snprintf(command, sizeof(command),
91 "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE);
92
hj.shaoc85a46f2025-06-23 23:59:51 -070093 for(level = 0; level < 8; level++)
94 {
95 if(0 == strcmp(log_lvl, log_level_params[level]))
96 break;
97 }
98
99 if(8 == level)
100 {
101 printf("Parameter error\n");
102 return -1;
103 }
104
hj.shao0bbdedc2025-06-20 04:18:11 -0700105 int exists = system(command);
106 if (exists != 0) {
107 printf("config option not exist.\n");
108 return GSW_HAL_NORMAL_FAIL;
109 }
110
hj.shaoc85a46f2025-06-23 23:59:51 -0700111 snprintf(command, sizeof(command),
112 "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s",
113 log_level_values[level], LOG_LEVLE_CONFIG_FILE);
114
115 int result = system(command);
116 if (result != 0) {
117 printf("command execution failed.\n");
118 return GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -0700119 }
120
hj.shaoc85a46f2025-06-23 23:59:51 -0700121
hj.shaofe9d0022025-06-11 20:22:48 -0700122 return GSW_HAL_NORMAL_FAIL;
123}
124
125