From: Yu Watanabe Date: Mon, 4 Jan 2021 18:07:23 +0000 (+0900) Subject: udev/cdrom: split main() into main() and run() X-Git-Tag: v248-rc1~400 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a084b3878955bc1b93adcaa7a41acb83b18eff9b;p=thirdparty%2Fsystemd.git udev/cdrom: split main() into main() and run() However, we do not use DEFINE_MAIN_FUNCTION() here, as ubuntu s390x CI does not like it... --- diff --git a/src/udev/cdrom_id/cdrom_id.c b/src/udev/cdrom_id/cdrom_id.c index 9c9182e16c8..a97ed8eabdd 100644 --- a/src/udev/cdrom_id/cdrom_id.c +++ b/src/udev/cdrom_id/cdrom_id.c @@ -943,33 +943,24 @@ static int parse_argv(int argc, char *argv[]) { return 1; } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { _cleanup_(context_clear) Context c; - int r, rc = 0; - - log_set_target(LOG_TARGET_AUTO); - udev_parse_config(); - log_parse_environment(); - log_open(); + int r; context_init(&c); r = parse_argv(argc, argv); - if (r <= 0) { - rc = r < 0; - goto exit; - } + if (r <= 0) + return r; - if (open_drive(&c) < 0) { - rc = 1; - goto exit; - } + r = open_drive(&c); + if (r < 0) + return r; /* same data as original cdrom_id */ - if (cd_capability_compat(&c) < 0) { - rc = 1; - goto exit; - } + r = cd_capability_compat(&c); + if (r < 0) + return r; /* check for media - don't bail if there's no media as we still need to * to read profiles */ @@ -979,8 +970,7 @@ int main(int argc, char *argv[]) { if (cd_inquiry(&c) < 0) goto work; - /* read drive and possibly current profile */ - r = cd_profiles(&c); + r = cd_profiles(&c); /* read drive and possibly current profile */ if (r > 0) { /* at this point we are guaranteed to have media in the drive - find out more about it */ @@ -1012,7 +1002,20 @@ work: print_properties(&c); -exit: + return 0; +} + +int main(int argc, char *argv[]) { + int r; + + log_set_target(LOG_TARGET_AUTO); + udev_parse_config(); + log_parse_environment(); + log_open(); + + r = run(argc, argv); + log_close(); - return rc; + + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }