Re: [PATCH] hwclock: add --systz option to set system clock from itself

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Feb 14, 2009 at 12:12:54PM +0000, Scott James Remnant wrote:
> Since the system clock time is already set from the hardware clock by

 it depends on kernel, for example the current Fedora:

    # CONFIG_RTC_HCTOSYS is not set

> the kernel, there's no particular need to read the hardware clock
> again.

 yes, that's a good idea. BTW, this option also seems like a good
 workaround for machines without writable HW clock (e.g s390) where
 crazy admins need to change TZ only.

> +This is an alternate option to
> +.B \-\-hctosys
> +that does not read the hardware clock, and may be used in system startup
> +scripts for recent 2.6 kernels where you know the System Time contains
> +the Hardware Clock time.  You must specify either
                             ^^^^^^^^^^^^^^^^^^^^
> +.B \-\-utc
> +or
> +.B \-\-localtime
> +to indicate whether an adjustment needs to be made.

 Is it really good idea to require the --{utc,localtime} option when
 we have all necessary information in /etc/adjtime? 
 
 I think it should be optional like for the others hwclock operations.
 IMHO it's really bad idea to hardcode --{utc,localtime} to udev rules.

> +static int
> +set_system_clock_timezone(const bool testing) {
> +/*----------------------------------------------------------------------------
> +   Reset the System Clock from local time to UTC, based on its current
> +   value and the timezone.
> +
> +   Also set the kernel time zone value to the value indicated by the
> +   TZ environment variable and/or /usr/lib/zoneinfo/, interpreted as
> +   tzset() would interpret them.
> +
> +   If 'testing' is true, don't actually update anything -- just say we
> +   would have.
> +-----------------------------------------------------------------------------*/
> +  int retcode;
> +  struct timeval tv;
> +  struct tm *broken;
> +  int minuteswest;
> +  int rc;
> +
> +  gettimeofday(&tv, NULL);
> +  if (debug) {
> +    struct tm broken_time;
> +    char ctime_now[200];
> +
> +    broken_time = *gmtime(&tv.tv_sec);
> +    strftime(ctime_now, sizeof(ctime_now), "%Y/%m/%d %H:%M:%S", &broken_time);
> +    printf(_("Current system time: %ld = %s\n"), (long) tv.tv_sec, ctime_now);
> +  }
> +
> +  broken = localtime(&tv.tv_sec);
> +#ifdef HAVE_TM_GMTOFF
> +  minuteswest = -broken->tm_gmtoff/60;		/* GNU extension */
> +#else
> +  minuteswest = timezone/60;
> +  if (broken->tm_isdst)
> +	  minuteswest -= 60;
> +#endif
> +
> +  gettimeofday(&tv, NULL);
> +  tv.tv_sec += minuteswest * 60;
> +  if (debug) {
> +    struct tm broken_time;
> +    char ctime_now[200];
> +
> +    broken_time = *gmtime(&tv.tv_sec);
> +    strftime(ctime_now, sizeof(ctime_now), "%Y/%m/%d %H:%M:%S", &broken_time);
> +
> +    printf(_("Calling settimeofday:\n"));
> +    printf(_("\tUTC: %s\n"), ctime_now);
> +    printf(_("\ttv.tv_sec = %ld, tv.tv_usec = %ld\n"),
> +           (long) tv.tv_sec, (long) tv.tv_usec);
> +    printf(_("\ttz.tz_minuteswest = %d\n"), minuteswest);
> +  }
> +  if (testing) {
> +    printf(_("Not setting system clock because running in test mode.\n"));
> +    retcode = 0;
> +  } else {
> +    const struct timezone tz = { minuteswest, 0 };
> +
> +    rc = settimeofday(&tv, &tz);
> +    if (rc) {
> +	    if (errno == EPERM) {
> +		    fprintf(stderr,
> +			    _("Must be superuser to set system clock.\n"));
> +		    retcode = EX_NOPERM;
> +	    } else {
> +		    outsyserr(_("settimeofday() failed"));
> +		    retcode = 1;
> +	    }
> +    } else retcode = 0;
> +  }
> +  return retcode;
> +}

 Here we duplicate a lot of code from set_system_clock(), right? :-)

> +	} else if (systz) {
> +	  if (!universal) {
> +	    rc = set_system_clock_timezone(testing);
> +	    if (rc) {
> +	      printf(_("Unable to set system clock.\n"));

 "Unable to set system timezone" ?


    Karel

-- 
 Karel Zak  <kzak@xxxxxxxxxx>
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux