Re: [PATCH] util-linux-ng/sys-utils/rtcwake : add show and disable actions/modes for rtc alarm

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

 



On Wed, Jan 27, 2010 at 11:59 AM, Karel Zak <kzak@xxxxxxxxxx> wrote:
>
>  Hi Marek,
>
>  (sorry for delay, but I'm ill in last days...)



Hello Karel,
first, I'd like to thank you for your advice and hope you get well soon!


>
> On Thu, Jan 07, 2010 at 08:26:58PM +0100, Marek Otahal wrote:
>> Changelog:
>>
>> Support for 'show' and 'disable' actions/modes (rtcwake -m <mode>)
>> * show : print current alarm settings (from /proc/driver/rtc)
>
>  this is nice idea, but the implementation is poor. It'd be nice to
>  have more user friendly output (convert to the local time, print
>  important information only, ...), for example:
>


I'm glad you like it:) Being not a good friend with C but will try to
get the code to an acceptable shape :p (or if sb more experienced can
help? )
I would especially like these features added as I'd like add an 'alarm
clock (even if suspended)' support to kalarm in kde or other apps.


>        # rtcwake --show
>        PENDING, alarm time: 11:22:33
>
>  maybe we can also use RTC_WKALM_RD ioctl instead /proc.
>
>> * disable: disable alarm on [optionally specified -d] rtc device
>
>  Good idea.
>
>> --- sys-utils/rtcwake.c       2010-01-07 19:08:21.673672059 +0100
>> +++ ../../util-linux-ng/util-linux-ng-2.17-rc3/sys-utils/rtcwake.c    2010-01-04 20:16:51.444954038 +0100
>> @@ -54,7 +54,7 @@
>>  #define ADJTIME_PATH         "/etc/adjtime"
>>  #define DEFAULT_DEVICE               "/dev/rtc0"
>>  #define DEFAULT_MODE         "standby"
>> -
>> +#define RTC_INFO             "/proc/driver/rtc"
>>  enum ClockMode {
>>       CM_AUTO,
>>       CM_UTC,
>> @@ -291,6 +291,35 @@
>>       return 0;
>>  }
>>
>> +static int disable_alarm(int fd) {
>> +     if (ioctl(fd, RTC_AIE_OFF, 0) < 0) {
>> +             perror(_("disable rtc alarm interrupt"));
>> +             return -1;
>> +     }
>> +     return 0;
>> +}
>> +
>> +static int print_alarm(void) {
>> +     int f = 0;
>> +     f = open(RTC_INFO, O_RDONLY);
>> +     if(f<0) {
>> +             fprintf(stderr, "Cannot open %s for reading .\n", RTC_INFO);
>> +             return 1;
>> +     }
>> +
>> +     char buf;
>> +     int i = 0;
>> +
>> +     do {
>> +             i = read(f, &buf, sizeof buf);
>> +             fprintf(stdout, "%c", buf);
>> +             buf = ' ';
>> +     }while( i > 0);
>> +
>> +     close(f);
>> +     return 0;
>> +}
>> +
>>  int main(int argc, char **argv)
>>  {
>>       char            *devname = DEFAULT_DEVICE;
>> @@ -338,6 +367,8 @@
>>                                       || strcmp(optarg, "on") == 0
>>                                       || strcmp(optarg, "no") == 0
>>                                       || strcmp(optarg, "off") == 0
>> +                                     || strcmp(optarg, "show") == 0
>> +                                     || strcmp(optarg, "disable") == 0
>>                          ) {
>>                               suspend = strdup(optarg);
>>                               break;
>> @@ -403,7 +434,7 @@
>>               printf(clock_mode == CM_UTC ? _("Using UTC time.\n") :
>>                               _("Using local time.\n"));
>>
>> -     if (!alarm && !seconds) {
>> +     if ( (!alarm && !seconds) && strcmp(suspend, "show") != 0 && strcmp(suspend, "disable") != 0 ) {
>>               fprintf(stderr, _("%s: must provide wake time\n"), progname);
>>               usage(EXIT_FAILURE);
>>       }
>> @@ -468,9 +499,11 @@
>>       fflush(stdout);
>>       usleep(10 * 1000);
>>
>> -     if (strcmp(suspend, "no") == 0)
>> +     if (strcmp(suspend, "no") == 0) {
>>               exit(EXIT_SUCCESS);
>> -     else if (strcmp(suspend, "on") != 0) {
>> +     }
>> +     // determine supported suspend action (nowadays only "mem" or "disk") & do the suspend
>> +     else if ( (strcmp(suspend, "mem") == 0) || (strcmp(suspend, "disk") == 0) ) {
>>               sync();
>>               suspend_system(suspend);
>>       } else if (strcmp(suspend, "off") == 0) {
>> @@ -487,7 +520,19 @@
>>               fprintf(stderr, _("%s: unable to execute %s: %s\n"),
>>                               progname, _PATH_SHUTDOWN, strerror(errno));
>>               rc = EXIT_FAILURE;
>> -     } else {
>> +     } else if(strcmp(suspend, "show") == 0) {
>> +             // print alarm info
>> +             fprintf(stdout, "Current alarm settings by rtc: \n");
>> +             print_alarm();
>
>  We shouldn't ignore return value from print_alarm(), the same problem
>  I see with suspend_system() call in the rtcwake code.
>


Ok, I'll try to look at some exception handling here.


>> +             close(fd);
>> +             return rc;
>> +
>> +     } else if(strcmp(suspend, "disable") == 0) {
>> +             // disable the alarm
>> +             fprintf(stdout, "Disabling alarm on device %s \n", devname);
>> +             // alarm is always disabled at the end, so just print info and skip
>> +
>> +     } else { // mode "on", "standby"
>>               unsigned long data;
>>
>>               do {
>> @@ -501,9 +546,7 @@
>>               } while (!(data & RTC_AF));
>>       }
>>
>> -     if (ioctl(fd, RTC_AIE_OFF, 0) < 0)
>> -             perror(_("disable rtc alarm interrupt"));
>> -
>> +     disable_alarm(fd);
>>       close(fd);
>>
>>       return rc;
>
>  Please, use CC: to util-linux-ng mailing list. Thanks.
>
>    Karel


Thanks and recover well soon.
Best regards, Marek

PS: zdravim spravne do Cech?



>
> --
>  Karel Zak  <kzak@xxxxxxxxxx>
>



-- 
Marek Otahal :o)
--
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