Skip to contentSkip to conversation

mtd-utils: ubinize: Always return error code (at least -1) in case of an error

PATCH Applied Enrico Jorns 3 participants 4 messages Sep 11, 2015 – Sep 29, 2015 Memory technology devices (MTD)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mtd-utils: ubinize: Always return error code (at least -1) in case of an error

ubinize should not fail silenty, this can be very annoying when using it from other tools that rely on the exit code for determining the success of their operation.

---
 ubi-utils/ubinize.c | 5 +++++
 1 file changed, 5 insertions(+)
ubi-utils/ubinize.c +5 -0
index 34f465a..60bbd9a 100644
@@ -519,6 +519,7 @@ int main(int argc, char * const argv[])
 	 */
 	seek = ui.peb_size * 2;
 	if (lseek(args.out_fd, seek, SEEK_SET) != seek) {
+		err = -1;
 		sys_errmsg("cannot seek file \"%s\"", args.f_out);
 		goto out_free;
 	}
@@ -530,6 +531,7 @@ int main(int argc, char * const argv[])
 		int fd, j;
 
 		if (!sname) {
+			err = -1;
 			errmsg("ini-file parsing error (iniparser_getsecname)");
 			goto out_free;
 		}
@@ -550,6 +552,7 @@ int main(int argc, char * const argv[])
 		 */
 		for (j = 0; j < i; j++) {
 			if (vi[i].id == vi[j].id) {
+				err = -1;
 				errmsg("volume IDs must be unique, but ID %d "
 				       "in section \"%s\" is not",
 				       vi[i].id, sname);
@@ -557,6 +560,7 @@ int main(int argc, char * const argv[])
 			}
 
 			if (!strcmp(vi[i].name, vi[j].name)) {
+				err = -1;
 				errmsg("volume name must be unique, but name "
 				       "\"%s\" in section \"%s\" is not",
 				       vi[i].name, sname);
@@ -580,6 +584,7 @@ int main(int argc, char * const argv[])
 		if (img) {
 			fd = open(img, O_RDONLY);
 			if (fd == -1) {
+				err = fd;
 				sys_errmsg("cannot open \"%s\"", img);
 				goto out_free;
 			}
Signature · 1 line
2.5.0
#1 lore raw

Any comments on this?

Quoted 54 lines · Enrico Jorns

ubinize should not fail silenty, this can be very annoying when using it from other tools that rely on the exit code for determining the success of their operation.

---
  ubi-utils/ubinize.c | 5 +++++
  1 file changed, 5 insertions(+)
ubi-utils/ubinize.c +5 -0
index 34f465a..60bbd9a 100644
@@ -519,6 +519,7 @@ int main(int argc, char * const argv[])
  	 */
  	seek = ui.peb_size * 2;
  	if (lseek(args.out_fd, seek, SEEK_SET) != seek) {
+		err = -1;
  		sys_errmsg("cannot seek file \"%s\"", args.f_out);
  		goto out_free;
  	}
@@ -530,6 +531,7 @@ int main(int argc, char * const argv[])
  		int fd, j;
 
  		if (!sname) {
+			err = -1;
  			errmsg("ini-file parsing error (iniparser_getsecname)");
  			goto out_free;
  		}
@@ -550,6 +552,7 @@ int main(int argc, char * const argv[])
  		 */
  		for (j = 0; j < i; j++) {
  			if (vi[i].id == vi[j].id) {
+				err = -1;
  				errmsg("volume IDs must be unique, but ID %d "
  				       "in section \"%s\" is not",
  				       vi[i].id, sname);
@@ -557,6 +560,7 @@ int main(int argc, char * const argv[])
  			}
 
  			if (!strcmp(vi[i].name, vi[j].name)) {
+				err = -1;
  				errmsg("volume name must be unique, but name "
  				       "\"%s\" in section \"%s\" is not",
  				       vi[i].name, sname);
@@ -580,6 +584,7 @@ int main(int argc, char * const argv[])
  		if (img) {
  			fd = open(img, O_RDONLY);
  			if (fd == -1) {
+				err = fd;
  				sys_errmsg("cannot open \"%s\"", img);
  				goto out_free;
  			}
#2 lore raw
Quoted 1 line · Enrico Joerns

Any comments on this?

Looks good to me!

Signature · 2 lines
Thanks,
//richard
Applied
#3 lore raw
Quoted 4 lines · Richard Weinberger
Quoted 1 line · Enrico Joerns

Any comments on this?

Looks good to me!

Pushed to mtd-utils.git.