diff options
| author | christos <christos@NetBSD.org> | 1997-06-29 18:01:12 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 1997-06-29 18:01:12 +0000 |
| commit | 5a6c78298fdf44c170d1d75be4c53a40dec5e432 (patch) | |
| tree | 640ab22ee582d0271b09088e8d74c2dca6734bdd /libexec | |
| parent | 86f86c044ced0bdfde021f743f281ea82e978f65 (diff) | |
Merge in lite-2
Diffstat (limited to 'libexec')
| -rw-r--r-- | libexec/talkd/Makefile | 9 | ||||
| -rw-r--r-- | libexec/talkd/announce.c | 93 | ||||
| -rw-r--r-- | libexec/talkd/print.c | 14 | ||||
| -rw-r--r-- | libexec/talkd/process.c | 28 | ||||
| -rw-r--r-- | libexec/talkd/table.c | 14 | ||||
| -rw-r--r-- | libexec/talkd/talkd.8 | 12 | ||||
| -rw-r--r-- | libexec/talkd/talkd.c | 23 |
7 files changed, 96 insertions, 97 deletions
diff --git a/libexec/talkd/Makefile b/libexec/talkd/Makefile index 660ff7b462e..7829724e9aa 100644 --- a/libexec/talkd/Makefile +++ b/libexec/talkd/Makefile @@ -1,8 +1,9 @@ -# from: @(#)Makefile 5.10 (Berkeley) 5/11/90 -# $Id: Makefile,v 1.3 1994/12/22 10:28:15 cgd Exp $ +# $NetBSD: Makefile,v 1.4 1997/06/29 18:01:12 christos Exp $ +# @(#)Makefile 8.1 (Berkeley) 6/4/93 -PROG= ntalkd -SRCS= talkd.c announce.c process.c table.c print.c +PROG= talkd +SRCS= talkd.c announce.c process.c table.c print.c ttymsg.c +.PATH: ${.CURDIR}/../../usr.bin/wall MAN= talkd.8 .include <bsd.prog.mk> diff --git a/libexec/talkd/announce.c b/libexec/talkd/announce.c index 8314dd504dd..b928718ce0f 100644 --- a/libexec/talkd/announce.c +++ b/libexec/talkd/announce.c @@ -1,6 +1,8 @@ +/* $NetBSD: announce.c,v 1.7 1997/06/29 18:01:13 christos Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,12 +33,18 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> + #ifndef lint -/*static char sccsid[] = "from: @(#)announce.c 5.9 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$Id: announce.c,v 1.6 1996/07/17 18:46:58 rat Exp $"; +#if 0 +static char sccsid[] = "@(#)announce.c 8.3 (Berkeley) 4/28/95"; +#else +__RCSID("$NetBSD: announce.c,v 1.7 1997/06/29 18:01:13 christos Exp $"); +#endif #endif /* not lint */ #include <sys/types.h> +#include <sys/uio.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> @@ -56,77 +64,30 @@ extern char hostname[]; /* * Announce an invitation to talk. - * - * Because the tty driver insists on attaching a terminal-less - * process to any terminal that it writes on, we must fork a child - * to protect ourselves */ -announce(request, remote_machine) - CTL_MSG *request; - char *remote_machine; -{ - int pid, val, status; - if (pid = fork()) { - /* we are the parent, so wait for the child */ - if (pid == -1) /* the fork failed */ - return (FAILED); - do { - val = wait(&status); - if (val == -1) { - if (errno == EINTR) - continue; - /* shouldn't happen */ - syslog(LOG_WARNING, "announce: wait: %m"); - return (FAILED); - } - } while (val != pid); - if (status&0377 > 0) /* we were killed by some signal */ - return (FAILED); - /* Get the second byte, this is the exit/return code */ - return ((status >> 8) & 0377); - } - /* we are the child, go and do it */ - _exit(announce_proc(request, remote_machine)); -} - /* * See if the user is accepting messages. If so, announce that * a talk is requested. */ -announce_proc(request, remote_machine) +announce(request, remote_machine) CTL_MSG *request; char *remote_machine; { - int pid, status; char full_tty[32]; FILE *tf; struct stat stbuf; - (void)snprintf(full_tty, sizeof(full_tty), "%s/%s", _PATH_DEV, - request->r_tty); - if (access(full_tty, 0) != 0) - return (FAILED); - if ((tf = fopen(full_tty, "w")) == NULL) + (void)snprintf(full_tty, sizeof(full_tty), + "%s%s", _PATH_DEV, request->r_tty); + if (stat(full_tty, &stbuf) < 0 || (stbuf.st_mode&020) == 0) return (PERMISSION_DENIED); - /* - * On first tty open, the server will have - * it's pgrp set, so disconnect us from the - * tty before we catch a signal. - */ - ioctl(fileno(tf), TIOCNOTTY, (struct sgttyb *) 0); - if (fstat(fileno(tf), &stbuf) < 0) - return (PERMISSION_DENIED); - if ((stbuf.st_mode&020) == 0) - return (PERMISSION_DENIED); - print_mesg(tf, request, remote_machine); - fclose(tf); - return (SUCCESS); + return (print_mesg(request->r_tty, tf, request, remote_machine)); } #define max(a,b) ( (a) > (b) ? (a) : (b) ) #define N_LINES 5 -#define N_CHARS 120 +#define N_CHARS 256 /* * Build a block of characters containing the message. @@ -134,7 +95,8 @@ announce_proc(request, remote_machine) * try to keep the message in one piece if the recipient * in in vi at the time */ -print_mesg(tf, request, remote_machine) +print_mesg(tty, tf, request, remote_machine) + char *tty; FILE *tf; CTL_MSG *request; char *remote_machine; @@ -143,6 +105,7 @@ print_mesg(tf, request, remote_machine) time_t clocktime; struct timezone zone; struct tm *localclock; + struct iovec iovec; char line_buf[N_LINES][N_CHARS]; int sizes[N_LINES]; char big_buf[N_LINES*N_CHARS]; @@ -196,7 +159,15 @@ print_mesg(tf, request, remote_machine) *(bptr++) = '\n'; } *bptr = '\0'; - fprintf(tf, big_buf); - fflush(tf); - ioctl(fileno(tf), TIOCNOTTY, (struct sgttyb *) 0); + iovec.iov_base = big_buf; + iovec.iov_len = bptr - big_buf; + /* + * we choose a timeout of RING_WAIT-5 seconds so that we don't + * stack up processes trying to write messages to a tty + * that is permanently blocked. + */ + if (ttymsg(&iovec, 1, tty, RING_WAIT - 5) != NULL) + return (FAILED); + + return (SUCCESS); } diff --git a/libexec/talkd/print.c b/libexec/talkd/print.c index d785656da3b..972f4dd4533 100644 --- a/libexec/talkd/print.c +++ b/libexec/talkd/print.c @@ -1,6 +1,8 @@ +/* $NetBSD: print.c,v 1.3 1997/06/29 18:01:13 christos Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,9 +33,13 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -/*static char sccsid[] = "from: @(#)print.c 5.8 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$Id: print.c,v 1.2 1993/08/01 18:29:35 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)print.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: print.c,v 1.3 1997/06/29 18:01:13 christos Exp $"); +#endif #endif /* not lint */ /* debug print routines */ diff --git a/libexec/talkd/process.c b/libexec/talkd/process.c index 93ec13a2781..b866f016542 100644 --- a/libexec/talkd/process.c +++ b/libexec/talkd/process.c @@ -1,6 +1,8 @@ +/* $NetBSD: process.c,v 1.3 1997/06/29 18:01:14 christos Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,9 +33,13 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -/*static char sccsid[] = "from: @(#)process.c 5.10 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$Id: process.c,v 1.2 1993/08/01 18:29:34 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)process.c 8.2 (Berkeley) 11/16/93"; +#else +__RCSID("$NetBSD: process.c,v 1.3 1997/06/29 18:01:14 christos Exp $"); +#endif #endif /* not lint */ /* @@ -183,7 +189,8 @@ find_user(name, tty) int status; FILE *fd; struct stat statb; - char ftty[20]; + char line[sizeof(ubuf.ut_line) + 1]; + char ftty[sizeof(_PATH_DEV) - 1 + sizeof(line)]; if ((fd = fopen(_PATH_UTMP, "r")) == NULL) { fprintf(stderr, "talkd: can't read %s.\n", _PATH_UTMP); @@ -194,19 +201,22 @@ find_user(name, tty) (void) strcpy(ftty, _PATH_DEV); while (fread((char *) &ubuf, sizeof ubuf, 1, fd) == 1) if (SCMPN(ubuf.ut_name, name) == 0) { + (void)strncpy(line, ubuf.ut_line, sizeof(ubuf.ut_line)); + line[sizeof(ubuf.ut_line)] = '\0'; if (*tty == '\0') { status = PERMISSION_DENIED; /* no particular tty was requested */ - (void) strcpy(ftty+5, ubuf.ut_line); - if (stat(ftty,&statb) == 0) { + (void) strcpy(ftty + sizeof(_PATH_DEV) - 1, + line); + if (stat(ftty, &statb) == 0) { if (!(statb.st_mode & 020)) continue; - (void) strcpy(tty, ubuf.ut_line); + (void) strcpy(tty, line); status = SUCCESS; break; } } - if (strcmp(ubuf.ut_line, tty) == 0) { + if (strcmp(line, tty) == 0) { status = SUCCESS; break; } diff --git a/libexec/talkd/table.c b/libexec/talkd/table.c index 91eb34bae4d..7965234627d 100644 --- a/libexec/talkd/table.c +++ b/libexec/talkd/table.c @@ -1,6 +1,8 @@ +/* $NetBSD: table.c,v 1.3 1997/06/29 18:01:15 christos Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,9 +33,13 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -/*static char sccsid[] = "from: @(#)table.c 5.7 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$Id: table.c,v 1.2 1993/08/01 18:29:32 mycroft Exp $"; +#if 0 +static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: table.c,v 1.3 1997/06/29 18:01:15 christos Exp $"); +#endif #endif /* not lint */ /* diff --git a/libexec/talkd/talkd.8 b/libexec/talkd/talkd.8 index 1918c1b8adc..8851586de2d 100644 --- a/libexec/talkd/talkd.8 +++ b/libexec/talkd/talkd.8 @@ -1,5 +1,6 @@ -.\" Copyright (c) 1983, 1991 The Regents of the University of California. -.\" All rights reserved. +.\" $NetBSD: talkd.8,v 1.3 1997/06/29 18:01:15 christos Exp $ +.\" Copyright (c) 1983, 1991, 1993 +.\" The Regents of the University of California. All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions @@ -29,10 +30,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" from: @(#)talkd.8 6.5 (Berkeley) 3/16/91 -.\" $Id: talkd.8,v 1.2 1993/08/01 07:39:52 mycroft Exp $ +.\" @(#)talkd.8 8.2 (Berkeley) 12/11/93 .\" -.Dd March 16, 1991 +.Dd December 11, 1993 .Dt TALKD 8 .Os BSD 4.3 .Sh NAME @@ -44,7 +44,7 @@ .Nm Talkd is the server that notifies a user that someone else wants to initiate a conversation. -It acts a repository of invitations, responding to requests +It acts as a repository of invitations, responding to requests by clients wishing to rendezvous to hold a conversation. In normal operation, a client, the caller, initiates a rendezvous by sending a diff --git a/libexec/talkd/talkd.c b/libexec/talkd/talkd.c index bc5244b7efa..911aaddf2dc 100644 --- a/libexec/talkd/talkd.c +++ b/libexec/talkd/talkd.c @@ -1,6 +1,8 @@ +/* $NetBSD: talkd.c,v 1.5 1997/06/29 18:01:16 christos Exp $ */ + /* - * Copyright (c) 1983 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -31,15 +33,18 @@ * SUCH DAMAGE. */ +#include <sys/cdefs.h> #ifndef lint -char copyright[] = -"@(#) Copyright (c) 1983 Regents of the University of California.\n\ - All rights reserved.\n"; +__COPYRIGHT("@(#) Copyright (c) 1983, 1993\n\ + The Regents of the University of California. All rights reserved.\n"); #endif /* not lint */ #ifndef lint -/*static char sccsid[] = "from: @(#)talkd.c 5.8 (Berkeley) 2/26/91";*/ -static char rcsid[] = "$Id: talkd.c,v 1.4 1997/01/29 10:30:14 explorer Exp $"; +#if 0 +static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93"; +#else +__RCSID("$NetBSD: talkd.c,v 1.5 1997/06/29 18:01:16 christos Exp $"); +#endif #endif /* not lint */ /* @@ -84,7 +89,7 @@ main(argc, argv) int cc; if (getuid()) { - fprintf(stderr, "%s: getuid: not super-user", argv[0]); + fprintf(stderr, "%s: getuid: not super-user\n", argv[0]); exit(1); } openlog("talkd", LOG_PID, LOG_DAEMON); @@ -92,7 +97,7 @@ main(argc, argv) syslog(LOG_ERR, "gethostname: %m"); _exit(1); } - hostname[MAXHOSTNAMELEN] = 0; /* ensure null termination */ + hostname[MAXHOSTNAMELEN] = '\0'; /* ensure null termination */ if (chdir(_PATH_DEV) < 0) { syslog(LOG_ERR, "chdir: %s: %m", _PATH_DEV); _exit(1); |
