FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Redhat > Cluster Development

 
 
LinkBack Thread Tools
 
Old 10-25-2011, 01:35 PM
Carlos Maiolino
 
Default mount.gfs2: Fix error handlers

On Tue, Oct 25, 2011 at 02:22:52PM -0200, Carlos Maiolino wrote:
> This patch removes some calls to die(), replacing them with perror(),
> and also removes some calls to warn().
> In both cases, the replacement code aimed to better deal with i18n stuff.
>
mount.gfs2 is deprecated, please disconsider this patch

--
--Carlos
 
Old 10-25-2011, 04:22 PM
Carlos Maiolino
 
Default mount.gfs2: Fix error handlers

This patch removes some calls to die(), replacing them with perror(),
and also removes some calls to warn().
In both cases, the replacement code aimed to better deal with i18n stuff.

Signed-off-by: Carlos Maiolino <cmaiolino@redhat.com>
---
gfs2/mount/mount.gfs2.c | 33 ++++++++++++++++-------
gfs2/mount/mtab.c | 34 +++++++++++-----------
gfs2/mount/util.c | 68 ++++++++++++++++++++++------------------------
gfs2/mount/util.h | 3 ++
4 files changed, 76 insertions(+), 62 deletions(-)

diff --git a/gfs2/mount/mount.gfs2.c b/gfs2/mount/mount.gfs2.c
index ed9408b..799056e 100644
--- a/gfs2/mount/mount.gfs2.c
+++ b/gfs2/mount/mount.gfs2.c
@@ -1,7 +1,10 @@
#include "clusterautoconfig.h"
+#include <libintl.h>

#include "util.h"

+#define _(String) gettext(String)
+
const char *fsname;
int verbose, fake_mount = 0, no_mtab = 0;
static sigset_t old_sigset;
@@ -85,8 +88,10 @@ static void read_options(int argc, char **argv, struct mount_options *mo)

if (optind < argc && argv[optind]) {
real = realpath(argv[optind], NULL);
- if (!real)
- die("invalid device path "%s"
", argv[optind]);
+ if (!real){
+ perror(argv[optind]);
+ exit(EXIT_FAILURE);
+ }
strncpy(mo->dev, real, PATH_MAX);
strncpy(mo->specified_dev, argv[optind], PATH_MAX);
free(real);
@@ -96,8 +101,10 @@ static void read_options(int argc, char **argv, struct mount_options *mo)

if (optind < argc && argv[optind]) {
real = realpath(argv[optind], NULL);
- if (!real)
- die("invalid mount point path "%s"
", argv[optind]);
+ if (!real){
+ perror(argv[optind]);
+ exit(EXIT_FAILURE);
+ }
strncpy(mo->dir, real, PATH_MAX);
free(real);
}
@@ -118,8 +125,10 @@ static void check_options(struct mount_options *mo)
if (strlen(mo->type) && strcmp(mo->type, fsname))
die("unknown file system type "%s"
", mo->type);

- if (stat(mo->dir, &buf) < 0)
- die("mount point %s does not exist
", mo->dir);
+ if (stat(mo->dir, &buf) < 0){
+ perror(mo->dir);
+ exit(EXIT_FAILURE);
+ }

if (!S_ISDIR(buf.st_mode))
die("mount point %s is not a directory
", mo->dir);
@@ -211,12 +220,16 @@ int main(int argc, char **argv)
if (!(mo.flags & MS_REMOUNT))
umount_lockproto(proto, &mo, &sb, errno);

- if (errno == EBUSY)
- die("%s already mounted or %s busy
", mo.dev, mo.dir);
+ if (errno == EBUSY){
+ perror(mo.dev);
+ exit(EXIT_FAILURE);
+ }
+
else if (errno == EUSERS)
die("Too many nodes mounting filesystem, no free journals
");
- die("error mounting %s on %s: %s
", mo.dev, mo.dir,
- strerror(errno));
+
+ perror(mo.dev);
+ exit(EXIT_FAILURE);
}
log_debug("mount(2) ok");
mount_done_lockproto(proto, &mo, &sb, 0);
diff --git a/gfs2/mount/mtab.c b/gfs2/mount/mtab.c
index fbe5f63..d1c0f4a 100644
--- a/gfs2/mount/mtab.c
+++ b/gfs2/mount/mtab.c
@@ -1,7 +1,9 @@
#include "clusterautoconfig.h"
+#include <libintl.h>

#include "util.h"

+
extern char *fsname;
extern int verbose;
static int ignoring_mtab;
@@ -54,8 +56,10 @@ static void lock_mtab(void)
retry:
fd = open(fname, O_WRONLY|O_CREAT, 0);
e = errno;
- if (fd < 0)
- die("can't create mtab lock file %s: %s
", fname, strerror(e));
+ if (fd < 0){
+ perror(fname);
+ exit(EXIT_FAILURE);
+ }
close(fd);

rv = link(fname, "/etc/mtab~");
@@ -63,13 +67,14 @@ static void lock_mtab(void)

unlink(fname);

- if (rv < 0 && e != EEXIST)
- die("can't link %s to /etc/mtab~: %s
", fname, strerror(e));
+ if (rv < 0 && e != EEXIST){
+ perror(fname);
+ exit(EXIT_FAILURE);
+ }

if (rv < 0) {
if (++retries > 5)
- warn("waiting to lock /etc/mtab~: try unlinking "
- "stale /etc/mtab~ file
");
+ warn("waiting to lock /etc/mtab~: try unlinking stale /etc/mtab~ file");
sleep(1);
goto retry;
}
@@ -159,8 +164,8 @@ void del_mtab_entry(struct mount_options *mo)
the next version of mtab */

if (fprintf(mtmp, "%s", line) < 0) {
- int e = errno;
- warn("error writing to /etc/mtab.tmp: %s", strerror(e));
+ perror("/etc/mtab.tmp");
+ exit(EXIT_FAILURE);
}
}

@@ -170,26 +175,21 @@ void del_mtab_entry(struct mount_options *mo)
}

if (fchmod(fileno(mtmp), S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH) < 0) {
- int e = errno;
- warn("error changing mode of /etc/mtab.tmp: %s", strerror(e));
+ perror("chmod in /etc/mtab.tmp");
}

if (stat("/etc/mtab", &sbuf) < 0) {
- int e = errno;
- warn("error stating /etc/mtab: %s", strerror(e));
+ perror("stating /etc/mtab");
} else
if(chown("/etc/mtab.tmp", sbuf.st_uid, sbuf.st_gid) < 0) {
- int e = errno;
- warn("error changing owner of /etc/mtab.tmp: %s", strerror(e));
+ perror("chown /etc/mtab.tmp");
}

fclose(mtmp);
fclose(mtab);

if (rename("/etc/mtab.tmp", "/etc/mtab") < 0) {
- int e = errno;
- warn("can't rename /etc/mtab.tmp to /etc/mtab: %s",
- strerror(e));
+ perror("renaming /etc/mtab.tmp");
goto fail_unlink;
}

diff --git a/gfs2/mount/util.c b/gfs2/mount/util.c
index 33ba90f..bf55aad 100644
--- a/gfs2/mount/util.c
+++ b/gfs2/mount/util.c
@@ -2,9 +2,12 @@

#include <endian.h>
#include <byteswap.h>
+#include <libintl.h>
#include "util.h"
#include "libgfscontrol.h"

+#define _(String) gettext(String)
+
#if __BYTE_ORDER == __BIG_ENDIAN

#define be16_to_cpu(x) (x)
@@ -153,7 +156,7 @@ void parse_opts(struct mount_options *mo)
}

if (extra_len + 1 + strlen(o) > PATH_MAX)
- die("extra options string is too long
");
+ die(_("extra options string is too long
"));

if (mo->extra[0]) {
strcat(mo->extra, ",");
@@ -174,13 +177,13 @@ void parse_opts(struct mount_options *mo)

if (!strcmp(o, "lockproto")) {
if (!v)
- die("option lockproto needs value
");
+ die(_("option lockproto needs value
"));
strncpy(mo->lockproto, v, 255);
}

if (!strcmp(o, "locktable")) {
if (!v)
- die("option locktable needs value
");
+ die(_("option locktable needs value
"));
strncpy(mo->locktable, v, 255);
}
}
@@ -266,13 +269,14 @@ void read_proc_mounts(struct mount_options *mo)
struct stat st_mo_dev, st_mounts_dev;

file = fopen("/proc/mounts", "r");
- if (!file)
- die("can't open /proc/mounts: %s
", strerror(errno));
-
+ if (!file){
+ perror("/proc/mounts");
+ exit(EXIT_FAILURE);
+ }
memset(&st_mo_dev, 0, sizeof(struct stat));
if (mo->dev[0]) {
if (stat(mo->dev, &st_mo_dev))
- warn("Can't stat device %s.
", mo->dev);
+ perror(mo->dev);
}

while (fgets(line, PATH_MAX, file)) {
@@ -295,7 +299,7 @@ void read_proc_mounts(struct mount_options *mo)
continue;
}
if (strcmp(type, fsname))
- die("%s is not a %s filesystem
", mo->dir, fsname);
+ die(_("%s is not a %s filesystem
"), mo->dir, fsname);

/* when there is an input dev specified (mount), we should get
only one matching line; when there is no input dev specified
@@ -310,7 +314,7 @@ void read_proc_mounts(struct mount_options *mo)
fclose(file);

if (!found)
- die("can't find /proc/mounts entry for directory %s
", mo->dir);
+ die(_("can't find /proc/mounts entry for directory %s
"), mo->dir);
else {
strncpy(mo->dev, save_device, PATH_MAX);
strncpy(mo->opts, save_opts, PATH_MAX);
@@ -362,8 +366,10 @@ int get_sb(char *device, struct gen_sb *sb_out)
int fd;

fd = open(device, O_RDONLY);
- if (fd < 0)
- die("can't open %s: %s
", device, strerror(errno));
+ if (fd < 0){
+ perror(device);
+ exit(EXIT_FAILURE);
+ }

if (!strcmp(fsname, "gfs2")) {
char buf[GFS2_BASIC_BLOCK];
@@ -371,25 +377,21 @@ int get_sb(char *device, struct gen_sb *sb_out)

if (lseek(fd, GFS2_SB_ADDR * GFS2_BASIC_BLOCK, SEEK_SET) !=
GFS2_SB_ADDR * GFS2_BASIC_BLOCK) {
- fprintf(stderr, "bad seek: %s from %s:%d: "
- "superblock
",
- strerror(errno), __FUNCTION__, __LINE__);
- exit(-1);
+ perror(__FUNCTION__);
+ exit(EXIT_FAILURE);
}
do_read(fd, buf, GFS2_BASIC_BLOCK);
gfs2_sb_in(&sb, buf);

if (sb.sb_header.mh_magic != GFS2_MAGIC ||
sb.sb_header.mh_type != GFS2_METATYPE_SB) {
- die("there isn't a GFS2 filesystem on %s, "
- "magic=%x type=%x
", device,
+ die(_("there isn't a GFS2 filesystem on %s, magic=%x type=%x
"), device,
sb.sb_header.mh_magic, sb.sb_header.mh_type);
}

if (sb.sb_fs_format != GFS2_FORMAT_FS ||
sb.sb_multihost_format != GFS2_FORMAT_MULTI) {
- die("there appears to be a GFS, not GFS2, filesystem "
- "on %s
", device);
+ die(_("there appears to be a GFS, not GFS2, filesystem on %s
"), device);
}

strncpy(sb_out->lockproto, sb.sb_lockproto, 256);
@@ -401,23 +403,20 @@ int get_sb(char *device, struct gen_sb *sb_out)

if (lseek(fd, GFS_SB_ADDR * GFS_BASIC_BLOCK, SEEK_SET) !=
GFS_SB_ADDR * GFS_BASIC_BLOCK) {
- fprintf(stderr, "bad seek: %s from %s:%d: "
- "superblock
",
- strerror(errno), __FUNCTION__, __LINE__);
- exit(-1);
+ perror(__FUNCTION__);
+ exit(EXIT_FAILURE);
}
do_read(fd, buf, GFS2_BASIC_BLOCK);
gfs_sb_in(&sb, buf);

if (sb.sb_header.mh_magic != GFS_MAGIC ||
sb.sb_header.mh_type != GFS_METATYPE_SB) {
- die("there isn't a GFS filesystem on %s
", device);
+ die(_("there isn't a GFS filesystem on %s
"), device);
}

if (sb.sb_fs_format != GFS_FORMAT_FS ||
sb.sb_multihost_format != GFS_FORMAT_MULTI) {
- die("there appears to be a GFS2, not GFS, filesystem "
- "on %s
", device);
+ die(_("there appears to be a GFS2, not GFS, filesystem on %s
"), device);
}

strncpy(sb_out->lockproto, sb.sb_lockproto, 256);
@@ -458,7 +457,7 @@ int lock_dlm_join(struct mount_options *mo, struct gen_sb *sb)

fd = gfsc_fs_connect();
if (fd < 0) {
- warn("gfs_controld join connect error: %s", strerror(errno));
+ perror(_("gfs_controld join connect error"));
return fd;
}

@@ -466,7 +465,7 @@ int lock_dlm_join(struct mount_options *mo, struct gen_sb *sb)

rv = gfsc_fs_join(fd, &ma);
if (rv < 0) {
- warn("gfs_controld join write error: %s", strerror(errno));
+ perror(_("gfs_controld join write error"));
goto fail;
}

@@ -474,7 +473,7 @@ int lock_dlm_join(struct mount_options *mo, struct gen_sb *sb)

rv = gfsc_fs_result(fd, &result, &ma);
if (rv < 0) {
- warn("gfs_controld result read error: %s", strerror(errno));
+ perror(_("gfs_controld result read error"));
goto fail;
}

@@ -611,8 +610,7 @@ void lock_dlm_mount_done(struct mount_options *mo, struct gen_sb *sb,

rv = gfsc_fs_mount_done(gfs_controld_fd, &ma, result);
if (rv)
- warn("gfs_controld mount_done write error: %s", strerror(errno));
-
+ perror(_("gfs_controld mount_done write error"));
gfsc_fs_disconnect(gfs_controld_fd);
}

@@ -632,7 +630,7 @@ int lock_dlm_leave(struct mount_options *mo, struct gen_sb *sb, int mnterr)

rv = gfsc_fs_leave(&ma, mnterr);
if (rv)
- warn("leave: gfs_controld leave error: %s", strerror(errno));
+ perror(_("leave: gfs_controld leave error"));

return rv;
}
@@ -666,7 +664,7 @@ int lock_dlm_remount(struct mount_options *mo, struct gen_sb *sb)

fd = gfsc_fs_connect();
if (fd < 0) {
- warn("gfs_controld remount connect error: %s", strerror(errno));
+ perror(_("gfs_controld remount connect error"));
return fd;
}

@@ -674,7 +672,7 @@ int lock_dlm_remount(struct mount_options *mo, struct gen_sb *sb)

rv = gfsc_fs_remount(fd, &ma);
if (rv) {
- warn("gfs_controld remount write error: %s", strerror(errno));
+ perror(_("gfs_controld remount write error"));
goto out;
}

@@ -682,7 +680,7 @@ int lock_dlm_remount(struct mount_options *mo, struct gen_sb *sb)

rv = gfsc_fs_result(fd, &result, &ma);
if (rv < 0) {
- warn("gfs_controld result read error: %s", strerror(errno));
+ perror(_("gfs_controld result read error"));
goto out;
}

diff --git a/gfs2/mount/util.h b/gfs2/mount/util.h
index e866cd4..9a1413e 100644
--- a/gfs2/mount/util.h
+++ b/gfs2/mount/util.h
@@ -19,8 +19,11 @@
#include <sys/un.h>
#include <linux/types.h>
#include <linux/gfs2_ondisk.h>
+#include <libintl.h>
#include "gfs_ondisk.h"

+#define _(String) gettext(String)
+
#define die(fmt, args...)
do {
fprintf(stderr, fmt, ##args);
--
1.7.6.2
 

Thread Tools




All times are GMT. The time now is 10:08 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org