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 | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame^] | 46 | 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.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 | 0bbdedc | 2025-06-20 04:18:11 -0700 | [diff] [blame^] | 70 | char command[] = "killall dropbear"; |
| 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}; |
| 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.shao | fe9d002 | 2025-06-11 20:22:48 -0700 | [diff] [blame] | 110 | return GSW_HAL_NORMAL_FAIL; |
| 111 | } |
| 112 | |
| 113 | |