Add rcsid. Remove unused #includes. Use err(3).

This commit is contained in:
Philippe Charnier 1998-06-30 06:09:37 +00:00
parent df394affa2
commit d286dcb026
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=37273
4 changed files with 68 additions and 64 deletions

View File

@ -1,4 +1,4 @@
.\" $Id: comcontrol.8,v 1.12 1997/02/22 14:32:27 peter Exp $ .\" $Id: comcontrol.8,v 1.13 1998/03/19 07:46:39 charnier Exp $
.Dd May 15, 1994 .Dd May 15, 1994
.Dt COMCONTROL 8 .Dt COMCONTROL 8
.Os FreeBSD .Os FreeBSD
@ -19,7 +19,7 @@ This usage requires only read access on the device.
Only the superuser can change the settings. Only the superuser can change the settings.
.Pp .Pp
The following options are available: The following options are available:
.Bl -tag -width Fl .Bl -tag -width indent
.It Cm dtrwait Ar number .It Cm dtrwait Ar number
Set the time to wait after dropping DTR Set the time to wait after dropping DTR
to the given number. to the given number.
@ -27,8 +27,6 @@ The units are hundredths of a second.
The default is 300 hundredths, i.e., 3 seconds. The default is 300 hundredths, i.e., 3 seconds.
This option needed mainly to set proper recover time after This option needed mainly to set proper recover time after
modem reset. modem reset.
.El
.Bl -tag -width Fl
.It Cm drainwait Ar number .It Cm drainwait Ar number
Set the time to wait for output drain Set the time to wait for output drain
to the given number. to the given number.
@ -39,23 +37,23 @@ to prevent modem hanging.
.El .El
.Pp .Pp
The standard way to use The standard way to use
.Nm comcontrol .Nm
is to put invocations of it in the is to put invocations of it in the
.Ar /etc/rc.serial .Pa /etc/rc.serial
startup script. startup script.
.Sh SEE ALSO .Sh SEE ALSO
.Xr stty 1 , .Xr stty 1 ,
.Xr sio 4 .Xr sio 4
.Sh FILES .Sh FILES
.Bl -tag -width Pa .Bl -tag -width /dev/ttyd? -compact
.It Pa /dev/ttyd? .It Pa /dev/ttyd?
dialin devices, hardwired terminals dialin devices, hardwired terminals
.It Pa /dev/cuaa? .It Pa /dev/cuaa?
dialout devices. dialout devices
.Sh AUTHORS .Sh AUTHORS
.An Christopher G. Demetriou .An Christopher G. Demetriou
.Sh BUGS .Sh BUGS
.Nm comcontrol .Nm Comcontrol
should be named should be named
.Nm siocontrol . .Nm siocontrol .
.Sh HISTORY .Sh HISTORY

View File

@ -26,79 +26,83 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* comcontrol.c */ #ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h> #include <ctype.h>
#include <sys/ioctl.h> #include <err.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <unistd.h>
#include <fcntl.h> #include <sys/types.h>
#include <sys/ioctl.h>
static void
void usage(char *progname) usage()
{ {
fprintf(stderr, "usage: %s <filename> [dtrwait <n>] [drainwait <n>]\n", progname); fprintf(stderr,
"usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
exit(1); exit(1);
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int fd; int fd;
int res = 0; int res = 0;
int dtrwait = -1, drainwait = -1; int dtrwait = -1, drainwait = -1;
if (argc < 2) if (argc < 2)
usage(argv[0]); usage();
fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0); fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
if (fd < 0) { if (fd < 0) {
perror("open"); warn("couldn't open file %s", argv[1]);
fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]);
return 1; return 1;
} }
if (argc == 2) { if (argc == 2) {
if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) { if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) {
res = 1; res = 1;
perror("TIOCMGDTRWAIT"); warn("TIOCMGDTRWAIT");
} }
if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) { if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) {
res = 1; res = 1;
perror("TIOCGDRAINWAIT"); warn("TIOCGDRAINWAIT");
} }
printf("dtrwait %d drainwait %d\n", dtrwait, drainwait); printf("dtrwait %d drainwait %d\n", dtrwait, drainwait);
} else { } else {
char *prg = argv[0];
while (argv[2] != NULL) { while (argv[2] != NULL) {
if (!strcmp(argv[2],"dtrwait")) { if (!strcmp(argv[2],"dtrwait")) {
if (dtrwait >= 0) if (dtrwait >= 0)
usage(prg); usage();
if (argv[3] == NULL || !isdigit(argv[3][0])) if (argv[3] == NULL || !isdigit(argv[3][0]))
usage(prg); usage();
dtrwait = atoi(argv[3]); dtrwait = atoi(argv[3]);
argv += 2; argv += 2;
} else if (!strcmp(argv[2],"drainwait")) { } else if (!strcmp(argv[2],"drainwait")) {
if (drainwait >= 0) if (drainwait >= 0)
usage(prg); usage();
if (argv[3] == NULL || !isdigit(argv[3][0])) if (argv[3] == NULL || !isdigit(argv[3][0]))
usage(prg); usage();
drainwait = atoi(argv[3]); drainwait = atoi(argv[3]);
argv += 2; argv += 2;
} else } else
usage(prg); usage();
} }
if (dtrwait >= 0) { if (dtrwait >= 0) {
if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) { if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {
res = 1; res = 1;
perror("TIOCMSDTRWAIT"); warn("TIOCMSDTRWAIT");
} }
} }
if (drainwait >= 0) { if (drainwait >= 0) {
if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) { if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) {
res = 1; res = 1;
perror("TIOCSDRAINWAIT"); warn("TIOCSDRAINWAIT");
} }
} }
} }

View File

@ -1,4 +1,4 @@
.\" $Id: comcontrol.8,v 1.12 1997/02/22 14:32:27 peter Exp $ .\" $Id: comcontrol.8,v 1.13 1998/03/19 07:46:39 charnier Exp $
.Dd May 15, 1994 .Dd May 15, 1994
.Dt COMCONTROL 8 .Dt COMCONTROL 8
.Os FreeBSD .Os FreeBSD
@ -19,7 +19,7 @@ This usage requires only read access on the device.
Only the superuser can change the settings. Only the superuser can change the settings.
.Pp .Pp
The following options are available: The following options are available:
.Bl -tag -width Fl .Bl -tag -width indent
.It Cm dtrwait Ar number .It Cm dtrwait Ar number
Set the time to wait after dropping DTR Set the time to wait after dropping DTR
to the given number. to the given number.
@ -27,8 +27,6 @@ The units are hundredths of a second.
The default is 300 hundredths, i.e., 3 seconds. The default is 300 hundredths, i.e., 3 seconds.
This option needed mainly to set proper recover time after This option needed mainly to set proper recover time after
modem reset. modem reset.
.El
.Bl -tag -width Fl
.It Cm drainwait Ar number .It Cm drainwait Ar number
Set the time to wait for output drain Set the time to wait for output drain
to the given number. to the given number.
@ -39,23 +37,23 @@ to prevent modem hanging.
.El .El
.Pp .Pp
The standard way to use The standard way to use
.Nm comcontrol .Nm
is to put invocations of it in the is to put invocations of it in the
.Ar /etc/rc.serial .Pa /etc/rc.serial
startup script. startup script.
.Sh SEE ALSO .Sh SEE ALSO
.Xr stty 1 , .Xr stty 1 ,
.Xr sio 4 .Xr sio 4
.Sh FILES .Sh FILES
.Bl -tag -width Pa .Bl -tag -width /dev/ttyd? -compact
.It Pa /dev/ttyd? .It Pa /dev/ttyd?
dialin devices, hardwired terminals dialin devices, hardwired terminals
.It Pa /dev/cuaa? .It Pa /dev/cuaa?
dialout devices. dialout devices
.Sh AUTHORS .Sh AUTHORS
.An Christopher G. Demetriou .An Christopher G. Demetriou
.Sh BUGS .Sh BUGS
.Nm comcontrol .Nm Comcontrol
should be named should be named
.Nm siocontrol . .Nm siocontrol .
.Sh HISTORY .Sh HISTORY

View File

@ -26,79 +26,83 @@
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
/* comcontrol.c */ #ifndef lint
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h> #include <ctype.h>
#include <sys/ioctl.h> #include <err.h>
#include <fcntl.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h> #include <unistd.h>
#include <fcntl.h> #include <sys/types.h>
#include <sys/ioctl.h>
static void
void usage(char *progname) usage()
{ {
fprintf(stderr, "usage: %s <filename> [dtrwait <n>] [drainwait <n>]\n", progname); fprintf(stderr,
"usage: comcontrol <filename> [dtrwait <n>] [drainwait <n>]\n");
exit(1); exit(1);
} }
int main(int argc, char *argv[]) int
main(int argc, char *argv[])
{ {
int fd; int fd;
int res = 0; int res = 0;
int dtrwait = -1, drainwait = -1; int dtrwait = -1, drainwait = -1;
if (argc < 2) if (argc < 2)
usage(argv[0]); usage();
fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0); fd = open(argv[1], O_RDONLY|O_NONBLOCK, 0);
if (fd < 0) { if (fd < 0) {
perror("open"); warn("couldn't open file %s", argv[1]);
fprintf(stderr, "%s: couldn't open file %s\n", argv[0], argv[1]);
return 1; return 1;
} }
if (argc == 2) { if (argc == 2) {
if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) { if (ioctl(fd, TIOCMGDTRWAIT, &dtrwait) < 0) {
res = 1; res = 1;
perror("TIOCMGDTRWAIT"); warn("TIOCMGDTRWAIT");
} }
if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) { if (ioctl(fd, TIOCGDRAINWAIT, &drainwait) < 0) {
res = 1; res = 1;
perror("TIOCGDRAINWAIT"); warn("TIOCGDRAINWAIT");
} }
printf("dtrwait %d drainwait %d\n", dtrwait, drainwait); printf("dtrwait %d drainwait %d\n", dtrwait, drainwait);
} else { } else {
char *prg = argv[0];
while (argv[2] != NULL) { while (argv[2] != NULL) {
if (!strcmp(argv[2],"dtrwait")) { if (!strcmp(argv[2],"dtrwait")) {
if (dtrwait >= 0) if (dtrwait >= 0)
usage(prg); usage();
if (argv[3] == NULL || !isdigit(argv[3][0])) if (argv[3] == NULL || !isdigit(argv[3][0]))
usage(prg); usage();
dtrwait = atoi(argv[3]); dtrwait = atoi(argv[3]);
argv += 2; argv += 2;
} else if (!strcmp(argv[2],"drainwait")) { } else if (!strcmp(argv[2],"drainwait")) {
if (drainwait >= 0) if (drainwait >= 0)
usage(prg); usage();
if (argv[3] == NULL || !isdigit(argv[3][0])) if (argv[3] == NULL || !isdigit(argv[3][0]))
usage(prg); usage();
drainwait = atoi(argv[3]); drainwait = atoi(argv[3]);
argv += 2; argv += 2;
} else } else
usage(prg); usage();
} }
if (dtrwait >= 0) { if (dtrwait >= 0) {
if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) { if (ioctl(fd, TIOCMSDTRWAIT, &dtrwait) < 0) {
res = 1; res = 1;
perror("TIOCMSDTRWAIT"); warn("TIOCMSDTRWAIT");
} }
} }
if (drainwait >= 0) { if (drainwait >= 0) {
if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) { if (ioctl(fd, TIOCSDRAINWAIT, &drainwait) < 0) {
res = 1; res = 1;
perror("TIOCSDRAINWAIT"); warn("TIOCSDRAINWAIT");
} }
} }
} }