PATCH] [2/2] util-linux-ng/sys-utils/rtcwake : add disable action/mode for rtc alarm

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

 



On Wednesday 27 of January 2010 11:59:00 you wrote:
>  Hi Marek,
> 
>  (sorry for delay, but I'm ill in last days...)
> 
> 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:
> 
>         # 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-0
> > 4 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.
> 
> > +		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

Change log: 
* update man pages (disable mode to rtcwake)

Signed-off-by: Marek Otahal <markotahal@xxxxxxxxx> 

Patch: 
--- ../../util-linux-ng/sys-utils/rtcwake.8     2010-04-14 18:31:25.094015939 
+0200
+++ rtcwake.8   2010-04-14 18:58:00.631357626 +0200
@@ -114,6 +114,9 @@
 .B on
 Don't suspend, but read RTC device until alarm time appears. This mode is
 useful for debugging.
+.TP
+.B disable
+Disable previously set alarm [on specified device -d].
 .RE
 .PP
 .SH NOTES



-- 

Marek Otahal :o)
--- ../../util-linux-ng/sys-utils/rtcwake.8	2010-04-14 18:31:25.094015939 +0200
+++ rtcwake.8	2010-04-14 18:58:00.631357626 +0200
@@ -114,6 +114,9 @@
 .B on
 Don't suspend, but read RTC device until alarm time appears. This mode is
 useful for debugging.
+.TP
+.B disable
+Disable previously set alarm [on specified device -d].
 .RE
 .PP
 .SH NOTES

[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