2008-07-21 17:36:57 +04:00
|
|
|
/* $NetBSD: screenblank.c,v 1.28 2008/07/21 13:36:59 lukem Exp $ */
|
1995-07-12 08:57:47 +04:00
|
|
|
|
1996-02-28 04:13:20 +03:00
|
|
|
/*-
|
2002-01-23 19:57:51 +03:00
|
|
|
* Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
|
1995-07-12 08:57:47 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
1996-02-28 04:13:20 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Jason R. Thorpe.
|
|
|
|
*
|
1995-07-12 08:57:47 +04:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
1996-02-28 04:13:20 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1997-07-31 02:53:50 +04:00
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
1996-02-28 04:13:20 +03:00
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
1995-07-12 08:57:47 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2002-01-23 19:57:51 +03:00
|
|
|
* Screensaver daemon for the Sun 3 and SPARC, and platforms using WSCONS.
|
1995-07-12 08:57:47 +04:00
|
|
|
*/
|
|
|
|
|
1997-07-24 00:22:48 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2008-07-21 17:36:57 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1996-2002\
|
|
|
|
The NetBSD Foundation, Inc. All rights reserved.");
|
|
|
|
__RCSID("$NetBSD: screenblank.c,v 1.28 2008/07/21 13:36:59 lukem Exp $");
|
1997-07-24 00:22:48 +04:00
|
|
|
#endif
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <paths.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
2001-10-28 04:32:46 +03:00
|
|
|
#include <syslog.h>
|
1995-07-12 08:57:47 +04:00
|
|
|
#include <unistd.h>
|
1999-06-06 07:27:35 +04:00
|
|
|
#include <util.h>
|
1995-07-12 08:57:47 +04:00
|
|
|
|
1998-12-18 04:15:43 +03:00
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
|
|
|
|
#ifdef HAVE_FBIO
|
2001-09-19 20:16:03 +04:00
|
|
|
#include <dev/sun/fbio.h>
|
1998-12-18 04:15:43 +03:00
|
|
|
#endif
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
#include "pathnames.h"
|
|
|
|
|
1998-12-18 04:15:43 +03:00
|
|
|
u_long setvideo = WSDISPLAYIO_SVIDEO; /* "set video" ioctl */
|
|
|
|
int videoon = WSDISPLAYIO_VIDEO_ON; /* value for "on" */
|
|
|
|
int videooff = WSDISPLAYIO_VIDEO_OFF; /* value for "off" */
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
struct dev_stat {
|
|
|
|
LIST_ENTRY(dev_stat) ds_link; /* linked list */
|
1998-12-18 04:15:43 +03:00
|
|
|
const char *ds_path; /* path to device */
|
1995-07-12 08:57:47 +04:00
|
|
|
int ds_isfb; /* boolean; framebuffer? */
|
|
|
|
time_t ds_atime; /* time device last accessed */
|
|
|
|
time_t ds_mtime; /* time device last modified */
|
|
|
|
};
|
|
|
|
LIST_HEAD(ds_list, dev_stat) ds_list;
|
|
|
|
|
2001-10-28 04:32:46 +03:00
|
|
|
int main(int, char *[]);
|
|
|
|
static void add_dev(const char *, int);
|
|
|
|
static void change_state(int);
|
2002-09-19 06:59:20 +04:00
|
|
|
static void cvt_arg(char *, struct timespec *);
|
2001-10-28 04:32:46 +03:00
|
|
|
static void sighandler(int);
|
2004-11-25 23:23:36 +03:00
|
|
|
static int is_graphics_fb(struct dev_stat *);
|
2001-10-28 04:32:46 +03:00
|
|
|
static void usage(void);
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
int
|
2001-10-28 04:32:46 +03:00
|
|
|
main(int argc, char *argv[])
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
|
|
|
struct dev_stat *dsp;
|
2002-09-19 06:59:20 +04:00
|
|
|
struct timespec timo_on, timo_off, *tvp, tv;
|
1995-07-12 08:57:47 +04:00
|
|
|
struct sigaction sa;
|
|
|
|
struct stat st;
|
|
|
|
int ch, change, fflag = 0, kflag = 0, mflag = 0, state;
|
2006-09-24 00:12:15 +04:00
|
|
|
int bflag = 0, uflag = 0;
|
1998-12-18 04:15:43 +03:00
|
|
|
const char *kbd, *mouse, *display;
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
LIST_INIT(&ds_list);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the default timeouts: 10 minutes on, .25 seconds off.
|
|
|
|
*/
|
|
|
|
timo_on.tv_sec = 600;
|
2002-09-19 06:59:20 +04:00
|
|
|
timo_on.tv_nsec = 0;
|
1995-07-12 08:57:47 +04:00
|
|
|
timo_off.tv_sec = 0;
|
2002-09-19 06:59:20 +04:00
|
|
|
timo_off.tv_nsec = 250000000;
|
1995-07-12 08:57:47 +04:00
|
|
|
|
2006-09-24 00:12:15 +04:00
|
|
|
while ((ch = getopt(argc, argv, "bd:e:f:i:kmu")) != -1) {
|
1995-07-12 08:57:47 +04:00
|
|
|
switch (ch) {
|
2006-09-24 00:12:15 +04:00
|
|
|
case 'b':
|
|
|
|
bflag = 1;
|
|
|
|
uflag = 0;
|
|
|
|
break;
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
case 'd':
|
|
|
|
cvt_arg(optarg, &timo_on);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'e':
|
|
|
|
cvt_arg(optarg, &timo_off);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
fflag = 1;
|
|
|
|
add_dev(optarg, 1);
|
|
|
|
break;
|
|
|
|
|
2002-01-24 04:34:13 +03:00
|
|
|
case 'i':
|
|
|
|
add_dev(optarg, 0);
|
|
|
|
break;
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
case 'k':
|
|
|
|
if (mflag || kflag)
|
|
|
|
usage();
|
|
|
|
kflag = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'm':
|
|
|
|
if (kflag || mflag)
|
|
|
|
usage();
|
|
|
|
mflag = 1;
|
|
|
|
break;
|
|
|
|
|
2006-09-24 00:12:15 +04:00
|
|
|
case 'u':
|
|
|
|
uflag = 1;
|
|
|
|
bflag = 0;
|
|
|
|
break;
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
if (argc)
|
|
|
|
usage();
|
|
|
|
|
1998-12-18 04:15:43 +03:00
|
|
|
/*
|
|
|
|
* Default to WSCONS support.
|
|
|
|
*/
|
|
|
|
kbd = _PATH_WSKBD;
|
|
|
|
mouse = _PATH_WSMOUSE;
|
|
|
|
display = _PATH_WSDISPLAY;
|
|
|
|
|
|
|
|
#ifdef HAVE_FBIO
|
|
|
|
/*
|
|
|
|
* If a display device wasn't specified, check to see which we
|
|
|
|
* have. If we can't open the WSCONS display, fall back to fbio.
|
|
|
|
*/
|
|
|
|
if (!fflag) {
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
if ((fd = open(display, O_RDONLY, 0666)) == -1)
|
|
|
|
setvideo = FBIOSVIDEO;
|
|
|
|
else
|
|
|
|
(void) close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do this here so that -f ... args above can influence us.
|
|
|
|
*/
|
|
|
|
if (setvideo == FBIOSVIDEO) {
|
|
|
|
videoon = FBVIDEO_ON;
|
|
|
|
videooff = FBVIDEO_OFF;
|
|
|
|
kbd = _PATH_KEYBOARD;
|
|
|
|
mouse = _PATH_MOUSE;
|
|
|
|
display = _PATH_FB;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-24 00:12:15 +04:00
|
|
|
/*
|
2006-09-24 05:57:03 +04:00
|
|
|
* Add the default framebuffer device if necessary.
|
|
|
|
* We _always_ check the console device.
|
|
|
|
*/
|
|
|
|
add_dev(_PATH_CONSOLE, 0);
|
|
|
|
if (!fflag)
|
|
|
|
add_dev(display, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is an one-off blank/unblank request, handle it now.
|
|
|
|
* We don't need to open keyboard/mouse device for that.
|
2006-09-24 00:12:15 +04:00
|
|
|
*/
|
|
|
|
if (bflag || uflag) {
|
|
|
|
change_state(bflag ? videooff : videoon);
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2006-09-24 05:57:03 +04:00
|
|
|
|
|
|
|
/* Add the keyboard and mouse devices as necessary. */
|
1995-07-12 08:57:47 +04:00
|
|
|
if (!kflag)
|
1998-12-18 04:15:43 +03:00
|
|
|
add_dev(kbd, 0);
|
1995-07-12 08:57:47 +04:00
|
|
|
if (!mflag)
|
1998-12-18 04:15:43 +03:00
|
|
|
add_dev(mouse, 0);
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
/* Ensure that the framebuffer is on. */
|
1998-12-18 04:15:43 +03:00
|
|
|
state = videoon;
|
1995-07-12 08:57:47 +04:00
|
|
|
change_state(state);
|
|
|
|
tvp = &timo_on;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure the framebuffer gets turned back on when we're
|
|
|
|
* killed.
|
|
|
|
*/
|
|
|
|
sa.sa_handler = sighandler;
|
|
|
|
sa.sa_flags = SA_NOCLDSTOP;
|
1996-06-24 02:08:43 +04:00
|
|
|
if (sigemptyset(&sa.sa_mask))
|
|
|
|
err(1, "sigemptyset");
|
1995-07-12 08:57:47 +04:00
|
|
|
if (sigaction(SIGINT, &sa, NULL) || sigaction(SIGTERM, &sa, NULL) ||
|
|
|
|
sigaction(SIGHUP, &sa, NULL))
|
|
|
|
err(1, "sigaction");
|
|
|
|
|
2001-10-28 04:32:46 +03:00
|
|
|
openlog("screenblank", LOG_PID, LOG_DAEMON);
|
1995-07-12 08:57:47 +04:00
|
|
|
/* Detach. */
|
|
|
|
if (daemon(0, 0))
|
|
|
|
err(1, "daemon");
|
1999-06-06 07:27:35 +04:00
|
|
|
pidfile(NULL);
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
/* Start the state machine. */
|
|
|
|
for (;;) {
|
|
|
|
change = 0;
|
2005-11-11 18:14:24 +03:00
|
|
|
LIST_FOREACH(dsp, &ds_list, ds_link) {
|
2004-11-25 23:23:36 +03:00
|
|
|
/* Don't check framebuffers in graphics mode. */
|
|
|
|
if (is_graphics_fb(dsp))
|
1995-07-12 08:57:47 +04:00
|
|
|
continue;
|
2001-10-28 04:32:46 +03:00
|
|
|
if (stat(dsp->ds_path, &st) == -1) {
|
|
|
|
syslog(LOG_CRIT,
|
|
|
|
"Can't stat `%s' (%m)", dsp->ds_path);
|
|
|
|
exit(1);
|
|
|
|
}
|
1995-07-12 08:57:47 +04:00
|
|
|
if (st.st_atime > dsp->ds_atime) {
|
|
|
|
change = 1;
|
|
|
|
dsp->ds_atime = st.st_atime;
|
|
|
|
}
|
|
|
|
if (st.st_mtime > dsp->ds_mtime) {
|
|
|
|
change = 1;
|
|
|
|
dsp->ds_mtime = st.st_mtime;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-12-18 04:15:43 +03:00
|
|
|
if (state == videoon) {
|
1995-07-12 08:57:47 +04:00
|
|
|
if (!change) {
|
1998-12-18 04:15:43 +03:00
|
|
|
state = videooff;
|
1995-07-12 08:57:47 +04:00
|
|
|
change_state(state);
|
|
|
|
tvp = &timo_off;
|
|
|
|
}
|
1998-12-18 04:15:43 +03:00
|
|
|
} else {
|
1995-07-12 08:57:47 +04:00
|
|
|
if (change) {
|
1998-12-18 04:15:43 +03:00
|
|
|
state = videoon;
|
1995-07-12 08:57:47 +04:00
|
|
|
change_state(state);
|
|
|
|
tvp = &timo_on;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-10-28 04:32:46 +03:00
|
|
|
tv = *tvp;
|
2002-09-19 06:59:20 +04:00
|
|
|
if (nanosleep(&tv, NULL) == -1)
|
|
|
|
err(1, "nanosleep");
|
1995-07-12 08:57:47 +04:00
|
|
|
}
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-28 04:32:46 +03:00
|
|
|
add_dev(const char *path, int isfb)
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
1998-12-18 04:15:43 +03:00
|
|
|
struct dev_stat *dsp;
|
2001-11-01 22:06:08 +03:00
|
|
|
struct stat sb;
|
1998-12-18 04:15:43 +03:00
|
|
|
|
2001-11-07 01:56:02 +03:00
|
|
|
/* Make sure we can stat the device. */
|
2001-11-01 22:06:08 +03:00
|
|
|
if (stat(path, &sb) == -1) {
|
|
|
|
warn("Can't stat `%s'", path);
|
2001-10-28 04:32:46 +03:00
|
|
|
return;
|
|
|
|
}
|
1998-12-18 04:15:43 +03:00
|
|
|
|
|
|
|
#ifdef HAVE_FBIO
|
|
|
|
/*
|
|
|
|
* We default to WSCONS. If this is a frame buffer
|
|
|
|
* device, check to see if it responds to the old
|
|
|
|
* Sun-style fbio ioctls. If so, switch to fbio mode.
|
|
|
|
*/
|
|
|
|
if (isfb && setvideo != FBIOSVIDEO) {
|
2001-11-01 22:06:08 +03:00
|
|
|
int onoff, fd;
|
1998-12-18 04:15:43 +03:00
|
|
|
|
2001-11-01 22:06:08 +03:00
|
|
|
if ((fd = open(path, O_RDWR, 0666)) == -1) {
|
|
|
|
warn("Can't open `%s'", path);
|
|
|
|
return;
|
|
|
|
}
|
1998-12-18 04:15:43 +03:00
|
|
|
if ((ioctl(fd, FBIOGVIDEO, &onoff)) == 0)
|
|
|
|
setvideo = FBIOSVIDEO;
|
2001-11-01 22:06:08 +03:00
|
|
|
(void)close(fd);
|
1998-12-18 04:15:43 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
/* Create the entry... */
|
1998-12-18 04:15:43 +03:00
|
|
|
dsp = malloc(sizeof(struct dev_stat));
|
|
|
|
if (dsp == NULL)
|
2001-10-28 04:32:46 +03:00
|
|
|
err(1, "Can't allocate memory for `%s'", path);
|
|
|
|
(void)memset(dsp, 0, sizeof(struct dev_stat));
|
1998-12-18 04:15:43 +03:00
|
|
|
dsp->ds_path = path;
|
|
|
|
dsp->ds_isfb = isfb;
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
/* ...and put it in the list. */
|
1998-12-18 04:15:43 +03:00
|
|
|
LIST_INSERT_HEAD(&ds_list, dsp, ds_link);
|
1995-07-12 08:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ARGSUSED */
|
|
|
|
static void
|
2001-10-28 04:32:46 +03:00
|
|
|
sighandler(int sig)
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
/* Kill the pid file and re-enable the framebuffer before exit. */
|
1998-12-18 04:15:43 +03:00
|
|
|
change_state(videoon);
|
1995-07-12 08:57:47 +04:00
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2004-11-25 23:23:36 +03:00
|
|
|
/*
|
|
|
|
* Return 1 if we are a framebuffer in graphics mode or a framebuffer
|
|
|
|
* where we cannot tell the mode. Return 0 if we are not a framebuffer
|
|
|
|
* device, or a wscons framebuffer in text mode.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
is_graphics_fb(struct dev_stat *dsp)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
int state;
|
|
|
|
|
|
|
|
if (dsp->ds_isfb == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* We can't tell if we are not a wscons device */
|
|
|
|
if (setvideo != WSDISPLAYIO_SVIDEO)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if ((fd = open(dsp->ds_path, O_RDWR, 0)) == -1) {
|
|
|
|
syslog(LOG_WARNING, "Cannot open `%s' (%m)", dsp->ds_path);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ioctl(fd, WSDISPLAYIO_GMODE, &state) == -1) {
|
|
|
|
syslog(LOG_WARNING, "Cannot get mode on `%s' (%m)",
|
|
|
|
dsp->ds_path);
|
|
|
|
/* We can't tell, so we say we are mapped */
|
|
|
|
state = WSDISPLAYIO_MODE_MAPPED;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)close(fd);
|
|
|
|
|
|
|
|
return state != WSDISPLAYIO_MODE_EMUL;
|
|
|
|
}
|
|
|
|
|
1995-07-12 08:57:47 +04:00
|
|
|
static void
|
2001-10-28 04:32:46 +03:00
|
|
|
change_state(int state)
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
|
|
|
struct dev_stat *dsp;
|
|
|
|
int fd;
|
2001-10-28 04:32:46 +03:00
|
|
|
int fail = 1;
|
1995-07-12 08:57:47 +04:00
|
|
|
|
2005-11-11 18:14:24 +03:00
|
|
|
LIST_FOREACH(dsp, &ds_list, ds_link) {
|
1995-07-12 08:57:47 +04:00
|
|
|
/* Don't change the state of non-framebuffers! */
|
|
|
|
if (dsp->ds_isfb == 0)
|
|
|
|
continue;
|
2001-10-28 04:32:46 +03:00
|
|
|
if ((fd = open(dsp->ds_path, O_RDWR, 0)) == -1) {
|
|
|
|
syslog(LOG_WARNING, "Can't open `%s' (%m)",
|
|
|
|
dsp->ds_path);
|
1995-07-12 08:57:47 +04:00
|
|
|
continue;
|
|
|
|
}
|
2001-10-28 04:32:46 +03:00
|
|
|
if (ioctl(fd, setvideo, &state) == -1)
|
|
|
|
syslog(LOG_WARNING, "Can't set video on `%s' (%m)",
|
|
|
|
dsp->ds_path);
|
|
|
|
else
|
|
|
|
fail = 0;
|
1995-07-12 08:57:47 +04:00
|
|
|
(void)close(fd);
|
|
|
|
}
|
2001-10-28 04:32:46 +03:00
|
|
|
if (fail) {
|
|
|
|
syslog(LOG_CRIT, "No frame buffer devices, exiting\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1995-07-12 08:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-09-19 06:59:20 +04:00
|
|
|
cvt_arg(char *arg, struct timespec *tvp)
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
|
|
|
char *cp;
|
2002-09-19 06:59:20 +04:00
|
|
|
int seconds, nanoseconds, factor;
|
1995-07-12 08:57:47 +04:00
|
|
|
int period = 0;
|
2002-09-19 06:59:20 +04:00
|
|
|
factor = 1000000000;
|
|
|
|
nanoseconds = 0;
|
1998-05-15 01:49:13 +04:00
|
|
|
seconds = 0;
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
for (cp = arg; *cp != '\0'; ++cp) {
|
|
|
|
if (*cp == '.') {
|
|
|
|
if (period)
|
2001-10-28 04:32:46 +03:00
|
|
|
errx(1, "Invalid argument: %s", arg);
|
1995-07-12 08:57:47 +04:00
|
|
|
period = 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2004-10-30 19:39:39 +04:00
|
|
|
if (!isdigit((unsigned char)*cp))
|
2001-10-28 04:32:46 +03:00
|
|
|
errx(1, "Invalid argument: %s", arg);
|
1995-07-12 08:57:47 +04:00
|
|
|
|
|
|
|
if (period) {
|
1998-05-15 01:49:13 +04:00
|
|
|
if (factor > 1) {
|
2002-09-19 06:59:20 +04:00
|
|
|
nanoseconds = nanoseconds * 10 + (*cp - '0');
|
1998-05-15 01:49:13 +04:00
|
|
|
factor /= 10;
|
|
|
|
}
|
1995-07-12 08:57:47 +04:00
|
|
|
} else
|
1998-05-15 01:49:13 +04:00
|
|
|
seconds = (seconds * 10) + (*cp - '0');
|
1995-07-12 08:57:47 +04:00
|
|
|
}
|
|
|
|
|
1998-05-15 01:49:13 +04:00
|
|
|
tvp->tv_sec = seconds;
|
|
|
|
if (factor > 1)
|
2002-09-19 06:59:20 +04:00
|
|
|
nanoseconds *= factor;
|
2006-09-24 00:12:15 +04:00
|
|
|
|
2002-09-19 06:59:20 +04:00
|
|
|
tvp->tv_nsec = nanoseconds;
|
1995-07-12 08:57:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2001-10-28 04:32:46 +03:00
|
|
|
usage(void)
|
1995-07-12 08:57:47 +04:00
|
|
|
{
|
|
|
|
|
2001-10-28 04:32:46 +03:00
|
|
|
(void)fprintf(stderr,
|
2004-01-06 02:23:32 +03:00
|
|
|
"usage: %s [-k | -m] [-d inactivity-timeout] [-e wakeup-delay]\n"
|
2006-09-24 00:26:25 +04:00
|
|
|
"\t\t[-f framebuffer] [-i input-device]\n"
|
|
|
|
" %s {-b | -u}\n",
|
|
|
|
getprogname(),
|
2001-10-28 04:32:46 +03:00
|
|
|
getprogname());
|
1995-07-12 08:57:47 +04:00
|
|
|
exit(1);
|
|
|
|
}
|