LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   rtc linux - setting the time (https://www.linuxquestions.org/questions/linux-newbie-8/rtc-linux-setting-the-time-907895/)

prabhuraj 10-13-2011 02:13 AM

rtc linux - setting the time
 
Hi all,
I working on a RTC(linux os) project where in I have to set the current date and time.I am using ioctl for reading and setting the time.I have used the linux_rtc_time struct mentioned in man page rtc.
When I use ioctl(rtc, RTC_SET_TIME, &tm) it is not giving rtc = -1.
I have used struct rtc_time tm. When I checked,I got to know that to set the RTC we should set CAP_SYS_TIME capability.Can anyone help me?

thanks

smallpond 10-13-2011 12:22 PM

Quote:

Originally Posted by prabhuraj (Post 4497149)
Hi all,
I working on a RTC(linux os) project where in I have to set the current date and time.I am using ioctl for reading and setting the time.I have used the linux_rtc_time struct mentioned in man page rtc.
When I use ioctl(rtc, RTC_SET_TIME, &tm) it is not giving rtc = -1.
I have used struct rtc_time tm. When I checked,I got to know that to set the RTC we should set CAP_SYS_TIME capability.Can anyone help me?

I am confused by your question. Your code should look something like this:

Code:

    int rtc, res;  /* note: two different variables */
    struct rtc_time tm;
    rtc = open("/dev/rtc", O_RDONLY);
    /* You must always check the result of open */
    if (rtc < 0) {
        print_error_and_die(rtc, errno);
    }
    res = ioctl(rtc, RTC_SET_TIME, &tm);
    if (res = -1) {
        print_error_and_die(res, errno);
    }
    print_success;

You likely won't be able to run this code except as root. Other users do not have hardware access unless you change permissions, especially if selinux is enabled.

prabhuraj 10-13-2011 12:57 PM

rtc
 
Hi,
Thanks a lot for your reply..
I already have followed and used a code as you mentioned. I am getting problem in setting the time using RTC_SET_TIME and when I searched in net I got to know that we have to set the capability CAP_SYS_TIME. You can have look at MAN RTC in linux and you will get the problem I am facing.

Thanks

smallpond 10-13-2011 02:39 PM

Quote:

Originally Posted by prabhuraj (Post 4497596)
Hi,
Thanks a lot for your reply..
I already have followed and used a code as you mentioned. I am getting problem in setting the time using RTC_SET_TIME and when I searched in net I got to know that we have to set the capability CAP_SYS_TIME. You can have look at MAN RTC in linux and you will get the problem I am facing.

Are you running as root? As I said, you won't be able to do this except as root.

Capabilities are a way of giving specific privileges to processes so they don't have to be run as root, but AFAIK a root process would still have to invoke the process to give it the capability.

prabhuraj 10-13-2011 11:59 PM

rtc
 
I am running in root. I only want to know a way provide the capabilities.An example code regarding this will be very helpful.

Thanks


All times are GMT -5. The time now is 11:16 PM.