Home | History | Annotate | Line # | Download | only in screenblank
screenblank.c revision 1.27.2.1
      1  1.27.2.1  wrstuden /*	$NetBSD: screenblank.c,v 1.27.2.1 2008/09/18 04:30:14 wrstuden Exp $	*/
      2       1.1   thorpej 
      3       1.2   thorpej /*-
      4      1.16     lukem  * Copyright (c) 1996-2002 The NetBSD Foundation, Inc.
      5       1.1   thorpej  * All rights reserved.
      6       1.1   thorpej  *
      7       1.2   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8       1.2   thorpej  * by Jason R. Thorpe.
      9       1.2   thorpej  *
     10       1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     11       1.1   thorpej  * modification, are permitted provided that the following conditions
     12       1.1   thorpej  * are met:
     13       1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     14       1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     15       1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     18       1.1   thorpej  *
     19       1.2   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.2   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.2   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.6       jtc  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.6       jtc  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.2   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.2   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.2   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.2   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.2   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.2   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1   thorpej  */
     31       1.1   thorpej 
     32       1.1   thorpej /*
     33      1.16     lukem  * Screensaver daemon for the Sun 3 and SPARC, and platforms using WSCONS.
     34       1.1   thorpej  */
     35       1.1   thorpej 
     36       1.5   thorpej #include <sys/cdefs.h>
     37       1.5   thorpej #ifndef lint
     38  1.27.2.1  wrstuden __COPYRIGHT("@(#) Copyright (c) 1996-2002\
     39  1.27.2.1  wrstuden  The NetBSD Foundation, Inc.  All rights reserved.");
     40  1.27.2.1  wrstuden __RCSID("$NetBSD: screenblank.c,v 1.27.2.1 2008/09/18 04:30:14 wrstuden Exp $");
     41       1.5   thorpej #endif
     42       1.5   thorpej 
     43       1.1   thorpej #include <sys/types.h>
     44       1.1   thorpej #include <sys/time.h>
     45       1.1   thorpej #include <sys/stat.h>
     46       1.1   thorpej #include <sys/ioctl.h>
     47       1.1   thorpej #include <sys/queue.h>
     48       1.1   thorpej #include <ctype.h>
     49       1.1   thorpej #include <err.h>
     50       1.1   thorpej #include <errno.h>
     51       1.1   thorpej #include <fcntl.h>
     52       1.1   thorpej #include <limits.h>
     53       1.1   thorpej #include <math.h>
     54       1.1   thorpej #include <paths.h>
     55       1.1   thorpej #include <stdlib.h>
     56       1.1   thorpej #include <stdio.h>
     57       1.1   thorpej #include <string.h>
     58       1.1   thorpej #include <signal.h>
     59      1.13  christos #include <syslog.h>
     60       1.1   thorpej #include <unistd.h>
     61      1.10   thorpej #include <util.h>
     62       1.1   thorpej 
     63       1.9   thorpej #include <dev/wscons/wsconsio.h>
     64       1.9   thorpej 
     65       1.9   thorpej #ifdef HAVE_FBIO
     66      1.12   thorpej #include <dev/sun/fbio.h>
     67       1.9   thorpej #endif
     68       1.1   thorpej 
     69       1.1   thorpej #include "pathnames.h"
     70       1.1   thorpej 
     71       1.9   thorpej u_long	setvideo = WSDISPLAYIO_SVIDEO;		/* "set video" ioctl */
     72       1.9   thorpej int	videoon  = WSDISPLAYIO_VIDEO_ON;	/* value for "on" */
     73       1.9   thorpej int	videooff = WSDISPLAYIO_VIDEO_OFF;	/* value for "off" */
     74       1.9   thorpej 
     75       1.1   thorpej struct	dev_stat {
     76       1.1   thorpej 	LIST_ENTRY(dev_stat) ds_link;	/* linked list */
     77       1.9   thorpej 	const char *ds_path;		/* path to device */
     78       1.1   thorpej 	int	ds_isfb;		/* boolean; framebuffer? */
     79       1.1   thorpej 	time_t	ds_atime;		/* time device last accessed */
     80       1.1   thorpej 	time_t	ds_mtime;		/* time device last modified */
     81       1.1   thorpej };
     82       1.1   thorpej LIST_HEAD(ds_list, dev_stat) ds_list;
     83       1.1   thorpej 
     84      1.13  christos int	main(int, char *[]);
     85      1.13  christos static	void add_dev(const char *, int);
     86      1.13  christos static	void change_state(int);
     87      1.19   mycroft static	void cvt_arg(char *, struct timespec *);
     88      1.13  christos static	void sighandler(int);
     89      1.22  christos static	int is_graphics_fb(struct dev_stat *);
     90      1.13  christos static	void usage(void);
     91       1.1   thorpej 
     92       1.1   thorpej int
     93      1.13  christos main(int argc, char *argv[])
     94       1.1   thorpej {
     95       1.1   thorpej 	struct dev_stat *dsp;
     96      1.19   mycroft 	struct timespec timo_on, timo_off, *tvp, tv;
     97       1.1   thorpej 	struct sigaction sa;
     98       1.1   thorpej 	struct stat st;
     99       1.1   thorpej 	int ch, change, fflag = 0, kflag = 0, mflag = 0, state;
    100      1.24      elad 	int bflag = 0, uflag = 0;
    101       1.9   thorpej 	const char *kbd, *mouse, *display;
    102       1.1   thorpej 
    103       1.1   thorpej 	LIST_INIT(&ds_list);
    104       1.1   thorpej 
    105       1.1   thorpej 	/*
    106       1.1   thorpej 	 * Set the default timeouts: 10 minutes on, .25 seconds off.
    107       1.1   thorpej 	 */
    108       1.1   thorpej 	timo_on.tv_sec = 600;
    109      1.19   mycroft 	timo_on.tv_nsec = 0;
    110       1.1   thorpej 	timo_off.tv_sec = 0;
    111      1.19   mycroft 	timo_off.tv_nsec = 250000000;
    112       1.1   thorpej 
    113      1.24      elad 	while ((ch = getopt(argc, argv, "bd:e:f:i:kmu")) != -1) {
    114       1.1   thorpej 		switch (ch) {
    115      1.24      elad 		case 'b':
    116      1.24      elad 			bflag = 1;
    117      1.24      elad 			uflag = 0;
    118      1.24      elad 			break;
    119      1.24      elad 
    120       1.1   thorpej 		case 'd':
    121       1.1   thorpej 			cvt_arg(optarg, &timo_on);
    122       1.1   thorpej 			break;
    123       1.1   thorpej 
    124       1.1   thorpej 		case 'e':
    125       1.1   thorpej 			cvt_arg(optarg, &timo_off);
    126       1.1   thorpej 			break;
    127       1.1   thorpej 
    128       1.1   thorpej 		case 'f':
    129       1.1   thorpej 			fflag = 1;
    130       1.1   thorpej 			add_dev(optarg, 1);
    131       1.1   thorpej 			break;
    132       1.1   thorpej 
    133      1.18     lukem 		case 'i':
    134      1.18     lukem 			add_dev(optarg, 0);
    135      1.18     lukem 			break;
    136      1.18     lukem 
    137       1.1   thorpej 		case 'k':
    138       1.1   thorpej 			if (mflag || kflag)
    139       1.1   thorpej 				usage();
    140       1.1   thorpej 			kflag = 1;
    141       1.1   thorpej 			break;
    142       1.1   thorpej 
    143       1.1   thorpej 		case 'm':
    144       1.1   thorpej 			if (kflag || mflag)
    145       1.1   thorpej 				usage();
    146       1.1   thorpej 			mflag = 1;
    147       1.1   thorpej 			break;
    148       1.1   thorpej 
    149      1.24      elad 		case 'u':
    150      1.24      elad 			uflag = 1;
    151      1.24      elad 			bflag = 0;
    152      1.24      elad 			break;
    153      1.24      elad 
    154       1.1   thorpej 		default:
    155       1.1   thorpej 			usage();
    156       1.1   thorpej 		}
    157       1.1   thorpej 	}
    158       1.1   thorpej 	argc -= optind;
    159       1.1   thorpej 	if (argc)
    160       1.1   thorpej 		usage();
    161       1.1   thorpej 
    162       1.1   thorpej 	/*
    163       1.9   thorpej 	 * Default to WSCONS support.
    164       1.9   thorpej 	 */
    165       1.9   thorpej 	kbd = _PATH_WSKBD;
    166       1.9   thorpej 	mouse = _PATH_WSMOUSE;
    167       1.9   thorpej 	display = _PATH_WSDISPLAY;
    168       1.9   thorpej 
    169       1.9   thorpej #ifdef HAVE_FBIO
    170       1.9   thorpej 	/*
    171       1.9   thorpej 	 * If a display device wasn't specified, check to see which we
    172       1.9   thorpej 	 * have.  If we can't open the WSCONS display, fall back to fbio.
    173       1.9   thorpej 	 */
    174       1.9   thorpej 	if (!fflag) {
    175       1.9   thorpej 		int fd;
    176       1.9   thorpej 
    177       1.9   thorpej 		if ((fd = open(display, O_RDONLY, 0666)) == -1)
    178       1.9   thorpej 			setvideo = FBIOSVIDEO;
    179       1.9   thorpej 		else
    180       1.9   thorpej 			(void) close(fd);
    181       1.9   thorpej 	}
    182       1.9   thorpej 
    183       1.9   thorpej 	/*
    184       1.9   thorpej 	 * Do this here so that -f ... args above can influence us.
    185       1.9   thorpej 	 */
    186       1.9   thorpej 	if (setvideo == FBIOSVIDEO) {
    187       1.9   thorpej 		videoon = FBVIDEO_ON;
    188       1.9   thorpej 		videooff = FBVIDEO_OFF;
    189       1.9   thorpej 		kbd = _PATH_KEYBOARD;
    190       1.9   thorpej 		mouse = _PATH_MOUSE;
    191       1.9   thorpej 		display = _PATH_FB;
    192       1.9   thorpej 	}
    193       1.9   thorpej #endif
    194       1.9   thorpej 
    195       1.9   thorpej 	/*
    196      1.26       uwe 	 * Add the default framebuffer device if necessary.
    197      1.26       uwe 	 * We _always_ check the console device.
    198      1.26       uwe 	 */
    199      1.26       uwe 	add_dev(_PATH_CONSOLE, 0);
    200      1.26       uwe 	if (!fflag)
    201      1.26       uwe 		add_dev(display, 1);
    202      1.26       uwe 
    203      1.26       uwe 	/*
    204      1.26       uwe 	 * If this is an one-off blank/unblank request, handle it now.
    205      1.26       uwe 	 * We don't need to open keyboard/mouse device for that.
    206      1.24      elad 	 */
    207      1.24      elad 	if (bflag || uflag) {
    208      1.24      elad 		change_state(bflag ? videooff : videoon);
    209      1.24      elad 		exit(0);
    210      1.24      elad 	}
    211      1.24      elad 
    212      1.26       uwe 
    213      1.26       uwe 	/* Add the keyboard and mouse devices as necessary. */
    214       1.1   thorpej 	if (!kflag)
    215       1.9   thorpej 		add_dev(kbd, 0);
    216       1.1   thorpej 	if (!mflag)
    217       1.9   thorpej 		add_dev(mouse, 0);
    218       1.1   thorpej 
    219       1.1   thorpej 	/* Ensure that the framebuffer is on. */
    220       1.9   thorpej 	state = videoon;
    221       1.1   thorpej 	change_state(state);
    222       1.1   thorpej 	tvp = &timo_on;
    223       1.1   thorpej 
    224       1.1   thorpej 	/*
    225       1.1   thorpej 	 * Make sure the framebuffer gets turned back on when we're
    226       1.1   thorpej 	 * killed.
    227       1.1   thorpej 	 */
    228       1.1   thorpej 	sa.sa_handler = sighandler;
    229       1.1   thorpej 	sa.sa_flags = SA_NOCLDSTOP;
    230       1.3   thorpej 	if (sigemptyset(&sa.sa_mask))
    231       1.3   thorpej 		err(1, "sigemptyset");
    232       1.1   thorpej 	if (sigaction(SIGINT, &sa, NULL) || sigaction(SIGTERM, &sa, NULL) ||
    233       1.1   thorpej 	    sigaction(SIGHUP, &sa, NULL))
    234       1.1   thorpej 		err(1, "sigaction");
    235       1.1   thorpej 
    236      1.13  christos 	openlog("screenblank", LOG_PID, LOG_DAEMON);
    237       1.1   thorpej 	/* Detach. */
    238       1.1   thorpej 	if (daemon(0, 0))
    239       1.1   thorpej 		err(1, "daemon");
    240      1.10   thorpej 	pidfile(NULL);
    241       1.1   thorpej 
    242       1.1   thorpej 	/* Start the state machine. */
    243       1.1   thorpej 	for (;;) {
    244       1.1   thorpej 		change = 0;
    245      1.23     peter 		LIST_FOREACH(dsp, &ds_list, ds_link) {
    246      1.22  christos 			/* Don't check framebuffers in graphics mode. */
    247      1.22  christos 			if (is_graphics_fb(dsp))
    248       1.1   thorpej 				continue;
    249      1.13  christos 			if (stat(dsp->ds_path, &st) == -1) {
    250      1.13  christos 				syslog(LOG_CRIT,
    251      1.13  christos 				    "Can't stat `%s' (%m)", dsp->ds_path);
    252      1.13  christos 				exit(1);
    253      1.13  christos 			}
    254       1.1   thorpej 			if (st.st_atime > dsp->ds_atime) {
    255       1.1   thorpej 				change = 1;
    256       1.1   thorpej 				dsp->ds_atime = st.st_atime;
    257       1.1   thorpej 			}
    258       1.1   thorpej 			if (st.st_mtime > dsp->ds_mtime) {
    259       1.1   thorpej 				change = 1;
    260       1.1   thorpej 				dsp->ds_mtime = st.st_mtime;
    261       1.1   thorpej 			}
    262       1.1   thorpej 		}
    263       1.1   thorpej 
    264       1.9   thorpej 		if (state == videoon) {
    265       1.1   thorpej 			if (!change) {
    266       1.9   thorpej 				state = videooff;
    267       1.1   thorpej 				change_state(state);
    268       1.1   thorpej 				tvp = &timo_off;
    269       1.1   thorpej 			}
    270       1.9   thorpej 		} else {
    271       1.1   thorpej 			if (change) {
    272       1.9   thorpej 				state = videoon;
    273       1.1   thorpej 				change_state(state);
    274       1.1   thorpej 				tvp = &timo_on;
    275       1.1   thorpej 			}
    276       1.1   thorpej 		}
    277       1.1   thorpej 
    278      1.13  christos 		tv = *tvp;
    279      1.19   mycroft 		if (nanosleep(&tv, NULL) == -1)
    280      1.19   mycroft 			err(1, "nanosleep");
    281       1.1   thorpej 	}
    282       1.1   thorpej 	/* NOTREACHED */
    283       1.1   thorpej }
    284       1.1   thorpej 
    285       1.1   thorpej static void
    286      1.13  christos add_dev(const char *path, int isfb)
    287       1.1   thorpej {
    288       1.9   thorpej 	struct dev_stat *dsp;
    289      1.14  augustss 	struct stat sb;
    290       1.9   thorpej 
    291      1.15  augustss 	/* Make sure we can stat the device. */
    292      1.14  augustss 	if (stat(path, &sb) == -1) {
    293      1.14  augustss 		warn("Can't stat `%s'", path);
    294      1.13  christos 		return;
    295      1.13  christos 	}
    296       1.9   thorpej 
    297       1.9   thorpej #ifdef HAVE_FBIO
    298       1.9   thorpej 	/*
    299       1.9   thorpej 	 * We default to WSCONS.  If this is a frame buffer
    300       1.9   thorpej 	 * device, check to see if it responds to the old
    301       1.9   thorpej 	 * Sun-style fbio ioctls.  If so, switch to fbio mode.
    302       1.9   thorpej 	 */
    303       1.9   thorpej 	if (isfb && setvideo != FBIOSVIDEO) {
    304      1.14  augustss 		int onoff, fd;
    305       1.9   thorpej 
    306      1.14  augustss 		if ((fd = open(path, O_RDWR, 0666)) == -1) {
    307      1.14  augustss 			warn("Can't open `%s'", path);
    308      1.14  augustss 			return;
    309      1.14  augustss 		}
    310       1.9   thorpej 		if ((ioctl(fd, FBIOGVIDEO, &onoff)) == 0)
    311       1.9   thorpej 			setvideo = FBIOSVIDEO;
    312      1.14  augustss 		(void)close(fd);
    313       1.9   thorpej 	}
    314       1.9   thorpej #endif
    315       1.1   thorpej 
    316       1.1   thorpej 	/* Create the entry... */
    317       1.9   thorpej 	dsp = malloc(sizeof(struct dev_stat));
    318       1.9   thorpej 	if (dsp == NULL)
    319      1.13  christos 		err(1, "Can't allocate memory for `%s'", path);
    320      1.13  christos 	(void)memset(dsp, 0, sizeof(struct dev_stat));
    321       1.9   thorpej 	dsp->ds_path = path;
    322       1.9   thorpej 	dsp->ds_isfb = isfb;
    323       1.1   thorpej 
    324       1.1   thorpej 	/* ...and put it in the list. */
    325       1.9   thorpej 	LIST_INSERT_HEAD(&ds_list, dsp, ds_link);
    326       1.1   thorpej }
    327       1.1   thorpej 
    328       1.1   thorpej /* ARGSUSED */
    329       1.1   thorpej static void
    330      1.13  christos sighandler(int sig)
    331       1.1   thorpej {
    332       1.1   thorpej 
    333       1.1   thorpej 	/* Kill the pid file and re-enable the framebuffer before exit. */
    334       1.9   thorpej 	change_state(videoon);
    335       1.1   thorpej 	exit(0);
    336       1.1   thorpej }
    337       1.1   thorpej 
    338      1.22  christos /*
    339      1.22  christos  * Return 1 if we are a framebuffer in graphics mode or a framebuffer
    340      1.22  christos  * where we cannot tell the mode. Return 0 if we are not a framebuffer
    341      1.22  christos  * device, or a wscons framebuffer in text mode.
    342      1.22  christos  */
    343      1.22  christos static int
    344      1.22  christos is_graphics_fb(struct dev_stat *dsp)
    345      1.22  christos {
    346      1.22  christos 	int fd;
    347      1.22  christos 	int state;
    348      1.22  christos 
    349      1.22  christos 	if (dsp->ds_isfb == 0)
    350      1.22  christos 		return 0;
    351      1.22  christos 
    352      1.22  christos 	/* We can't tell if we are not a wscons device */
    353      1.22  christos 	if (setvideo != WSDISPLAYIO_SVIDEO)
    354      1.22  christos 		return 1;
    355      1.22  christos 
    356      1.22  christos 	if ((fd = open(dsp->ds_path, O_RDWR, 0)) == -1) {
    357      1.22  christos 		syslog(LOG_WARNING, "Cannot open `%s' (%m)", dsp->ds_path);
    358      1.22  christos 		return 1;
    359      1.22  christos 	}
    360      1.22  christos 
    361      1.22  christos 	if (ioctl(fd, WSDISPLAYIO_GMODE, &state) == -1) {
    362      1.22  christos 		syslog(LOG_WARNING, "Cannot get mode on `%s' (%m)",
    363      1.22  christos 		    dsp->ds_path);
    364      1.22  christos 		/* We can't tell, so we say we are mapped */
    365      1.22  christos 		state = WSDISPLAYIO_MODE_MAPPED;
    366      1.22  christos 	}
    367      1.22  christos 
    368      1.22  christos 	(void)close(fd);
    369      1.22  christos 
    370      1.22  christos 	return state != WSDISPLAYIO_MODE_EMUL;
    371      1.22  christos }
    372      1.22  christos 
    373       1.1   thorpej static void
    374      1.13  christos change_state(int state)
    375       1.1   thorpej {
    376       1.1   thorpej 	struct dev_stat *dsp;
    377       1.1   thorpej 	int fd;
    378      1.13  christos 	int fail = 1;
    379       1.1   thorpej 
    380      1.23     peter 	LIST_FOREACH(dsp, &ds_list, ds_link) {
    381       1.1   thorpej 		/* Don't change the state of non-framebuffers! */
    382       1.1   thorpej 		if (dsp->ds_isfb == 0)
    383       1.1   thorpej 			continue;
    384      1.13  christos 		if ((fd = open(dsp->ds_path, O_RDWR, 0)) == -1) {
    385      1.13  christos 			syslog(LOG_WARNING, "Can't open `%s' (%m)",
    386      1.13  christos 			    dsp->ds_path);
    387       1.1   thorpej 			continue;
    388       1.1   thorpej 		}
    389      1.13  christos 		if (ioctl(fd, setvideo, &state) == -1)
    390      1.13  christos 			syslog(LOG_WARNING, "Can't set video on `%s' (%m)",
    391      1.13  christos 			    dsp->ds_path);
    392      1.13  christos 		else
    393      1.13  christos 			fail = 0;
    394       1.1   thorpej 		(void)close(fd);
    395       1.1   thorpej 	}
    396      1.13  christos 	if (fail) {
    397      1.13  christos 		syslog(LOG_CRIT, "No frame buffer devices, exiting\n");
    398      1.13  christos 		exit(1);
    399      1.13  christos 	}
    400       1.1   thorpej }
    401       1.1   thorpej 
    402       1.1   thorpej static void
    403      1.19   mycroft cvt_arg(char *arg, struct timespec *tvp)
    404       1.1   thorpej {
    405       1.1   thorpej 	char *cp;
    406      1.19   mycroft 	int seconds, nanoseconds, factor;
    407       1.1   thorpej 	int period = 0;
    408      1.19   mycroft 	factor = 1000000000;
    409      1.19   mycroft 	nanoseconds = 0;
    410       1.8        is 	seconds = 0;
    411       1.1   thorpej 
    412       1.1   thorpej 	for (cp = arg; *cp != '\0'; ++cp) {
    413       1.1   thorpej 		if (*cp == '.') {
    414       1.1   thorpej 			if (period)
    415      1.13  christos 				errx(1, "Invalid argument: %s", arg);
    416       1.1   thorpej 			period = 1;
    417       1.1   thorpej 			continue;
    418       1.1   thorpej 		}
    419       1.1   thorpej 
    420      1.21       dsl 		if (!isdigit((unsigned char)*cp))
    421      1.13  christos 			errx(1, "Invalid argument: %s", arg);
    422       1.1   thorpej 
    423       1.1   thorpej 		if (period) {
    424       1.8        is 			if (factor > 1) {
    425      1.19   mycroft 				nanoseconds = nanoseconds * 10 + (*cp - '0');
    426       1.8        is 				factor /= 10;
    427       1.8        is 			}
    428       1.1   thorpej 		} else
    429       1.8        is 			seconds = (seconds * 10) + (*cp - '0');
    430       1.1   thorpej 	}
    431       1.1   thorpej 
    432       1.8        is 	tvp->tv_sec = seconds;
    433       1.8        is 	if (factor > 1)
    434      1.19   mycroft 		nanoseconds *= factor;
    435      1.24      elad 
    436      1.19   mycroft 	tvp->tv_nsec = nanoseconds;
    437       1.1   thorpej }
    438       1.1   thorpej 
    439       1.1   thorpej static void
    440      1.13  christos usage(void)
    441       1.1   thorpej {
    442       1.1   thorpej 
    443      1.13  christos 	(void)fprintf(stderr,
    444      1.20      jmmv 	    "usage: %s [-k | -m] [-d inactivity-timeout] [-e wakeup-delay]\n"
    445      1.25       wiz 	    "\t\t[-f framebuffer] [-i input-device]\n"
    446      1.25       wiz 	    "       %s {-b | -u}\n",
    447      1.25       wiz 	    getprogname(),
    448      1.13  christos 	    getprogname());
    449       1.1   thorpej 	exit(1);
    450       1.1   thorpej }
    451