From 12429918b4acbd5ea2a5113625fbdfb14d781bae Mon Sep 17 00:00:00 2001 From: Romit Kumar Date: Mon, 13 Dec 2021 13:03:42 +0530 Subject: [PATCH 1/6] Prefer Python3 over Python2 --- .../ConsistencyInvoker/ConsistencyInvoker.c | 18 +++--- .../ca/CAInfrastructure/WebPullClient.c | 47 ++++++++------- LCM/scripts/InstallModule.py | 2 +- LCM/scripts/calcPythonPath.sh | 22 ++++--- Providers/PythonProvider.cpp | 27 +++++---- installbuilder/datafiles/Base_DSC.data | 60 +++++++++---------- 6 files changed, 91 insertions(+), 85 deletions(-) diff --git a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c index 5df34cad0..bb5479b47 100644 --- a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c +++ b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c @@ -61,35 +61,35 @@ char* getPythonProvider() char* result = malloc(1); *result = 0; - FILE* pipe = popen("python2 --version 2>&1", "r"); + FILE* pipe = popen("python3 --version 2>&1", "r"); if(!pipe) { - printf("Cant start command."); + printf("Cant start command."); } while(fgets(buffer, 128, pipe) != NULL) { result = realloc(result, (result ? strlen(result) : 0) + buffer_length ); strcat(result,buffer); } - // If python2 --version does not contain 'not found' return python2 + // If python3 --version does not contain 'not found' return python3 if(strstr(result, "not found") == NULL) { - return PYTHON2_COMMAND; + return PYTHON3_COMMAND; } - // Look for python3 + // Look for python2 result = malloc(1); *result = 0; - pipe = popen("python3 --version 2>&1", "r"); + pipe = popen("python2 --version 2>&1", "r"); if(!pipe) { - printf("Cant start command."); + printf("Cant start command."); } while(fgets(buffer, 128, pipe) != NULL) { result = realloc(result, (result ? strlen(result) : 0) + buffer_length ); strcat(result,buffer); } - // If python3 --version does not contain 'not found' return python3 + // If python2 --version does not contain 'not found' return python2 if(strstr(result, "not found") == NULL) { - return PYTHON3_COMMAND; + return PYTHON2_COMMAND; } return PYTHON_COMMAND; diff --git a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c index 2cd52e9b6..4aab4bdcf 100755 --- a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c +++ b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c @@ -2073,38 +2073,39 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, } // Determine python version char data[BUFSIZ]; - int isPython2 = 1; + int isPython3 = 0; DSC_LOG_INFO("Assuming python2 in WebPullClient\n"); - // Look for python2 - FILE * pipe = popen("python2 --version 2>&1", "r"); + // Look for python3 + FILE * pipe = popen("python3 --version 2>&1", "r"); fgets(data, BUFSIZ, pipe); if (!strstr(data, "not found")) { - DSC_LOG_INFO("Found python2 in WebPullClient.\n"); - isPython2 = 1; - } + DSC_LOG_INFO("Found python3 in WebPullClient.\n"); + isPython3 = 1; + } else { - // If python2 does not exist, look for python3 + // If python3 does not exist, look for python2 memset(&data[0], 0, sizeof(data)); - pipe = popen("python3 --version 2>&1", "r"); - fgets(data, BUFSIZ, pipe); - if (!strstr(data, "not found")) { - DSC_LOG_INFO("Found python3 in WebPullClient.\n"); - isPython2 = 0; - } + pipe = popen("python2 --version 2>&1", "r"); + fgets(data, BUFSIZ, pipe); + if (!strstr(data, "not found")) + { + DSC_LOG_INFO("Found python2 in WebPullClient.\n"); + isPython3 = 0; + } } - if (isPython2 == 1) + if (isPython3 == 1) { - DSC_LOG_INFO("Calling InstallModule with python2"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); + DSC_LOG_INFO("Calling InstallModule with python3"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); } else { - DSC_LOG_INFO("Calling InstallModule with python3"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); + DSC_LOG_INFO("Calling InstallModule with python2"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); } DSC_LOG_INFO("executing '%T'\n", stringBuffer); retval = system(stringBuffer); @@ -2119,15 +2120,15 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, else { // Attempt to remove the module as a last resort. If it fails too, a reinstall may be necessary. - if (isPython2 == 1) + if (isPython3 == 1) { - DSC_LOG_INFO("Calling RemoveModule with python2"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s", DSC_SCRIPT_PATH "/RemoveModule.py", current->moduleName); + DSC_LOG_INFO("Calling RemoveModule with python3"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/RemoveModule.py", current->moduleName, " 2>&1"); } else { - DSC_LOG_INFO("Calling RemoveModule with python3"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/RemoveModule.py", current->moduleName, " 2>&1"); + DSC_LOG_INFO("Calling RemoveModule with python2"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s", DSC_SCRIPT_PATH "/RemoveModule.py", current->moduleName); } retval = system(stringBuffer); diff --git a/LCM/scripts/InstallModule.py b/LCM/scripts/InstallModule.py index 03f72c483..b00217900 100755 --- a/LCM/scripts/InstallModule.py +++ b/LCM/scripts/InstallModule.py @@ -66,7 +66,7 @@ def getPlatformArchitectureFolderName(): def regenerateDscPythonScriptInitFiles(): regenerateInitFilesScriptPath = join(helperlib.DSC_SCRIPT_PATH, 'RegenerateInitFiles.py') - regenerateInitFilesResult = subprocess.call("(python " + regenerateInitFilesScriptPath + ")", shell=True) + regenerateInitFilesResult = subprocess.call("(python2 " + regenerateInitFilesScriptPath + ")", shell=True) if regenerateInitFilesResult != 0: exitWithError("Failed to regenerate the DSC __init__.py files with the result code", regenerateInitFilesResult) diff --git a/LCM/scripts/calcPythonPath.sh b/LCM/scripts/calcPythonPath.sh index 6b91dd1b1..ea0a0553a 100755 --- a/LCM/scripts/calcPythonPath.sh +++ b/LCM/scripts/calcPythonPath.sh @@ -4,17 +4,21 @@ if [ "$#" -ne 0 ] then # Checking which python version is available # python3 - if [[ -z $(python2 --version 2>&1 | grep 'not found') ]] - then - #echo "python exists"; - pythonVer="python2" - elif [[ -z $(python3 --version 2>&1 | grep 'not found') ]] + version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + if [ ! -z "$version" ] then #echo "python3 exists"; - pythonVer="python3" - else - echo "'python2' or 'python3' not found on this machine. Please install python." - exit 1 + pythonVer="python3" + else + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') + if [ ! -z "$version" ] + then + #echo "python exists"; + pythonVer="python2" + else + echo "'python2' or 'python3' not found on this machine. Please install python." + exit 1 + fi fi # Detemine file location diff --git a/Providers/PythonProvider.cpp b/Providers/PythonProvider.cpp index 4b0706832..c022feadf 100755 --- a/Providers/PythonProvider.cpp +++ b/Providers/PythonProvider.cpp @@ -58,40 +58,41 @@ std::string determinePythonVersion(){ char* result = (char*)malloc(1); *result = 0; - // Check for python2 - FILE* pipe = popen("python2 --version 2>&1", "r"); + // Check for python3 + FILE* pipe = popen("python3 --version 2>&1", "r"); if(!pipe) { - std::cout << "Couldn't start command." << std::endl; + std::cout << "Couldn't start command." << std::endl; } - while(fgets(buffer, 128, pipe) != NULL) { result = (char*)realloc(result, (result ? strlen(result) : 0) + buffer_length ); strcat(result,buffer); } - // If python2 --version does not contain 'not found' return python2 + // If python3 --version does not contain 'not found' return python3 if(strstr(result, "not found") == NULL) { - std::cout << "Found python2." << std::endl; - return "python2"; + std::cout << "Found python3." << std::endl; + return "python3"; } - // Look for python3 + // Look for python2 result = (char*)malloc(1); *result = 0; - pipe = popen("python3 --version 2>&1", "r"); + pipe = popen("python2 --version 2>&1", "r"); if(!pipe) { - std::cout << "Couldn't start command." << std::endl; + std::cout << "Couldn't start command." << std::endl; } + while(fgets(buffer, 128, pipe) != NULL) { result = (char*)realloc(result, (result ? strlen(result) : 0) + buffer_length ); strcat(result,buffer); } - // If python3 --version does not contain 'not found' return python3 + // If python2 --version does not contain 'not found' return python2 if(strstr(result, "not found") == NULL) { - std::cout << "Found python3." << std::endl; - return "python3"; + std::cout << "Found python2." << std::endl; + return "python2"; } + return "python"; } diff --git a/installbuilder/datafiles/Base_DSC.data b/installbuilder/datafiles/Base_DSC.data index 6c060c685..6b2b265fd 100755 --- a/installbuilder/datafiles/Base_DSC.data +++ b/installbuilder/datafiles/Base_DSC.data @@ -212,15 +212,15 @@ fi %Preinstall_200 # pythonVersion check must be repeated for each section -version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') +version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python2" - pythonVersion="python2" + echo "Using python3" + pythonVersion="python3" else - version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python3" - pythonVersion="python3" + echo "Using python2" + pythonVersion="python2" else echo "Python not found." fi @@ -372,15 +372,15 @@ chmod 1775 /opt/microsoft/omsconfig/Scripts # pythonVersion check must be repeated for each section -version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') +version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python2" - pythonVersion="python2" + echo "Using python3" + pythonVersion="python3" else - version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python3" - pythonVersion="python3" + echo "Using python2" + pythonVersion="python2" else echo "Python not found." fi @@ -464,15 +464,15 @@ if [ -d "/etc/opt/omi/conf/omsconfig" ]; then chown -R omsagent:omiusers /etc/op #else # pythonVersion check must be repeated for each section -version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') +version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python2" - pythonVersion="python2" + echo "Using python3" + pythonVersion="python3" else - version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python3" - pythonVersion="python3" + echo "Using python2" + pythonVersion="python2" else echo "Python not found." fi @@ -573,15 +573,15 @@ mv /etc/crontabtmp /etc/crontab #if BUILD_OMS == 1 # pythonVersion check must be repeated for each section -version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') +version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python2" - pythonVersion="python2" + echo "Using python3" + pythonVersion="python3" else - version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python3" - pythonVersion="python3" + echo "Using python2" + pythonVersion="python2" else echo "Python not found." fi @@ -619,15 +619,15 @@ echo "Cleaned up existing dsc_hosts before uninstall..." %Preuninstall_999 # pythonVersion check must be repeated for each section -version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') +version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python2" - pythonVersion="python2" + echo "Using python3" + pythonVersion="python3" else - version=$(python3 -V 2>&1 | grep -Po '(?<=Python )(.+)') + version=$(python2 -V 2>&1 | grep -Po '(?<=Python )(.+)') if [ ! -z "$version" ]; then - echo "Using python3" - pythonVersion="python3" + echo "Using python2" + pythonVersion="python2" else echo "Python not found." fi From 881a3d9cd4a3333613b19eb3c3ef25c107894257 Mon Sep 17 00:00:00 2001 From: Romit Kumar Date: Mon, 13 Dec 2021 17:00:14 +0530 Subject: [PATCH 2/6] fix language barier to identify python version --- .../engine/ConsistencyInvoker/ConsistencyInvoker.c | 12 ++++++------ LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c | 8 ++++---- Providers/PythonProvider.cpp | 12 ++++++------ 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c index bb5479b47..e234dd5eb 100644 --- a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c +++ b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c @@ -61,7 +61,7 @@ char* getPythonProvider() char* result = malloc(1); *result = 0; - FILE* pipe = popen("python3 --version 2>&1", "r"); + FILE* pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { printf("Cant start command."); } @@ -70,15 +70,15 @@ char* getPythonProvider() strcat(result,buffer); } - // If python3 --version does not contain 'not found' return python3 - if(strstr(result, "not found") == NULL) { + // Checking if Python version starts with 3.*.* + if(result[0] == '3') { return PYTHON3_COMMAND; } // Look for python2 result = malloc(1); *result = 0; - pipe = popen("python2 --version 2>&1", "r"); + pipe = popen("python2 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { printf("Cant start command."); } @@ -87,8 +87,8 @@ char* getPythonProvider() strcat(result,buffer); } - // If python2 --version does not contain 'not found' return python2 - if(strstr(result, "not found") == NULL) { + // Checking if Python version starts with 2.*.* + if(result[0] == '2') { return PYTHON2_COMMAND; } diff --git a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c index 4aab4bdcf..f51e3838a 100755 --- a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c +++ b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c @@ -2077,9 +2077,9 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, DSC_LOG_INFO("Assuming python2 in WebPullClient\n"); // Look for python3 - FILE * pipe = popen("python3 --version 2>&1", "r"); + FILE * pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); fgets(data, BUFSIZ, pipe); - if (!strstr(data, "not found")) + if (data[0] == '3') { DSC_LOG_INFO("Found python3 in WebPullClient.\n"); isPython3 = 1; @@ -2088,9 +2088,9 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, { // If python3 does not exist, look for python2 memset(&data[0], 0, sizeof(data)); - pipe = popen("python2 --version 2>&1", "r"); + pipe = popen("python2 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); fgets(data, BUFSIZ, pipe); - if (!strstr(data, "not found")) + if (data[0] == '2') { DSC_LOG_INFO("Found python2 in WebPullClient.\n"); isPython3 = 0; diff --git a/Providers/PythonProvider.cpp b/Providers/PythonProvider.cpp index c022feadf..828d89799 100755 --- a/Providers/PythonProvider.cpp +++ b/Providers/PythonProvider.cpp @@ -59,7 +59,7 @@ std::string determinePythonVersion(){ *result = 0; // Check for python3 - FILE* pipe = popen("python3 --version 2>&1", "r"); + FILE* pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { std::cout << "Couldn't start command." << std::endl; } @@ -68,8 +68,8 @@ std::string determinePythonVersion(){ strcat(result,buffer); } - // If python3 --version does not contain 'not found' return python3 - if(strstr(result, "not found") == NULL) { + // Checking if Python version starts with 3.*.* + if(result[0] == '3') { std::cout << "Found python3." << std::endl; return "python3"; } @@ -77,7 +77,7 @@ std::string determinePythonVersion(){ // Look for python2 result = (char*)malloc(1); *result = 0; - pipe = popen("python2 --version 2>&1", "r"); + pipe = popen("python2 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { std::cout << "Couldn't start command." << std::endl; } @@ -87,8 +87,8 @@ std::string determinePythonVersion(){ strcat(result,buffer); } - // If python2 --version does not contain 'not found' return python2 - if(strstr(result, "not found") == NULL) { + // Checking if Python version starts with 2.*.* + if(result[0] == '2') { std::cout << "Found python2." << std::endl; return "python2"; } From 7aa63ed5a934b8dd7e0e4ce92d08dcd68ed02737 Mon Sep 17 00:00:00 2001 From: Romit Kumar Date: Mon, 13 Dec 2021 17:20:00 +0530 Subject: [PATCH 3/6] Indentation fix --- LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c | 8 ++++---- Providers/PythonProvider.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c index f51e3838a..283cd70df 100755 --- a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c +++ b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c @@ -2076,7 +2076,7 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, int isPython3 = 0; DSC_LOG_INFO("Assuming python2 in WebPullClient\n"); - // Look for python3 + // Look for python3 FILE * pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); fgets(data, BUFSIZ, pipe); if (data[0] == '3') @@ -2100,12 +2100,12 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, if (isPython3 == 1) { DSC_LOG_INFO("Calling InstallModule with python3"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); } else { - DSC_LOG_INFO("Calling InstallModule with python2"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); + DSC_LOG_INFO("Calling InstallModule with python2"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); } DSC_LOG_INFO("executing '%T'\n", stringBuffer); retval = system(stringBuffer); diff --git a/Providers/PythonProvider.cpp b/Providers/PythonProvider.cpp index 828d89799..31af12ed9 100755 --- a/Providers/PythonProvider.cpp +++ b/Providers/PythonProvider.cpp @@ -61,7 +61,7 @@ std::string determinePythonVersion(){ // Check for python3 FILE* pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { - std::cout << "Couldn't start command." << std::endl; + std::cout << "Couldn't start command." << std::endl; } while(fgets(buffer, 128, pipe) != NULL) { result = (char*)realloc(result, (result ? strlen(result) : 0) + buffer_length ); @@ -71,7 +71,7 @@ std::string determinePythonVersion(){ // Checking if Python version starts with 3.*.* if(result[0] == '3') { std::cout << "Found python3." << std::endl; - return "python3"; + return "python3"; } // Look for python2 @@ -90,7 +90,7 @@ std::string determinePythonVersion(){ // Checking if Python version starts with 2.*.* if(result[0] == '2') { std::cout << "Found python2." << std::endl; - return "python2"; + return "python2"; } return "python"; From 50c5298d405fe8d130bf7058583da26321ec0a03 Mon Sep 17 00:00:00 2001 From: Romit Kumar Date: Mon, 13 Dec 2021 17:22:36 +0530 Subject: [PATCH 4/6] Revert "Indentation fix" This reverts commit 7aa63ed5a934b8dd7e0e4ce92d08dcd68ed02737. --- LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c | 8 ++++---- Providers/PythonProvider.cpp | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c index 283cd70df..f51e3838a 100755 --- a/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c +++ b/LCM/dsc/engine/ca/CAInfrastructure/WebPullClient.c @@ -2076,7 +2076,7 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, int isPython3 = 0; DSC_LOG_INFO("Assuming python2 in WebPullClient\n"); - // Look for python3 + // Look for python3 FILE * pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); fgets(data, BUFSIZ, pipe); if (data[0] == '3') @@ -2100,12 +2100,12 @@ MI_Result MI_CALL Pull_GetModules(_Out_ MI_Uint32 * numModulesInstalled, if (isPython3 == 1) { DSC_LOG_INFO("Calling InstallModule with python3"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s %s", "/usr/bin/python3 " DSC_SCRIPT_PATH "/python3/InstallModule.py", zipPath, verifyFlag, " 2>&1"); } else { - DSC_LOG_INFO("Calling InstallModule with python2"); - Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); + DSC_LOG_INFO("Calling InstallModule with python2"); + Snprintf(stringBuffer, MAX_URL_LENGTH, "%s %s %s", DSC_SCRIPT_PATH "/InstallModule.py", zipPath, verifyFlag); } DSC_LOG_INFO("executing '%T'\n", stringBuffer); retval = system(stringBuffer); diff --git a/Providers/PythonProvider.cpp b/Providers/PythonProvider.cpp index 31af12ed9..828d89799 100755 --- a/Providers/PythonProvider.cpp +++ b/Providers/PythonProvider.cpp @@ -61,7 +61,7 @@ std::string determinePythonVersion(){ // Check for python3 FILE* pipe = popen("python3 -V 2>&1 | grep -Po '(?<=Python )(.+)'", "r"); if(!pipe) { - std::cout << "Couldn't start command." << std::endl; + std::cout << "Couldn't start command." << std::endl; } while(fgets(buffer, 128, pipe) != NULL) { result = (char*)realloc(result, (result ? strlen(result) : 0) + buffer_length ); @@ -71,7 +71,7 @@ std::string determinePythonVersion(){ // Checking if Python version starts with 3.*.* if(result[0] == '3') { std::cout << "Found python3." << std::endl; - return "python3"; + return "python3"; } // Look for python2 @@ -90,7 +90,7 @@ std::string determinePythonVersion(){ // Checking if Python version starts with 2.*.* if(result[0] == '2') { std::cout << "Found python2." << std::endl; - return "python2"; + return "python2"; } return "python"; From 4dfbfc69766037d26e692e96ca5a7a2992469403 Mon Sep 17 00:00:00 2001 From: romit-kumar <86049525+romit-kumar@users.noreply.github.com> Date: Mon, 14 Mar 2022 18:22:33 +0530 Subject: [PATCH 5/6] Checking pointer value as null. --- LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c index e234dd5eb..d56c7bae3 100644 --- a/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c +++ b/LCM/dsc/engine/ConsistencyInvoker/ConsistencyInvoker.c @@ -71,7 +71,7 @@ char* getPythonProvider() } // Checking if Python version starts with 3.*.* - if(result[0] == '3') { + if(*result != '\0' && result[0] == '3') { return PYTHON3_COMMAND; } @@ -88,7 +88,7 @@ char* getPythonProvider() } // Checking if Python version starts with 2.*.* - if(result[0] == '2') { + if(*result != '\0' && result[0] == '2') { return PYTHON2_COMMAND; } From 2b6754cd5d4a3e819205e3397b48f9b1b4c72b1d Mon Sep 17 00:00:00 2001 From: romit-kumar <86049525+romit-kumar@users.noreply.github.com> Date: Mon, 14 Mar 2022 18:28:06 +0530 Subject: [PATCH 6/6] check result value is not null --- Providers/PythonProvider.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Providers/PythonProvider.cpp b/Providers/PythonProvider.cpp index 828d89799..e580741bc 100755 --- a/Providers/PythonProvider.cpp +++ b/Providers/PythonProvider.cpp @@ -69,7 +69,7 @@ std::string determinePythonVersion(){ } // Checking if Python version starts with 3.*.* - if(result[0] == '3') { + if(*result != '\0' && result[0] == '3') { std::cout << "Found python3." << std::endl; return "python3"; } @@ -88,7 +88,7 @@ std::string determinePythonVersion(){ } // Checking if Python version starts with 2.*.* - if(result[0] == '2') { + if(*result != '\0' && result[0] == '2') { std::cout << "Found python2." << std::endl; return "python2"; }