| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| #include <unistd.h> |
| #include <pthread.h> |
| #include <stddef.h> |
| #include <dlfcn.h> |
| #include "gsw_sys_interface.h" |
| #include "gsw_log_interface.h" |
| #define LOG_LEVLE_CONFIG_FILE "/etc/telinit" |
| |
| #define GSW_SYS "[HAL][GSW_SYS]" |
| int gsw_sys_svr_ftp_start(const char *cfg) |
| { |
| int ret = GSW_HAL_SUCCESS; |
| char command[128]; |
| |
| if(NULL == cfg) |
| { |
| strcpy(command, "/etc/init.d/vsftpd start"); |
| } |
| else |
| { |
| snprintf(command, sizeof(command), "vsftpd %s &", cfg); |
| } |
| ret = system(command); |
| if(ret != 0) { |
| LOGE(GSW_SYS, "command execution failed command:%s.\n", command); |
| goto exit; |
| } |
| exit: |
| return ret; |
| } |
| int gsw_sys_svr_ftp_stop() |
| { |
| int ret = GSW_HAL_SUCCESS; |
| |
| ret = system("/etc/init.d/vsftpd stop"); |
| if(ret != 0) |
| { |
| LOGE(GSW_SYS, "command /etc/init.d/vsftpd stop execution failed\n"); |
| printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret); |
| ret = system("killall -TERM vsftpd"); |
| if(ret != 0) |
| { |
| printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret); |
| LOGE(GSW_SYS, "command killall -TERM vsftpd execution failed\n"); |
| goto exit; |
| } |
| } |
| |
| exit: |
| return ret; |
| } |
| int gsw_sys_svr_ssh_start(const char *cfg) |
| { |
| int ret= GSW_HAL_SUCCESS; |
| char command[128]; |
| |
| if(NULL == cfg) |
| { |
| strcpy(command, "/etc/init.d/sshd start"); |
| } |
| else |
| { |
| snprintf(command, sizeof(command), "/usr/sbin/sshd -f %s &", cfg); |
| } |
| |
| ret = system(command); |
| if(ret != 0) |
| { |
| LOGE(GSW_SYS, "command execution failed command:%s.\n", command); |
| goto exit; |
| } |
| |
| exit: |
| return ret; |
| } |
| int gsw_sys_svr_ssh_stop() |
| { |
| int ret = GSW_HAL_SUCCESS; |
| |
| ret = system("/etc/init.d/sshd stop"); |
| if(ret != 0) |
| { |
| printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret); |
| LOGE(GSW_SYS, "command /etc/init.d/sshd stop sshd execution failed\n"); |
| ret = system("killall sshd"); |
| if(ret != 0) |
| { |
| printf("FUNC:[%s] %d ret:%d\n", __FUNCTION__, __LINE__, ret); |
| LOGE(GSW_SYS, "command killall sshd execution failed\n"); |
| goto exit; |
| } |
| } |
| |
| exit: |
| return ret; |
| } |
| int gsw_sys_svr_syslog_restart(const char *log_lvl) |
| { |
| (void)log_lvl; |
| int ret = GSW_HAL_SUCCESS; |
| 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) |
| { |
| LOGE(GSW_SYS, "Parameter error\n"); |
| ret = GSW_HAL_NORMAL_FAIL; |
| goto exit; |
| } |
| |
| ret = system(command); |
| if (ret != 0) |
| { |
| LOGE(GSW_SYS, "config option not exist.\n"); |
| goto exit; |
| } |
| snprintf(command, sizeof(command), |
| "sed -i 's/\\(setprop sys.default.loglevel \\)\\S*/\\1%s/' %s", |
| log_level_values[level], LOG_LEVLE_CONFIG_FILE); |
| |
| ret = system(command); |
| if (ret != 0) |
| { |
| LOGE(GSW_SYS, "command execution failed.\n"); |
| goto exit; |
| } |
| exit: |
| return ret; |
| } |
| |