npm

Nihal's Password Manager (WIP)
git clone git://git.nihaljere.xyz/npm
Log | Files | Refs | README | LICENSE

commit ae4c978c6ca467af34f26b3cbfab93926ac0e6f0
parent 3ad6def9f80d9f1e778e1f682656329ad6d75bac
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu,  7 Oct 2021 10:53:58 -0500

npm-agent: do proper error handling when retrieving the master password

also rename get_password to get_master for clarity

Diffstat:
Mnpm-agent.c | 26++++++++++++++++----------
1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/npm-agent.c b/npm-agent.c @@ -89,31 +89,35 @@ clear_master() } int -get_password() +get_master() { - int stdoutpipe[2], stdinpipe[2], status; + int stdoutpipe[2], stdinpipe[2], status = 1; - if (pipe(stdoutpipe) == -1) + if (pipe(stdoutpipe) == -1) { perror("failed to create stdout pipe"); + return status; + } - if (pipe(stdinpipe) == -1) + if (pipe(stdinpipe) == -1) { perror("failed to create stdin pipe"); + return status; + } pid_t pid = fork(); switch (pid) { case -1: fprintf(stderr, "fork failed\n"); - return -1; + return status; case 0: close(stdoutpipe[0]); dup2(stdoutpipe[1], 1); close(stdinpipe[1]); dup2(stdinpipe[0], 0); - if (execvp(getpasscmd[0], getpasscmd) == -1) - perror("exec failed"); - - break; + if (execvp(getpasscmd[0], getpasscmd) == -1) { + perror("failed to start password retrieval program"); + exit(1); + } default: close(stdoutpipe[1]); close(stdinpipe[0]); @@ -190,7 +194,9 @@ agent() int status; if (!cached) { - get_password(); + if (get_master() != 0) + return; + set_timer(); }