summaryrefslogtreecommitdiffstats
path: root/usr.bin/script
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-08 12:24:49 +0000
committercharnier <charnier@FreeBSD.org>1997-08-08 12:24:49 +0000
commit589d243b0950108d54f474d4143448c60c5cc065 (patch)
tree49a9ac7bf8ddce5eb549f6b4faa38ca92126dd3b /usr.bin/script
parent9a0308a35455e1c84e03211da112146975348f61 (diff)
downloadFreeBSD-src-589d243b0950108d54f474d4143448c60c5cc065.zip
FreeBSD-src-589d243b0950108d54f474d4143448c60c5cc065.tar.gz
Add usage(). Use err(3) instead of local redefinition.
Diffstat (limited to 'usr.bin/script')
-rw-r--r--usr.bin/script/script.16
-rw-r--r--usr.bin/script/script.c60
2 files changed, 24 insertions, 42 deletions
diff --git a/usr.bin/script/script.1 b/usr.bin/script/script.1
index deda037..7c1032f0 100644
--- a/usr.bin/script/script.1
+++ b/usr.bin/script/script.1
@@ -38,7 +38,7 @@
.Nm script
.Nd make typescript of terminal session
.Sh SYNOPSIS
-.Nm script
+.Nm
.Op Fl a
.Op Ar file
.Sh DESCRIPTION
@@ -99,7 +99,7 @@ The following environment variable is utilized by
If the variable
.Ev SHELL
exists, the shell forked by
-.Nm script
+.Nm
will be that shell. If
.Ev SHELL
is not set, the Bourne shell
@@ -112,7 +112,7 @@ is assumed. (Most shells set this variable automatically).
mechanism).
.Sh HISTORY
The
-.Nm script
+.Nm
command appeared in
.Bx 3.0 .
.Sh BUGS
diff --git a/usr.bin/script/script.c b/usr.bin/script/script.c
index 6c9ed08..5952a9b 100644
--- a/usr.bin/script/script.c
+++ b/usr.bin/script/script.c
@@ -32,13 +32,17 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1980, 1992, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/types.h>
@@ -47,8 +51,9 @@ static char sccsid[] = "@(#)script.c 8.1 (Berkeley) 6/6/93";
#include <sys/ioctl.h>
#include <sys/time.h>
-#include <errno.h>
+#include <err.h>
#include <fcntl.h>
+#include <libutil.h>
#include <paths.h>
#include <signal.h>
#include <stdio.h>
@@ -68,10 +73,10 @@ struct termios tt;
void done __P((void)) __dead2;
void dooutput __P((void));
void doshell __P((void));
-void err __P((const char *, ...));
void fail __P((void));
void finish __P((int));
void scriptflush __P((int));
+static void usage __P((void));
int
main(argc, argv)
@@ -92,8 +97,7 @@ main(argc, argv)
break;
case '?':
default:
- (void)fprintf(stderr, "usage: script [-a] [file]\n");
- exit(1);
+ usage();
}
argc -= optind;
argv += optind;
@@ -104,12 +108,12 @@ main(argc, argv)
fname = "typescript";
if ((fscript = fopen(fname, aflg ? "a" : "w")) == NULL)
- err("%s: %s", fname, strerror(errno));
+ err(1, "%s", fname);
(void)tcgetattr(STDIN_FILENO, &tt);
(void)ioctl(STDIN_FILENO, TIOCGWINSZ, &win);
if (openpty(&master, &slave, NULL, &tt, &win) == -1)
- err("openpty: %s", strerror(errno));
+ err(1, "openpty");
(void)printf("Script started, output file is %s\n", fname);
rtt = tt;
@@ -120,13 +124,13 @@ main(argc, argv)
(void)signal(SIGCHLD, finish);
child = fork();
if (child < 0) {
- perror("fork");
+ warn("fork");
fail();
}
if (child == 0) {
subchild = child = fork();
if (child < 0) {
- perror("fork");
+ warn("fork");
fail();
}
if (child)
@@ -141,6 +145,13 @@ main(argc, argv)
done();
}
+static void
+usage()
+{
+ (void)fprintf(stderr, "usage: script [-a] [file]\n");
+ exit(1);
+}
+
void
finish(signo)
int signo;
@@ -208,7 +219,7 @@ doshell()
(void)fclose(fscript);
login_tty(slave);
execl(shell, "sh", "-i", NULL);
- perror(shell);
+ warn(shell);
fail();
}
@@ -236,32 +247,3 @@ done()
}
exit(0);
}
-
-#if __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
-
-void
-#if __STDC__
-err(const char *fmt, ...)
-#else
-err(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- (void)fprintf(stderr, "script: ");
- (void)vfprintf(stderr, fmt, ap);
- va_end(ap);
- (void)fprintf(stderr, "\n");
- exit(1);
- /* NOTREACHED */
-}
OpenPOWER on IntegriCloud