Minor cleanup of askpass code.
This commit is contained in:
parent
554c0129a2
commit
ef2494118b
@ -51,13 +51,13 @@ const char *mpw_askpass(const char *prompt) {
|
|||||||
|
|
||||||
int pipes[2];
|
int pipes[2];
|
||||||
if (pipe( pipes ) == ERR) {
|
if (pipe( pipes ) == ERR) {
|
||||||
wrn( "Couldn't pipe: %s", strerror( errno ) );
|
wrn( "Couldn't create pipes for askpass: %s", strerror( errno ) );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
if (pid == ERR) {
|
if (pid == ERR) {
|
||||||
wrn( "Couldn't fork for askpass:\n %s: %s", askpass, strerror( errno ) );
|
wrn( "Couldn't fork for askpass: %s", askpass, strerror( errno ) );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -83,17 +83,18 @@ const char *mpw_askpass(const char *prompt) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (WIFEXITED( status ) && WEXITSTATUS( status ) == EXIT_SUCCESS && answer && strlen( answer )) {
|
if (!WIFEXITED( status ) || WEXITSTATUS( status ) != EXIT_SUCCESS || !answer || !strlen( answer )) {
|
||||||
|
// askpass failed.
|
||||||
|
mpw_free_string( &answer );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Remove trailing newline.
|
// Remove trailing newline.
|
||||||
if (answer[strlen( answer ) - 1] == '\n')
|
if (answer[strlen( answer ) - 1] == '\n')
|
||||||
mpw_replace_string( answer, mpw_strndup( answer, strlen( answer ) - 1 ) );
|
mpw_replace_string( answer, mpw_strndup( answer, strlen( answer ) - 1 ) );
|
||||||
return answer;
|
return answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpw_free_string( &answer );
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char *_mpw_getline(const char *prompt, bool silent) {
|
static const char *_mpw_getline(const char *prompt, bool silent) {
|
||||||
|
|
||||||
// Get answer from askpass.
|
// Get answer from askpass.
|
||||||
|
Loading…
Reference in New Issue
Block a user