Import from AlmaLinux stable repository
This commit is contained in:
parent
f1e6514d13
commit
d2ee2270bc
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1 @@
|
||||
SOURCES/sbd-6bb085f5704dd4c3841c79504f2aed2228e6d76a.tar.gz
|
||||
SOURCES/sbd-cf5c2208bad2db2dff9b09624b89b05415c3bc11.tar.gz
|
||||
|
@ -1 +1 @@
|
||||
50c4fbd14ecf01d05a1bcf014aaa3ab128930d03 SOURCES/sbd-6bb085f5704dd4c3841c79504f2aed2228e6d76a.tar.gz
|
||||
e8adcf4624bdebd17e112f3edc973b430c9c9e5c SOURCES/sbd-cf5c2208bad2db2dff9b09624b89b05415c3bc11.tar.gz
|
||||
|
@ -1,572 +0,0 @@
|
||||
From 230586043d9efd3a431b64427b0760b3ffbd6b58 Mon Sep 17 00:00:00 2001
|
||||
From: Klaus Wenninger <klaus.wenninger@aon.at>
|
||||
Date: Wed, 13 Jul 2022 14:46:38 +0200
|
||||
Subject: [PATCH] Fix: Be a bit more descriptive on issues opening
|
||||
watchdog-devices
|
||||
|
||||
Both when running as daemon and with 'test/query-watchdog'
|
||||
---
|
||||
src/sbd-common.c | 495 +++++++++++++++++++++++++++++++++----------------------
|
||||
1 file changed, 302 insertions(+), 193 deletions(-)
|
||||
|
||||
diff --git a/src/sbd-common.c b/src/sbd-common.c
|
||||
index b14575f..f3f226a 100644
|
||||
--- a/src/sbd-common.c
|
||||
+++ b/src/sbd-common.c
|
||||
@@ -118,6 +118,62 @@ usage(void)
|
||||
, cmdname);
|
||||
}
|
||||
|
||||
+#define MAX_WATCHDOGS 64
|
||||
+#define SYS_CLASS_WATCHDOG "/sys/class/watchdog"
|
||||
+#define SYS_CHAR_DEV_DIR "/sys/dev/char"
|
||||
+#define WATCHDOG_NODEDIR "/dev/"
|
||||
+
|
||||
+static bool
|
||||
+is_watchdog(dev_t device)
|
||||
+{
|
||||
+ static int num_watchdog_devs = 0;
|
||||
+ static dev_t watchdog_devs[MAX_WATCHDOGS];
|
||||
+ struct dirent *entry;
|
||||
+ int i;
|
||||
+
|
||||
+ /* populate on first call */
|
||||
+ if (num_watchdog_devs == 0) {
|
||||
+ DIR *dp;
|
||||
+
|
||||
+ watchdog_devs[0] = makedev(10,130);
|
||||
+ num_watchdog_devs = 1;
|
||||
+
|
||||
+ /* get additional devices from /sys/class/watchdog */
|
||||
+ dp = opendir(SYS_CLASS_WATCHDOG);
|
||||
+ if (dp) {
|
||||
+ while ((entry = readdir(dp))) {
|
||||
+ if (entry->d_type == DT_LNK) {
|
||||
+ FILE *file;
|
||||
+ char entry_name[NAME_MAX+sizeof(SYS_CLASS_WATCHDOG)+5];
|
||||
+
|
||||
+ snprintf(entry_name, sizeof(entry_name),
|
||||
+ SYS_CLASS_WATCHDOG "/%s/dev", entry->d_name);
|
||||
+ file = fopen(entry_name, "r");
|
||||
+ if (file) {
|
||||
+ int major, minor;
|
||||
+
|
||||
+ if (fscanf(file, "%d:%d", &major, &minor) == 2) {
|
||||
+ watchdog_devs[num_watchdog_devs++] = makedev(major, minor);
|
||||
+ }
|
||||
+ fclose(file);
|
||||
+ if (num_watchdog_devs == MAX_WATCHDOGS) {
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ closedir(dp);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ for (i=0; i < num_watchdog_devs; i++) {
|
||||
+ if (device == watchdog_devs[i]) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ }
|
||||
+ return false;
|
||||
+}
|
||||
+
|
||||
static int
|
||||
watchdog_init_interval_fd(int wdfd, int timeout)
|
||||
{
|
||||
@@ -173,20 +229,27 @@ watchdog_tickle(void)
|
||||
static int
|
||||
watchdog_init_fd(char *wddev, int timeout)
|
||||
{
|
||||
- int wdfd;
|
||||
+ int wdfd;
|
||||
+
|
||||
+ wdfd = open(wddev, O_WRONLY);
|
||||
+ if (wdfd >= 0) {
|
||||
+ if (((timeout >= 0) && (watchdog_init_interval_fd(wdfd, timeout) < 0)) ||
|
||||
+ (watchdog_tickle_fd(wdfd, wddev) < 0)) {
|
||||
+ close(wdfd);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ } else {
|
||||
+ struct stat statbuf;
|
||||
|
||||
- wdfd = open(wddev, O_WRONLY);
|
||||
- if (wdfd >= 0) {
|
||||
- if (((timeout >= 0) && (watchdog_init_interval_fd(wdfd, timeout) < 0))
|
||||
- || (watchdog_tickle_fd(wdfd, wddev) < 0)) {
|
||||
- close(wdfd);
|
||||
- return -1;
|
||||
- }
|
||||
- } else {
|
||||
- cl_perror("Cannot open watchdog device '%s'", wddev);
|
||||
- return -1;
|
||||
- }
|
||||
- return wdfd;
|
||||
+ if(!stat(wddev, &statbuf) && S_ISCHR(statbuf.st_mode) &&
|
||||
+ is_watchdog(statbuf.st_rdev)) {
|
||||
+ cl_perror("Cannot open watchdog device '%s'", wddev);
|
||||
+ } else {
|
||||
+ cl_perror("Seems as if '%s' isn't a valid watchdog-device", wddev);
|
||||
+ }
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return wdfd;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -250,17 +313,13 @@ watchdog_close(bool disarm)
|
||||
watchdogfd = -1;
|
||||
}
|
||||
|
||||
-#define MAX_WATCHDOGS 64
|
||||
-#define SYS_CLASS_WATCHDOG "/sys/class/watchdog"
|
||||
-#define SYS_CHAR_DEV_DIR "/sys/dev/char"
|
||||
-#define WATCHDOG_NODEDIR "/dev/"
|
||||
-#define WATCHDOG_NODEDIR_LEN 5
|
||||
-
|
||||
struct watchdog_list_item {
|
||||
dev_t dev;
|
||||
char *dev_node;
|
||||
char *dev_ident;
|
||||
char *dev_driver;
|
||||
+ pid_t busy_pid;
|
||||
+ char *busy_name;
|
||||
struct watchdog_list_item *next;
|
||||
};
|
||||
|
||||
@@ -276,184 +335,223 @@ static int watchdog_list_items = 0;
|
||||
static void
|
||||
watchdog_populate_list(void)
|
||||
{
|
||||
- dev_t watchdogs[MAX_WATCHDOGS + 1] =
|
||||
- {makedev(10,130), 0};
|
||||
- int num_watchdogs = 1;
|
||||
- struct dirent *entry;
|
||||
- char entry_name[280];
|
||||
- DIR *dp;
|
||||
- char buf[280] = "";
|
||||
- struct link_list_item *link_list = NULL;
|
||||
-
|
||||
- if (watchdog_list != NULL) {
|
||||
- return;
|
||||
- }
|
||||
+ struct dirent *entry;
|
||||
+ char entry_name[sizeof(WATCHDOG_NODEDIR)+NAME_MAX];
|
||||
+ DIR *dp;
|
||||
+ char buf[NAME_MAX+sizeof(WATCHDOG_NODEDIR)] = "";
|
||||
+ struct link_list_item *link_list = NULL;
|
||||
|
||||
- /* get additional devices from /sys/class/watchdog */
|
||||
- dp = opendir(SYS_CLASS_WATCHDOG);
|
||||
- if (dp) {
|
||||
- while ((entry = readdir(dp))) {
|
||||
- if (entry->d_type == DT_LNK) {
|
||||
- FILE *file;
|
||||
-
|
||||
- snprintf(entry_name, sizeof(entry_name),
|
||||
- SYS_CLASS_WATCHDOG "/%s/dev", entry->d_name);
|
||||
- file = fopen(entry_name, "r");
|
||||
- if (file) {
|
||||
- int major, minor;
|
||||
-
|
||||
- if (fscanf(file, "%d:%d", &major, &minor) == 2) {
|
||||
- watchdogs[num_watchdogs++] = makedev(major, minor);
|
||||
- }
|
||||
- fclose(file);
|
||||
- if (num_watchdogs == MAX_WATCHDOGS) {
|
||||
- break;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- closedir(dp);
|
||||
- }
|
||||
+ if (watchdog_list != NULL) {
|
||||
+ return;
|
||||
+ }
|
||||
|
||||
- /* search for watchdog nodes in /dev */
|
||||
- dp = opendir(WATCHDOG_NODEDIR);
|
||||
- if (dp) {
|
||||
- /* first go for links and memorize them */
|
||||
- while ((entry = readdir(dp))) {
|
||||
- if (entry->d_type == DT_LNK) {
|
||||
- int len;
|
||||
-
|
||||
- snprintf(entry_name, sizeof(entry_name),
|
||||
- WATCHDOG_NODEDIR "%s", entry->d_name);
|
||||
-
|
||||
- /* !realpath(entry_name, buf) unfortunately does a stat on
|
||||
- * target so we can't really use it to check if links stay
|
||||
- * within /dev without triggering e.g. AVC-logs (with
|
||||
- * SELinux policy that just allows stat within /dev).
|
||||
- * Without canonicalization that doesn't actually touch the
|
||||
- * filesystem easily available introduce some limitations
|
||||
- * for simplicity:
|
||||
- * - just simple path without '..'
|
||||
- * - just one level of symlinks (avoid e.g. loop-checking)
|
||||
- */
|
||||
- len = readlink(entry_name, buf, sizeof(buf) - 1);
|
||||
- if ((len < 1) ||
|
||||
- (len > sizeof(buf) - WATCHDOG_NODEDIR_LEN - 1)) {
|
||||
- continue;
|
||||
- }
|
||||
- buf[len] = '\0';
|
||||
- if (buf[0] != '/') {
|
||||
- memmove(&buf[WATCHDOG_NODEDIR_LEN], buf, len+1);
|
||||
- memcpy(buf, WATCHDOG_NODEDIR, WATCHDOG_NODEDIR_LEN);
|
||||
- len += WATCHDOG_NODEDIR_LEN;
|
||||
- }
|
||||
- if (strstr(buf, "/../") ||
|
||||
- strncmp(WATCHDOG_NODEDIR, buf, WATCHDOG_NODEDIR_LEN)) {
|
||||
- continue;
|
||||
- } else {
|
||||
- /* just memorize to avoid statting the target - SELinux */
|
||||
- struct link_list_item *lli =
|
||||
- calloc(1, sizeof(struct link_list_item));
|
||||
-
|
||||
- lli->dev_node = strdup(buf);
|
||||
- lli->link_name = strdup(entry_name);
|
||||
- lli->next = link_list;
|
||||
- link_list = lli;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ /* search for watchdog nodes in /dev */
|
||||
+ dp = opendir(WATCHDOG_NODEDIR);
|
||||
+ if (dp) {
|
||||
+ /* first go for links and memorize them */
|
||||
+ while ((entry = readdir(dp))) {
|
||||
+ if (entry->d_type == DT_LNK) {
|
||||
+ int len;
|
||||
+
|
||||
+ snprintf(entry_name, sizeof(entry_name),
|
||||
+ WATCHDOG_NODEDIR "%s", entry->d_name);
|
||||
+
|
||||
+ /* realpath(entry_name, buf) unfortunately does a stat on
|
||||
+ * target so we can't really use it to check if links stay
|
||||
+ * within /dev without triggering e.g. AVC-logs (with
|
||||
+ * SELinux policy that just allows stat within /dev).
|
||||
+ * Without canonicalization that doesn't actually touch the
|
||||
+ * filesystem easily available introduce some limitations
|
||||
+ * for simplicity:
|
||||
+ * - just simple path without '..'
|
||||
+ * - just one level of symlinks (avoid e.g. loop-checking)
|
||||
+ */
|
||||
+ len = readlink(entry_name, buf, sizeof(buf) - 1);
|
||||
+ if ((len < 1) ||
|
||||
+ (len > sizeof(buf) - sizeof(WATCHDOG_NODEDIR) -1 - 1)) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ buf[len] = '\0';
|
||||
+ if (buf[0] != '/') {
|
||||
+ memmove(&buf[sizeof(WATCHDOG_NODEDIR)-1], buf, len+1);
|
||||
+ memcpy(buf, WATCHDOG_NODEDIR, sizeof(WATCHDOG_NODEDIR)-1);
|
||||
+ len += sizeof(WATCHDOG_NODEDIR)-1;
|
||||
+ }
|
||||
+ if (strstr(buf, "/../") ||
|
||||
+ strncmp(WATCHDOG_NODEDIR, buf, sizeof(WATCHDOG_NODEDIR)-1)) {
|
||||
+ continue;
|
||||
+ } else {
|
||||
+ /* just memorize to avoid statting the target - SELinux */
|
||||
+ struct link_list_item *lli =
|
||||
+ calloc(1, sizeof(struct link_list_item));
|
||||
+
|
||||
+ lli->dev_node = strdup(buf);
|
||||
+ lli->link_name = strdup(entry_name);
|
||||
+ lli->next = link_list;
|
||||
+ link_list = lli;
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- rewinddir(dp);
|
||||
-
|
||||
- while ((entry = readdir(dp))) {
|
||||
- if (entry->d_type == DT_CHR) {
|
||||
- struct stat statbuf;
|
||||
-
|
||||
- snprintf(entry_name, sizeof(entry_name),
|
||||
- WATCHDOG_NODEDIR "%s", entry->d_name);
|
||||
- if(!stat(entry_name, &statbuf) && S_ISCHR(statbuf.st_mode)) {
|
||||
- int i;
|
||||
-
|
||||
- for (i=0; i<num_watchdogs; i++) {
|
||||
- if (statbuf.st_rdev == watchdogs[i]) {
|
||||
- int wdfd = watchdog_init_fd(entry_name, -1);
|
||||
- struct watchdog_list_item *wdg =
|
||||
- calloc(1, sizeof(struct watchdog_list_item));
|
||||
- int len;
|
||||
- struct link_list_item *tmp_list = NULL;
|
||||
-
|
||||
- wdg->dev = watchdogs[i];
|
||||
- wdg->dev_node = strdup(entry_name);
|
||||
- wdg->next = watchdog_list;
|
||||
- watchdog_list = wdg;
|
||||
- watchdog_list_items++;
|
||||
-
|
||||
- if (wdfd >= 0) {
|
||||
- struct watchdog_info ident;
|
||||
-
|
||||
- ident.identity[0] = '\0';
|
||||
- ioctl(wdfd, WDIOC_GETSUPPORT, &ident);
|
||||
- watchdog_close_fd(wdfd, entry_name, true);
|
||||
- if (ident.identity[0]) {
|
||||
- wdg->dev_ident = strdup((char *) ident.identity);
|
||||
- }
|
||||
- }
|
||||
-
|
||||
- snprintf(entry_name, sizeof(entry_name),
|
||||
- SYS_CHAR_DEV_DIR "/%d:%d/device/driver",
|
||||
- major(watchdogs[i]), minor(watchdogs[i]));
|
||||
- len = readlink(entry_name, buf, sizeof(buf) - 1);
|
||||
- if (len > 0) {
|
||||
- buf[len] = '\0';
|
||||
- wdg->dev_driver = strdup(basename(buf));
|
||||
- } else if ((wdg->dev_ident) &&
|
||||
- (strcmp(wdg->dev_ident,
|
||||
- "Software Watchdog") == 0)) {
|
||||
- wdg->dev_driver = strdup("softdog");
|
||||
- }
|
||||
-
|
||||
- /* create dupes if we have memorized links
|
||||
- * to this node
|
||||
- */
|
||||
- for (tmp_list = link_list; tmp_list;
|
||||
- tmp_list = tmp_list->next) {
|
||||
- if (!strcmp(tmp_list->dev_node,
|
||||
- wdg->dev_node)) {
|
||||
- struct watchdog_list_item *dupe_wdg =
|
||||
- calloc(1, sizeof(struct watchdog_list_item));
|
||||
-
|
||||
- /* as long as we never purge watchdog_list
|
||||
- * there is no need to dupe strings
|
||||
- */
|
||||
- *dupe_wdg = *wdg;
|
||||
- dupe_wdg->dev_node = strdup(tmp_list->link_name);
|
||||
- dupe_wdg->next = watchdog_list;
|
||||
- watchdog_list = dupe_wdg;
|
||||
- watchdog_list_items++;
|
||||
- }
|
||||
- /* for performance reasons we could remove
|
||||
- * the link_list entry
|
||||
- */
|
||||
- }
|
||||
- break;
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
- }
|
||||
+ rewinddir(dp);
|
||||
+
|
||||
+ while ((entry = readdir(dp))) {
|
||||
+ if (entry->d_type == DT_CHR) {
|
||||
+ struct stat statbuf;
|
||||
+
|
||||
+ snprintf(entry_name, sizeof(entry_name),
|
||||
+ WATCHDOG_NODEDIR "%s", entry->d_name);
|
||||
+ if(!stat(entry_name, &statbuf) && S_ISCHR(statbuf.st_mode) &&
|
||||
+ is_watchdog(statbuf.st_rdev)) {
|
||||
+
|
||||
+ int wdfd = watchdog_init_fd(entry_name, -1);
|
||||
+ struct watchdog_list_item *wdg =
|
||||
+ calloc(1, sizeof(struct watchdog_list_item));
|
||||
+ int len;
|
||||
+ struct link_list_item *tmp_list = NULL;
|
||||
+
|
||||
+ wdg->dev = statbuf.st_rdev;
|
||||
+ wdg->dev_node = strdup(entry_name);
|
||||
+ wdg->next = watchdog_list;
|
||||
+ watchdog_list = wdg;
|
||||
+ watchdog_list_items++;
|
||||
+
|
||||
+ if (wdfd >= 0) {
|
||||
+ struct watchdog_info ident;
|
||||
+
|
||||
+ ident.identity[0] = '\0';
|
||||
+ ioctl(wdfd, WDIOC_GETSUPPORT, &ident);
|
||||
+ watchdog_close_fd(wdfd, entry_name, true);
|
||||
+ if (ident.identity[0]) {
|
||||
+ wdg->dev_ident = strdup((char *) ident.identity);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ snprintf(entry_name, sizeof(entry_name),
|
||||
+ SYS_CHAR_DEV_DIR "/%d:%d/device/driver",
|
||||
+ major(wdg->dev), minor(wdg->dev));
|
||||
+ len = readlink(entry_name, buf, sizeof(buf) - 1);
|
||||
+ if (len > 0) {
|
||||
+ buf[len] = '\0';
|
||||
+ wdg->dev_driver = strdup(basename(buf));
|
||||
+ } else if ((wdg->dev_ident) &&
|
||||
+ (strcmp(wdg->dev_ident,
|
||||
+ "Software Watchdog") == 0)) {
|
||||
+ wdg->dev_driver = strdup("softdog");
|
||||
+ }
|
||||
+
|
||||
+ /* create dupes if we have memorized links
|
||||
+ * to this node
|
||||
+ */
|
||||
+ for (tmp_list = link_list; tmp_list;
|
||||
+ tmp_list = tmp_list->next) {
|
||||
+ if (!strcmp(tmp_list->dev_node,
|
||||
+ wdg->dev_node)) {
|
||||
+ struct watchdog_list_item *dupe_wdg =
|
||||
+ calloc(1, sizeof(struct watchdog_list_item));
|
||||
+
|
||||
+ /* as long as we never purge watchdog_list
|
||||
+ * there is no need to dupe strings
|
||||
+ */
|
||||
+ *dupe_wdg = *wdg;
|
||||
+ dupe_wdg->dev_node = strdup(tmp_list->link_name);
|
||||
+ dupe_wdg->next = watchdog_list;
|
||||
+ watchdog_list = dupe_wdg;
|
||||
+ watchdog_list_items++;
|
||||
+ }
|
||||
+ /* for performance reasons we could remove
|
||||
+ * the link_list entry
|
||||
+ */
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
|
||||
- closedir(dp);
|
||||
- }
|
||||
+ closedir(dp);
|
||||
+ }
|
||||
|
||||
- /* cleanup link list */
|
||||
- while (link_list) {
|
||||
- struct link_list_item *tmp_list = link_list;
|
||||
+ /* cleanup link list */
|
||||
+ while (link_list) {
|
||||
+ struct link_list_item *tmp_list = link_list;
|
||||
|
||||
- link_list = link_list->next;
|
||||
- free(tmp_list->dev_node);
|
||||
- free(tmp_list->link_name);
|
||||
- free(tmp_list);
|
||||
- }
|
||||
+ link_list = link_list->next;
|
||||
+ free(tmp_list->dev_node);
|
||||
+ free(tmp_list->link_name);
|
||||
+ free(tmp_list);
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+static void
|
||||
+watchdog_checkbusy()
|
||||
+{
|
||||
+ DIR *dproc;
|
||||
+ struct dirent *entry;
|
||||
+
|
||||
+ dproc = opendir("/proc");
|
||||
+ if (!dproc) {
|
||||
+ /* no proc directory to search through */
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ while ((entry = readdir(dproc)) != NULL) {
|
||||
+ pid_t local_pid;
|
||||
+ char *leftover;
|
||||
+ DIR *dpid;
|
||||
+ char procpath[NAME_MAX+10] = { 0 };
|
||||
+
|
||||
+ if (entry->d_name[0] == '.') {
|
||||
+ continue;
|
||||
+ }
|
||||
+
|
||||
+ local_pid = strtol(entry->d_name, &leftover, 10);
|
||||
+ if (leftover[0] != '\0')
|
||||
+ continue;
|
||||
+
|
||||
+ snprintf(procpath, sizeof(procpath), "/proc/%s/fd", entry->d_name);
|
||||
+ dpid = opendir(procpath);
|
||||
+ if (!dpid) {
|
||||
+ /* silently continue - might be just a race */
|
||||
+ continue;
|
||||
+ }
|
||||
+ while ((entry = readdir(dpid)) != NULL) {
|
||||
+ struct watchdog_list_item *wdg;
|
||||
+ char entry_name[sizeof(procpath)+NAME_MAX+1] = { 0 };
|
||||
+ char buf[NAME_MAX+1] = { 0 };
|
||||
+ int len;
|
||||
+
|
||||
+ if (entry->d_type != DT_LNK) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ snprintf(entry_name, sizeof(entry_name),
|
||||
+ "%s/%s", procpath, entry->d_name);
|
||||
+ len = readlink(entry_name, buf, sizeof(buf) - 1);
|
||||
+ if (len < 1) {
|
||||
+ continue;
|
||||
+ }
|
||||
+ buf[len] = '\0';
|
||||
+ for (wdg = watchdog_list; wdg != NULL; wdg = wdg->next) {
|
||||
+ if (!strcmp(buf, wdg->dev_node)) {
|
||||
+ char name[16];
|
||||
+ FILE *file;
|
||||
+
|
||||
+ wdg->busy_pid = local_pid;
|
||||
+ snprintf(procpath, sizeof(procpath), "/proc/%d/status", local_pid);
|
||||
+ file = fopen(procpath, "r");
|
||||
+ if (file) {
|
||||
+ if (fscanf(file, "Name:\t%15[a-zA-Z0-9 _-]", name) == 1) {
|
||||
+ wdg->busy_name = strdup(name);
|
||||
+ }
|
||||
+ fclose(file);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+ closedir(dpid);
|
||||
+ }
|
||||
+
|
||||
+ closedir(dproc);
|
||||
+
|
||||
+ return;
|
||||
}
|
||||
|
||||
int watchdog_info(void)
|
||||
@@ -462,13 +560,23 @@ int watchdog_info(void)
|
||||
int wdg_cnt = 0;
|
||||
|
||||
watchdog_populate_list();
|
||||
+ watchdog_checkbusy();
|
||||
printf("\nDiscovered %d watchdog devices:\n", watchdog_list_items);
|
||||
for (wdg = watchdog_list; wdg != NULL; wdg = wdg->next) {
|
||||
wdg_cnt++;
|
||||
- printf("\n[%d] %s\nIdentity: %s\nDriver: %s\n",
|
||||
+ if (wdg->busy_pid) {
|
||||
+ printf("\n[%d] %s\nIdentity: Busy: PID %d (%s)\nDriver: %s\n",
|
||||
wdg_cnt, wdg->dev_node,
|
||||
- wdg->dev_ident?wdg->dev_ident:"Error: Check if hogged by e.g. sbd-daemon!",
|
||||
+ wdg->busy_pid,
|
||||
+ wdg->busy_name?wdg->busy_name:"<unknown>",
|
||||
wdg->dev_driver?wdg->dev_driver:"<unknown>");
|
||||
+ } else {
|
||||
+ printf("\n[%d] %s\nIdentity: %s\nDriver: %s\n",
|
||||
+ wdg_cnt, wdg->dev_node,
|
||||
+ wdg->dev_ident?wdg->dev_ident:
|
||||
+ "Error: device hogged via alias major/minor?",
|
||||
+ wdg->dev_driver?wdg->dev_driver:"<unknown>");
|
||||
+ }
|
||||
if ((wdg->dev_driver) && (strcmp(wdg->dev_driver, "softdog") == 0)) {
|
||||
printf("CAUTION: Not recommended for use with sbd.\n");
|
||||
}
|
||||
@@ -512,6 +620,7 @@ int watchdog_test(void)
|
||||
watchdogdev, (int) timeout_watchdog);
|
||||
if ((watchdog_init() < 0) || (watchdog_init_interval() < 0)) {
|
||||
printf("Failed to initialize watchdog!!!\n");
|
||||
+ watchdog_info();
|
||||
return -1;
|
||||
}
|
||||
printf("\n");
|
||||
--
|
||||
1.8.3.1
|
||||
|
@ -0,0 +1,84 @@
|
||||
From 030d7edb179235b7df65ada3a79837b01e682a5b Mon Sep 17 00:00:00 2001
|
||||
From: Klaus Wenninger <klaus.wenninger@aon.at>
|
||||
Date: Thu, 21 Jul 2022 10:48:21 +0200
|
||||
Subject: [PATCH] Fix: query-watchdog: avoid issues on heap allocation failing
|
||||
|
||||
coverity is moaning either due to slight code rearangement
|
||||
or new version/settings.
|
||||
---
|
||||
src/sbd-common.c | 27 ++++++++++++++++++++++++++-
|
||||
1 file changed, 26 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/sbd-common.c b/src/sbd-common.c
|
||||
index f3f226a..3abf75f 100644
|
||||
--- a/src/sbd-common.c
|
||||
+++ b/src/sbd-common.c
|
||||
@@ -385,8 +385,17 @@ watchdog_populate_list(void)
|
||||
struct link_list_item *lli =
|
||||
calloc(1, sizeof(struct link_list_item));
|
||||
|
||||
+ if (lli == NULL) {
|
||||
+ break;
|
||||
+ }
|
||||
lli->dev_node = strdup(buf);
|
||||
lli->link_name = strdup(entry_name);
|
||||
+ if ((lli->dev_node == NULL) || (lli->link_name == NULL)) {
|
||||
+ free(lli->dev_node);
|
||||
+ free(lli->link_name);
|
||||
+ free(lli);
|
||||
+ break;
|
||||
+ }
|
||||
lli->next = link_list;
|
||||
link_list = lli;
|
||||
}
|
||||
@@ -404,18 +413,27 @@ watchdog_populate_list(void)
|
||||
if(!stat(entry_name, &statbuf) && S_ISCHR(statbuf.st_mode) &&
|
||||
is_watchdog(statbuf.st_rdev)) {
|
||||
|
||||
- int wdfd = watchdog_init_fd(entry_name, -1);
|
||||
+ int wdfd;
|
||||
struct watchdog_list_item *wdg =
|
||||
calloc(1, sizeof(struct watchdog_list_item));
|
||||
int len;
|
||||
struct link_list_item *tmp_list = NULL;
|
||||
|
||||
+ if (wdg == NULL) {
|
||||
+ break;
|
||||
+ }
|
||||
+
|
||||
wdg->dev = statbuf.st_rdev;
|
||||
wdg->dev_node = strdup(entry_name);
|
||||
+ if (wdg->dev_node == NULL) {
|
||||
+ free(wdg);
|
||||
+ break;
|
||||
+ }
|
||||
wdg->next = watchdog_list;
|
||||
watchdog_list = wdg;
|
||||
watchdog_list_items++;
|
||||
|
||||
+ wdfd = watchdog_init_fd(entry_name, -1);
|
||||
if (wdfd >= 0) {
|
||||
struct watchdog_info ident;
|
||||
|
||||
@@ -450,11 +468,18 @@ watchdog_populate_list(void)
|
||||
struct watchdog_list_item *dupe_wdg =
|
||||
calloc(1, sizeof(struct watchdog_list_item));
|
||||
|
||||
+ if (dupe_wdg == NULL) {
|
||||
+ break;
|
||||
+ }
|
||||
/* as long as we never purge watchdog_list
|
||||
* there is no need to dupe strings
|
||||
*/
|
||||
*dupe_wdg = *wdg;
|
||||
dupe_wdg->dev_node = strdup(tmp_list->link_name);
|
||||
+ if (dupe_wdg->dev_node == NULL) {
|
||||
+ free(dupe_wdg);
|
||||
+ break;
|
||||
+ }
|
||||
dupe_wdg->next = watchdog_list;
|
||||
watchdog_list = dupe_wdg;
|
||||
watchdog_list_items++;
|
||||
--
|
||||
2.39.0
|
||||
|
@ -0,0 +1,56 @@
|
||||
From 48c9a11e5b4ace22011e51d4c5dcacaddf9bbc43 Mon Sep 17 00:00:00 2001
|
||||
From: Klaus Wenninger <klaus.wenninger@aon.at>
|
||||
Date: Fri, 3 Feb 2023 10:58:10 +0100
|
||||
Subject: [PATCH] Refactor: sbd-md: alloc/de-alloc reverse order
|
||||
|
||||
Having de-allocation in the reverse order compared to
|
||||
allocation seems to make gcc-12 static analysis of
|
||||
dynamic-memory-management happy.
|
||||
---
|
||||
src/sbd-md.c | 11 +++++------
|
||||
1 file changed, 5 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/sbd-md.c b/src/sbd-md.c
|
||||
index 7a37522..2a237ad 100644
|
||||
--- a/src/sbd-md.c
|
||||
+++ b/src/sbd-md.c
|
||||
@@ -441,9 +441,9 @@ init_device(struct sbd_context *st)
|
||||
}
|
||||
}
|
||||
|
||||
-out: free(s_node);
|
||||
+out: free(s_mbox);
|
||||
+ free(s_node);
|
||||
free(s_header);
|
||||
- free(s_mbox);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
@@ -556,9 +556,9 @@ slot_allocate(struct sbd_context *st, const char *name)
|
||||
}
|
||||
}
|
||||
|
||||
-out: free(s_node);
|
||||
+out: free(s_mbox);
|
||||
+ free(s_node);
|
||||
free(s_header);
|
||||
- free(s_mbox);
|
||||
return(rc);
|
||||
}
|
||||
|
||||
@@ -1279,11 +1279,10 @@ int servant_md(const char *diskname, int mode, const void* argp)
|
||||
}
|
||||
}
|
||||
out:
|
||||
- free(s_header);
|
||||
free(s_node);
|
||||
free(s_mbox);
|
||||
+ free(s_header);
|
||||
close_device(st);
|
||||
exit(rc);
|
||||
}
|
||||
|
||||
-
|
||||
--
|
||||
2.39.0
|
||||
|
34
SOURCES/0003-spec-convert-license-naming-to-SPDX.patch
Normal file
34
SOURCES/0003-spec-convert-license-naming-to-SPDX.patch
Normal file
@ -0,0 +1,34 @@
|
||||
From 0e4534ebdfe8d7a37beb0028e604e560a5674891 Mon Sep 17 00:00:00 2001
|
||||
From: Klaus Wenninger <klaus.wenninger@aon.at>
|
||||
Date: Fri, 3 Feb 2023 15:35:22 +0100
|
||||
Subject: [PATCH] spec: convert license naming to SPDX
|
||||
|
||||
---
|
||||
sbd.spec | 4 ++--
|
||||
1 file changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/sbd.spec b/sbd.spec
|
||||
index e9ff7bc..b9e7f72 100644
|
||||
--- a/sbd.spec
|
||||
+++ b/sbd.spec
|
||||
@@ -49,7 +49,7 @@
|
||||
|
||||
Name: sbd
|
||||
Summary: Storage-based death
|
||||
-License: GPLv2+
|
||||
+License: GPL-2.0-or-later
|
||||
Group: System Environment/Daemons
|
||||
Version: 1.5.2
|
||||
Release: 99.%{buildnum}.%{shortcommit}.%{modified}git%{?dist}
|
||||
@@ -95,7 +95,7 @@ Available rpmbuild rebuild options:
|
||||
|
||||
%package tests
|
||||
Summary: Storage-based death environment for regression tests
|
||||
-License: GPLv2+
|
||||
+License: GPL-2.0-or-later
|
||||
Group: System Environment/Daemons
|
||||
|
||||
%description tests
|
||||
--
|
||||
2.39.0
|
||||
|
@ -15,11 +15,11 @@
|
||||
|
||||
# Please submit bugfixes or comments via http://bugs.opensuse.org/
|
||||
#
|
||||
%global longcommit 6bb085f5704dd4c3841c79504f2aed2228e6d76a
|
||||
%global longcommit cf5c2208bad2db2dff9b09624b89b05415c3bc11
|
||||
%global shortcommit %(echo %{longcommit}|cut -c1-8)
|
||||
%global modified %(echo %{longcommit}-|cut -f2 -d-)
|
||||
%global github_owner Clusterlabs
|
||||
%global buildnum 3
|
||||
%global buildnum 1
|
||||
|
||||
%ifarch s390x s390
|
||||
# minimum timeout on LPAR diag288 watchdog is 15s
|
||||
@ -47,12 +47,14 @@
|
||||
|
||||
Name: sbd
|
||||
Summary: Storage-based death
|
||||
License: GPLv2+
|
||||
Version: 1.5.1
|
||||
License: GPL-2.0-or-later
|
||||
Version: 1.5.2
|
||||
Release: %{buildnum}%{?dist}
|
||||
Url: https://github.com/%{github_owner}/%{name}
|
||||
Source0: https://github.com/%{github_owner}/%{name}/archive/%{longcommit}/%{name}-%{longcommit}.tar.gz
|
||||
Patch0: 0001-Fix-Be-a-bit-more-descriptive-on-issues-opening-watc.patch
|
||||
Patch0: 0001-Fix-query-watchdog-avoid-issues-on-heap-allocation-f.patch
|
||||
Patch1: 0002-Refactor-sbd-md-alloc-de-alloc-reverse-order.patch
|
||||
Patch2: 0003-spec-convert-license-naming-to-SPDX.patch
|
||||
BuildRequires: autoconf
|
||||
BuildRequires: automake
|
||||
BuildRequires: libuuid-devel
|
||||
@ -86,7 +88,7 @@ Available rpmbuild rebuild options:
|
||||
|
||||
%package tests
|
||||
Summary: Storage-based death environment for regression tests
|
||||
License: GPLv2+
|
||||
License: GPL-2.0-or-later
|
||||
|
||||
%description tests
|
||||
This package provides an environment + testscripts for
|
||||
@ -177,6 +179,14 @@ fi
|
||||
%{_libdir}/libsbdtestbed*
|
||||
|
||||
%changelog
|
||||
* Tue May 23 2023 Klaus Wenninger <kwenning@redhat.com> - 1.5.2-1
|
||||
- rebase to upstream v1.5.2
|
||||
- convert license naming to SPDX
|
||||
- make static analysis happy with a few checks & rearanges with
|
||||
dynamic-memory-management
|
||||
|
||||
Resolves: rhbz#2168579
|
||||
|
||||
* Mon Jul 18 2022 Klaus Wenninger <kwenning@redhat.com> - 1.5.1-3
|
||||
- Be a bit more descriptive on issues opening watchdog-devices
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user