diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-16 14:52:25 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2018-11-17 09:13:35 +0100 |
commit | fb1fa5a88283a108988b9357f2f312f8cee806aa (patch) | |
tree | e33617fecaee29a95c5447284777ba6aa6ed8d2c /src/partition/makefs.c | |
parent | notify: define main through macro (diff) | |
download | systemd-fb1fa5a88283a108988b9357f2f312f8cee806aa.tar.xz systemd-fb1fa5a88283a108988b9357f2f312f8cee806aa.zip |
makefs: define main through macro
Diffstat (limited to '')
-rw-r--r-- | src/partition/makefs.c | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/src/partition/makefs.c b/src/partition/makefs.c index 8c2a783e9d..dcc69c6a20 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); |