summaryrefslogtreecommitdiffstats
path: root/shlibs/mount/src/lock.c
diff options
context:
space:
mode:
authorKarel Zak2011-03-30 09:30:05 +0200
committerKarel Zak2011-03-30 09:30:05 +0200
commit5976114f628c96285c9b3f2cc55994f216afe6f2 (patch)
tree7ec6963afb34654f2f44810c31a04af1c413cc52 /shlibs/mount/src/lock.c
parentdocs: update TODO (diff)
downloadkernel-qcow2-util-linux-5976114f628c96285c9b3f2cc55994f216afe6f2.tar.gz
kernel-qcow2-util-linux-5976114f628c96285c9b3f2cc55994f216afe6f2.tar.xz
kernel-qcow2-util-linux-5976114f628c96285c9b3f2cc55994f216afe6f2.zip
libmount: block signals when writing to mtab
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'shlibs/mount/src/lock.c')
-rw-r--r--shlibs/mount/src/lock.c43
1 files changed, 42 insertions, 1 deletions
diff --git a/shlibs/mount/src/lock.c b/shlibs/mount/src/lock.c
index 554915876..55dcf73b2 100644
--- a/shlibs/mount/src/lock.c
+++ b/shlibs/mount/src/lock.c
@@ -40,7 +40,11 @@ struct libmnt_lock {
char *lockfile; /* path to lock file (e.g. /etc/mtab~) */
char *linkfile; /* path to link file (e.g. /etc/mtab~.<id>) */
int lockfile_fd; /* lock file descriptor */
- int locked; /* do we own the lock? */
+
+ int locked :1; /* do we own the lock? */
+ int sigblock: 1; /* block signals when locked */
+
+ sigset_t oldsigmask;
};
@@ -102,6 +106,24 @@ void mnt_free_lock(struct libmnt_lock *ml)
free(ml);
}
+/**
+ * mnt_lock_block_signals:
+ * @ml: struct libmnt_lock handler
+ * @enable: TRUE/FALSE
+ *
+ * Block/unblock signals when the lock is locked, the signals are not blocked
+ * by default.
+ *
+ * Returns: <0 on error, 0 on success.
+ */
+int mnt_lock_block_signals(struct libmnt_lock *ml, int enable)
+{
+ if (!ml)
+ return -EINVAL;
+ ml->sigblock = enable;
+ return 0;
+}
+
/*
* Returns path to lockfile.
*/
@@ -254,6 +276,11 @@ void mnt_unlock_file(struct libmnt_lock *ml)
ml->locked = 0;
ml->lockfile_fd = -1;
+
+ if (ml->sigblock)
+ sigprocmask(SIG_SETMASK, &ml->oldsigmask, NULL);
+
+ ml->sigblock = 0;
}
/**
@@ -337,6 +364,20 @@ int mnt_lock_file(struct libmnt_lock *ml)
if (!linkfile)
return -EINVAL;
+ if (ml->sigblock) {
+ /*
+ * Block all signals when locked, mnt_unlock_file() will
+ * restore the old mask.
+ */
+ sigset_t sigs;
+
+ sigemptyset(&ml->oldsigmask);
+ sigfillset(&sigs);
+ sigdelset(&sigs, SIGTRAP);
+ sigdelset(&sigs, SIGALRM);
+ sigprocmask(SIG_BLOCK, &sigs, &ml->oldsigmask);
+ }
+
i = open(linkfile, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR);
if (i < 0) {
/* linkfile does not exist (as a file) and we cannot create it.