diff --git a/src/sreport/sreport.c b/src/sreport/sreport.c index 6089d0d942c95bbe8c4e0dcad49fb7e7df4e6bc2..fb8c281c3469fc3ff8c0d942419435c10fd52baa 100644 --- a/src/sreport/sreport.c +++ b/src/sreport/sreport.c @@ -197,7 +197,8 @@ main (int argc, char *argv[]) break; error_code = _get_command (&input_field_count, input_fields); } - + if (exit_flag == 2) + putchar('\n'); slurmdb_connection_close(&db_conn); slurm_acct_storage_fini(); exit(exit_code); @@ -214,9 +215,10 @@ static char *_getline(const char *prompt) int len; printf("%s", prompt); - /* we only set this here to avoid a warning. We throw it away - later. */ + /* Set "line" here to avoid a warning and discard it later. */ line = fgets(buf, 4096, stdin); + if (line == NULL) + return NULL; len = strlen(buf); if ((len > 0) && (buf[len-1] == '\n')) buf[len-1] = '\0'; @@ -380,8 +382,10 @@ _get_command (int *argc, char **argv) #else in_line = _getline("sreport: "); #endif - if (in_line == NULL) + if (in_line == NULL) { + exit_flag = 2; return 0; + } else if (strncmp (in_line, "#", 1) == 0) { free (in_line); return 0;