char *linkfile; /* path to link file (e.g. /etc/mtab~.<id>) */
int lockfile_fd; /* lock file descriptor */
- int locked :1; /* do we own the lock? */
- int sigblock: 1; /* block signals when locked */
+ int locked : 1; /* do we own the lock? */
+ int sigblock : 1; /* block signals when locked */
sigset_t oldsigmask;
};
{
if (!ml)
return;
- DBG(LOCKS, mnt_debug_h(ml, "free"));
+ DBG(LOCKS, mnt_debug_h(ml, "free%s", ml->locked ? " !!! LOCKED !!!" : ""));
free(ml->lockfile);
free(ml->linkfile);
free(ml);
{
if (!ml)
return -EINVAL;
- ml->sigblock = enable;
+ DBG(LOCKS, mnt_debug_h(ml, "signals: %s", enable ? "BLOCKED" : "UNBLOCKED"));
+ ml->sigblock = enable ? 1 : 0;
return 0;
}
if (!ml)
return;
-
- if (ml->locked == 0 && ml->lockfile && ml->linkfile)
+ if (!ml->locked && ml->lockfile && ml->linkfile)
{
/* We have (probably) all files, but we don't own the lock,
* Really? Check it! Maybe ml->locked wasn't set properly
unlink(ml->linkfile);
if (ml->lockfile_fd >= 0)
close(ml->lockfile_fd);
- if (ml->locked == 1 && ml->lockfile)
+ if (ml->locked && ml->lockfile) {
unlink(ml->lockfile);
-
+ DBG(LOCKS, mnt_debug_h(ml, "unlink %s", ml->lockfile));
+ }
ml->locked = 0;
ml->lockfile_fd = -1;
- if (ml->sigblock)
+ if (ml->sigblock) {
+ DBG(LOCKS, mnt_debug_h(ml, "restoring sigmask"));
sigprocmask(SIG_SETMASK, &ml->oldsigmask, NULL);
-
+ }
ml->sigblock = 0;
}
waittime.tv_nsec = (1000 * MOUNTLOCK_WAITTIME);
/* Repeat until it was us who made the link */
- while (ml->locked == 0) {
+ while (!ml->locked) {
struct timeval now;
struct flock flock;
int j;
ml->lockfile_fd = -1;
}
}
- DBG(LOCKS, mnt_debug_h(ml,
- "%s: (%d) successfully locked\n",
- lockfile, getpid()));
+ DBG(LOCKS, mnt_debug_h(ml, "%s: (%d) successfully locked",
+ lockfile, getpid()));
unlink(linkfile);
return 0;
}
/*
- * Returns 0 on success, 1 if not file available, -1 in case of error.
+ * Returns 0 on success, <0 in case of error.
*/
int mnt_update_set_filename(struct libmnt_update *upd, const char *filename,
int userspace_only)
path = NULL;
mnt_has_regular_utab(&path, &rw);
if (!rw)
- return 1;
+ return -EACCES;
upd->userspace_only = TRUE;
}
upd->filename = strdup(path);
* @target: umount target, must be num for mount
* @fs: mount filesystem description, must be NULL for umount
*
- * Returns: -1 in case on error, 0 on success, 1 if update is unnecessary.
+ * Returns: <0 in case on error, 0 on success, 1 if update is unnecessary.
*/
int mnt_update_set_fs(struct libmnt_update *upd, unsigned long mountflags,
const char *target, struct libmnt_fs *fs)
upd->mountflags = mountflags;
rc = mnt_update_set_filename(upd, NULL, 0);
- if (rc)
+ if (rc) {
+ DBG(UPDATE, mnt_debug_h(upd, "no writable file available [rc=%d]", rc));
return rc; /* error or no file available (rc = 1) */
-
+ }
if (target) {
upd->target = strdup(target);
if (!upd->target)
rc = update_table(upd, tb);
mnt_free_fs(rem);
}
- mnt_free_table(tb);
}
if (lc)
mnt_unlock_file(lc);
else if (u_lc != -1)
utab_unlock(u_lc);
+
+ mnt_free_table(tb);
return rc;
}
if (!rc)
rc = update_table(upd, tb);
}
- mnt_free_table(tb);
}
if (lc)
mnt_unlock_file(lc);
else if (u_lc != -1)
utab_unlock(u_lc);
+
+ mnt_free_table(tb);
return rc;
}
if (!rc)
rc = update_table(upd, tb);
}
- mnt_free_table(tb);
}
if (lc)
mnt_unlock_file(lc);
else if (u_lc != -1)
utab_unlock(u_lc);
+
+ mnt_free_table(tb);
return rc;
}
if (upd->fs) {
DBG(UPDATE, mnt_fs_print_debug(upd->fs, stderr));
}
-
if (!lc && !upd->userspace_only) {
lc = mnt_new_lock(upd->filename, 0);
if (lc)
* If the file does not exist and @writable argument is not NULL then it will
* try to create the directory (e.g. /dev/.mount) and the file.
*
- * Returns: 1 if /etc/utab is a reqular file, and 0 in case of error (check
- * errno for more details).
+ * Returns: 1 if /dev/.mount/utab is a reqular file, and 0 in case of
+ * error (check errno for more details).
*/
int mnt_has_regular_utab(const char **utab, int *writable)