]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
build-sys: add --disable-hwclock-gplv3
authorKarel Zak <kzak@redhat.com>
Mon, 27 Jan 2020 15:17:10 +0000 (16:17 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 27 Jan 2020 15:23:21 +0000 (16:23 +0100)
The currently used date/time parser (for hwclock --set --date <date>)
is gnulib based code with GPLv3.

This patch allows to avoid this code and replace it with minimalistic
date/time parser.

Addresses: https://github.com/karelzak/util-linux/issues/891
Reported-by: Carlos Santos <unixmania@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
sys-utils/Makemodule.am
sys-utils/hwclock.c

index 84b375543bad1c7b3d226dbec88710276fb3dcac..960e2016d1c041970463ae3a904fbdd57c3faf33 100644 (file)
@@ -1558,6 +1558,15 @@ AS_IF([test "x$build_hwclock_cmos" = xyes ], [
     AC_DEFINE([USE_HWCLOCK_CMOS], [1], [Define to 1 if want to use CMOS clock.])
 ])
 
+AC_ARG_ENABLE([hwclock_gplv3],
+  AS_HELP_STRING([--disable-hwclock-gplv3], [do not use datetime parsing GPLv3 code]),
+  [], [enable_hwclock_gplv3=yes]
+)
+AM_CONDITIONAL([USE_HWCLOCK_GPLv3_DATETIME], [test "x$enable_hwclock_gplv3" = xyes])
+AS_IF([test "x$enable_hwclock_gplv3" = xyes ], [
+    AC_DEFINE([USE_HWCLOCK_GPLv3_DATETIME], [1], [use datetime parsing GPLv3 code to hwclock])
+])
+
 
 UL_BUILD_INIT([mkfs], [yes])
 AM_CONDITIONAL([BUILD_MKFS], [test "x$build_mkfs" = xyes])
index baf851e5b8d1f067f65f4254941c822e11d1841a..07228f75fe0d5263186dc4838ccd0aecdab742bf 100644 (file)
@@ -451,8 +451,11 @@ dist_man_MANS += \
 PATHFILES += sys-utils/hwclock.8
 hwclock_SOURCES = \
        sys-utils/hwclock.c \
-       sys-utils/hwclock.h \
+       sys-utils/hwclock.h
+if USE_HWCLOCK_GPLv3_DATETIME
+hwclock_SOURCES += \
        sys-utils/hwclock-parse-date.y
+endif
 hwclock_LDADD = $(LDADD) libcommon.la -lm
 hwclock_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/sys-utils
 if USE_HWCLOCK_CMOS
index 15fc19afd509373d24e48d8134b5fad5206f0391..e736da7179f8f88f32cbb8ddd154008aeef401e0 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Since 7a3000f7ba548cf7d74ac77cc63fe8de228a669e (v2.30) hwclock is linked
  * with parse_date.y from gnullib. This gnulib code is distributed with GPLv3.
+ * Use --disable-hwclock-gplv3 to exclude this code.
  *
  *
  * clock.c was written by Charles Hedrick, hedrick@cs.rutgers.edu, Apr 1992
@@ -1170,7 +1171,6 @@ int main(int argc, char **argv)
        };
        struct timeval startup_time;
        struct adjtime adjtime = { 0 };
-       struct timespec when = { 0 };
        /*
         * The time we started up, in seconds into the epoch, including
         * fractions.
@@ -1398,11 +1398,22 @@ int main(int argc, char **argv)
 
        if (ctl.set || ctl.predict) {
                if (!ctl.date_opt) {
-               warnx(_("--date is required for --set or --predict"));
-               exit(EXIT_FAILURE);
+                       warnx(_("--date is required for --set or --predict"));
+                       exit(EXIT_FAILURE);
                }
+#ifdef USE_HWCLOCK_GPLv3_DATETIME
+               /* date(1) compatible GPLv3 parser */
+               struct timespec when = { 0 };
+
                if (parse_date(&when, ctl.date_opt, NULL))
                        set_time = when.tv_sec;
+#else
+               /* minimalistic GPLv2 based parser */
+               usec_t usec;
+
+               if (parse_timestamp(ctl.date_opt, &usec) == 0)
+                       set_time = (time_t) (usec / 1000000);
+#endif
                else {
                        warnx(_("invalid date '%s'"), ctl.date_opt);
                        exit(EXIT_FAILURE);