From f7b951cb72d9c010f5e67548e2cb63470f2db7de Mon Sep 17 00:00:00 2001 From: Enrico Fraccaroli Date: Mon, 20 Dec 2021 16:29:41 +0100 Subject: [PATCH] Improve debugging code. Set login to override env variables. --- CMakeLists.txt | 1 - libc/src/debug.c | 4 ---- libc/src/pwd.c | 11 +++++++++-- mentos/CMakeLists.txt | 4 +--- mentos/src/boot.c | 4 ---- mentos/src/io/debug.c | 4 ---- programs/login.c | 14 +++++++------- 7 files changed, 17 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c8642d7..59b459f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,7 +59,6 @@ endif() set(DEBUGGING_TYPE "DEBUG_STDIO" CACHE STRING "Chose the type of debugging: DEBUG_STDIO DEBUG_LOG") set_property(CACHE DEBUGGING_TYPE PROPERTY STRINGS DEBUG_STDIO DEBUG_LOG) if("${DEBUGGING_TYPE}" STREQUAL "DEBUG_STDIO" OR "${DEBUGGING_TYPE}" STREQUAL "DEBUG_LOG") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D${DEBUGGING_TYPE}") message(STATUS "Setting debugging type to ${DEBUGGING_TYPE}.") else() message(FATAL_ERROR "Debugging type ${DEBUGGING_TYPE} is not valid.") diff --git a/libc/src/debug.c b/libc/src/debug.c index d421768..088253e 100644 --- a/libc/src/debug.c +++ b/libc/src/debug.c @@ -18,17 +18,13 @@ void dbg_putchar(char c) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) outportb(SERIAL_COM1, (uint8_t)c); -#endif } void dbg_puts(const char *s) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) while ((*s) != 0) dbg_putchar(*s++); -#endif } static inline void __debug_print_header(const char *file, const char *fun, int line) diff --git a/libc/src/pwd.c b/libc/src/pwd.c index a5d2e97..cc4039a 100644 --- a/libc/src/pwd.c +++ b/libc/src/pwd.c @@ -16,7 +16,7 @@ static inline void __parse_line(passwd_t *pwd, char *buf) { assert(pwd && "Received null pwd!"); - char *token; + char *token, *ch; // Parse the username. if ((token = strtok(buf, ":")) != NULL) pwd->pw_name = token; @@ -36,8 +36,15 @@ static inline void __parse_line(passwd_t *pwd, char *buf) if ((token = strtok(NULL, ":")) != NULL) pwd->pw_dir = token; // Parse the shell. - if ((token = strtok(NULL, ":")) != NULL) + if ((token = strtok(NULL, ":")) != NULL) { pwd->pw_shell = token; + // Find carriege return. + if ((ch = strchr(pwd->pw_shell, '\r'))) + *ch = 0; + // Find newline. + if ((ch = strchr(pwd->pw_shell, '\n'))) + *ch = 0; + } } ssize_t __readline(int fd, char *buffer, size_t buflen) diff --git a/mentos/CMakeLists.txt b/mentos/CMakeLists.txt index 3ff7235..e3780fe 100644 --- a/mentos/CMakeLists.txt +++ b/mentos/CMakeLists.txt @@ -15,9 +15,7 @@ set(BUDDY_SYSTEM_FILE ${PROJECT_SOURCE_DIR}/src/mem/libbuddysystem.a) # Set the default build type to Debug. if(NOT CMAKE_BUILD_TYPE) message(STATUS "Setting build type to 'Debug' as none was specified.") - set(CMAKE_BUILD_TYPE - "Debug" - CACHE STRING "Choose the type of build." FORCE) + set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build." FORCE) endif() # ============================================================================= diff --git a/mentos/src/boot.c b/mentos/src/boot.c index b4796a2..949411a 100644 --- a/mentos/src/boot.c +++ b/mentos/src/boot.c @@ -54,19 +54,15 @@ static inline void __outportb(uint16_t port, uint8_t data) /// @param c the character to send to the debug port. static inline void __debug_putchar(char c) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) __outportb(SERIAL_COM1, c); -#endif } /// @brief Writes the given string on the debug port. /// @param s the string to send to the debug port. static inline void __debug_puts(char *s) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) while ((*s) != 0) __outportb(SERIAL_COM1, *s++); -#endif } /// @brief Align memory address to the specified value (round up). diff --git a/mentos/src/io/debug.c b/mentos/src/io/debug.c index 358645e..5f7543b 100644 --- a/mentos/src/io/debug.c +++ b/mentos/src/io/debug.c @@ -21,17 +21,13 @@ static int max_log_level = LOGLEVEL_DEBUG; void dbg_putchar(char c) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) outportb(SERIAL_COM1, (uint8_t)c); -#endif } void dbg_puts(const char *s) { -#if (defined(DEBUG_STDIO) || defined(DEBUG_LOG)) while ((*s) != 0) dbg_putchar(*s++); -#endif } static inline void __debug_print_header(const char *file, const char *fun, int line, int log_level, char *header) diff --git a/programs/login.c b/programs/login.c index b0853be..209afea 100644 --- a/programs/login.c +++ b/programs/login.c @@ -17,6 +17,8 @@ #include #include +#include + #define CREDENTIALS_LENGTH 50 #define FG_BLACK "\033[30m" @@ -125,20 +127,18 @@ static bool_t get_input(char *input, size_t max_len, bool_t hide) static inline int setup_env(passwd_t *pwd) { - // Set the HOME. - char env_buffer[BUFSIZ]; // Set the USER. - if (setenv("USER", pwd->pw_name, 0) == -1) { - printf( "Failed to set env: `USER`\n"); + if (setenv("USER", pwd->pw_name, 1) == -1) { + printf("Failed to set env: `USER`\n"); return 0; } // Set the SHELL. - if (setenv("SHELL", pwd->pw_shell, 0) == -1) { - printf( "Failed to set env: `SHELL`\n"); + if (setenv("SHELL", pwd->pw_shell, 1) == -1) { + printf("Failed to set env: `SHELL`\n"); return 0; } // Set the HOME. - if (setenv("HOME", pwd->pw_dir, 0) == -1) { + if (setenv("HOME", pwd->pw_dir, 1) == -1) { printf("Failed to set env: `HOME`\n"); return 0; }