4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
30 #pragma ident "%Z%%M% %I% %E% SMI"
33 #include <sys/types.h>
38 #if !defined(__cplusplus) && !defined(c_plusplus)
39 typedef void (*SIG_PF
) (int);
44 static SIG_PF
catcher(void);
46 static SIG_PF
catcher(void)
48 /* do nothing, but allow the write() to break */
53 notify(char *user
, char *msg
, int check_mesg_y
, char *etcdir
)
55 /* search the utmp file for this user */
57 unsigned int oldalarm
;
58 struct utmpx utmpx
, *putmpx
= &utmpx
;
62 /* grab the tty name */
63 while ((putmpx
= getutxent()) != NULL
) {
64 if (strncmp(user
, utmpx
.ut_name
,
65 sizeof (utmpx
.ut_name
)) == 0) {
66 char tty
[sizeof (utmpx
.ut_line
)+1];
67 char dev
[MAXFILENAME
];
72 for (i
= 0; i
< sizeof (utmpx
.ut_line
); i
++)
73 tty
[i
] = utmpx
.ut_line
[i
];
76 /* stick /dev/ in front */
77 (void) sprintf(dev
, "%s/dev/%s", etcdir
, tty
);
79 /* break out if write() to the tty hangs */
80 old
= (SIG_PF
)signal(SIGALRM
, (SIG_PF
)catcher
);
81 oldalarm
= alarm(300);
83 /* check if device is really a tty */
84 if ((fd
= open(dev
, O_WRONLY
|O_NOCTTY
)) == -1) {
85 (void) fprintf(stderr
,
86 "Cannot open %s.\n", dev
);
90 (void) fprintf(stderr
, "%s in utmpx is "
92 openlog("mail", 0, LOG_AUTH
);
93 syslog(LOG_CRIT
, "%s in utmp is "
102 /* write to the tty */
103 port
= fopen(dev
, "w");
105 (void) fprintf(port
, "\r\n%s\r\n", msg
);
109 /* clean up our alarm */
111 (void) signal(SIGALRM
, old
);
112 (void) alarm(oldalarm
);