talkd.c (9e522f7a18a64d3b9ea901ed70d0eee78342f0c6) | talkd.c (a846453c5ebbf21be4af27ac1e1679a3c00d8103) |
---|---|
1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. | 1/* 2 * Copyright (c) 1983, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. |
32 * 33 * $Id$ | |
34 */ 35 36#ifndef lint | 32 */ 33 34#ifndef lint |
37static char copyright[] = | 35static const char copyright[] = |
38"@(#) Copyright (c) 1983, 1993\n\ 39 The Regents of the University of California. All rights reserved.\n"; 40#endif /* not lint */ 41 42#ifndef lint | 36"@(#) Copyright (c) 1983, 1993\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint |
41#if 0 |
|
43static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93"; | 42static char sccsid[] = "@(#)talkd.c 8.1 (Berkeley) 6/4/93"; |
43#endif 44static const char rcsid[] = 45 "$Id$"; |
|
44#endif /* not lint */ 45 46/* 47 * The top level of the daemon, the format is heavily borrowed 48 * from rwhod.c. Basically: find out who and where you are; 49 * disconnect all descriptors and ttys, and then endless 50 * loop on waiting for and processing requests 51 */ 52#include <sys/types.h> 53#include <sys/socket.h> 54#include <sys/param.h> 55#include <protocols/talkd.h> | 46#endif /* not lint */ 47 48/* 49 * The top level of the daemon, the format is heavily borrowed 50 * from rwhod.c. Basically: find out who and where you are; 51 * disconnect all descriptors and ttys, and then endless 52 * loop on waiting for and processing requests 53 */ 54#include <sys/types.h> 55#include <sys/socket.h> 56#include <sys/param.h> 57#include <protocols/talkd.h> |
56#include <signal.h> 57#include <syslog.h> 58#include <time.h> | 58#include <err.h> |
59#include <errno.h> | 59#include <errno.h> |
60#include <unistd.h> | 60#include <paths.h> 61#include <signal.h> |
61#include <stdio.h> 62#include <stdlib.h> 63#include <string.h> | 62#include <stdio.h> 63#include <stdlib.h> 64#include <string.h> |
64#include <paths.h> | 65#include <syslog.h> 66#include <time.h> 67#include <unistd.h> |
65 66CTL_MSG request; 67CTL_RESPONSE response; 68 69int sockt; 70int debug = 0; | 68 69CTL_MSG request; 70CTL_RESPONSE response; 71 72int sockt; 73int debug = 0; |
71void timeout(); | |
72long lastmsgtime; 73 74char hostname[MAXHOSTNAMELEN + 1]; 75 76#define TIMEOUT 30 77#define MAXIDLE 120 78 | 74long lastmsgtime; 75 76char hostname[MAXHOSTNAMELEN + 1]; 77 78#define TIMEOUT 30 79#define MAXIDLE 120 80 |
81void process_request __P((CTL_MSG *, CTL_RESPONSE *)); 82void timeout(); 83 84int |
|
79main(argc, argv) 80 int argc; 81 char *argv[]; 82{ 83 register CTL_MSG *mp = &request; 84 int cc; 85 | 85main(argc, argv) 86 int argc; 87 char *argv[]; 88{ 89 register CTL_MSG *mp = &request; 90 int cc; 91 |
86 if (getuid()) { 87 fprintf(stderr, "%s: getuid: not super-user\n", argv[0]); 88 exit(1); 89 } | 92 if (getuid()) 93 errx(1, "getuid: not super-user"); |
90 openlog("talkd", LOG_PID, LOG_DAEMON); 91 if (gethostname(hostname, sizeof (hostname) - 1) < 0) { 92 syslog(LOG_ERR, "gethostname: %m"); 93 _exit(1); 94 } 95 if (chdir(_PATH_DEV) < 0) { 96 syslog(LOG_ERR, "chdir: %s: %m", _PATH_DEV); 97 _exit(1); 98 } 99 if (argc > 1 && strcmp(argv[1], "-d") == 0) 100 debug = 1; 101 signal(SIGALRM, timeout); 102 alarm(TIMEOUT); 103 for (;;) { | 94 openlog("talkd", LOG_PID, LOG_DAEMON); 95 if (gethostname(hostname, sizeof (hostname) - 1) < 0) { 96 syslog(LOG_ERR, "gethostname: %m"); 97 _exit(1); 98 } 99 if (chdir(_PATH_DEV) < 0) { 100 syslog(LOG_ERR, "chdir: %s: %m", _PATH_DEV); 101 _exit(1); 102 } 103 if (argc > 1 && strcmp(argv[1], "-d") == 0) 104 debug = 1; 105 signal(SIGALRM, timeout); 106 alarm(TIMEOUT); 107 for (;;) { |
104 extern int errno; 105 | |
106 cc = recv(0, (char *)mp, sizeof (*mp), 0); 107 if (cc != sizeof (*mp)) { 108 if (cc < 0 && errno != EINTR) 109 syslog(LOG_WARNING, "recv: %m"); 110 continue; 111 } 112 lastmsgtime = time(0); 113 process_request(mp, &response); --- 18 unchanged lines hidden --- | 108 cc = recv(0, (char *)mp, sizeof (*mp), 0); 109 if (cc != sizeof (*mp)) { 110 if (cc < 0 && errno != EINTR) 111 syslog(LOG_WARNING, "recv: %m"); 112 continue; 113 } 114 lastmsgtime = time(0); 115 process_request(mp, &response); --- 18 unchanged lines hidden --- |