mount.gfs2: Fix error handlers
PATCH 1/1 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 <[email protected]>
--- 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(-)
gfs2/mount/mount.gfs2.c +23 -10
@@ -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\"\n" , 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\"\n" , 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\"\n" , mo->type); -if (stat (mo->dir, &buf) <0 ) -die ("mount point %s does not exist\n" , 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\n" , 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\n" , 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\n" ); -die ("error mounting %s on %s: %s\n" , mo.dev, mo.dir, -strerror (errno)); + +perror (mo.dev); +exit (EXIT_FAILURE ); }log_debug ("mount(2) ok" );mount_done_lockproto (proto, &mo, &sb,0 );
gfs2/mount/mtab.c +17 -17
@@ -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\n" , 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\n" , 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\n" ); +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; }
gfs2/mount/util.c +33 -35
202 lines not on this page · raw message
gfs2/mount/util.h +3 -0
@@ -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); \
Signature · 1 line
1.7.6.2
PATCH 1/1 mount.gfs2: Fix error handlers
Quoted 4 lines · Carlos Maiolino
This patch removes some calls to
die(), replacing them withperror(), and also removes some calls towarn().
In both cases, the replacement code aimed to better deal with i18n stuff.
mount.gfs2 is deprecated, please disconsider this patch
Signature · 1 line
--Carlos