Файлы System/bin Android 12. Справочник.


  Все     Команда     Скрипт     Служба     Приложение  

systemmixservice - исходный текст
int SystemMixService::runShell(const char *cmd, char *result) {
	if (DEBUG) {
		ALOGD("SystemMixService::runshell() cmd = %s", cmd);
	}
 
	char buffer[MAX_BUFFER_SIZE] = {0};
	FILE *fp;
	int ret = 0;
 
	// write command to buffer, %s 2>&1
	snprintf(buffer, sizeof(buffer), "%s\n", cmd);
	fp = popen(buffer, "r");
	if (fp != NULL){
		int remainder = MAX_BUFFER_SIZE;
		int len = 0;
		memset(buffer, 0, MAX_BUFFER_SIZE);
		while (fgets(buffer, MAX_BUFFER_SIZE, fp) != NULL){
			len = strlen(buffer);
			if (remainder > len){
				strcat(result, buffer);
				remainder -= len;
			}else{
				if (remainder > 1){
					strncat(result, buffer, remainder - 1);
					remainder = 0;
					break;
				}
			}
			//ALOGD("%s", buffer);
		}
 
		ret = pclose(fp);
		if (ret == -1){
			ALOGD("SystemMixService::runshell() pclose() failed\n");
			return -1;
		}
 
		if (WIFEXITED(ret)){
			ALOGD("SystemMixService::runshell() subprocess exited, exit code: %d\n", WEXITSTATUS(ret));
			if (0 != WEXITSTATUS(ret)){
				ALOGD("SystemMixService::runshell() command failed: %s\n", strerror(WEXITSTATUS(ret)));
				return WEXITSTATUS(ret);
			}
		}else{
			ALOGD("SystemMixService::runshell() subprocess exit failed\n");
			return -1;
		}
	}else{
		ALOGD("SystemMixService::runshell() popen() %s error\n", cmd);
		return -1;
	}
 
	//ALOGD("SystemMixService::runshell()  result = %s", result);
	return 0;
}