source: trunk/athena/bin/get_message/view_message_by_zephyr.c @ 23691

Revision 23691, 1.8 KB checked in by broder, 15 years ago (diff)
In get_message: * Try $ATHENA_USER before using $USER.
Line 
1/* Copyright 1988, 1998 by the Massachusetts Institute of Technology.
2 *
3 * Permission to use, copy, modify, and distribute this
4 * software and its documentation for any purpose and without
5 * fee is hereby granted, provided that the above copyright
6 * notice appear in all copies and that both that copyright
7 * notice and this permission notice appear in supporting
8 * documentation, and that the name of M.I.T. not be used in
9 * advertising or publicity pertaining to distribution of the
10 * software without specific, written prior permission.
11 * M.I.T. makes no representations about the suitability of
12 * this software for any purpose.  It is provided "as is"
13 * without express or implied warranty.
14 */
15
16static const char rcsid[] = "$Id: view_message_by_zephyr.c,v 1.1 1999-12-08 22:06:46 danw Exp $";
17
18#include "globalmessage.h"
19#include <pwd.h>
20#include <stdio.h>
21#include <stdlib.h>
22#include <syslog.h>
23#include <unistd.h>
24#include <com_err.h>
25
26void view_message_by_zephyr(char *message)
27{
28  char *whoami;
29  char *ptr;
30 
31  whoami = getenv("ATHENA_USER");
32  if (!whoami)
33    whoami = getenv("USER");
34 
35  if(!whoami)
36    whoami = getlogin();
37 
38  if(!whoami) {
39    struct passwd *pw;
40    pw = getpwuid(getuid());
41    if(pw) {
42      whoami = pw->pw_name;
43    } else {
44      fprintf(stderr,
45              "get_message: couldn't find username to send zephyr notice\n");
46      exit(2);
47    }
48  }
49  /* skip magic headers */
50  ptr = strchr(message, '\n')+1;
51 
52  /* check that there is *something* after the headers */
53  if(*ptr) {
54    /* don't even fork... this just exits anyway... */
55    execl("/usr/bin/zwrite",
56          "zwrite", "-d", "-q", "-n",  whoami, "-m", ptr, 0);
57    /* put logging here in case the exec fails. */
58    syslog(LOG_INFO, "GMS client execl of zwrite failed [%s]",
59           error_message(errno));
60  }
61}
Note: See TracBrowser for help on using the repository browser.