From d30454fc5af3c3dbe684d01d99c17efbdf186dc9 Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 2 Nov 2018 18:27:42 +0100 Subject: [PATCH] fix: fflush(stdout), should sort out the blocking pipe problem add: line length (@merlokk) --- client/comms.c | 6 +++--- client/proxmark3.c | 12 +++++++----- client/ui.c | 19 ++++++++----------- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/client/comms.c b/client/comms.c index e297e9057..7204aa1c4 100644 --- a/client/comms.c +++ b/client/comms.c @@ -107,7 +107,7 @@ static void storeCommand(UsbCommand *command) { //If these two are equal, we're about to overwrite in the // circular buffer. PrintAndLogEx(FAILED, "WARNING: Command buffer about to overwrite command! This needs to be fixed!"); - fflush(NULL); + fflush(stdout); } //Store the command at the 'head' location UsbCommand* destination = &rxBuffer[cmd_head]; @@ -185,7 +185,7 @@ static void UsbCommandReceived(UsbCommand* c) { } else { PrintAndLogEx(NORMAL, "#db# %s", s); } - fflush(NULL); + fflush(stdout); break; } case CMD_DEBUG_PRINT_INTEGERS: { @@ -339,7 +339,7 @@ bool OpenProxmark(void *port, bool wait_for_port, int timeout, bool flash_mode) pthread_create(&USB_communication_thread, NULL, &uart_communication, &conn); //pthread_create(&FPC_communication_thread, NULL, &uart_communication, &conn); - fflush(NULL); + fflush(stdout); // create a mutex to avoid interlacing print commands from our different threads //pthread_mutex_init(&print_lock, NULL); return true; diff --git a/client/proxmark3.c b/client/proxmark3.c index ae528a9e9..6f664f4ce 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -40,7 +40,7 @@ static void showBanner(void){ printf("\nKeep iceman fork alive with a donation! https://paypal.me/iceman1001/"); printf("\nMONERO: 43mNJLpgBVaTvyZmX9ajcohpvVkaRy1kbZPm8tqAb7itZgfuYecgkRF36rXrKFUkwEGeZedPsASRxgv4HPBHvJwyJdyvQuP"); printf("\n\n\n"); - fflush(NULL); + fflush(stdout); } #endif @@ -260,6 +260,8 @@ int main(int argc, char* argv[]) { /* initialize history */ using_history(); + + rl_extend_line_buffer(1024); if (argc < 2) { show_help(true, argv[0]); @@ -282,23 +284,23 @@ int main(int argc, char* argv[]) { } // flush output - if(strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "-flush") == 0){ + if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "-flush") == 0){ SetFlushAfterWrite(true); PrintAndLogEx(INFO, "Output will be flushed after every print.\n"); } // wait for comport - if(strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "-wait") == 0){ + if (strcmp(argv[i], "-w") == 0 || strcmp(argv[i], "-wait") == 0){ waitCOMPort = true; } // execute pm3 command - if(strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-command") == 0){ + if (strcmp(argv[i], "-c") == 0 || strcmp(argv[i], "-command") == 0){ executeCommand = true; } // execute lua script - if(strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "-lua") == 0){ + if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "-lua") == 0){ executeCommand = true; addLuaExec = true; } diff --git a/client/ui.c b/client/ui.c index a8b45273d..070f75b7a 100644 --- a/client/ui.c +++ b/client/ui.c @@ -25,23 +25,20 @@ void PrintAndLogOptions(char *str[][2], size_t size, size_t space) { char buff[2000] = "Options:\n"; char format[2000] = ""; size_t counts[2] = {0, 0}; - for(int i = 0; i < size; i++) - for(int j = 0 ; j < 2 ; j++) - if(counts[j] < strlen(str[i][j])) - { + for (int i = 0; i < size; i++) + for (int j = 0 ; j < 2 ; j++) + if (counts[j] < strlen(str[i][j])) { counts[j] = strlen(str[i][j]); } - for(int i = 0; i < size; i++) - { - for(int j = 0; j < 2; j++) - { - if(j == 0) + for (int i = 0; i < size; i++) { + for (int j = 0; j < 2; j++) { + if (j == 0) snprintf(format, sizeof(format), "%%%zus%%%zus", space, counts[j]); else snprintf(format, sizeof(format), "%%%zus%%-%zus", space, counts[j]); snprintf(buff + strlen(buff), sizeof(buff) - strlen(buff), format, " ", str[i][j]); } - if(i