talkd.c
来自「<B>Digital的Unix操作系统VAX 4.2源码</B>」· C语言 代码 · 共 128 行
C
128 行
#ifndef lintstatic char *sccsid = "@(#)talkd.c 4.1 (ULTRIX) 7/2/90";#endif lint/************************************************************************ * * * Copyright (c) 1984,1988 by * * Digital Equipment Corporation, Maynard, MA * * All rights reserved. * * * * This software is furnished under a license and may be used and * * copied only in accordance with the terms of such license and * * with the inclusion of the above copyright notice. This * * software or any other copies thereof may not be provided or * * otherwise made available to any other person. No title to and * * ownership of the software is hereby transferred. * * * * This software is derived from software received from the * * University of California, Berkeley, and from Bell * * Laboratories. Use, duplication, or disclosure is subject to * * restrictions under license agreements with University of * * California and with AT&T. * * * * The information in this software is subject to change without * * notice and should not be construed as a commitment by Digital * * Equipment Corporation. * * * * Digital assumes no responsibility for the use or reliability * * of its software on equipment which is not supplied by Digital. * * * ************************************************************************//* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. *//*#ifndef lintchar copyright[] =" Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n";#endif not lint#ifndef lintstatic char sccsid[] = "talkd.c 5.2 (Berkeley) 3/13/86";#endif not lint*//* * The top level of the daemon, the format is heavily borrowed * from rwhod.c. Basically: find out who and where you are; * disconnect all descriptors and ttys, and then endless * loop on waiting for and processing requests */#include <stdio.h>#include <errno.h>#include <signal.h>#include <syslog.h>#include <protocols/talkd.h>CTL_MSG request;CTL_RESPONSE response;int sockt;int debug = 0;int timeout();long lastmsgtime;char hostname[32];#define TIMEOUT 30#define MAXIDLE 120main(argc, argv) int argc; char *argv[];{ register CTL_MSG *mp = &request; int cc; if (getuid()) { fprintf(stderr, "%s: getuid: not super-user", argv[0]); exit(1); }#ifdef 43BSD openlog("talkd", LOG_PID, LOG_DAEMON);#else openlog("talkd", LOG_PID);#endif if (gethostname(hostname, sizeof (hostname) - 1) < 0) { syslog(LOG_ERR, "gethostname: %m"); _exit(1); } if (chdir("/dev") < 0) { syslog(LOG_ERR, "chdir: /dev: %m"); _exit(1); } if (argc > 1 && strcmp(argv[1], "-d") == 0) debug = 1; signal(SIGALRM, timeout); alarm(TIMEOUT); for (;;) { extern int errno; cc = recv(0, (char *)mp, sizeof (*mp), 0); if (cc != sizeof (*mp)) { if (cc < 0 && errno != EINTR) syslog(LOG_WARNING, "recv: %m"); continue; } lastmsgtime = time(0); process_request(mp, &response); /* can block here, is this what I want? */ cc = sendto(sockt, (char *)&response, sizeof (response), 0, &mp->ctl_addr, sizeof (mp->ctl_addr)); if (cc != sizeof (response)) syslog(LOG_WARNING, "sendto: %m"); }}timeout(){ if (time(0) - lastmsgtime >= MAXIDLE) _exit(0); alarm(TIMEOUT);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?