libgfs2: Remove 'die' from mp2fsname and find_debugfs_mount
PATCH 1/1 libgfs2: Remove 'die' from mp2fsname and find_debugfs_mount
Removes the call to 'die' from mp2fsname and updates its callers to handle the error. Also removes the die calls from find_debugfs_mount which only has one caller that already handles the error cases.
Signed-off-by Andrew Price <[email protected]>
--- gfs2/libgfs2/misc.c | 10 ++++++---- gfs2/quota/check.c | 8 +++++++- gfs2/quota/main.c | 10 ++++++++++ gfs2/tool/df.c | 5 +++++ gfs2/tool/misc.c | 15 +++++++++++++++ gfs2/tool/tune.c | 10 ++++++++++ 6 files changed, 53 insertions(+), 5 deletions(-)
gfs2/libgfs2/misc.c +6 -4
@@ -291,11 +291,13 @@ char *find_debugfs_mount(void) file =fopen ("/proc/mounts" ,"rt" );if (!file) -die ("can't open /proc/mounts: %s\n" ,strerror (errno)); +return NULL ; path =malloc (PATH_MAX ); -if (!path) -die ("Can't allocate memory for debugfs.\n" ); +if (!path) { +fclose (file); +return NULL ; + }while (fgets (line,PATH_MAX , file)) {if (sscanf (line,"%s %s %s" , device, path, type) !=3 )
@@ -432,7 +434,7 @@ char *mp2fsname(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 ] =='.' )
gfs2/quota/check.c +7 -1
@@ -507,8 +507,14 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user, goto out; } -/* Write the id to sysfs quota refresh file to refresh gfs quotas */ fs =mp2fsname (comline->filesystem); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + comline->filesystem); +exit (-1 ); + } + +/* Write the id to sysfs quota refresh file to refresh gfs quotas */ sprintf (id_str,"%d" , comline->id);if (set_sysfs (fs, (user) ?"quota_refresh_user" :"quota_refresh_group" , id_str)) {
gfs2/quota/main.c +10 -0
@@ -783,6 +783,11 @@ do_sync_one(struct gfs2_sbd *sdp, char *filesystem)char *fsname; fsname =mp2fsname (filesystem); +if (!fsname) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + filesystem); +exit (-1 ); + }if (set_sysfs (fsname,"quota_sync" ,"1" )) {fprintf (stderr,"Error writing to sysfs quota sync file: %s\n" ,strerror (errno));
@@ -992,6 +997,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline) } fs =mp2fsname (comline->filesystem); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + comline->filesystem); +exit (-1 ); + }sprintf (id_str,"%d" , comline->id);if (set_sysfs (fs, comline->id_type ==GQ_ID_USER ?"quota_refresh_user" :"quota_refresh_group" , id_str)) {
gfs2/tool/df.c +5 -0
@@ -95,6 +95,11 @@ do_df_one(char *path)exit (-1 ); } fs =mp2fsname (sbd.path_name); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + sbd.path_name); +exit (-1 ); + } sbd.device_fd =open (sbd.device_name,O_RDONLY );if (sbd.device_fd <0 )
gfs2/tool/misc.c +15 -0
@@ -272,6 +272,11 @@ print_args(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }memset (path,0 ,PATH_MAX );snprintf (path,PATH_MAX -1 ,"%s/%s/args/" ,SYS_BASE , fs);
@@ -457,6 +462,11 @@ do_shrink(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }if (set_sysfs (fs,"shrink" ,"1" )) { fprintf(stderr, "Error writing to sysfs shrink file: %s\n",
@@ -491,6 +501,11 @@ do_withdraw(int argc, char **argv)exit (-1 ); } name =mp2fsname (argv[optind]); +if (!name) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }if (set_sysfs (name,"withdraw" ,"1" )) { fprintf(stderr, "Error writing to sysfs withdraw file: %s\n",
gfs2/tool/tune.c +10 -0
@@ -54,6 +54,11 @@ get_tune(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }memset (path,0 ,PATH_MAX );snprintf (path,PATH_MAX -1 ,"%s/%s/tune" ,SYS_BASE , fs);
@@ -117,6 +122,11 @@ set_tune(int argc, char **argv)exit (-1 ); } fs =mp2fsname (sbd.path_name); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted@%s\n" , + sbd.path_name); +exit (-1 ); + }if (strcmp (param,"quota_scale" ) ==0 ) {float s;
Signature · 1 line
1.6.2
PATCH 1/1 libgfs2: Remove 'die' from mp2fsname and find_debugfs_mount
Hi,
Looks good to me,
Steve.
Quoted 176 lines · Andrew Price
Removes the call to 'die' from mp2fsname and updates its callers to handle the error. Also removes the die calls from
find_debugfs_mountwhich only has one caller that already handles the error cases.Signed-off-by Andrew Price <[email protected]>--- gfs2/libgfs2/misc.c | 10 ++++++---- gfs2/quota/check.c | 8 +++++++- gfs2/quota/main.c | 10 ++++++++++ gfs2/tool/df.c | 5 +++++ gfs2/tool/misc.c | 15 +++++++++++++++ gfs2/tool/tune.c | 10 ++++++++++ 6 files changed, 53 insertions(+), 5 deletions(-)gfs2/libgfs2/misc.c +6
-4@@ -291,11 +291,13 @@ char *find_debugfs_mount(void) file =fopen ("/proc/mounts" ,"rt" );if (!file) -die ("can't open /proc/mounts: %s\n" ,strerror (errno)); +return NULL ; path =malloc (PATH_MAX ); -if (!path) -die ("Can't allocate memory for debugfs.\n" ); +if (!path) { +fclose (file); +return NULL ; + }while (fgets (line,PATH_MAX , file)) {if (sscanf (line,"%s %s %s" , device, path, type) !=3 )@@ -432,7 +434,7 @@ char *mp2fsname(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 ] =='.' )gfs2/quota/check.c +7
-1@@ -507,8 +507,14 @@ set_list(struct gfs2_sbd *sdp, commandline_t *comline, int user, goto out; } -/* Write the id to sysfs quota refresh file to refresh gfs quotas */ fs =mp2fsname (comline->filesystem); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + comline->filesystem); +exit (-1 ); + } + +/* Write the id to sysfs quota refresh file to refresh gfs quotas */ sprintf (id_str,"%d" , comline->id);if (set_sysfs (fs, (user) ?"quota_refresh_user" :"quota_refresh_group" , id_str)) {gfs2/quota/main.c +10
-0@@ -783,6 +783,11 @@ do_sync_one(struct gfs2_sbd *sdp, char *filesystem)char *fsname; fsname =mp2fsname (filesystem); +if (!fsname) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + filesystem); +exit (-1 ); + }if (set_sysfs (fsname,"quota_sync" ,"1" )) {fprintf (stderr,"Error writing to sysfs quota sync file: %s\n" ,strerror (errno));@@ -992,6 +997,11 @@ do_set(struct gfs2_sbd *sdp, commandline_t *comline) } fs =mp2fsname (comline->filesystem); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + comline->filesystem); +exit (-1 ); + }sprintf (id_str,"%d" , comline->id);if (set_sysfs (fs, comline->id_type ==GQ_ID_USER ?"quota_refresh_user" :"quota_refresh_group" , id_str)) {gfs2/tool/df.c +5
-0@@ -95,6 +95,11 @@ do_df_one(char *path)exit (-1 ); } fs =mp2fsname (sbd.path_name); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + sbd.path_name); +exit (-1 ); + } sbd.device_fd =open (sbd.device_name,O_RDONLY );if (sbd.device_fd <0 )gfs2/tool/misc.c +15
-0@@ -272,6 +272,11 @@ print_args(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }memset (path,0 ,PATH_MAX );snprintf (path,PATH_MAX -1 ,"%s/%s/args/" ,SYS_BASE , fs);@@ -457,6 +462,11 @@ do_shrink(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }if (set_sysfs (fs,"shrink" ,"1" )) { fprintf(stderr, "Error writing to sysfs shrink file: %s\n",@@ -491,6 +501,11 @@ do_withdraw(int argc, char **argv)exit (-1 ); } name =mp2fsname (argv[optind]); +if (!name) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }if (set_sysfs (name,"withdraw" ,"1" )) { fprintf(stderr, "Error writing to sysfs withdraw file: %s\n",gfs2/tool/tune.c +10
-0@@ -54,6 +54,11 @@ get_tune(int argc, char **argv)exit (-1 ); } fs =mp2fsname (argv[optind]); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + argv[optind]); +exit (-1 ); + }memset (path,0 ,PATH_MAX );snprintf (path,PATH_MAX -1 ,"%s/%s/tune" ,SYS_BASE , fs);@@ -117,6 +122,11 @@ set_tune(int argc, char **argv)exit (-1 ); } fs =mp2fsname (sbd.path_name); +if (!fs) { +fprintf (stderr,"Couldn't find GFS2 filesystem mounted at %s\n" , + sbd.path_name); +exit (-1 ); + }if (strcmp (param,"quota_scale" ) ==0 ) {float s;