From 96adb827a38d50a944e476873849fc35a70aaede Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Mon, 24 Feb 2020 17:17:16 +0800 Subject: [PATCH] arch/sim: Ensure all host printf end with \r\n Since simulator switch console to raw mode, we have to add \r manually --- arch/sim/src/sim/up_head.c | 4 ++-- arch/sim/src/sim/up_tapdev.c | 32 ++++++++++++++-------------- arch/sim/src/sim/up_wpcap.c | 30 +++++++++++++------------- arch/sim/src/sim/up_x11framebuffer.c | 12 ++++------- 4 files changed, 37 insertions(+), 41 deletions(-) diff --git a/arch/sim/src/sim/up_head.c b/arch/sim/src/sim/up_head.c index 33e86879bc..9fd93e70f1 100644 --- a/arch/sim/src/sim/up_head.c +++ b/arch/sim/src/sim/up_head.c @@ -113,10 +113,10 @@ void up_assert(const uint8_t *filename, int line) /* Show the location of the failed assertion */ #ifdef CONFIG_SMP - fprintf(stderr, "CPU%d: Assertion failed at file:%s line: %d\n", + fprintf(stderr, "CPU%d: Assertion failed at file:%s line: %d\r\n", up_cpu_index(), filename, line); #else - fprintf(stderr, "Assertion failed at file:%s line: %d\n", + fprintf(stderr, "Assertion failed at file:%s line: %d\r\n", filename, line); #endif diff --git a/arch/sim/src/sim/up_tapdev.c b/arch/sim/src/sim/up_tapdev.c index 7d2eef9f29..8ea4ccae68 100644 --- a/arch/sim/src/sim/up_tapdev.c +++ b/arch/sim/src/sim/up_tapdev.c @@ -115,9 +115,9 @@ static struct rtentry ghostroute; static inline void dump_ethhdr(const char *msg, unsigned char *buf, int buflen) { - printf("TAPDEV: %s %d bytes\n", msg, buflen); + printf("TAPDEV: %s %d bytes\r\n", msg, buflen); printf(" %02x:%02x:%02x:%02x:%02x:%02x " - "%02x:%02x:%02x:%02x:%02x:%02x %02x%02x\n", + "%02x:%02x:%02x:%02x:%02x:%02x %02x%02x\r\n", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], buf[8], buf[9], buf[10], buf[11], #ifdef CONFIG_ENDIAN_BIG @@ -178,7 +178,7 @@ void tapdev_init(void) gtapdevfd = open(DEVTAP, O_RDWR, 0644); if (gtapdevfd < 0) { - printf("TAPDEV: open failed: %d\n", -gtapdevfd); + printf("TAPDEV: open failed: %d\r\n", -gtapdevfd); return; } @@ -189,7 +189,7 @@ void tapdev_init(void) ret = ioctl(gtapdevfd, TUNSETIFF, (unsigned long) &ifr); if (ret < 0) { - printf("TAPDEV: ioctl failed: %d\n", -ret); + printf("TAPDEV: ioctl failed: %d\r\n", -ret); return; } @@ -205,7 +205,7 @@ void tapdev_init(void) sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { - printf("TAPDEV: Can't open socket: %d\n", -sockfd); + printf("TAPDEV: Can't open socket: %d\r\n", -sockfd); return; } @@ -219,7 +219,7 @@ void tapdev_init(void) if (ret < 0) { printf("TAPDEV: ioctl failed (can't add interface %s to " - "bridge %s): %d\n", + "bridge %s): %d\r\n", gdevname, CONFIG_SIM_NET_BRIDGE_DEVICE, -ret); } @@ -266,7 +266,7 @@ unsigned int tapdev_read(unsigned char *buf, unsigned int buflen) ret = read(gtapdevfd, buf, buflen); if (ret < 0) { - printf("TAPDEV: read failed: %d\n", -ret); + printf("TAPDEV: read failed: %d\r\n", -ret); return 0; } @@ -278,12 +278,12 @@ void tapdev_send(unsigned char *buf, unsigned int buflen) { int ret; #ifdef TAPDEV_DEBUG - printf("tapdev_send: sending %d bytes\n", buflen); + printf("tapdev_send: sending %d bytes\r\n", buflen); gdrop++; if (gdrop % 8 == 7) { - printf("TAPDEV: Dropped a packet!\n"); + printf("TAPDEV: Dropped a packet!\r\n"); return; } #endif @@ -291,7 +291,7 @@ void tapdev_send(unsigned char *buf, unsigned int buflen) ret = write(gtapdevfd, buf, buflen); if (ret < 0) { - printf("TAPDEV: write failed: %d", -ret); + printf("TAPDEV: write failed: %d\r\n", -ret); exit(1); } @@ -313,7 +313,7 @@ void tapdev_ifup(in_addr_t ifaddr) sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { - printf("TAPDEV: Can't open socket: %d\n", -sockfd); + printf("TAPDEV: Can't open socket: %d\r\n", -sockfd); return; } @@ -324,7 +324,7 @@ void tapdev_ifup(in_addr_t ifaddr) ret = ioctl(sockfd, SIOCGIFFLAGS, (unsigned long)&ifr); if (ret < 0) { - printf("TAPDEV: ioctl failed (can't get interface flags): %d\n", -ret); + printf("TAPDEV: ioctl failed (can't get interface flags): %d\r\n", -ret); close(sockfd); return; } @@ -333,7 +333,7 @@ void tapdev_ifup(in_addr_t ifaddr) ret = ioctl(sockfd, SIOCSIFFLAGS, (unsigned long)&ifr); if (ret < 0) { - printf("TAPDEV: ioctl failed (can't set interface flags): %d\n", -ret); + printf("TAPDEV: ioctl failed (can't set interface flags): %d\r\n", -ret); close(sockfd); return; } @@ -354,7 +354,7 @@ void tapdev_ifup(in_addr_t ifaddr) ret = ioctl(sockfd, SIOCADDRT, (unsigned long)&ghostroute); if (ret < 0) { - printf("TAPDEV: ioctl failed (can't add host route): %d\n", -ret); + printf("TAPDEV: ioctl failed (can't add host route): %d\r\n", -ret); close(sockfd); return; } @@ -376,14 +376,14 @@ void tapdev_ifdown(void) sockfd = socket(AF_INET, SOCK_DGRAM, 0); if (sockfd < 0) { - printf("TAPDEV: Can't open socket: %d\n", -sockfd); + printf("TAPDEV: Can't open socket: %d\r\n", -sockfd); return; } ret = ioctl(sockfd, SIOCDELRT, (unsigned long)&ghostroute); if (ret < 0) { - printf("TAPDEV: ioctl failed (can't delete host route): %d\n", -ret); + printf("TAPDEV: ioctl failed (can't delete host route): %d\r\n", -ret); } close(sockfd); diff --git a/arch/sim/src/sim/up_wpcap.c b/arch/sim/src/sim/up_wpcap.c index 0cf91385dc..ef7b4b3a0c 100644 --- a/arch/sim/src/sim/up_wpcap.c +++ b/arch/sim/src/sim/up_wpcap.c @@ -126,7 +126,7 @@ void netdriver_setmacaddr(unsigned char *macaddr); static void error_exit(char *message) { - printf("error_exit: %s", message); + printf("error_exit: %s\r\n", message); exit(EXIT_FAILURE); } @@ -142,7 +142,7 @@ static void init_pcap(struct in_addr addr) while (interfaces != NULL) { - printf("init_pcap: found interface: %s\n", interfaces->description); + printf("init_pcap: found interface: %s\r\n", interfaces->description); if (interfaces->addresses != NULL && interfaces->addresses->addr != NULL && @@ -151,7 +151,7 @@ static void init_pcap(struct in_addr addr) struct in_addr interface_addr; interface_addr = ((struct sockaddr_in *)interfaces->addresses->addr)->sin_addr; - printf("init_pcap: with address: %s\n", inet_ntoa(interface_addr)); + printf("init_pcap: with address: %s\r\n", inet_ntoa(interface_addr)); if (interface_addr.s_addr == addr.s_addr) { @@ -164,7 +164,7 @@ static void init_pcap(struct in_addr addr) if (interfaces == NULL) { - error_exit("No interface found with IP address\n"); + error_exit("No interface found with IP address"); } pcap = pcap_open_live(interfaces->name, NETDEV_BUFSIZE, 0, -1, error); @@ -184,7 +184,7 @@ static void set_ethaddr(struct in_addr addr) GAA_FLAG_SKIP_DNS_SERVER, NULL, NULL, &size) != ERROR_BUFFER_OVERFLOW) { - error_exit("error on access to adapter list size\n"); + error_exit("error on access to adapter list size"); } adapters = alloca(size); @@ -194,7 +194,7 @@ static void set_ethaddr(struct in_addr addr) GAA_FLAG_SKIP_DNS_SERVER, NULL, adapters, &size) != ERROR_SUCCESS) { - error_exit("error on access to adapter list\n"); + error_exit("error on access to adapter list"); } while (adapters != NULL) @@ -202,7 +202,7 @@ static void set_ethaddr(struct in_addr addr) char buffer[256]; WideCharToMultiByte(CP_ACP, 0, adapters->Description, -1, buffer, sizeof(buffer), NULL, NULL); - printf("set_ethaddr: found adapter: %s\n", buffer); + printf("set_ethaddr: found adapter: %s\r\n", buffer); if (adapters->FirstUnicastAddress != NULL && adapters->FirstUnicastAddress->Address.lpSockaddr != NULL && @@ -213,18 +213,18 @@ static void set_ethaddr(struct in_addr addr) adapter_addr = ((struct sockaddr_in *)adapters->FirstUnicastAddress->Address. lpSockaddr)->sin_addr; - printf("set_ethaddr: with address: %s\n", inet_ntoa(adapter_addr)); + printf("set_ethaddr: with address: %s\r\n", inet_ntoa(adapter_addr)); if (adapter_addr.s_addr == addr.s_addr) { if (adapters->PhysicalAddressLength != 6) { error_exit - ("ip addr specified does not belong to an ethernet card\n"); + ("ip addr specified does not belong to an ethernet card"); } printf - ("set_ethaddr: ethernetaddr: %02X-%02X-%02X-%02X-%02X-%02X\n", + ("set_ethaddr: ethernetaddr: %02X-%02X-%02X-%02X-%02X-%02X\r\n", adapters->PhysicalAddress[0], adapters->PhysicalAddress[1], adapters->PhysicalAddress[2], adapters->PhysicalAddress[3], adapters->PhysicalAddress[4], adapters->PhysicalAddress[5]); @@ -239,7 +239,7 @@ static void set_ethaddr(struct in_addr addr) if (adapters == NULL) { - error_exit("No adaptor found with IP address\n"); + error_exit("No adaptor found with IP address"); } } @@ -253,7 +253,7 @@ void wpcap_init(void) FARPROC dlladdr; addr.s_addr = htonl(WCAP_IPADDR); - printf("wpcap_init: IP address: %s\n", inet_ntoa(addr)); + printf("wpcap_init: IP address: %s\r\n", inet_ntoa(addr)); wpcap = LoadLibrary("wpcap.dll"); dlladdr = GetProcAddress(wpcap, "pcap_findalldevs"); @@ -271,7 +271,7 @@ void wpcap_init(void) if (pcap_findalldevs == NULL || pcap_open_live == NULL || pcap_next_ex == NULL || pcap_sendpacket == NULL) { - error_exit("error on access to winpcap library\n"); + error_exit("error on access to winpcap library"); } init_pcap(addr); @@ -286,7 +286,7 @@ unsigned int wpcap_read(unsigned char *buf, unsigned int buflen) switch (pcap_next_ex(pcap, &packet_header, &packet)) { case -1: - error_exit("error on read\n"); + error_exit("error on read"); case 0: return 0; } @@ -304,6 +304,6 @@ void wpcap_send(unsigned char *buf, unsigned int buflen) { if (pcap_sendpacket(pcap, buf, buflen) == -1) { - error_exit("error on send\n"); + error_exit("error on send"); } } diff --git a/arch/sim/src/sim/up_x11framebuffer.c b/arch/sim/src/sim/up_x11framebuffer.c index 0ff5d0fbe3..ee8a309602 100644 --- a/arch/sim/src/sim/up_x11framebuffer.c +++ b/arch/sim/src/sim/up_x11framebuffer.c @@ -96,7 +96,7 @@ static inline int up_x11createframe(void) g_display = XOpenDisplay(NULL); if (g_display == NULL) { - printf("Unable to open display.\n"); + printf("Unable to open display.\r\n"); return -1; } @@ -228,7 +228,6 @@ static void up_x11uninitX(void) #ifndef CONFIG_SIM_X11NOSHM static void up_x11uninitialize(void) { - fprintf(stderr, "Uninitializing\n"); if (g_shmcheckpoint > 1) { if (!b_useshm && g_framebuffer) @@ -263,7 +262,6 @@ static inline int up_x11mapsharedmem(int depth, unsigned int fblen) if (XShmQueryExtension(g_display)) { b_useshm = 1; - printf("Using shared memory.\n"); up_x11traperrors(); g_image = XShmCreateImage(g_display, @@ -278,7 +276,7 @@ static inline int up_x11mapsharedmem(int depth, unsigned int fblen) if (!g_image) { - fprintf(stderr, "Unable to create g_image."); + fprintf(stderr, "Unable to create g_image.\r\n"); return -1; } @@ -336,7 +334,7 @@ shmerror: if (g_image == NULL) { - fprintf(stderr, "Unable to create g_image\n"); + fprintf(stderr, "Unable to create g_image\r\n"); return -1; } @@ -417,8 +415,6 @@ int up_x11cmap(unsigned short first, unsigned short len, Colormap cMap; int ndx; - printf("Creating Colormap\n"); - /* Convert each color to X11 scaling */ cMap = DefaultColormap(g_display, g_screen); @@ -439,7 +435,7 @@ int up_x11cmap(unsigned short first, unsigned short len, if (!XAllocColor(g_display, cMap, &color)) { - fprintf(stderr, "Failed to allocate color%d\n", ndx); + fprintf(stderr, "Failed to allocate color%d\r\n", ndx); return -1; } }