]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hwclock: add -param-index
authorKarel Zak <kzak@redhat.com>
Thu, 5 Sep 2024 10:23:15 +0000 (12:23 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 5 Sep 2024 10:23:15 +0000 (12:23 +0200)
Addresses: https://github.com/util-linux/util-linux/issues/3180
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/hwclock-rtc.c
sys-utils/hwclock.c
sys-utils/hwclock.h

index 659a7a707b406401198741dea45ff27b258927fe..2796f2e8a5ef8e124512ac003612f66b3a2e8998 100644 (file)
@@ -439,7 +439,7 @@ int get_param_rtc(const struct hwclock_control *ctl,
                  const char *name, uint64_t *id, uint64_t *value)
 {
        int rtc_fd;
-       struct rtc_param param = { .param = 0 };
+       struct rtc_param param = { .index = ctl->param_idx };
 
        /* handle name */
        if (resolve_rtc_param_alias(name, &param.param) != 0
@@ -479,7 +479,7 @@ int get_param_rtc(const struct hwclock_control *ctl,
 int set_param_rtc(const struct hwclock_control *ctl, const char *opt0)
 {
        int rtc_fd, rc = 1;
-       struct rtc_param param = { .param = 0 };
+       struct rtc_param param = { .index = ctl->param_idx };
        char *tok, *opt = xstrdup(opt0);
 
        /* handle name */
index ca851a49129d67414ae4aea6fd1db47580e73e63..cea249ebb10d66a8e2ae432d442ddf12da023c8f 100644 (file)
@@ -1236,6 +1236,7 @@ usage(void)
 #ifdef __linux__
        puts(_("     --param-get <param>         display the RTC parameter"));
        puts(_("     --param-set <param>=<value> set the RTC parameter"));
+       puts(_("     --param-index <number>      parameter index (default 0)"));
        puts(_("     --vl-read                   read voltage low information"));
        puts(_("     --vl-clear                  clear voltage low information"));
 #endif
@@ -1309,6 +1310,7 @@ int main(int argc, char **argv)
                OPT_NOADJFILE,
                OPT_PARAM_GET,
                OPT_PARAM_SET,
+               OPT_PARAM_IDX,
                OPT_VL_READ,
                OPT_VL_CLEAR,
                OPT_PREDICT,
@@ -1340,6 +1342,7 @@ int main(int argc, char **argv)
 #ifdef __linux__
                { "param-get",    required_argument, NULL, OPT_PARAM_GET  },
                { "param-set",    required_argument, NULL, OPT_PARAM_SET  },
+               { "param-index",  required_argument, NULL, OPT_PARAM_IDX  },
                { "vl-read",      no_argument,       NULL, OPT_VL_READ    },
                { "vl-clear",     no_argument,       NULL, OPT_VL_CLEAR   },
 #endif
@@ -1466,6 +1469,9 @@ int main(int argc, char **argv)
                        ctl.show = 0;
                        ctl.hwaudit_on = 1;
                        break;
+               case OPT_PARAM_IDX:
+                       ctl.param_idx = strtou32_or_err(optarg, _("failed to parse param-index"));
+                       break;
                case OPT_VL_READ:
                        ctl.vl_read = 1;
                        ctl.show = 0;
index 91b10a73bb9f3fc55223e4814f9201e80100627a..21b7efa3d2852d95b32cef97d77a307c69a2d0a6 100644 (file)
@@ -37,6 +37,7 @@ struct hwclock_control {
 #endif
 #ifdef __linux__
        char *rtc_dev_name;
+       uint32_t param_idx;     /* --param-index <n> */
 #endif
        char *param_get_option;
        char *param_set_option;