blob: e674fd6fbdd8d1d9ed75078c3bb5f77184f7d024 [file] [log] [blame]
hong.liud2417072025-06-27 07:10:37 -07001#include <stdio.h>
2#include <stdlib.h>
hong.liud2417072025-06-27 07:10:37 -07003#include <string.h>
hj.shao07bd13f2025-07-07 03:09:04 -07004#include <unistd.h>
5#include <pthread.h>
6#include <stddef.h>
7#include <dlfcn.h>
hj.shaofe9d0022025-06-11 20:22:48 -07008#include "gsw_sys_interface.h"
hj.shao4a9a5052025-07-19 03:56:43 -07009#include "gsw_log_interface.h"
hj.shao0bbdedc2025-06-20 04:18:11 -070010#define LOG_LEVLE_CONFIG_FILE "/etc/telinit"
hj.shao4a9a5052025-07-19 03:56:43 -070011
12#define GSW_SYS "[HAL][GSW_SYS]"
hj.shaofe9d0022025-06-11 20:22:48 -070013int gsw_sys_svr_ftp_start(const char *cfg)
14{
15 int ret = GSW_HAL_SUCCESS;
hj.shao07bd13f2025-07-07 03:09:04 -070016 char command[128];
hj.shao4a9a5052025-07-19 03:56:43 -070017
hj.shao0bbdedc2025-06-20 04:18:11 -070018 if(NULL == cfg)
19 {
hj.shao07bd13f2025-07-07 03:09:04 -070020 strcpy(command, "/etc/init.d/vsftpd start");
hj.shao0bbdedc2025-06-20 04:18:11 -070021 }
22 else
23 {
hj.shao07bd13f2025-07-07 03:09:04 -070024 snprintf(command, sizeof(command), "vsftpd %s &", cfg);
hj.shao0bbdedc2025-06-20 04:18:11 -070025 }
hj.shao07bd13f2025-07-07 03:09:04 -070026 ret = system(command);
hj.shao0bbdedc2025-06-20 04:18:11 -070027 if(ret != 0) {
hj.shao4a9a5052025-07-19 03:56:43 -070028 LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
hj.shao07bd13f2025-07-07 03:09:04 -070029 goto exit;
hj.shao0bbdedc2025-06-20 04:18:11 -070030 }
hj.shao07bd13f2025-07-07 03:09:04 -070031exit:
hj.shao07bd13f2025-07-07 03:09:04 -070032 return ret;
hj.shaofe9d0022025-06-11 20:22:48 -070033}
hj.shaofe9d0022025-06-11 20:22:48 -070034int gsw_sys_svr_ftp_stop()
35{
36 int ret = GSW_HAL_SUCCESS;
hj.shao07bd13f2025-07-07 03:09:04 -070037
hj.shao4a9a5052025-07-19 03:56:43 -070038 ret = system("/etc/init.d/vsftpd stop");
hj.shao0bbdedc2025-06-20 04:18:11 -070039 if(ret != 0)
40 {
hj.shao4a9a5052025-07-19 03:56:43 -070041 LOGE(GSW_SYS, "command /etc/init.d/vsftpd stop execution failed\n");
42 printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
43 ret = system("killall -TERM vsftpd");
44 if(ret != 0)
45 {
46 printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
47 LOGE(GSW_SYS, "command killall -TERM vsftpd execution failed\n");
48 goto exit;
49 }
hj.shao0bbdedc2025-06-20 04:18:11 -070050 }
51
hj.shao07bd13f2025-07-07 03:09:04 -070052exit:
hj.shao07bd13f2025-07-07 03:09:04 -070053 return ret;
hj.shaofe9d0022025-06-11 20:22:48 -070054}
hj.shaofe9d0022025-06-11 20:22:48 -070055int gsw_sys_svr_ssh_start(const char *cfg)
56{
57 int ret= GSW_HAL_SUCCESS;
hj.shao07bd13f2025-07-07 03:09:04 -070058 char command[128];
hj.shao07bd13f2025-07-07 03:09:04 -070059
hj.shao0bbdedc2025-06-20 04:18:11 -070060 if(NULL == cfg)
hj.shao07bd13f2025-07-07 03:09:04 -070061 {
hj.shao07bd13f2025-07-07 03:09:04 -070062 strcpy(command, "/etc/init.d/sshd start");
hj.shao0bbdedc2025-06-20 04:18:11 -070063 }
64 else
65 {
hj.shao07bd13f2025-07-07 03:09:04 -070066 snprintf(command, sizeof(command), "/usr/sbin/sshd -f %s &", cfg);
hj.shao0bbdedc2025-06-20 04:18:11 -070067 }
68
hj.shao07bd13f2025-07-07 03:09:04 -070069 ret = system(command);
hj.shaofe9d0022025-06-11 20:22:48 -070070 if(ret != 0)
hj.shao0bbdedc2025-06-20 04:18:11 -070071 {
hj.shao4a9a5052025-07-19 03:56:43 -070072 LOGE(GSW_SYS, "command execution failed command:%s.\n", command);
hj.shao07bd13f2025-07-07 03:09:04 -070073 goto exit;
hj.shao0bbdedc2025-06-20 04:18:11 -070074 }
hj.shao07bd13f2025-07-07 03:09:04 -070075
hj.shao4a9a5052025-07-19 03:56:43 -070076exit:
hj.shao07bd13f2025-07-07 03:09:04 -070077 return ret;
hj.shaofe9d0022025-06-11 20:22:48 -070078}
hj.shaofe9d0022025-06-11 20:22:48 -070079int gsw_sys_svr_ssh_stop()
80{
81 int ret = GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -070082
hj.shao4a9a5052025-07-19 03:56:43 -070083 ret = system("/etc/init.d/sshd stop");
hj.shaofe9d0022025-06-11 20:22:48 -070084 if(ret != 0)
hj.shao0bbdedc2025-06-20 04:18:11 -070085 {
hj.shao4a9a5052025-07-19 03:56:43 -070086 printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
87 LOGE(GSW_SYS, "command /etc/init.d/sshd stop sshd execution failed\n");
88 ret = system("killall sshd");
89 if(ret != 0)
90 {
91 printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret);
92 LOGE(GSW_SYS, "command killall sshd execution failed\n");
93 goto exit;
94 }
hj.shao0bbdedc2025-06-20 04:18:11 -070095 }
hj.shaofe9d0022025-06-11 20:22:48 -070096
hj.shao4a9a5052025-07-19 03:56:43 -070097exit:
hj.shao07bd13f2025-07-07 03:09:04 -070098 return ret;
hj.shaofe9d0022025-06-11 20:22:48 -070099}
hj.shaofe9d0022025-06-11 20:22:48 -0700100int gsw_sys_svr_syslog_restart(const char *log_lvl)
101{
102 (void)log_lvl;
hj.shao07bd13f2025-07-07 03:09:04 -0700103 int ret = GSW_HAL_SUCCESS;
hj.shao0bbdedc2025-06-20 04:18:11 -0700104 char command[256] = {0};
hj.shaoc85a46f2025-06-23 23:59:51 -0700105 int level = 0;
106 char *log_level_params[8] = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"};
107 char *log_level_values[8] = {"1", "2", "3", "4", "5", "6", "7", "8"};
hj.shao0bbdedc2025-06-20 04:18:11 -0700108 snprintf(command, sizeof(command),
109 "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE);
hj.shaoc85a46f2025-06-23 23:59:51 -0700110 for(level = 0; level < 8; level++)
111 {
112 if(0 == strcmp(log_lvl, log_level_params[level]))
113 break;
114 }
hj.shaoc85a46f2025-06-23 23:59:51 -0700115 if(8 == level)
116 {
hj.shao4a9a5052025-07-19 03:56:43 -0700117 LOGE(GSW_SYS, "Parameter error\n");
hj.shao07bd13f2025-07-07 03:09:04 -0700118 ret = GSW_HAL_NORMAL_FAIL;
119 goto exit;
hj.shaoc85a46f2025-06-23 23:59:51 -0700120 }
121
hj.shao07bd13f2025-07-07 03:09:04 -0700122 ret = system(command);
123 if (ret != 0)
124 {
hj.shao4a9a5052025-07-19 03:56:43 -0700125 LOGE(GSW_SYS, "config option not exist.\n");
hj.shao07bd13f2025-07-07 03:09:04 -0700126 goto exit;
hj.shao0bbdedc2025-06-20 04:18:11 -0700127 }
hj.shaoc85a46f2025-06-23 23:59:51 -0700128 snprintf(command, sizeof(command),
129 "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s",
130 log_level_values[level], LOG_LEVLE_CONFIG_FILE);
131
hj.shao07bd13f2025-07-07 03:09:04 -0700132 ret = system(command);
133 if (ret != 0)
134 {
hj.shao4a9a5052025-07-19 03:56:43 -0700135 LOGE(GSW_SYS, "command execution failed.\n");
hj.shao07bd13f2025-07-07 03:09:04 -0700136 goto exit;
hj.shao0bbdedc2025-06-20 04:18:11 -0700137 }
hj.shao4a9a5052025-07-19 03:56:43 -0700138exit:
hj.shao07bd13f2025-07-07 03:09:04 -0700139 return ret;
hj.shaofe9d0022025-06-11 20:22:48 -0700140}
hj.shao07bd13f2025-07-07 03:09:04 -0700141