aboutsummaryrefslogtreecommitdiffstats
path: root/src/lpass.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lpass.c')
-rw-r--r--src/lpass.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/src/lpass.c b/src/lpass.c
index f2281e2..2fcc1ad 100644
--- a/src/lpass.c
+++ b/src/lpass.c
@@ -61,18 +61,23 @@ static struct cmd_struct *get_cmd(const char *name)
static int goto_maindir()
{
- int retval = 0, result;
+ int result;
char *rootdir = xstrcat(getenv("HOME"), LOCKPASS_DIR, "/");
- if(chdir(rootdir)) // failed
+ int retval = chdir(rootdir);
+ if(retval) // failed
{
- // create main directory:
- result = mkdir(rootdir, S_IRWXU);
- if(result) {
- if(errno != EEXIST)
- print_error("Error: %s\n", strerror(errno));
+ if(errno == ENOENT) {
+ // create main directory:
+ result = mkdir(rootdir, S_IRWXU);
+ if(result) {
+ if(errno != EEXIST)
+ print_error("Error: %s\n", strerror(errno));
+ }
+ else // try again:
+ retval = chdir(rootdir);
+ } else {
+ print_error("Error: %s\n", strerror(errno));
}
- else // try again:
- retval = chdir(rootdir);
}
free(rootdir);