hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 1 | #include "gsw_sys_interface.h" |
| 2 | |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 3 | #define LOG_LEVLE_CONFIG_FILE "/etc/telinit" |
| 4 | |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 5 | int gsw_sys_svr_ftp_start(const char *cfg) |
| 6 | { |
| 7 | int ret = GSW_HAL_SUCCESS; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 8 | 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.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 21 | return GSW_HAL_NORMAL_FAIL; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 22 | } |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 23 | |
| 24 | return GSW_HAL_SUCCESS; |
| 25 | } |
| 26 | |
| 27 | int gsw_sys_svr_ftp_stop() |
| 28 | { |
| 29 | int ret = GSW_HAL_SUCCESS; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 30 | 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.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | int gsw_sys_svr_ssh_start(const char *cfg) |
| 44 | { |
| 45 | int ret= GSW_HAL_SUCCESS; |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 46 | char command[128] = "/usr/sbin/sshd &"; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 47 | |
| 48 | if(NULL == cfg) |
| 49 | { |
| 50 | ret = system(command); |
| 51 | } |
| 52 | else |
| 53 | { |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 54 | sprintf(command, "/usr/sbin/sshd %s &", cfg); |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 55 | ret = system(command); |
| 56 | } |
| 57 | |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 58 | if(ret != 0) |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 59 | { |
| 60 | printf("command execution failed command:%s.\n", command); |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 61 | return GSW_HAL_NORMAL_FAIL; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 62 | |
| 63 | } |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 64 | return GSW_HAL_SUCCESS; |
| 65 | } |
| 66 | |
| 67 | int gsw_sys_svr_ssh_stop() |
| 68 | { |
| 69 | int ret = GSW_HAL_SUCCESS; |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 70 | char command[] = "killall sshd"; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 71 | |
| 72 | ret = system(command); |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 73 | if(ret != 0) |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 74 | { |
| 75 | printf("command execution failed command:%s.\n", command); |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 76 | return GSW_HAL_NORMAL_FAIL; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 77 | } |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 78 | |
| 79 | return GSW_HAL_SUCCESS; |
| 80 | } |
| 81 | |
| 82 | int gsw_sys_svr_syslog_restart(const char *log_lvl) |
| 83 | { |
| 84 | (void)log_lvl; |
hj.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 85 | char command[256] = {0}; |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 86 | 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.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 89 | |
| 90 | snprintf(command, sizeof(command), |
| 91 | "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE); |
| 92 | |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 93 | 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.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 105 | int exists = system(command); |
| 106 | if (exists != 0) { |
| 107 | printf("config option not exist.\n"); |
| 108 | return GSW_HAL_NORMAL_FAIL; |
| 109 | } |
| 110 | |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 111 | 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.shao | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame] | 119 | } |
| 120 | |
hj.shao | c85a46f | 2025-06-23 23:59:51 -0700 | [diff] [blame^] | 121 | |
hj.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 122 | return GSW_HAL_NORMAL_FAIL; |
| 123 | } |
| 124 | |
| 125 | |