LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-13-2011, 03:13 AM   #1
prabhuraj
LQ Newbie
 
Registered: Aug 2011
Posts: 26

Rep: Reputation: Disabled
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
 
Old 10-13-2011, 01:22 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,666

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
Quote:
Originally Posted by prabhuraj View Post
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.
 
Old 10-13-2011, 01:57 PM   #3
prabhuraj
LQ Newbie
 
Registered: Aug 2011
Posts: 26

Original Poster
Rep: Reputation: Disabled
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
 
Old 10-13-2011, 03:39 PM   #4
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,666

Rep: Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710Reputation: 710
Quote:
Originally Posted by prabhuraj View Post
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.
 
Old 10-14-2011, 12:59 AM   #5
prabhuraj
LQ Newbie
 
Registered: Aug 2011
Posts: 26

Original Poster
Rep: Reputation: Disabled
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RTC Alarm wakes up, even while BIOS has RTC alarm disabled mastermind2501 Linux - Newbie 2 12-22-2008 04:32 PM
Problems setting time and time zone in RH Linux am_mitra Linux - Newbie 1 12-03-2008 09:09 PM
date command counts time quicker than hwclock (RTC) carl0ski Linux - Software 2 12-29-2005 06:32 AM
Real Time Clock(RTC) problem gongcon Linux - Software 6 01-06-2005 10:36 PM
RTC time on a locally set clock pe2338 Debian 8 09-06-2003 05:30 AM


All times are GMT -5. The time now is 12:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration