Blame SOURCES/0001-Fix-Be-a-bit-more-descriptive-on-issues-opening-watc.patch

30bbda
From 230586043d9efd3a431b64427b0760b3ffbd6b58 Mon Sep 17 00:00:00 2001
30bbda
From: Klaus Wenninger <klaus.wenninger@aon.at>
30bbda
Date: Wed, 13 Jul 2022 14:46:38 +0200
30bbda
Subject: [PATCH] Fix: Be a bit more descriptive on issues opening
30bbda
 watchdog-devices
30bbda
30bbda
Both when running as daemon and with 'test/query-watchdog'
30bbda
---
30bbda
 src/sbd-common.c | 495 +++++++++++++++++++++++++++++++++----------------------
30bbda
 1 file changed, 302 insertions(+), 193 deletions(-)
30bbda
30bbda
diff --git a/src/sbd-common.c b/src/sbd-common.c
30bbda
index b14575f..f3f226a 100644
30bbda
--- a/src/sbd-common.c
30bbda
+++ b/src/sbd-common.c
30bbda
@@ -118,6 +118,62 @@ usage(void)
30bbda
                 , cmdname);
30bbda
 }
30bbda
 
30bbda
+#define MAX_WATCHDOGS 64
30bbda
+#define SYS_CLASS_WATCHDOG "/sys/class/watchdog"
30bbda
+#define SYS_CHAR_DEV_DIR "/sys/dev/char"
30bbda
+#define WATCHDOG_NODEDIR "/dev/"
30bbda
+
30bbda
+static bool
30bbda
+is_watchdog(dev_t device)
30bbda
+{
30bbda
+    static int num_watchdog_devs = 0;
30bbda
+    static dev_t watchdog_devs[MAX_WATCHDOGS];
30bbda
+    struct dirent *entry;
30bbda
+    int i;
30bbda
+
30bbda
+    /* populate on first call */
30bbda
+    if (num_watchdog_devs == 0) {
30bbda
+        DIR *dp;
30bbda
+
30bbda
+        watchdog_devs[0] = makedev(10,130);
30bbda
+        num_watchdog_devs = 1;
30bbda
+
30bbda
+        /* get additional devices from /sys/class/watchdog */
30bbda
+        dp = opendir(SYS_CLASS_WATCHDOG);
30bbda
+        if (dp) {
30bbda
+            while ((entry = readdir(dp))) {
30bbda
+                if (entry->d_type == DT_LNK) {
30bbda
+                    FILE *file;
30bbda
+                    char entry_name[NAME_MAX+sizeof(SYS_CLASS_WATCHDOG)+5];
30bbda
+
30bbda
+                    snprintf(entry_name, sizeof(entry_name),
30bbda
+                        SYS_CLASS_WATCHDOG "/%s/dev", entry->d_name);
30bbda
+                    file = fopen(entry_name, "r");
30bbda
+                    if (file) {
30bbda
+                        int major, minor;
30bbda
+
30bbda
+                        if (fscanf(file, "%d:%d", &major, &minor) == 2) {
30bbda
+                            watchdog_devs[num_watchdog_devs++] = makedev(major, minor);
30bbda
+                        }
30bbda
+                        fclose(file);
30bbda
+                        if (num_watchdog_devs == MAX_WATCHDOGS) {
30bbda
+                            break;
30bbda
+                        }
30bbda
+                    }
30bbda
+                }
30bbda
+            }
30bbda
+            closedir(dp);
30bbda
+        }
30bbda
+    }
30bbda
+
30bbda
+    for (i=0; i < num_watchdog_devs; i++) {
30bbda
+        if (device == watchdog_devs[i]) {
30bbda
+            return true;
30bbda
+        }
30bbda
+    }
30bbda
+    return false;
30bbda
+}
30bbda
+
30bbda
 static int
30bbda
 watchdog_init_interval_fd(int wdfd, int timeout)
30bbda
 {
30bbda
@@ -173,20 +229,27 @@ watchdog_tickle(void)
30bbda
 static int
30bbda
 watchdog_init_fd(char *wddev, int timeout)
30bbda
 {
30bbda
-	int wdfd;
30bbda
+    int wdfd;
30bbda
+
30bbda
+    wdfd = open(wddev, O_WRONLY);
30bbda
+    if (wdfd >= 0) {
30bbda
+        if (((timeout >= 0) && (watchdog_init_interval_fd(wdfd, timeout) < 0)) ||
30bbda
+            (watchdog_tickle_fd(wdfd, wddev) < 0)) {
30bbda
+            close(wdfd);
30bbda
+            return -1;
30bbda
+        }
30bbda
+    } else {
30bbda
+        struct stat statbuf;
30bbda
 
30bbda
-	wdfd = open(wddev, O_WRONLY);
30bbda
-	if (wdfd >= 0) {
30bbda
-		if (((timeout >= 0) && (watchdog_init_interval_fd(wdfd, timeout) < 0))
30bbda
-					|| (watchdog_tickle_fd(wdfd, wddev) < 0)) {
30bbda
-			close(wdfd);
30bbda
-			return -1;
30bbda
-		}
30bbda
-	} else {
30bbda
-		cl_perror("Cannot open watchdog device '%s'", wddev);
30bbda
-		return -1;
30bbda
-	}
30bbda
-	return wdfd;
30bbda
+        if(!stat(wddev, &statbuf) && S_ISCHR(statbuf.st_mode) &&
30bbda
+           is_watchdog(statbuf.st_rdev)) {
30bbda
+            cl_perror("Cannot open watchdog device '%s'", wddev);
30bbda
+        } else {
30bbda
+            cl_perror("Seems as if '%s' isn't a valid watchdog-device", wddev);
30bbda
+        }
30bbda
+        return -1;
30bbda
+    }
30bbda
+    return wdfd;
30bbda
 }
30bbda
 
30bbda
 int
30bbda
@@ -250,17 +313,13 @@ watchdog_close(bool disarm)
30bbda
     watchdogfd = -1;
30bbda
 }
30bbda
 
30bbda
-#define MAX_WATCHDOGS 64
30bbda
-#define SYS_CLASS_WATCHDOG "/sys/class/watchdog"
30bbda
-#define SYS_CHAR_DEV_DIR "/sys/dev/char"
30bbda
-#define WATCHDOG_NODEDIR "/dev/"
30bbda
-#define WATCHDOG_NODEDIR_LEN 5
30bbda
-
30bbda
 struct watchdog_list_item {
30bbda
 	dev_t dev;
30bbda
 	char *dev_node;
30bbda
 	char *dev_ident;
30bbda
 	char *dev_driver;
30bbda
+	pid_t busy_pid;
30bbda
+	char *busy_name;
30bbda
 	struct watchdog_list_item *next;
30bbda
 };
30bbda
 
30bbda
@@ -276,184 +335,223 @@ static int watchdog_list_items = 0;
30bbda
 static void
30bbda
 watchdog_populate_list(void)
30bbda
 {
30bbda
-	dev_t watchdogs[MAX_WATCHDOGS + 1] =
30bbda
-		{makedev(10,130), 0};
30bbda
-	int num_watchdogs = 1;
30bbda
-	struct dirent *entry;
30bbda
-	char entry_name[280];
30bbda
-	DIR *dp;
30bbda
-	char buf[280] = "";
30bbda
-	struct link_list_item *link_list = NULL;
30bbda
-
30bbda
-	if (watchdog_list != NULL) {
30bbda
-		return;
30bbda
-	}
30bbda
+    struct dirent *entry;
30bbda
+    char entry_name[sizeof(WATCHDOG_NODEDIR)+NAME_MAX];
30bbda
+    DIR *dp;
30bbda
+    char buf[NAME_MAX+sizeof(WATCHDOG_NODEDIR)] = "";
30bbda
+    struct link_list_item *link_list = NULL;
30bbda
 
30bbda
-	/* get additional devices from /sys/class/watchdog */
30bbda
-	dp = opendir(SYS_CLASS_WATCHDOG);
30bbda
-	if (dp) {
30bbda
-		while ((entry = readdir(dp))) {
30bbda
-			if (entry->d_type == DT_LNK) {
30bbda
-				FILE *file;
30bbda
-
30bbda
-				snprintf(entry_name, sizeof(entry_name),
30bbda
-						 SYS_CLASS_WATCHDOG "/%s/dev", entry->d_name);
30bbda
-				file = fopen(entry_name, "r");
30bbda
-				if (file) {
30bbda
-					int major, minor;
30bbda
-
30bbda
-					if (fscanf(file, "%d:%d", &major, &minor) == 2) {
30bbda
-						watchdogs[num_watchdogs++] = makedev(major, minor);
30bbda
-					}
30bbda
-					fclose(file);
30bbda
-					if (num_watchdogs == MAX_WATCHDOGS) {
30bbda
-						break;
30bbda
-					}
30bbda
-				}
30bbda
-			}
30bbda
-		}
30bbda
-		closedir(dp);
30bbda
-	}
30bbda
+    if (watchdog_list != NULL) {
30bbda
+        return;
30bbda
+    }
30bbda
 
30bbda
-	/* search for watchdog nodes in /dev */
30bbda
-	dp = opendir(WATCHDOG_NODEDIR);
30bbda
-	if (dp) {
30bbda
-		/* first go for links and memorize them */
30bbda
-		while ((entry = readdir(dp))) {
30bbda
-			if (entry->d_type == DT_LNK) {
30bbda
-				int len;
30bbda
-
30bbda
-				snprintf(entry_name, sizeof(entry_name),
30bbda
-				         WATCHDOG_NODEDIR "%s", entry->d_name);
30bbda
-
30bbda
-				/* !realpath(entry_name, buf) unfortunately does a stat on
30bbda
-				 * target so we can't really use it to check if links stay
30bbda
-				 * within /dev without triggering e.g. AVC-logs (with
30bbda
-				 * SELinux policy that just allows stat within /dev).
30bbda
-				 * Without canonicalization that doesn't actually touch the
30bbda
-				 * filesystem easily available introduce some limitations
30bbda
-				 * for simplicity:
30bbda
-				 * - just simple path without '..'
30bbda
-				 * - just one level of symlinks (avoid e.g. loop-checking)
30bbda
-				 */
30bbda
-				len = readlink(entry_name, buf, sizeof(buf) - 1);
30bbda
-				if ((len < 1) ||
30bbda
-				    (len > sizeof(buf) - WATCHDOG_NODEDIR_LEN - 1)) {
30bbda
-					continue;
30bbda
-				}
30bbda
-				buf[len] = '\0';
30bbda
-				if (buf[0] != '/') {
30bbda
-					memmove(&buf[WATCHDOG_NODEDIR_LEN], buf, len+1);
30bbda
-					memcpy(buf, WATCHDOG_NODEDIR, WATCHDOG_NODEDIR_LEN);
30bbda
-					len += WATCHDOG_NODEDIR_LEN;
30bbda
-				}
30bbda
-				if (strstr(buf, "/../") ||
30bbda
-				    strncmp(WATCHDOG_NODEDIR, buf, WATCHDOG_NODEDIR_LEN)) {
30bbda
-					continue;
30bbda
-				} else {
30bbda
-					/* just memorize to avoid statting the target - SELinux */
30bbda
-					struct link_list_item *lli =
30bbda
-						calloc(1, sizeof(struct link_list_item));
30bbda
-
30bbda
-					lli->dev_node = strdup(buf);
30bbda
-					lli->link_name = strdup(entry_name);
30bbda
-					lli->next = link_list;
30bbda
-					link_list = lli;
30bbda
-				}
30bbda
-			}
30bbda
-		}
30bbda
+    /* search for watchdog nodes in /dev */
30bbda
+    dp = opendir(WATCHDOG_NODEDIR);
30bbda
+    if (dp) {
30bbda
+        /* first go for links and memorize them */
30bbda
+        while ((entry = readdir(dp))) {
30bbda
+            if (entry->d_type == DT_LNK) {
30bbda
+                int len;
30bbda
+
30bbda
+                snprintf(entry_name, sizeof(entry_name),
30bbda
+                         WATCHDOG_NODEDIR "%s", entry->d_name);
30bbda
+
30bbda
+                /* realpath(entry_name, buf) unfortunately does a stat on
30bbda
+                 * target so we can't really use it to check if links stay
30bbda
+                 * within /dev without triggering e.g. AVC-logs (with
30bbda
+                 * SELinux policy that just allows stat within /dev).
30bbda
+                 * Without canonicalization that doesn't actually touch the
30bbda
+                 * filesystem easily available introduce some limitations
30bbda
+                 * for simplicity:
30bbda
+                 * - just simple path without '..'
30bbda
+                 * - just one level of symlinks (avoid e.g. loop-checking)
30bbda
+                 */
30bbda
+                len = readlink(entry_name, buf, sizeof(buf) - 1);
30bbda
+                if ((len < 1) ||
30bbda
+                    (len > sizeof(buf) - sizeof(WATCHDOG_NODEDIR) -1 - 1)) {
30bbda
+                    continue;
30bbda
+                }
30bbda
+                buf[len] = '\0';
30bbda
+                if (buf[0] != '/') {
30bbda
+                    memmove(&buf[sizeof(WATCHDOG_NODEDIR)-1], buf, len+1);
30bbda
+                    memcpy(buf, WATCHDOG_NODEDIR, sizeof(WATCHDOG_NODEDIR)-1);
30bbda
+                    len += sizeof(WATCHDOG_NODEDIR)-1;
30bbda
+                }
30bbda
+                if (strstr(buf, "/../") ||
30bbda
+                    strncmp(WATCHDOG_NODEDIR, buf, sizeof(WATCHDOG_NODEDIR)-1)) {
30bbda
+                    continue;
30bbda
+                } else {
30bbda
+                    /* just memorize to avoid statting the target - SELinux */
30bbda
+                    struct link_list_item *lli =
30bbda
+                        calloc(1, sizeof(struct link_list_item));
30bbda
+
30bbda
+                    lli->dev_node = strdup(buf);
30bbda
+                    lli->link_name = strdup(entry_name);
30bbda
+                    lli->next = link_list;
30bbda
+                    link_list = lli;
30bbda
+                }
30bbda
+            }
30bbda
+        }
30bbda
 
30bbda
-		rewinddir(dp);
30bbda
-
30bbda
-		while ((entry = readdir(dp))) {
30bbda
-			if (entry->d_type == DT_CHR) {
30bbda
-				struct stat statbuf;
30bbda
-
30bbda
-				snprintf(entry_name, sizeof(entry_name),
30bbda
-				         WATCHDOG_NODEDIR "%s", entry->d_name);
30bbda
-				if(!stat(entry_name, &statbuf) && S_ISCHR(statbuf.st_mode)) {
30bbda
-					int i;
30bbda
-
30bbda
-					for (i=0; i
30bbda
-						if (statbuf.st_rdev == watchdogs[i]) {
30bbda
-							int wdfd = watchdog_init_fd(entry_name, -1);
30bbda
-							struct watchdog_list_item *wdg =
30bbda
-								calloc(1, sizeof(struct watchdog_list_item));
30bbda
-							int len;
30bbda
-							struct link_list_item *tmp_list = NULL;
30bbda
-
30bbda
-							wdg->dev = watchdogs[i];
30bbda
-							wdg->dev_node = strdup(entry_name);
30bbda
-							wdg->next = watchdog_list;
30bbda
-							watchdog_list = wdg;
30bbda
-							watchdog_list_items++;
30bbda
-
30bbda
-							if (wdfd >= 0) {
30bbda
-								struct watchdog_info ident;
30bbda
-
30bbda
-								ident.identity[0] = '\0';
30bbda
-								ioctl(wdfd, WDIOC_GETSUPPORT, &ident);
30bbda
-								watchdog_close_fd(wdfd, entry_name, true);
30bbda
-								if (ident.identity[0]) {
30bbda
-									wdg->dev_ident = strdup((char *) ident.identity);
30bbda
-								}
30bbda
-							}
30bbda
-
30bbda
-							snprintf(entry_name, sizeof(entry_name),
30bbda
-							         SYS_CHAR_DEV_DIR "/%d:%d/device/driver",
30bbda
-							         major(watchdogs[i]), minor(watchdogs[i]));
30bbda
-							len = readlink(entry_name, buf, sizeof(buf) - 1);
30bbda
-							if (len > 0) {
30bbda
-								buf[len] = '\0';
30bbda
-								wdg->dev_driver = strdup(basename(buf));
30bbda
-							} else if ((wdg->dev_ident) &&
30bbda
-							           (strcmp(wdg->dev_ident,
30bbda
-							                   "Software Watchdog") == 0)) {
30bbda
-								wdg->dev_driver = strdup("softdog");
30bbda
-							}
30bbda
-
30bbda
-							/* create dupes if we have memorized links
30bbda
-							 * to this node
30bbda
-							 */
30bbda
-							for (tmp_list = link_list; tmp_list;
30bbda
-							     tmp_list = tmp_list->next) {
30bbda
-								if (!strcmp(tmp_list->dev_node,
30bbda
-								            wdg->dev_node)) {
30bbda
-									struct watchdog_list_item *dupe_wdg =
30bbda
-										calloc(1, sizeof(struct watchdog_list_item));
30bbda
-
30bbda
-									/* as long as we never purge watchdog_list
30bbda
-									 * there is no need to dupe strings
30bbda
-									 */
30bbda
-									*dupe_wdg = *wdg;
30bbda
-									dupe_wdg->dev_node = strdup(tmp_list->link_name);
30bbda
-									dupe_wdg->next = watchdog_list;
30bbda
-									watchdog_list = dupe_wdg;
30bbda
-									watchdog_list_items++;
30bbda
-								}
30bbda
-								/* for performance reasons we could remove
30bbda
-								 * the link_list entry
30bbda
-								 */
30bbda
-							}
30bbda
-							break;
30bbda
-						}
30bbda
-					}
30bbda
-				}
30bbda
-			}
30bbda
-		}
30bbda
+        rewinddir(dp);
30bbda
+
30bbda
+        while ((entry = readdir(dp))) {
30bbda
+            if (entry->d_type == DT_CHR) {
30bbda
+                struct stat statbuf;
30bbda
+
30bbda
+                snprintf(entry_name, sizeof(entry_name),
30bbda
+                            WATCHDOG_NODEDIR "%s", entry->d_name);
30bbda
+                if(!stat(entry_name, &statbuf) && S_ISCHR(statbuf.st_mode) &&
30bbda
+                   is_watchdog(statbuf.st_rdev)) {
30bbda
+
30bbda
+                    int wdfd = watchdog_init_fd(entry_name, -1);
30bbda
+                    struct watchdog_list_item *wdg =
30bbda
+                        calloc(1, sizeof(struct watchdog_list_item));
30bbda
+                    int len;
30bbda
+                    struct link_list_item *tmp_list = NULL;
30bbda
+
30bbda
+                    wdg->dev = statbuf.st_rdev;
30bbda
+                    wdg->dev_node = strdup(entry_name);
30bbda
+                    wdg->next = watchdog_list;
30bbda
+                    watchdog_list = wdg;
30bbda
+                    watchdog_list_items++;
30bbda
+
30bbda
+                    if (wdfd >= 0) {
30bbda
+                        struct watchdog_info ident;
30bbda
+
30bbda
+                        ident.identity[0] = '\0';
30bbda
+                        ioctl(wdfd, WDIOC_GETSUPPORT, &ident);
30bbda
+                        watchdog_close_fd(wdfd, entry_name, true);
30bbda
+                        if (ident.identity[0]) {
30bbda
+                            wdg->dev_ident = strdup((char *) ident.identity);
30bbda
+                        }
30bbda
+                    }
30bbda
+
30bbda
+                    snprintf(entry_name, sizeof(entry_name),
30bbda
+                                SYS_CHAR_DEV_DIR "/%d:%d/device/driver",
30bbda
+                                major(wdg->dev), minor(wdg->dev));
30bbda
+                    len = readlink(entry_name, buf, sizeof(buf) - 1);
30bbda
+                    if (len > 0) {
30bbda
+                        buf[len] = '\0';
30bbda
+                        wdg->dev_driver = strdup(basename(buf));
30bbda
+                    } else if ((wdg->dev_ident) &&
30bbda
+                               (strcmp(wdg->dev_ident,
30bbda
+                                       "Software Watchdog") == 0)) {
30bbda
+                        wdg->dev_driver = strdup("softdog");
30bbda
+                    }
30bbda
+
30bbda
+                    /* create dupes if we have memorized links
30bbda
+                     * to this node
30bbda
+                     */
30bbda
+                    for (tmp_list = link_list; tmp_list;
30bbda
+                            tmp_list = tmp_list->next) {
30bbda
+                        if (!strcmp(tmp_list->dev_node,
30bbda
+                                    wdg->dev_node)) {
30bbda
+                            struct watchdog_list_item *dupe_wdg =
30bbda
+                                calloc(1, sizeof(struct watchdog_list_item));
30bbda
+
30bbda
+                            /* as long as we never purge watchdog_list
30bbda
+                             * there is no need to dupe strings
30bbda
+                             */
30bbda
+                            *dupe_wdg = *wdg;
30bbda
+                            dupe_wdg->dev_node = strdup(tmp_list->link_name);
30bbda
+                            dupe_wdg->next = watchdog_list;
30bbda
+                            watchdog_list = dupe_wdg;
30bbda
+                            watchdog_list_items++;
30bbda
+                        }
30bbda
+                        /* for performance reasons we could remove
30bbda
+                         * the link_list entry
30bbda
+                         */
30bbda
+                    }
30bbda
+                }
30bbda
+            }
30bbda
+        }
30bbda
 
30bbda
-		closedir(dp);
30bbda
-	}
30bbda
+        closedir(dp);
30bbda
+    }
30bbda
 
30bbda
-	/* cleanup link list */
30bbda
-	while (link_list) {
30bbda
-		struct link_list_item *tmp_list = link_list;
30bbda
+    /* cleanup link list */
30bbda
+    while (link_list) {
30bbda
+        struct link_list_item *tmp_list = link_list;
30bbda
 
30bbda
-		link_list = link_list->next;
30bbda
-		free(tmp_list->dev_node);
30bbda
-		free(tmp_list->link_name);
30bbda
-		free(tmp_list);
30bbda
-	}
30bbda
+        link_list = link_list->next;
30bbda
+        free(tmp_list->dev_node);
30bbda
+        free(tmp_list->link_name);
30bbda
+        free(tmp_list);
30bbda
+    }
30bbda
+}
30bbda
+
30bbda
+static void
30bbda
+watchdog_checkbusy()
30bbda
+{
30bbda
+    DIR *dproc;
30bbda
+    struct dirent *entry;
30bbda
+
30bbda
+    dproc = opendir("/proc");
30bbda
+    if (!dproc) {
30bbda
+        /* no proc directory to search through */
30bbda
+        return;
30bbda
+    }
30bbda
+
30bbda
+    while ((entry = readdir(dproc)) != NULL) {
30bbda
+        pid_t local_pid;
30bbda
+        char *leftover;
30bbda
+        DIR *dpid;
30bbda
+        char procpath[NAME_MAX+10] = { 0 };
30bbda
+
30bbda
+        if (entry->d_name[0] == '.') {
30bbda
+            continue;
30bbda
+        }
30bbda
+
30bbda
+        local_pid = strtol(entry->d_name, &leftover, 10);
30bbda
+        if (leftover[0] != '\0')
30bbda
+            continue;
30bbda
+
30bbda
+        snprintf(procpath, sizeof(procpath), "/proc/%s/fd", entry->d_name);
30bbda
+        dpid = opendir(procpath);
30bbda
+        if (!dpid) {
30bbda
+            /* silently continue - might be just a race */
30bbda
+            continue;
30bbda
+        }
30bbda
+        while ((entry = readdir(dpid)) != NULL) {
30bbda
+            struct watchdog_list_item *wdg;
30bbda
+            char entry_name[sizeof(procpath)+NAME_MAX+1] = { 0 };
30bbda
+            char buf[NAME_MAX+1] = { 0 };
30bbda
+            int len;
30bbda
+
30bbda
+            if (entry->d_type != DT_LNK) {
30bbda
+                continue;
30bbda
+            }
30bbda
+            snprintf(entry_name, sizeof(entry_name),
30bbda
+                     "%s/%s", procpath, entry->d_name);
30bbda
+            len = readlink(entry_name, buf, sizeof(buf) - 1);
30bbda
+            if (len < 1) {
30bbda
+                continue;
30bbda
+            }
30bbda
+            buf[len] = '\0';
30bbda
+            for (wdg = watchdog_list; wdg != NULL; wdg = wdg->next) {
30bbda
+                if (!strcmp(buf, wdg->dev_node)) {
30bbda
+                    char name[16];
30bbda
+                    FILE *file;
30bbda
+
30bbda
+                    wdg->busy_pid = local_pid;
30bbda
+                    snprintf(procpath, sizeof(procpath), "/proc/%d/status", local_pid);
30bbda
+                    file = fopen(procpath, "r");
30bbda
+                    if (file) {
30bbda
+                        if (fscanf(file, "Name:\t%15[a-zA-Z0-9 _-]", name) == 1) {
30bbda
+                            wdg->busy_name = strdup(name);
30bbda
+                        }
30bbda
+                        fclose(file);
30bbda
+                    }
30bbda
+                }
30bbda
+            }
30bbda
+        }
30bbda
+        closedir(dpid);
30bbda
+    }
30bbda
+
30bbda
+    closedir(dproc);
30bbda
+
30bbda
+    return;
30bbda
 }
30bbda
 
30bbda
 int watchdog_info(void)
30bbda
@@ -462,13 +560,23 @@ int watchdog_info(void)
30bbda
 	int wdg_cnt = 0;
30bbda
 
30bbda
 	watchdog_populate_list();
30bbda
+	watchdog_checkbusy();
30bbda
 	printf("\nDiscovered %d watchdog devices:\n", watchdog_list_items);
30bbda
 	for (wdg = watchdog_list; wdg != NULL; wdg = wdg->next) {
30bbda
 		wdg_cnt++;
30bbda
-		printf("\n[%d] %s\nIdentity: %s\nDriver: %s\n",
30bbda
+		if (wdg->busy_pid) {
30bbda
+			printf("\n[%d] %s\nIdentity: Busy: PID %d (%s)\nDriver: %s\n",
30bbda
 				wdg_cnt, wdg->dev_node,
30bbda
-				wdg->dev_ident?wdg->dev_ident:"Error: Check if hogged by e.g. sbd-daemon!",
30bbda
+				wdg->busy_pid,
30bbda
+				wdg->busy_name?wdg->busy_name:"<unknown>",
30bbda
 				wdg->dev_driver?wdg->dev_driver:"<unknown>");
30bbda
+		} else {
30bbda
+			printf("\n[%d] %s\nIdentity: %s\nDriver: %s\n",
30bbda
+				wdg_cnt, wdg->dev_node,
30bbda
+				wdg->dev_ident?wdg->dev_ident:
30bbda
+					"Error: device hogged via alias major/minor?",
30bbda
+				wdg->dev_driver?wdg->dev_driver:"<unknown>");
30bbda
+		}
30bbda
 		if ((wdg->dev_driver) && (strcmp(wdg->dev_driver, "softdog") == 0)) {
30bbda
 			printf("CAUTION: Not recommended for use with sbd.\n"); 
30bbda
 		}
30bbda
@@ -512,6 +620,7 @@ int watchdog_test(void)
30bbda
 		watchdogdev, (int) timeout_watchdog);
30bbda
 	if ((watchdog_init() < 0) || (watchdog_init_interval() < 0)) {
30bbda
 		printf("Failed to initialize watchdog!!!\n");
30bbda
+		watchdog_info();
30bbda
 		return -1;
30bbda
 	}
30bbda
 	printf("\n");
30bbda
-- 
30bbda
1.8.3.1
30bbda