diff --git a/src/lang.h b/src/lang.h index c4f8412..c686237 100644 --- a/src/lang.h +++ b/src/lang.h @@ -13,8 +13,9 @@ #define LY_LANG_PASSWORD "password : " /* ioctl */ -#define LY_ERR_FD "Failed to create the console file descriptor" -#define LY_ERR_FD_ADVICE "(ly probably wasn't run with enough privileges)" +#define LY_ERR_FD_CONSOLE "Failed to create the console file descriptor" +#define LY_ERR_FD_CONSOLE_ADVICE "(ly probably wasn't run with enough privileges)" +#define LY_ERR_FD_CFG_SAVE "Failed to create the config file" /* pam */ #define LY_ERR_PAM_BUF "Memory buffer error" diff --git a/src/main.c b/src/main.c index 700e7eb..ff34556 100644 --- a/src/main.c +++ b/src/main.c @@ -58,11 +58,20 @@ int main(void) if(!console) { - fprintf(stderr, "%s\n", LY_ERR_FD); - fprintf(stderr, "%s\n", LY_ERR_FD_ADVICE); + fprintf(stderr, "%s\n", LY_ERR_FD_CONSOLE); + fprintf(stderr, "%s\n", LY_ERR_FD_CONSOLE_ADVICE); return 0; } + /* create LY_CFG_SAVE if it doesn't exist yet */ + FILE* cfg_save = fopen(LY_CFG_SAVE, "ab+"); + if (!cfg_save) + { + fprintf(stderr, "%s: %s\n", LY_ERR_FD_CFG_SAVE, LY_CFG_SAVE); + return 0; + } + fclose(cfg_save); + kernel_log(0); /* initializes ncurses UI */ init_ncurses(console); @@ -102,8 +111,7 @@ int main(void) /* saves the username and DE if enabled */ if(LY_CFG_WRITE_SAVE) { - FILE* file = fopen(LY_CFG_SAVE, "ab+"); - file = fopen(LY_CFG_SAVE, "wb"); + FILE* file = fopen(LY_CFG_SAVE, "wb"); fprintf(file, "%s\n%d", username, de_id); fclose(file); } diff --git a/src/ncui.c b/src/ncui.c index 70f4c63..568d7a1 100644 --- a/src/ncui.c +++ b/src/ncui.c @@ -40,9 +40,7 @@ void init_form(struct ncform* form, char** list, int max_de, int* de_id) char line[LY_LIM_LINE_FILE]; char user[LY_LIM_LINE_FILE]; int de; - /* creates the file if it can't be found */ - file = fopen(LY_CFG_SAVE, "ab+"); - fclose(file); + /* opens the file */ file = fopen(LY_CFG_SAVE, "rb"); memset(user, '\0', LY_LIM_LINE_FILE);