From 06d0d9f142c0012bdcf617016f60fc8327bad88b Mon Sep 17 00:00:00 2001 From: Andrew Price Date: Jan 14 2022 10:58:09 +0000 Subject: gfs2_edit: Remove the remaining die() calls Signed-off-by: Andrew Price --- diff --git a/gfs2/edit/hexedit.c b/gfs2/edit/hexedit.c index cf12120..773fbb3 100644 --- a/gfs2/edit/hexedit.c +++ b/gfs2/edit/hexedit.c @@ -2317,8 +2317,8 @@ static void process_parameters(int argc, char *argv[], int pass) uint64_t keyword_blk; if (argc < 2) { - usage(); - die("no device specified\n"); + fprintf(stderr, "No device specified\n"); + exit(1); } for (i = 1; i < argc; i++) { if (!pass) { /* first pass */ @@ -2500,8 +2500,10 @@ int main(int argc, char *argv[]) int i, j, fd; indirect = malloc(sizeof(struct iinfo)); - if (!indirect) - die("Out of memory."); + if (indirect == NULL) { + perror("Failed to allocate indirect info"); + exit(1); + } memset(indirect, 0, sizeof(struct iinfo)); memset(start_row, 0, sizeof(start_row)); memset(lines_per_row, 0, sizeof(lines_per_row)); @@ -2533,8 +2535,10 @@ int main(int argc, char *argv[]) dmode = HEX_MODE; fd = open(device, O_RDWR); - if (fd < 0) - die("can't open %s: %s\n", device, strerror(errno)); + if (fd < 0) { + fprintf(stderr, "Failed to open '%s': %s\n", device, strerror(errno)); + exit(1); + } max_block = lseek(fd, 0, SEEK_END) / sbd.sd_bsize; read_superblock(fd); diff --git a/gfs2/edit/hexedit.h b/gfs2/edit/hexedit.h index 3b1d8e8..543cc3a 100644 --- a/gfs2/edit/hexedit.h +++ b/gfs2/edit/hexedit.h @@ -128,17 +128,6 @@ static inline int block_is_journals(uint64_t blk) #define SCREEN_HEIGHT (16) #define SCREEN_WIDTH (16) -/* die() used to be in libgfs2.h */ -static __inline__ __attribute__((noreturn, format (printf, 1, 2))) -void die(const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - exit(-1); -} - #define TITLE1 "gfs2_edit - Global File System Editor (use with extreme caution)" #define TITLE2 REDHAT_COPYRIGHT " - Press H for help" diff --git a/gfs2/edit/savemeta.c b/gfs2/edit/savemeta.c index 2d53ff1..8fde8c8 100644 --- a/gfs2/edit/savemeta.c +++ b/gfs2/edit/savemeta.c @@ -1324,11 +1324,10 @@ static int restore_data(int fd, struct metafd *mfd, int printonly) return 0; } -static void complain(const char *complaint) +static void restoremeta_usage(void) { - fprintf(stderr, "%s\n", complaint); - die("Format is: \ngfs2_edit restoremeta " - "\n"); + fprintf(stderr, "Usage:\n"); + fprintf(stderr, "gfs2_edit restoremeta \n"); } static int restore_init(const char *path, struct metafd *mfd, int printonly) @@ -1413,16 +1412,23 @@ void restoremeta(const char *in_fn, const char *out_device, uint64_t printonly) int error; termlines = 0; - if (!in_fn) - complain("No source file specified."); - if (!printonly && !out_device) - complain("No destination file system specified."); - + if (in_fn == NULL || in_fn[0] == '\0') { + fprintf(stderr, "No source file specified."); + restoremeta_usage(); + exit(1); + } + if (!printonly && (out_device == NULL || out_device[0] == '\0')) { + fprintf(stderr, "No destination file system specified."); + restoremeta_usage(); + exit(1); + } if (!printonly) { sbd.device_fd = open(out_device, O_RDWR); - if (sbd.device_fd < 0) - die("Can't open destination file system %s: %s\n", + if (sbd.device_fd < 0) { + fprintf(stderr, "Failed to open target '%s': %s\n", out_device, strerror(errno)); + exit(1); + } } else if (out_device) /* for printsavedmeta, the out_device is an optional block no */ printonly = check_keywords(out_device);