From 5976114f628c96285c9b3f2cc55994f216afe6f2 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 30 Mar 2011 09:30:05 +0200 Subject: libmount: block signals when writing to mtab Signed-off-by: Karel Zak --- shlibs/mount/src/context.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) (limited to 'shlibs/mount/src/context.c') diff --git a/shlibs/mount/src/context.c b/shlibs/mount/src/context.c index dba49430d..f24e90ebb 100644 --- a/shlibs/mount/src/context.c +++ b/shlibs/mount/src/context.c @@ -794,13 +794,21 @@ struct libmnt_cache *mnt_context_get_cache(struct libmnt_context *cxt) * mnt_context_get_lock: * @cxt: mount context * - * The application that uses libmount context does not have to care about - * mtab locking, but with a small exceptions: the application has to be able to - * remove the lock file when interrupted by signal. It means that properly written - * mount(8)-like application has to call mnt_unlock_file() from a signal handler. + * The libmount applications don't have to care about mtab locking, but with a + * small exception: the application has to be able to remove the lock file when + * interrupted by signal or signals have to be ignored when the lock is locked. * - * This function returns NULL if mtab file is not writable or nolock or nomtab - * flags is enabled. + * The default behavior is to ignore all signals (except SIGALRM and SIGTRAP) + * when the lock is locked. If this behavior is unacceptable then use: + * + * lc = mnt_context_get_lock(cxt); + * if (lc) + * mnt_lock_block_signals(lc, FALSE); + * + * and don't forget to call mnt_unlock_file(lc) before exit. + * + * This function returns NULL if the lock is unnecessary (mtab file is not writable + * or /etc/mtab is symlink to /proc/mounts). * * Returns: pointer to lock struct or NULL. */ @@ -809,9 +817,11 @@ struct libmnt_lock *mnt_context_get_lock(struct libmnt_context *cxt) if (!cxt || (cxt->flags & MNT_FL_NOMTAB) || !cxt->mtab_writable) return NULL; - if (!cxt->lock && cxt->mtab_path) + if (!cxt->lock && cxt->mtab_path) { cxt->lock = mnt_new_lock(cxt->mtab_path, 0); - + if (cxt->lock) + mnt_lock_block_signals(cxt->lock, TRUE); + } return cxt->lock; } -- cgit v1.2.3-55-g7522