If no lock is held, do not unlock. With glibc this is fine, but let's
not put too many expectations on library implementations.
Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
{
FILE *fp = NULL, *pwf = NULL;
int save_errno, rc;
- uint8_t found = 0;
+ uint8_t found = 0, locked = 0;
size_t namelen;
size_t contlen;
size_t buflen = 256;
/* acquire exclusive lock */
if (lckpwdf() < 0)
goto fail;
+ locked = 1;
pwf = fopen(PASSWD_FILE, "r");
if (!pwf)
goto fail;
fail:
save_errno = errno;
- ulckpwdf();
+ if (locked)
+ ulckpwdf();
if (fp != NULL)
fclose(fp);
if (tmpname != NULL)