* Copyright (c) 1983 Regents of the University of California.
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
"@(#) Copyright (c) 1983 Regents of the University of California.\n\
static char sccsid
[] = "@(#)talkd.c 5.4 (Berkeley) 6/18/88";
* 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 <protocols/talkd.h>
register CTL_MSG
*mp
= &request
;
fprintf(stderr
, "%s: getuid: not super-user", argv
[0]);
openlog("talkd", LOG_PID
, LOG_DAEMON
);
if (gethostname(hostname
, sizeof (hostname
) - 1) < 0) {
syslog(LOG_ERR
, "gethostname: %m");
syslog(LOG_ERR
, "chdir: /dev: %m");
if (argc
> 1 && strcmp(argv
[1], "-d") == 0)
signal(SIGALRM
, timeout
);
cc
= recv(0, (char *)mp
, sizeof (*mp
), 0);
if (cc
!= sizeof (*mp
)) {
if (cc
< 0 && errno
!= EINTR
)
syslog(LOG_WARNING
, "recv: %m");
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");
if (time(0) - lastmsgtime
>= MAXIDLE
)