From 20f7f0a89177214298b7c70fffef2c512cd7a384 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 19 Mar 2025 16:47:02 +0100 Subject: [PATCH] update-done: add basic argument parsing and --help We certainly want to reject calls with any args specified. Previously we would just silently ignore any args. --- man/systemd-update-done.service.xml | 14 ++++++- src/update-done/update-done.c | 61 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 2 deletions(-) diff --git a/man/systemd-update-done.service.xml b/man/systemd-update-done.service.xml index fb228796885..2db2e407b6f 100644 --- a/man/systemd-update-done.service.xml +++ b/man/systemd-update-done.service.xml @@ -3,7 +3,7 @@ - + systemd-update-done.service @@ -18,7 +18,7 @@ systemd-update-done.service systemd-update-done - Mark /etc/ and /var/ fully updated + Mark /etc/ and /var/ as fully updated @@ -63,6 +63,16 @@ reboot where the kernel switch is not specified anymore. + + Options + + The following options are understood: + + + + + + See Also diff --git a/src/update-done/update-done.c b/src/update-done/update-done.c index a4289ddf2ad..f9c8ec4f429 100644 --- a/src/update-done/update-done.c +++ b/src/update-done/update-done.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include #include @@ -8,6 +9,7 @@ #include "fileio.h" #include "main-func.h" #include "path-util.h" +#include "pretty-print.h" #include "selinux-util.h" #include "time-util.h" @@ -41,10 +43,69 @@ static int save_timestamp(const char *dir, struct timespec *ts) { return 0; } +static int help(void) { + _cleanup_free_ char *link = NULL; + int r; + + r = terminal_urlify_man("systemd-update-done", "8", &link); + if (r < 0) + return log_oom(); + + printf("%1$s [OPTIONS...]\n\n" + "%5$sMark /etc/ and /var/ as fully updated.%6$s\n" + "\n%3$sOptions:%4$s\n" + " -h --help Show this help\n" + "\nSee the %2$s for details.\n", + program_invocation_short_name, + link, + ansi_underline(), + ansi_normal(), + ansi_highlight(), + ansi_normal()); + + return 0; +} + +static int parse_argv(int argc, char *argv[]) { + static const struct option options[] = { + { "help", no_argument, NULL, 'h' }, + {}, + }; + + int c; + + assert(argc >= 0); + assert(argv); + + while ((c = getopt_long(argc, argv, "h", options, NULL)) >= 0) + + switch (c) { + + case 'h': + return help(); + + case '?': + return -EINVAL; + + default: + assert_not_reached(); + } + + if (optind < argc) + return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "This program takes no arguments."); + + return 1; +} + + static int run(int argc, char *argv[]) { struct stat st; int r; + r = parse_argv(argc, argv); + if (r <= 0) + return r; + log_setup(); if (stat("/usr", &st) < 0) -- 2.47.3