From: Zbigniew Jędrzejewski-Szmek Date: Fri, 16 Nov 2018 13:52:25 +0000 (+0100) Subject: makefs: define main through macro X-Git-Tag: v240~280^2~11 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fb1fa5a88283a108988b9357f2f312f8cee806aa;p=thirdparty%2Fsystemd.git makefs: define main through macro --- diff --git a/src/partition/makefs.c b/src/partition/makefs.c index 8c2a783e9d9..dcc69c6a207 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -42,7 +42,7 @@ static int makefs(const char *type, const char *device) { return wait_for_terminate_and_check(mkfs, pid, WAIT_LOG); } -int main(int argc, char *argv[]) { +static int run(int argc, char *argv[]) { const char *device, *type; _cleanup_free_ char *detected = NULL; struct stat st; @@ -54,37 +54,32 @@ int main(int argc, char *argv[]) { if (argc != 3) { log_error("This program expects two arguments."); - return EXIT_FAILURE; + return -EINVAL; } type = argv[1]; device = argv[2]; - if (stat(device, &st) < 0) { - r = log_error_errno(errno, "Failed to stat \"%s\": %m", device); - goto finish; - } + if (stat(device, &st) < 0) + return log_error_errno(errno, "Failed to stat \"%s\": %m", device); if (!S_ISBLK(st.st_mode)) log_info("%s is not a block device.", device); r = probe_filesystem(device, &detected); - if (r < 0) { - log_warning_errno(r, - r == -EUCLEAN ? - "Cannot reliably determine probe \"%s\", refusing to proceed." : - "Failed to probe \"%s\": %m", - device); - goto finish; - } + if (r < 0) + return log_warning_errno(r, + r == -EUCLEAN ? + "Cannot reliably determine probe \"%s\", refusing to proceed." : + "Failed to probe \"%s\": %m", + device); if (detected) { log_info("%s is not empty (type %s), exiting", device, detected); - goto finish; + return 0; } - r = makefs(type, device); - -finish: - return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; + return makefs(type, device); } + +DEFINE_MAIN_FUNCTION(run);