public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
From: Andrew Price <andyp@fedoraproject.org>
To: cluster-cvs-relay@redhat.com
Subject: gfs2-utils: master - libgfs2: Clean up mp2fsname2
Date: Fri, 20 Mar 2009 11:50:00 -0000	[thread overview]
Message-ID: <20090320114930.5522B1202D3@lists.fedorahosted.org> (raw)

Gitweb:        http://git.fedorahosted.org/git/gfs2-utils.git?p=gfs2-utils.git;a=commitdiff;h=7e0eb7013b43289473e4dc7c934d1ea8aa6fac5b
Commit:        7e0eb7013b43289473e4dc7c934d1ea8aa6fac5b
Parent:        f4a9ca2a74fae23456293dd2577526513b014215
Author:        Andrew Price <andy@andrewprice.me.uk>
AuthorDate:    Fri Mar 20 00:05:34 2009 +0000
Committer:     Andrew Price <andy@andrewprice.me.uk>
CommitterDate: Fri Mar 20 11:48:43 2009 +0000

libgfs2: Clean up mp2fsname2

This patch removes the calls to 'die' and 'exit' from mp2fsname2 and
cleans up the function a bit. Namely, it removes an unused variable
(sb), adds error checking and fixes a typo.

Signed-off-by: Andrew Price <andy@andrewprice.me.uk>
---
 gfs2/libgfs2/libgfs2.h |    2 +-
 gfs2/libgfs2/misc.c    |   21 ++++++++++++---------
 gfs2/tool/misc.c       |    5 +++++
 3 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/gfs2/libgfs2/libgfs2.h b/gfs2/libgfs2/libgfs2.h
index d8faf45..1742da9 100644
--- a/gfs2/libgfs2/libgfs2.h
+++ b/gfs2/libgfs2/libgfs2.h
@@ -632,7 +632,7 @@ extern int mount_gfs2_meta(struct gfs2_sbd *sdp);
 extern void cleanup_metafs(struct gfs2_sbd *sdp);
 extern char *find_debugfs_mount(void);
 extern char *mp2fsname(char *mp);
-extern char *mp2fsname2(char *devname);
+extern char *mp2fsname2(char *mp);
 extern char *get_sysfs(char *fsname, char *filename);
 extern int get_sysfs_uint(char *fsname, char *filename, unsigned int *val);
 extern int set_sysfs(char *fsname, char *filename, char *val);
diff --git a/gfs2/libgfs2/misc.c b/gfs2/libgfs2/misc.c
index 60b2d4f..7666ded 100644
--- a/gfs2/libgfs2/misc.c
+++ b/gfs2/libgfs2/misc.c
@@ -314,7 +314,7 @@ char *find_debugfs_mount(void)
 /*
  * Same as mp2fsname, except that this function doesn't stat() the mountpoint
  * to get the device no. Used by gfs2_tool freeze/unfreeze where we don't want
- * to touch the potetially frozen filesytem and hang gfs2_tool itself.
+ * to touch the potentially frozen filesytem and hang gfs2_tool itself.
  */
 char *
 mp2fsname2(char *mp)
@@ -323,8 +323,7 @@ mp2fsname2(char *mp)
 	struct stat statbuf;
 	DIR *d;
 	struct dirent *de;
-	struct gfs2_sbd sb;
-	FILE *fp = fopen("/proc/mounts", "r");
+	FILE *fp;
 	char buffer[PATH_MAX], device_name[PATH_MAX];
 	int fsdump, fspass, ret, found = 0;
 	char fspath[PATH_MAX], fsoptions[PATH_MAX], fstype[80];
@@ -334,9 +333,9 @@ mp2fsname2(char *mp)
 	if (mp[strlen(mp) - 1] == '/')
 		mp[strlen(mp) - 1] = 0;
 
+	fp = fopen("/proc/mounts", "r");
 	if (fp == NULL) {
-		perror("open: /proc/mounts");
-		exit(EXIT_FAILURE);
+		return NULL;
 	}
 
 	while ((fgets(buffer, PATH_MAX - 1, fp)) != NULL) {
@@ -358,9 +357,12 @@ mp2fsname2(char *mp)
 		found = 1;
 		break;
 	}
+	fclose(fp);
 
-	if (!found)
-		die("can't find gfs2 filesystem mounted at %s\n", mp);
+	if (!found) {
+		errno = ENOENT;
+		return NULL;
+	}
 
 	if (stat(device_name, &statbuf))
 		return NULL;
@@ -371,7 +373,7 @@ mp2fsname2(char *mp)
 
 	d = opendir(SYS_BASE);
 	if (!d)
-		die("can't open %s: %s\n", SYS_BASE, strerror(errno));
+		return NULL;
 
 	while ((de = readdir(d))) {
 		if (de->d_name[0] == '.')
@@ -386,9 +388,10 @@ mp2fsname2(char *mp)
 		}
 	}
 
-	fclose(fp);
 	closedir(d);
 
+	if (!fsname)
+		errno = ENOENT;
 	return fsname;
 }
 
diff --git a/gfs2/tool/misc.c b/gfs2/tool/misc.c
index 6b054c6..694acb8 100644
--- a/gfs2/tool/misc.c
+++ b/gfs2/tool/misc.c
@@ -40,6 +40,11 @@ do_freeze(int argc, char **argv)
 		die("Usage: gfs2_tool %s <mountpoint>\n", command);
 
 	name = mp2fsname2(argv[optind]);
+	if (!name) {
+		fprintf(stderr, "Couldn't find a GFS2 filesystem mounted at %s\n",
+				argv[optind]);
+		exit(-1);
+	}
 
 	if (strcmp(command, "freeze") == 0) {
 		if (set_sysfs(name, "freeze", "1")) {


                 reply	other threads:[~2009-03-20 11:50 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090320114930.5522B1202D3@lists.fedorahosted.org \
    --to=andyp@fedoraproject.org \
    --cc=cluster-cvs-relay@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).