| #include <stdio.h> |
| #include <stdlib.h> |
| #include <sys/types.h> |
| #include <unistd.h> |
| #include <fcntl.h> |
| #include <string.h> |
| #include "gsw_sys_interface.h" |
| |
| #define LOG_LEVLE_CONFIG_FILE "/etc/telinit" |
| |
| int gsw_sys_svr_ftp_start(const char *cfg) |
| { |
| int ret = GSW_HAL_SUCCESS; |
| char command[128] = "vsftpd &"; |
| if(NULL == cfg) |
| { |
| ret = system(command); |
| } |
| else |
| { |
| sprintf(command, "vsftpd %s &", cfg); |
| ret = system(command); |
| } |
| |
| if(ret != 0) { |
| printf("command execution failed command:%s.\n", command); |
| return GSW_HAL_NORMAL_FAIL; |
| } |
| |
| return GSW_HAL_SUCCESS; |
| } |
| |
| int gsw_sys_svr_ftp_stop() |
| { |
| int ret = GSW_HAL_SUCCESS; |
| char command[] = "killall -TERM vsftpd"; |
| |
| ret = system(command); |
| if(ret != 0) |
| { |
| printf("command execution failed command:%s.\n", command); |
| return GSW_HAL_NORMAL_FAIL; |
| } |
| |
| return GSW_HAL_SUCCESS; |
| |
| } |
| |
| int gsw_sys_svr_ssh_start(const char *cfg) |
| { |
| int ret= GSW_HAL_SUCCESS; |
| char command[128] = "/usr/sbin/sshd &"; |
| |
| if(NULL == cfg) |
| { |
| ret = system(command); |
| } |
| else |
| { |
| sprintf(command, "/usr/sbin/sshd %s &", cfg); |
| ret = system(command); |
| } |
| |
| if(ret != 0) |
| { |
| printf("command execution failed command:%s.\n", command); |
| return GSW_HAL_NORMAL_FAIL; |
| |
| } |
| return GSW_HAL_SUCCESS; |
| } |
| |
| int gsw_sys_svr_ssh_stop() |
| { |
| int ret = GSW_HAL_SUCCESS; |
| char command[] = "killall sshd"; |
| |
| ret = system(command); |
| if(ret != 0) |
| { |
| printf("command execution failed command:%s.\n", command); |
| return GSW_HAL_NORMAL_FAIL; |
| } |
| |
| return GSW_HAL_SUCCESS; |
| } |
| |
| int gsw_sys_svr_syslog_restart(const char *log_lvl) |
| { |
| (void)log_lvl; |
| char command[256] = {0}; |
| int level = 0; |
| char *log_level_params[8] = {"emerg", "alert", "crit", "err", "warning", "notice", "info", "debug"}; |
| char *log_level_values[8] = {"1", "2", "3", "4", "5", "6", "7", "8"}; |
| |
| snprintf(command, sizeof(command), |
| "grep -q 'setprop sys.default.loglevel' %s", LOG_LEVLE_CONFIG_FILE); |
| |
| for(level = 0; level < 8; level++) |
| { |
| if(0 == strcmp(log_lvl, log_level_params[level])) |
| break; |
| } |
| |
| if(8 == level) |
| { |
| printf("Parameter error\n"); |
| return -1; |
| } |
| |
| int exists = system(command); |
| if (exists != 0) { |
| printf("config option not exist.\n"); |
| return GSW_HAL_NORMAL_FAIL; |
| } |
| |
| snprintf(command, sizeof(command), |
| "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s", |
| log_level_values[level], LOG_LEVLE_CONFIG_FILE); |
| |
| int result = system(command); |
| if (result != 0) { |
| printf("command execution failed.\n"); |
| return GSW_HAL_SUCCESS; |
| } |
| |
| |
| return GSW_HAL_NORMAL_FAIL; |
| } |