master - cleanup: missed conversion to dm_malloc/free usage
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=9bccaf7ae40ca0...
Commit: 9bccaf7ae40ca0d17e5d1b65f7c7aaf2d78eb2b9
Parent: d3e68c8a71c3bc36135d73cd8028cec56eca5cb2
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 11:54:12 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:17:46 2014 +0200
cleanup: missed conversion to dm_malloc/free usage
Few missed unconverted dm_malloc/free calls.
---
daemons/clvmd/lvm-functions.c | 9 ++++-----
1 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/daemons/clvmd/lvm-functions.c b/daemons/clvmd/lvm-functions.c
index e36e206..9fd71e8 100644
--- a/daemons/clvmd/lvm-functions.c
+++ b/daemons/clvmd/lvm-functions.c
@@ -236,7 +236,7 @@ void destroy_lvhash(void)
if ((status = sync_unlock(resource, lvi->lock_id)))
DEBUGLOG("unlock_all. unlock failed(%d): %s\n",
status, strerror(errno));
- free(lvi);
+ dm_free(lvi);
}
dm_hash_destroy(lv_hash);
@@ -286,8 +286,7 @@ static int hold_lock(char *resource, int mode, int flags)
strerror(errno));
errno = saved_errno;
} else {
- lvi = malloc(sizeof(struct lv_info));
- if (!lvi) {
+ if (!(lvi = dm_malloc(sizeof(struct lv_info)))) {
errno = ENOMEM;
return -1;
}
@@ -296,7 +295,7 @@ static int hold_lock(char *resource, int mode, int flags)
status = sync_lock(resource, mode, flags & ~LCKF_CONVERT, &lvi->lock_id);
saved_errno = errno;
if (status) {
- free(lvi);
+ dm_free(lvi);
DEBUGLOG("hold_lock. lock at %d failed: %s\n", mode,
strerror(errno));
} else
@@ -326,7 +325,7 @@ static int hold_unlock(char *resource)
saved_errno = errno;
if (!status) {
remove_info(resource);
- free(lvi);
+ dm_free(lvi);
} else {
DEBUGLOG("hold_unlock. unlock failed(%d): %s\n", status,
strerror(errno));
10 years
master - cleanup: cosmetics.
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d3e68c8a71c3bc...
Commit: d3e68c8a71c3bc36135d73cd8028cec56eca5cb2
Parent: d88fab8d3a64cb492c808a50d247686febedc9e3
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 11:44:33 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:17:46 2014 +0200
cleanup: cosmetics.
Initialized attrs so analyzers are less confused
(since currently our method calls should always initialize attrs on
return).
---
lib/metadata/snapshot_manip.c | 2 +-
libdm/libdm-common.c | 3 ++-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/metadata/snapshot_manip.c b/lib/metadata/snapshot_manip.c
index a0a3e3c..5df0f98 100644
--- a/lib/metadata/snapshot_manip.c
+++ b/lib/metadata/snapshot_manip.c
@@ -41,7 +41,7 @@ int lv_is_cow(const struct logical_volume *lv)
static uint64_t _cow_extra_chunks(struct cmd_context *cmd, uint64_t n_chunks)
{
const struct segment_type *segtype;
- unsigned attrs;
+ unsigned attrs = 0;
if (activation() &&
(segtype = get_segtype_from_string(cmd, "snapshot")) &&
diff --git a/libdm/libdm-common.c b/libdm/libdm-common.c
index f404c63..bb793e3 100644
--- a/libdm/libdm-common.c
+++ b/libdm/libdm-common.c
@@ -1907,7 +1907,8 @@ static int _device_has_mounted_fs(char *buffer, unsigned major, unsigned minor,
char kernel_dev_name[PATH_MAX];
if ((major == data->maj) && (minor == data->min)) {
- if (!dm_device_get_name(major, minor, 1, kernel_dev_name, PATH_MAX)) {
+ if (!dm_device_get_name(major, minor, 1, kernel_dev_name,
+ sizeof(kernel_dev_name))) {
stack;
*kernel_dev_name = '\0';
}
10 years
master - cleanup: drop uneeded headers
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d88fab8d3a64cb...
Commit: d88fab8d3a64cb492c808a50d247686febedc9e3
Parent: bcd6deea18673cedfa833fc40399949955e7f834
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 10:50:06 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:17:45 2014 +0200
cleanup: drop uneeded headers
---
daemons/clvmd/clvmd-singlenode.c | 1 -
lib/locking/external_locking.c | 1 -
lib/locking/file_locking.c | 2 --
lib/metadata/cache_manip.c | 6 ------
4 files changed, 0 insertions(+), 10 deletions(-)
diff --git a/daemons/clvmd/clvmd-singlenode.c b/daemons/clvmd/clvmd-singlenode.c
index e65ab28..e6d2b0d 100644
--- a/daemons/clvmd/clvmd-singlenode.c
+++ b/daemons/clvmd/clvmd-singlenode.c
@@ -19,7 +19,6 @@
#include "locking.h"
#include "clvm.h"
#include "clvmd-comms.h"
-#include "lvm-functions.h"
#include "clvmd.h"
#include <sys/un.h>
diff --git a/lib/locking/external_locking.c b/lib/locking/external_locking.c
index 1e669bb..bc597ff 100644
--- a/lib/locking/external_locking.c
+++ b/lib/locking/external_locking.c
@@ -19,7 +19,6 @@
#include "sharedlib.h"
#include "toolcontext.h"
#include "activate.h"
-#include "locking.h"
static void *_locking_lib = NULL;
static void (*_reset_fn) (void) = NULL;
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index d79d7a9..10431ab 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -19,7 +19,6 @@
#include "activate.h"
#include "config.h"
#include "defaults.h"
-#include "lvm-file.h"
#include "lvm-string.h"
#include "lvm-flock.h"
#include "lvmcache.h"
@@ -28,7 +27,6 @@
#include <limits.h>
#include <unistd.h>
#include <sys/stat.h>
-#include <sys/file.h>
#include <fcntl.h>
#include <signal.h>
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index deae6f2..6a0f0f6 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -15,18 +15,12 @@
#include "lib.h"
#include "metadata.h"
#include "locking.h"
-#include "pv_map.h"
#include "lvm-string.h"
#include "toolcontext.h"
-#include "lv_alloc.h"
-#include "pv_alloc.h"
#include "display.h"
#include "segtype.h"
-#include "archiver.h"
#include "activate.h"
-#include "str_list.h"
#include "defaults.h"
-#include "lvm-exec.h"
int update_cache_pool_params(struct volume_group *vg, unsigned attr,
int passed_args,
10 years
master - coverity: ignore ret val
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=bcd6deea18673c...
Commit: bcd6deea18673cedfa833fc40399949955e7f834
Parent: d11617864a6434c3775e1fbc8c55af6d3ae5dc57
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 11:22:14 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:17:12 2014 +0200
coverity: ignore ret val
Since we intentionaly do not want to check them,
cast result values to void.
---
lib/device/dev-type.c | 7 ++++---
1 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/device/dev-type.c b/lib/device/dev-type.c
index 193e9bd..9d610d4 100644
--- a/lib/device/dev-type.c
+++ b/lib/device/dev-type.c
@@ -495,9 +495,10 @@ static int _blkid_wipe(blkid_probe probe, struct device *dev, const char *name,
offset_value = strtoll(offset, NULL, 10);
if (!usage)
- blkid_probe_lookup_value(probe, "USAGE", &usage, NULL);
- blkid_probe_lookup_value(probe, "LABEL", &label, NULL);
- blkid_probe_lookup_value(probe, "UUID", &uuid, NULL);
+ (void) blkid_probe_lookup_value(probe, "USAGE", &usage, NULL);
+ (void) blkid_probe_lookup_value(probe, "LABEL", &label, NULL);
+ (void) blkid_probe_lookup_value(probe, "UUID", &uuid, NULL);
+ /* Return values ignored here, in the worst case we print NULL */
log_verbose("Found existing signature on %s at offset %s: LABEL=\"%s\" "
"UUID=\"%s\" TYPE=\"%s\" USAGE=\"%s\"",
10 years
master - coverity: error for undefined origin
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=d11617864a6434...
Commit: d11617864a6434c3775e1fbc8c55af6d3ae5dc57
Parent: a8042f33d0ee7f71952d65f2cc408775fa440c8a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 11:14:22 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:16:18 2014 +0200
coverity: error for undefined origin
If we would have been missing origin here, it would
be an internal error - since these values are validated
earlier.
---
lib/metadata/lv_manip.c | 4 ++++
tools/lvcreate.c | 5 ++++-
2 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/lib/metadata/lv_manip.c b/lib/metadata/lv_manip.c
index 6817831..b47e2d2 100644
--- a/lib/metadata/lv_manip.c
+++ b/lib/metadata/lv_manip.c
@@ -5993,6 +5993,10 @@ static struct logical_volume *_lv_create_an_lv(struct volume_group *vg,
"cache-pool")))
return_0;
} else if (seg_is_thin(lp) && lp->snapshot) {
+ if (!lp->origin) {
+ log_error(INTERNAL_ERROR "Origin LV is not defined.");
+ return 0;
+ }
if (!(org = find_lv(vg, lp->origin))) {
log_error("Couldn't find origin volume '%s'.",
lp->origin);
diff --git a/tools/lvcreate.c b/tools/lvcreate.c
index 6a9264a..0e009b1 100644
--- a/tools/lvcreate.c
+++ b/tools/lvcreate.c
@@ -304,7 +304,10 @@ static int _determine_cache_argument(struct volume_group *vg,
lp->segtype->name);
return 0;
}
-
+ if (!lp->origin) {
+ log_error(INTERNAL_ERROR "Origin LV is not defined.");
+ return 0;
+ }
if (!(lvl = find_lv_in_vg(vg, lp->origin))) {
log_error("LV %s not found in Volume group %s.",
lp->origin, vg->name);
10 years
master - coverity: check for profile
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=a8042f33d0ee7f...
Commit: a8042f33d0ee7f71952d65f2cc408775fa440c8a
Parent: 48a8cf28f751156471a3fc65650fc600cd24833c
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 10:52:00 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:15:52 2014 +0200
coverity: check for profile
Ensure str is not NULL for analyzer.
---
lib/config/config.c | 5 ++++-
lib/metadata/thin_manip.c | 10 ++++++++--
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/lib/config/config.c b/lib/config/config.c
index a751d3e..1a9f636 100644
--- a/lib/config/config.c
+++ b/lib/config/config.c
@@ -1766,7 +1766,10 @@ int get_default_allocation_thin_pool_chunk_size_CFG(struct cmd_context *cmd, str
const char *str;
uint32_t chunk_size;
- str = find_config_tree_str(cmd, allocation_thin_pool_chunk_size_policy_CFG, profile);
+ if (!(str = find_config_tree_str(cmd, allocation_thin_pool_chunk_size_policy_CFG, profile))) {
+ log_error(INTERNAL_ERROR "Cannot find profile.");
+ return 0;
+ }
if (!strcasecmp(str, "generic"))
chunk_size = DEFAULT_THIN_POOL_CHUNK_SIZE;
diff --git a/lib/metadata/thin_manip.c b/lib/metadata/thin_manip.c
index 78231a2..c1c90b4 100644
--- a/lib/metadata/thin_manip.c
+++ b/lib/metadata/thin_manip.c
@@ -375,7 +375,10 @@ int update_profilable_pool_params(struct cmd_context *cmd, struct profile *profi
if (!(passed_args & PASS_ARG_CHUNK_SIZE)) {
if (!(*chunk_size = find_config_tree_int(cmd, allocation_thin_pool_chunk_size_CFG, profile) * 2)) {
- str = find_config_tree_str(cmd, allocation_thin_pool_chunk_size_policy_CFG, profile);
+ if (!(str = find_config_tree_str(cmd, allocation_thin_pool_chunk_size_policy_CFG, profile))) {
+ log_error(INTERNAL_ERROR "Could not find profile.");
+ return 0;
+ }
if (!strcasecmp(str, "generic"))
*chunk_size_calc_method = THIN_CHUNK_SIZE_CALC_METHOD_GENERIC;
else if (!strcasecmp(str, "performance"))
@@ -397,7 +400,10 @@ int update_profilable_pool_params(struct cmd_context *cmd, struct profile *profi
}
if (!(passed_args & PASS_ARG_DISCARDS)) {
- str = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG, profile);
+ if (!(str = find_config_tree_str(cmd, allocation_thin_pool_discards_CFG, profile))) {
+ log_error(INTERNAL_ERROR "Could not find profile.");
+ return 0;
+ }
if (!get_pool_discards(str, discards))
return_0;
}
10 years
master - cache: avoid expression overflow
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=48a8cf28f75115...
Commit: 48a8cf28f751156471a3fc65650fc600cd24833c
Parent: e585a6bbcf8416f5eeb6b57e0b02ca5e52f23f96
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Wed May 7 11:12:05 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:14:54 2014 +0200
cache: avoid expression overflow
Cast data_extents to 64bit so calculation is in 64b arithmetic.
---
WHATS_NEW | 1 +
lib/metadata/cache_manip.c | 2 +-
2 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index f0c36cb..88ae713 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.107 -
==================================
+ Use proper uint64 casting for calculation of cache metadata size.
Better support for nesting of blocking signals.
Use only sigaction handler and drop duplicate signal handler.
Separate signal handling and flock code out into lib/misc.
diff --git a/lib/metadata/cache_manip.c b/lib/metadata/cache_manip.c
index 9a055e8..deae6f2 100644
--- a/lib/metadata/cache_manip.c
+++ b/lib/metadata/cache_manip.c
@@ -57,7 +57,7 @@ int update_cache_pool_params(struct volume_group *vg, unsigned attr,
* ... plus a good amount of padding (2x) to cover any
* policy hint data that may be added in the future.
*/
- min_meta_size = 16 * (data_extents * vg->extent_size);
+ min_meta_size = (uint64_t)data_extents * vg->extent_size * 16;
min_meta_size /= *chunk_size; /* # of Bytes we need */
min_meta_size *= 2; /* plus some padding */
min_meta_size /= 512; /* in sectors */
10 years
master - signals: better nesting support
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=e585a6bbcf8416...
Commit: e585a6bbcf8416f5eeb6b57e0b02ca5e52f23f96
Parent: 31ac200a374e101ddfb60fbef0591efee58b478a
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 2 17:30:27 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:09:33 2014 +0200
signals: better nesting support
Support upto 3 levels os nesting signal blocking.
As of today - code blocks signals immediatelly when it opens
VG in read-write mode - this however makes current prompt usage
then partially unusable since user may not 'break' command
during prompt (something most user would expect).
Until a better fix for prompting is implemented, put in support
for signal nesting - thus when prompt enables signal acceptance,
make it possible to really break command at this point.
---
WHATS_NEW | 1 +
lib/misc/lvm-signal.c | 35 ++++++++++++++---------------------
2 files changed, 15 insertions(+), 21 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 1cb97d9..f0c36cb 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.107 -
==================================
+ Better support for nesting of blocking signals.
Use only sigaction handler and drop duplicate signal handler.
Separate signal handling and flock code out into lib/misc.
Don't start dmeventd checking seg_monitor and monitoring is disabled.
diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c
index 8aeb192..d5dac6f 100644
--- a/lib/misc/lvm-signal.c
+++ b/lib/misc/lvm-signal.c
@@ -21,9 +21,12 @@
static sigset_t _oldset;
static int _signals_blocked = 0;
static volatile sig_atomic_t _sigint_caught = 0;
-static volatile sig_atomic_t _handler_installed2;
-static struct sigaction _oldhandler2;
-static int _oldmasked;
+static volatile sig_atomic_t _handler_installed;
+
+/* Support 3 level nesting, increase if needed more */
+#define MAX_SIGINTS 3
+static struct sigaction _oldhandler[MAX_SIGINTS];
+static int _oldmasked[MAX_SIGINTS];
static void _catch_sigint(int unused __attribute__((unused)))
{
@@ -61,10 +64,8 @@ void sigint_allow(void)
* Do not overwrite the backed-up handler data -
* just increase nesting count.
*/
- if (_handler_installed2) {
- _handler_installed2++;
+ if (++_handler_installed >= MAX_SIGINTS)
return;
- }
/* Grab old sigaction for SIGINT: shall not fail. */
if (sigaction(SIGINT, NULL, &handler))
@@ -73,17 +74,15 @@ void sigint_allow(void)
handler.sa_flags &= ~SA_RESTART; /* Clear restart flag */
handler.sa_handler = _catch_sigint;
- _handler_installed2 = 1;
-
/* Override the signal handler: shall not fail. */
- if (sigaction(SIGINT, &handler, &_oldhandler2))
+ if (sigaction(SIGINT, &handler, &_oldhandler[_handler_installed - 1]))
log_sys_debug("sigaction", "SIGINT");
/* Unmask SIGINT. Remember to mask it again on restore. */
if (sigprocmask(0, NULL, &sigs))
log_sys_debug("sigprocmask", "");
- if ((_oldmasked = sigismember(&sigs, SIGINT))) {
+ if ((_oldmasked[_handler_installed] = sigismember(&sigs, SIGINT))) {
sigdelset(&sigs, SIGINT);
if (sigprocmask(SIG_SETMASK, &sigs, NULL))
log_sys_debug("sigprocmask", "SIG_SETMASK");
@@ -92,18 +91,12 @@ void sigint_allow(void)
void sigint_restore(void)
{
- if (!_handler_installed2)
+ if (!_handler_installed ||
+ --_handler_installed >= MAX_SIGINTS)
return;
- if (_handler_installed2 > 1) {
- _handler_installed2--;
- return;
- }
-
- /* Nesting count went down to 0. */
- _handler_installed2 = 0;
-
- if (_oldmasked) {
+ /* Nesting count went bellow MAX_SIGINTS. */
+ if (_oldmasked[_handler_installed]) {
sigset_t sigs;
sigprocmask(0, NULL, &sigs);
sigaddset(&sigs, SIGINT);
@@ -111,7 +104,7 @@ void sigint_restore(void)
log_sys_debug("sigprocmask", "SIG_SETMASK");
}
- if (sigaction(SIGINT, &_oldhandler2, NULL))
+ if (sigaction(SIGINT, &_oldhandler[_handler_installed], NULL))
log_sys_debug("sigaction", "SIGINT restore");
}
10 years
master - debug: add more debug message for signal handling
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=31ac200a374e10...
Commit: 31ac200a374e101ddfb60fbef0591efee58b478a
Parent: 04b29a3587737375303f2f37b41a33e181ac8623
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 2 17:34:22 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:07:13 2014 +0200
debug: add more debug message for signal handling
Adding log_sys_debug for eventual logging of system errors.
(Using debug level, since currently signal handling functions
do not fail when any error is encoutered).
---
lib/misc/lvm-signal.c | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c
index 679f089..8aeb192 100644
--- a/lib/misc/lvm-signal.c
+++ b/lib/misc/lvm-signal.c
@@ -67,20 +67,26 @@ void sigint_allow(void)
}
/* Grab old sigaction for SIGINT: shall not fail. */
- sigaction(SIGINT, NULL, &handler);
+ if (sigaction(SIGINT, NULL, &handler))
+ log_sys_debug("sigaction", "SIGINT");
+
handler.sa_flags &= ~SA_RESTART; /* Clear restart flag */
handler.sa_handler = _catch_sigint;
_handler_installed2 = 1;
/* Override the signal handler: shall not fail. */
- sigaction(SIGINT, &handler, &_oldhandler2);
+ if (sigaction(SIGINT, &handler, &_oldhandler2))
+ log_sys_debug("sigaction", "SIGINT");
/* Unmask SIGINT. Remember to mask it again on restore. */
- sigprocmask(0, NULL, &sigs);
+ if (sigprocmask(0, NULL, &sigs))
+ log_sys_debug("sigprocmask", "");
+
if ((_oldmasked = sigismember(&sigs, SIGINT))) {
sigdelset(&sigs, SIGINT);
- sigprocmask(SIG_SETMASK, &sigs, NULL);
+ if (sigprocmask(SIG_SETMASK, &sigs, NULL))
+ log_sys_debug("sigprocmask", "SIG_SETMASK");
}
}
@@ -101,10 +107,12 @@ void sigint_restore(void)
sigset_t sigs;
sigprocmask(0, NULL, &sigs);
sigaddset(&sigs, SIGINT);
- sigprocmask(SIG_SETMASK, &sigs, NULL);
+ if (sigprocmask(SIG_SETMASK, &sigs, NULL))
+ log_sys_debug("sigprocmask", "SIG_SETMASK");
}
- sigaction(SIGINT, &_oldhandler2, NULL);
+ if (sigaction(SIGINT, &_oldhandler2, NULL))
+ log_sys_debug("sigaction", "SIGINT restore");
}
void block_signals(uint32_t flags __attribute__((unused)))
10 years
master - locking: use sigaction signal handling
by Zdenek Kabelac
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=04b29a35877373...
Commit: 04b29a3587737375303f2f37b41a33e181ac8623
Parent: 9d64573da135b489e1b3079612e77363526ca44d
Author: Zdenek Kabelac <zkabelac(a)redhat.com>
AuthorDate: Fri May 2 17:27:51 2014 +0200
Committer: Zdenek Kabelac <zkabelac(a)redhat.com>
CommitterDate: Wed May 7 14:01:13 2014 +0200
locking: use sigaction signal handling
Use sigint_allow/restore function instead of duplicating code
and switch to use only sigactiction based signal handling.
---
WHATS_NEW | 1 +
lib/locking/file_locking.c | 3 --
lib/misc/lvm-flock.c | 9 +++++--
lib/misc/lvm-signal.c | 54 --------------------------------------------
4 files changed, 7 insertions(+), 60 deletions(-)
diff --git a/WHATS_NEW b/WHATS_NEW
index 37225fe..1cb97d9 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,5 +1,6 @@
Version 2.02.107 -
==================================
+ Use only sigaction handler and drop duplicate signal handler.
Separate signal handling and flock code out into lib/misc.
Don't start dmeventd checking seg_monitor and monitoring is disabled.
Catch CTRL-c during pvremove prompts.
diff --git a/lib/locking/file_locking.c b/lib/locking/file_locking.c
index d3794db..d79d7a9 100644
--- a/lib/locking/file_locking.c
+++ b/lib/locking/file_locking.c
@@ -160,8 +160,5 @@ int init_file_locking(struct locking_type *locking, struct cmd_context *cmd,
if ((access(_lock_dir, R_OK | W_OK | X_OK) == -1) && (errno == EROFS))
return 0;
- if (!init_signals(suppress_messages))
- return_0;
-
return 1;
}
diff --git a/lib/misc/lvm-flock.c b/lib/misc/lvm-flock.c
index ca05e1c..8b70a0c 100644
--- a/lib/misc/lvm-flock.c
+++ b/lib/misc/lvm-flock.c
@@ -111,12 +111,15 @@ static int _do_flock(const char *file, int *fd, int operation, uint32_t nonblock
if (nonblock)
operation |= LOCK_NB;
else
- install_ctrl_c_handler();
+ sigint_allow();
r = flock(*fd, operation);
old_errno = errno;
- if (!nonblock)
- remove_ctrl_c_handler();
+ if (!nonblock) {
+ sigint_restore();
+ if (sigint_caught())
+ log_error("Giving up waiting for lock.");
+ }
if (r) {
errno = old_errno;
diff --git a/lib/misc/lvm-signal.c b/lib/misc/lvm-signal.c
index 690733b..679f089 100644
--- a/lib/misc/lvm-signal.c
+++ b/lib/misc/lvm-signal.c
@@ -18,10 +18,6 @@
#include <signal.h>
-static sig_t _oldhandler;
-static sigset_t _fullsigset, _intsigset;
-static volatile sig_atomic_t _handler_installed;
-
static sigset_t _oldset;
static int _signals_blocked = 0;
static volatile sig_atomic_t _sigint_caught = 0;
@@ -29,56 +25,6 @@ static volatile sig_atomic_t _handler_installed2;
static struct sigaction _oldhandler2;
static int _oldmasked;
-void remove_ctrl_c_handler(void)
-{
- siginterrupt(SIGINT, 0);
- if (!_handler_installed)
- return;
-
- _handler_installed = 0;
-
- sigprocmask(SIG_SETMASK, &_fullsigset, NULL);
- if (signal(SIGINT, _oldhandler) == SIG_ERR)
- log_sys_error("signal", "_remove_ctrl_c_handler");
-}
-
-static void _trap_ctrl_c(int sig __attribute__((unused)))
-{
- remove_ctrl_c_handler();
-
- log_error("CTRL-c detected: giving up waiting for lock");
-}
-
-void install_ctrl_c_handler(void)
-{
- _handler_installed = 1;
-
- if ((_oldhandler = signal(SIGINT, _trap_ctrl_c)) == SIG_ERR) {
- _handler_installed = 0;
- return;
- }
-
- sigprocmask(SIG_SETMASK, &_intsigset, NULL);
- siginterrupt(SIGINT, 1);
-}
-
-int init_signals(int suppress_messages)
-{
- if (sigfillset(&_intsigset) || sigfillset(&_fullsigset)) {
- log_sys_error_suppress(suppress_messages, "sigfillset",
- "init_signals");
- return 0;
- }
-
- if (sigdelset(&_intsigset, SIGINT)) {
- log_sys_error_suppress(suppress_messages, "sigdelset",
- "init_signals");
- return 0;
- }
-
- return 1;
-}
-
static void _catch_sigint(int unused __attribute__((unused)))
{
_sigint_caught = 1;
10 years