[Bug/Testcase]: sys-utils/rtcwake RTC Alarm problem setting date further months/years

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

 



Hello, 

please check and test the code included. I'm either stupid or there is 
something smelly.. 

I'm unable to set RTC alarm date to different month and year than now. (time 
and days work ok). I use ioctl and RTC_WKALM_RD/SET flags. 

I noticed this when working on rtcwake code, Both util-linux-ng 2.17.2 and 
git. Kernel 2.6.33.2, archlinux latest userland.

Thanks, Marek

The code: 

/*
 *	Real Time Clock Driver Test/Example Program
 *
 *	Compile with:
 *		gcc -s -Wall -Wstrict-prototypes rtctest.c -o rtctest
 *
 *
 *	Released under the GNU General Public License, version 2,
 *	included herein by reference.
 *
 */
#include <stdio.h>
#include <string.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

int main(void) {


    int fd, retval = 0;
    struct rtc_wkalrm wk;

    fd = open("/dev/rtc", O_RDONLY);
    if (fd == -1) {
        perror("/dev/rtc");
        return -1;
    }

    fprintf(stderr, "\n\t\t\tRTC Driver Test Example.\n\n");


    /* Read the RTC time/date */
    retval = ioctl(fd, RTC_WKALM_RD, &wk);
    if (retval == -1) {
        perror("ioctl WLALM rd");
        return -1;
    }
    time_t t=time(0); //now
    char* msg=0;
    msg=ctime(&t);
    fprintf(stderr,"Current time and date is: %s",msg);
    fprintf(stderr, "Current RTC Alarm date/time is %d-%d-%d, %02d:%02d:%02d.
\n",
            wk.time.tm_mday, wk.time.tm_mon + 1, wk.time.tm_year + 1900,
            wk.time.tm_hour, wk.time.tm_min, wk.time.tm_sec);

    // set alarm time to future - values in months and years must change, 
these make me troubles.
    wk.time.tm_year = 2012 - 1900; //tp.tm_year;
    wk.time.tm_mon = 8 - 1;
    wk.time.tm_mday = 24;
    wk.time.tm_hour = 11;
    wk.time.tm_min = 22;
    wk.time.tm_sec = 33;
    // these 3 are ignored by linux
    wk.time.tm_isdst = -1;
    wk.time.tm_wday = -1;
    wk.time.tm_yday = -1;
    wk.enabled = 1;
    wk.pending = 1;

    retval = ioctl(fd, RTC_WKALM_SET, &wk);
    if (retval == -1) {
        perror("ioctl SET");
        return -1;
    }

    /* Read the new alarm settings */
    retval = ioctl(fd, RTC_WKALM_RD, &wk);
    if (retval == -1) {
        perror("ioctl RD");
        return -1;
    }

    fprintf(stderr, "New RTC ALARM date/time is %d-%d-%d, %02d:%02d:%02d.\n",
            wk.time.tm_mday, wk.time.tm_mon + 1, wk.time.tm_year + 1900,
            wk.time.tm_hour, wk.time.tm_min, wk.time.tm_sec);
    fprintf(stderr, "\nCheck whether the month and year values in the date 
field differ from current time!");

    fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n Thank you \n\n");
    fflush(stderr);
    close(fd);
    return 0;
} 

-- 

Marek Otahal :o)
/*
 *	Real Time Clock Driver Test/Example Program
 *
 *	Compile with:
 *		gcc -s -Wall -Wstrict-prototypes rtctest.c -o rtctest
 *
 *
 *	Released under the GNU General Public License, version 2,
 *	included herein by reference.
 *
 */
#include <stdio.h>
#include <string.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>

int main(void) {


    int fd, retval = 0;
    struct rtc_wkalrm wk;

    fd = open("/dev/rtc", O_RDONLY);
    if (fd == -1) {
        perror("/dev/rtc");
        return -1;
    }

    fprintf(stderr, "\n\t\t\tRTC Driver Test Example.\n\n");


    /* Read the RTC time/date */
    retval = ioctl(fd, RTC_WKALM_RD, &wk);
    if (retval == -1) {
        perror("ioctl WLALM rd");
        return -1;
    }
    time_t t=time(0); //now
    char* msg=0;
    msg=ctime(&t);
    fprintf(stderr,"Current time and date is: %s",msg);
    fprintf(stderr, "Current RTC Alarm date/time is %d-%d-%d, %02d:%02d:%02d.\n",
            wk.time.tm_mday, wk.time.tm_mon + 1, wk.time.tm_year + 1900,
            wk.time.tm_hour, wk.time.tm_min, wk.time.tm_sec);

    // set alarm time to future - values in months and years must change, these make me troubles.
    wk.time.tm_year = 2012 - 1900; //tp.tm_year;
    wk.time.tm_mon = 8 - 1;
    wk.time.tm_mday = 24;
    wk.time.tm_hour = 11;
    wk.time.tm_min = 22;
    wk.time.tm_sec = 33;
    // these 3 are ignored by linux
    wk.time.tm_isdst = -1;
    wk.time.tm_wday = -1;
    wk.time.tm_yday = -1;
    wk.enabled = 1;
    wk.pending = 1;

    retval = ioctl(fd, RTC_WKALM_SET, &wk);
    if (retval == -1) {
        perror("ioctl SET");
        return -1;
    }

    /* Read the new alarm settings */
    retval = ioctl(fd, RTC_WKALM_RD, &wk);
    if (retval == -1) {
        perror("ioctl RD");
        return -1;
    }

    fprintf(stderr, "New RTC ALARM date/time is %d-%d-%d, %02d:%02d:%02d.\n",
            wk.time.tm_mday, wk.time.tm_mon + 1, wk.time.tm_year + 1900,
            wk.time.tm_hour, wk.time.tm_min, wk.time.tm_sec);
    fprintf(stderr, "\nCheck whether the month and year values in the date field differ from current time!");

    fprintf(stderr, "\n\n\t\t\t *** Test complete ***\n Thank you \n\n");
    fflush(stderr);
    close(fd);
    return 0;
} 

[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