~ubuntu-branches/ubuntu/quantal/util-linux/quantal

« back to all changes in this revision

Viewing changes to hwclock/hwclock.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
1134
1134
                 const bool hctosys, const bool systohc, const bool systz,
1135
1135
                 const struct timeval startup_time,
1136
1136
                 const bool utc, const bool local_opt,
1137
 
                 const bool testing) {
 
1137
                 const bool testing, const bool predict) {
1138
1138
/*---------------------------------------------------------------------------
1139
1139
  Do all the normal work of hwclock - read, set clock, etc.
1140
1140
 
1147
1147
    int rc;  /* local return code */
1148
1148
    bool no_auth;  /* User lacks necessary authorization to access the clock */
1149
1149
 
1150
 
    if (!systz) {
 
1150
    if (!systz && !predict) {
1151
1151
      no_auth = ur->get_permissions();
1152
1152
      if (no_auth)
1153
1153
              return EX_NOPERM;
1154
1154
    }
1155
1155
 
1156
 
    if (!noadjfile && (adjust || set || systohc || (!utc && !local_opt))) {
 
1156
    if (!noadjfile && (adjust || set || systohc || (!utc && !local_opt) || predict)) {
1157
1157
      rc = read_adjtime(&adjtime);
1158
1158
      if (rc)
1159
1159
              return rc;
1187
1187
             Defined only if hclock_valid is true.
1188
1188
             */
1189
1189
 
1190
 
        if (show || adjust || hctosys || (!noadjfile && !systz)) {
 
1190
        if (show || adjust || hctosys || (!noadjfile && !systz && !predict)) {
1191
1191
          /* data from HW-clock are required */
1192
1192
          rc = synchronize_to_clock_tick();
1193
 
          if (rc && rc != 2)            /* 2= synchronization timeout */
 
1193
 
 
1194
          /* 2 = synchronization timeout.  We don't error out if the user is
 
1195
             attempting to set the RTC - the RTC could be functioning but
 
1196
             contain invalid time data so we still want to allow a user to set
 
1197
             the RTC time.
 
1198
             */
 
1199
 
 
1200
          if (rc && rc != 2 && !set && !systohc)
1194
1201
            return EX_IOERR;
1195
1202
          gettimeofday(&read_time, NULL);
1196
 
          rc = read_hardware_clock(universal, &hclock_valid, &hclocktime);
1197
 
          if (rc)
1198
 
             return EX_IOERR;
 
1203
 
 
1204
          /* If we can't synchronize to a clock tick, we likely can't read
 
1205
             from the RTC so don't bother reading it again. */
 
1206
          if (!rc) {
 
1207
            rc = read_hardware_clock(universal, &hclock_valid, &hclocktime);
 
1208
            if (rc && !set && !systohc)
 
1209
              return EX_IOERR;
 
1210
          }
1199
1211
        }
1200
1212
 
1201
1213
        if (show) {
1237
1249
            printf(_("Unable to set system clock.\n"));
1238
1250
            return rc;
1239
1251
          }
 
1252
        } else if (predict) {
 
1253
            int adjustment;
 
1254
            double retro;
 
1255
 
 
1256
            calculate_adjustment(adjtime.drift_factor,
 
1257
                                 adjtime.last_adj_time,
 
1258
                                 adjtime.not_adjusted,
 
1259
                                 set_time,
 
1260
                                 &adjustment, &retro);
 
1261
            if (debug) {
 
1262
                printf(_("At %ld seconds after 1969, RTC is predicted to read %ld seconds after 1969.\n"),
 
1263
                       set_time, set_time + adjustment);
 
1264
            }
 
1265
            display_time(TRUE, set_time + adjustment, -retro);
1240
1266
        }
1241
1267
        if (!noadjfile)
1242
1268
         save_adjtime(adjtime, testing);
1332
1358
        "       --getepoch     print out the kernel's hardware clock epoch value\n"
1333
1359
        "       --setepoch     set the kernel's hardware clock epoch value to the \n"
1334
1360
        "                      value given with --epoch\n"
 
1361
        "       --predict      predict rtc reading at time given with --date\n"
1335
1362
        "  -v | --version      print out the version of hwclock to stdout\n"
1336
1363
        "\nOptions: \n"
1337
1364
        "  -u | --utc          the hardware clock is kept in UTC\n"
1401
1428
        { "rtc", 1, 0, 'f' },
1402
1429
        { "adjfile", 1, 0, 138 },
1403
1430
        { "systz", 0, 0, 139 },
 
1431
        { "predict-hc", 0, 0, 140 },
1404
1432
        { NULL, 0, 0, 0 }
1405
1433
};
1406
1434
 
1426
1454
 
1427
1455
        /* Variables set by various options; show may also be set later */
1428
1456
        /* The options debug, badyear and epoch_option are global */
1429
 
        bool show, set, systohc, hctosys, systz, adjust, getepoch, setepoch;
 
1457
        bool show, set, systohc, hctosys, systz, adjust, getepoch, setepoch, predict;
1430
1458
        bool utc, testing, local_opt, noadjfile, directisa;
1431
1459
        bool ARCconsole, Jensen, SRM, funky_toy;
1432
1460
        char *date_opt;
1456
1484
        textdomain(PACKAGE);
1457
1485
 
1458
1486
        /* Set option defaults */
1459
 
        show = set = systohc = hctosys = systz = adjust = noadjfile = FALSE;
 
1487
        show = set = systohc = hctosys = systz = adjust = noadjfile = predict = FALSE;
1460
1488
        getepoch = setepoch = utc = local_opt = testing = debug = FALSE;
1461
1489
        ARCconsole = Jensen = SRM = funky_toy = directisa = badyear = FALSE;
1462
1490
        date_opt = NULL;
1532
1560
                case 139:
1533
1561
                        systz = TRUE;                   /* --systz */
1534
1562
                        break;
 
1563
                case 140:
 
1564
                        predict = TRUE;                 /* --predict-hc */
 
1565
                        break;
1535
1566
                case 'f':
1536
1567
                        rtc_dev_name = optarg;          /* --rtc */
1537
1568
                        break;
1564
1595
        }
1565
1596
 
1566
1597
        if (show + set + systohc + hctosys + systz + adjust + getepoch
1567
 
            + setepoch > 1){
 
1598
            + setepoch + predict > 1){
1568
1599
                fprintf(stderr, _("You have specified multiple functions.\n"
1569
1600
                                  "You can only perform one function "
1570
1601
                                  "at a time.\n"));
1605
1636
        set_cmos_access(Jensen, funky_toy);
1606
1637
#endif
1607
1638
 
1608
 
        if (set) {
 
1639
        if (set || predict) {
1609
1640
                rc = interpret_date_string(date_opt, &set_time);
1610
1641
                /* (time-consuming) */
1611
1642
                if (rc != 0) {
1616
1647
        }
1617
1648
 
1618
1649
        if (!(show | set | systohc | hctosys | systz | adjust | getepoch
1619
 
              | setepoch))
 
1650
              | setepoch | predict))
1620
1651
                show = 1; /* default to show */
1621
1652
 
1622
1653
 
1653
1684
 
1654
1685
        if (debug)
1655
1686
                out_version();
1656
 
        if (!systz) {
 
1687
        if (!systz && !predict) {
1657
1688
                determine_clock_access_method(directisa);
1658
1689
                if (!ur) {
1659
1690
                        fprintf(stderr,
1670
1701
 
1671
1702
        rc = manipulate_clock(show, adjust, noadjfile, set, set_time,
1672
1703
                                hctosys, systohc, systz, startup_time, utc,
1673
 
                                local_opt, testing);
 
1704
                                local_opt, testing, predict);
1674
1705
        hwclock_exit(rc);
1675
1706
        return rc;      /* Not reached */
1676
1707
}