source: trunk/athena/bin/attach/zephyr.c @ 7155

Revision 7155, 3.0 KB checked in by miki, 30 years ago (diff)
removed a call to sigaddset which was unnecessary
Line 
1/*      Created by:     Robert French
2 *
3 *      $Source: /afs/dev.mit.edu/source/repository/athena/bin/attach/zephyr.c,v $
4 *      $Author: miki $
5 *
6 *      Copyright (c) 1988 by the Massachusetts Institute of Technology.
7 */
8
9#ifndef lint
10static char rcsid_zephyr_c[] = "$Header: /afs/dev.mit.edu/source/repository/athena/bin/attach/zephyr.c,v 1.10 1994-03-25 15:59:13 miki Exp $";
11#endif
12
13#include "attach.h"
14#ifdef ZEPHYR
15#include <zephyr/zephyr.h>
16#include <setjmp.h>
17#include <signal.h>
18
19#ifdef __HIGHC__
20#define min(x,y)        _min(x,y)
21#else
22#define min(x,y)        ((x)<(y)?(x):(y))
23#endif
24
25#define ZEPHYR_MAXONEPACKET 5
26Code_t ZSubscribeTo(), ZUnsubscribeTo();
27
28static ZSubscription_t subs[ZEPHYR_MAXSUBS];
29static int num_subs = 0;
30
31static jmp_buf  timeout;
32
33static sig_catch zephyr_timeout()
34{
35        longjmp(timeout, 1);
36}
37
38static int zephyr_op(func)
39    Code_t (*func)();
40{
41    static int inited = 0;
42    static int wgport = 0;
43    int count, count2;
44    ZSubscription_t shortsubs[ZEPHYR_MAXONEPACKET];
45    Code_t retval;
46#ifdef POSIX
47    struct sigaction newsig, oldsig;
48#else
49    sig_catch   (*oldsig)();
50#endif
51
52    if (setjmp(timeout))
53            return 1;           /* We timed out, punt */
54
55#ifdef POSIX
56    newsig.sa_handler = zephyr_timeout;
57    sigemptyset(&newsig.sa_mask);
58    newsig.sa_flags = 0;
59    sigaction(SIGALRM, &newsig, &oldsig);
60#else
61    oldsig = signal(SIGALRM, zephyr_timeout);
62#endif
63    alarm(ZEPHYR_TIMEOUT);
64   
65    if (inited < 0)
66        return 1;
67
68    if (!num_subs)
69        return 0;       /* Can't lose if doing nothing */
70
71    if (!inited) {
72        if ((retval = ZInitialize()) != ZERR_NONE) {
73            com_err(progname, retval, "while intializing Zephyr library");
74            inited = -1;
75            return 1;
76        }
77        if ((wgport = ZGetWGPort()) == -1) {
78            /*
79             * Be quiet about windowgram lossage
80             */
81            inited = -1;
82            return 1;
83        }
84        inited = 1;
85    }
86
87    for (count=0; count<num_subs; count += ZEPHYR_MAXONEPACKET) {
88        for (count2=0; count2<min(ZEPHYR_MAXONEPACKET,num_subs-count); count2++)
89            shortsubs[count2] = subs[count+count2];
90        if ((retval = (func)(shortsubs,
91                             min(ZEPHYR_MAXONEPACKET,num_subs-count),
92                             wgport)) != ZERR_NONE) {
93            fprintf(stderr, "Error while subscribing: %s\n",
94                    error_message(retval));
95            inited = -1;
96            return 1;
97        }
98    }
99    alarm(0);
100#ifdef POSIX
101    sigaction(SIGALRM, &oldsig, (struct sigaction *)0);
102#else
103    (void) signal(SIGALRM, oldsig);
104#endif
105    return 0;
106}
107
108void zephyr_addsub(class)
109    const char *class;
110{
111    if (num_subs == ZEPHYR_MAXSUBS)
112        return;
113   
114    if (debug_flag)
115            printf("Subscribing to zephyr instance %s.\n", class);
116    subs[num_subs].zsub_recipient = "*";
117    subs[num_subs].zsub_classinst = strdup(class);
118    subs[num_subs].zsub_class = ZEPHYR_CLASS;
119    num_subs++;
120}
121
122int zephyr_sub(iszinit)
123int iszinit;
124{
125    if(zephyr_op(ZSubscribeTo) && iszinit)
126      {
127        error_status = ERR_ZINITZLOSING;
128        return FAILURE;
129      }
130    return SUCCESS;
131}
132
133int zephyr_unsub(iszinit)
134int iszinit;
135{
136    if(zephyr_op(ZUnsubscribeTo) && iszinit)
137      {
138        error_status = ERR_ZINITZLOSING;
139        return FAILURE;
140      }
141    return SUCCESS;
142}
143#endif
Note: See TracBrowser for help on using the repository browser.