]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
update-done: add basic argument parsing and --help
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 19 Mar 2025 15:47:02 +0000 (16:47 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 20 Mar 2025 14:15:48 +0000 (15:15 +0100)
We certainly want to reject calls with any args specified. Previously
we would just silently ignore any args.

man/systemd-update-done.service.xml
src/update-done/update-done.c

index fb228796885cfec0f63421abefe9896bfe4ab032..2db2e407b6fe1fa97e4661cb9f2fe4ed02eb6d9b 100644 (file)
@@ -3,7 +3,7 @@
 <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
   "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
 <!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
-<refentry id="systemd-update-done.service">
+<refentry id="systemd-update-done.service" xmlns:xi="http://www.w3.org/2001/XInclude">
 
   <refentryinfo>
     <title>systemd-update-done.service</title>
@@ -18,7 +18,7 @@
   <refnamediv>
     <refname>systemd-update-done.service</refname>
     <refname>systemd-update-done</refname>
-    <refpurpose>Mark <filename>/etc/</filename> and <filename>/var/</filename> fully updated</refpurpose>
+    <refpurpose>Mark <filename>/etc/</filename> and <filename>/var/</filename> as fully updated</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     reboot where the kernel switch is not specified anymore.</para>
   </refsect1>
 
+  <refsect1>
+    <title>Options</title>
+
+    <para>The following options are understood:</para>
+
+    <variablelist>
+      <xi:include href="standard-options.xml" xpointer="help" />
+    </variablelist>
+  </refsect1>
+
   <refsect1>
     <title>See Also</title>
     <para><simplelist type="inline">
index a4289ddf2adebfdc80cf94e9fa067758e30d62c5..f9c8ec4f4299a11746d69519ab7c6ccbf12bf66d 100644 (file)
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 
+#include <getopt.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <unistd.h>
@@ -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)