summaryrefslogtreecommitdiffstats
path: root/usr.bin/lock
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-21 12:09:34 +0000
committercharnier <charnier@FreeBSD.org>1997-07-21 12:09:34 +0000
commit8df0f01f5826daffbe0697534d72179b3716380e (patch)
tree12f57a46d976a394c033220103d9aec89ed9ba29 /usr.bin/lock
parentf85d3627d41f2210f7f56ee192dc55e5b8494610 (diff)
downloadFreeBSD-src-8df0f01f5826daffbe0697534d72179b3716380e.zip
FreeBSD-src-8df0f01f5826daffbe0697534d72179b3716380e.tar.gz
Use err(3). Add usage().
Diffstat (limited to 'usr.bin/lock')
-rw-r--r--usr.bin/lock/lock.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/usr.bin/lock/lock.c b/usr.bin/lock/lock.c
index 9f76971..1bbec1d 100644
--- a/usr.bin/lock/lock.c
+++ b/usr.bin/lock/lock.c
@@ -35,13 +35,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1980, 1987, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)lock.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
/*
@@ -56,15 +60,19 @@ static char sccsid[] = "@(#)lock.c 8.1 (Berkeley) 6/6/93";
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/signal.h>
-#include <sgtty.h>
+#include <err.h>
+#include <ctype.h>
#include <pwd.h>
+#include <sgtty.h>
#include <stdio.h>
-#include <ctype.h>
+#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#define TIMEOUT 15
void quit(), bye(), hi();
+static void usage __P((void));
struct timeval timeout;
struct timeval zerotime;
@@ -73,12 +81,11 @@ long nexttime; /* keep the timeout time */
int no_timeout; /* lock terminal forever */
/*ARGSUSED*/
+int
main(argc, argv)
int argc;
char **argv;
{
- extern char *optarg;
- extern int errno, optind;
struct passwd *pw;
struct timeval timval;
struct itimerval ntimer, otimer;
@@ -95,19 +102,13 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "npt:")) != -1)
switch((char)ch) {
case 't':
- if ((sectimeout = atoi(optarg)) <= 0) {
- (void)fprintf(stderr,
- "lock: illegal timeout value.\n");
- exit(1);
- }
+ if ((sectimeout = atoi(optarg)) <= 0)
+ errx(1, "illegal timeout value");
break;
case 'p':
usemine = 1;
- if (!(pw = getpwuid(getuid()))) {
- (void)fprintf(stderr,
- "lock: unknown uid %d.\n", getuid());
- exit(1);
- }
+ if (!(pw = getpwuid(getuid())))
+ errx(1, "unknown uid %d", getuid());
mypw = strdup(pw->pw_passwd);
break;
case 'n':
@@ -115,9 +116,7 @@ main(argc, argv)
break;
case '?':
default:
- (void)fprintf(stderr,
- "usage: lock [-n] [-p] [-t timeout]\n");
- exit(1);
+ usage();
}
timeout.tv_sec = sectimeout * 60;
@@ -126,15 +125,10 @@ main(argc, argv)
if (ioctl(0, TIOCGETP, &tty)) /* get information for header */
exit(1);
gethostname(hostname, sizeof(hostname));
- if (!(ttynam = ttyname(0))) {
- (void)printf("lock: not a terminal?\n");
- exit(1);
- }
- if (gettimeofday(&timval, (struct timezone *)NULL)) {
- (void)fprintf(stderr,
- "lock: gettimeofday: %s\n", strerror(errno));
- exit(1);
- }
+ if (!(ttynam = ttyname(0)))
+ errx(1, "not a terminal?");
+ if (gettimeofday(&timval, (struct timezone *)NULL))
+ err(1, "gettimeofday");
nexttime = timval.tv_sec + (sectimeout * 60);
timp = localtime(&timval.tv_sec);
ap = asctime(timp);
@@ -162,7 +156,7 @@ main(argc, argv)
ioctl(0, TIOCSETP, &tty);
exit(1);
}
- s[0] = NULL;
+ s[0] = '\0';
mypw = s1;
}
@@ -205,6 +199,15 @@ main(argc, argv)
exit(1);
}
quit();
+ return(0); /* not reached */
+}
+
+
+static void
+usage()
+{
+ (void)fprintf(stderr, "usage: lock [-n] [-p] [-t timeout]\n");
+ exit(1);
}
void
OpenPOWER on IntegriCloud