Changeset 52a0f14


Ignore:
Timestamp:
Feb 16, 2009, 2:48:16 PM (15 years ago)
Author:
Nelson Elhage <nelhage@mit.edu>
Branches:
master, debian, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
Children:
330c55a
Parents:
5008e51
Message:
stat the zhm asynchronously at startup.

If Zephyr is not present, this means we can continue booting
immediately, rather than waiting a second for the zhm to not
respond. The downside is that you no longer get an error message if
Zephyr is unavailable, but that can be fixed by adding a timeout
timer.
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • functions.c

    r23e1110 r52a0f14  
    921921  if (!owl_context_is_interactive(owl_global_get_context(&g))) return;
    922922  if (ret==0) {
    923     owl_function_makemsg("Subscribed to login messages from file.");
    924923  } else if (ret==-1) {
    925924    owl_function_error("Could not open file for login subscriptions.");
  • owl.c

    r23e1110 r52a0f14  
    4343  owl_editwin *tw;
    4444  owl_popwin *pw;
    45   int ret, initialsubs, debug, argcsave, followlast;
     45  int ret, debug, argcsave, followlast;
    4646  int newmsgs, nexttimediff;
    4747  struct sigaction sigact;
     
    6565  tty=NULL;
    6666  debug=0;
    67   initialsubs=1;
     67  g.load_initial_subs = 1;
    6868
    6969  setlocale(LC_ALL, "");
     
    7575  while (argc>0) {
    7676    if (!strcmp(argv[0], "-n")) {
    77       initialsubs=0;
     77      g.load_initial_subs = 0;
    7878      argv++;
    7979      argc--;
     
    191191    owl_select_add_dispatch(d);
    192192  }
    193  
    194 #ifdef HAVE_LIBZEPHYR
    195   /* zephyr init */
    196   ret=owl_zephyr_initialize();
    197   if (!ret) {
    198     owl_dispatch *d = owl_malloc(sizeof(owl_dispatch));
    199     d->fd = ZGetFD();
    200     d->cfunc = &owl_zephyr_process_events;
    201     d->destroy = NULL;
    202     owl_select_add_dispatch(d);
    203     owl_global_set_havezephyr(&g);
    204   }
    205 
    206 #endif
     193
     194  owl_zephyr_initialize();
    207195
    208196#if OWL_STDERR_REDIR
     
    339327
    340328  wrefresh(sepwin);
    341 
    342   /* load zephyr subs */
    343   if (initialsubs) {
    344     int ret2;
    345     owl_function_debugmsg("startup: loading initial zephyr subs");
    346 
    347     /* load default subscriptions */
    348     ret=owl_zephyr_loaddefaultsubs();
    349    
    350     /* load subscriptions from subs file */
    351     ret2=owl_zephyr_loadsubs(NULL, 0);
    352 
    353     if (ret || ret2) {
    354       owl_function_adminmsg("", "Error loading zephyr subscriptions");
    355     } else if (ret2!=-1) {
    356       owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES);
    357     }
    358 
    359     /* load login subscriptions */
    360     if (owl_global_is_loginsubs(&g)) {
    361       owl_function_debugmsg("startup: loading login subs");
    362       owl_function_loadloginsubs(NULL);
    363     }
    364   }
    365329
    366330  /* First buddy check to sync the list without notifications */
  • owl.h

    r23e1110 r52a0f14  
    594594  GList *timerlist;
    595595  owl_timer *aim_nop_timer;
     596  int load_initial_subs;
    596597} owl_global;
    597598
  • zephyr.c

    re2a620b r52a0f14  
    1313#endif
    1414
    15 int owl_zephyr_initialize()
    16 {
    17 #ifdef HAVE_LIBZEPHYR
     15#define HM_SVC_FALLBACK         htons((unsigned short) 2104)
     16
     17#ifdef HAVE_LIBZEPHYR
     18void owl_zephyr_initialize()
     19{
    1820  int ret;
    19   ZNotice_t notice;
    20 
    21   /* Stat the zhm manually, with a shorter timeout */
    22   if ((ret = ZOpenPort(NULL)) != ZERR_NONE)
    23     return(ret);
    24 
    25   if ((ret = owl_zhm_stat(&notice)) != ZERR_NONE)
    26     return(ret);
    27 
    28   ZClosePort();
    29 
    30   if ((ret = ZInitialize()) != ZERR_NONE) {
    31     com_err("owl",ret,"while initializing");
    32     return(1);
    33   }
    34   if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
    35     com_err("owl",ret,"while opening port");
    36     return(1);
    37   }
    38 #endif
    39   return(0);
    40 }
    41 
    42 #ifdef HAVE_LIBZEPHYR
    43 #define HM_SVC_FALLBACK         htons((unsigned short) 2104)
    44 
    45 /*
    46  * Code modified from libzephyr's ZhmStat.c
    47  *
    48  * Modified to only wait one second to time out if there is no
    49  * hostmanager present, rather than a rather excessive 10 seconds.
    50  */
    51 Code_t owl_zhm_stat(ZNotice_t *notice) {
    5221  struct servent *sp;
    5322  struct sockaddr_in sin;
    5423  ZNotice_t req;
    5524  Code_t code;
    56   struct timeval tv;
    57   fd_set readers;
     25  owl_dispatch *dispatch;
     26
     27  /*
     28   * Code modified from libzephyr's ZhmStat.c
     29   *
     30   * Modified to add the fd to our select loop, rather than hanging
     31   * until we get an ack.
     32   */
     33
     34  if ((ret = ZOpenPort(NULL)) != ZERR_NONE) {
     35    owl_function_error("Error opening Zephyr port: %s", error_message(ret));
     36    return;
     37  }
    5838
    5939  (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in));
     
    7656  req.z_default_format = "";
    7757  req.z_message_len = 0;
    78        
    79   if ((code = ZSetDestAddr(&sin)) != ZERR_NONE)
    80     return(code);
    81 
    82   if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE)
    83     return(code);
    84 
    85   /* Wait up to 1 second for a response. */
    86   FD_ZERO(&readers);
    87   FD_SET(ZGetFD(), &readers);
    88   tv.tv_sec = 1;
    89   tv.tv_usec = 0;
    90   code = select(ZGetFD() + 1, &readers, NULL, NULL, &tv);
    91   if (code < 0 && errno != EINTR)
    92     return(errno);
    93   if (code == 0 || (code < 0 && errno == EINTR) || ZPending() == 0)
    94     return(ZERR_HMDEAD);
    95 
    96   return(ZReceiveNotice(notice, (struct sockaddr_in *) 0));
    97 }
    98 
    99 #endif
     58
     59  if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) {
     60    owl_function_error("Initializing Zephyr: %s", error_message(code));
     61    return;
     62  }
     63
     64  if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) {
     65    owl_function_error("Initializing Zephyr: %s", error_message(code));
     66    return;
     67  }
     68
     69  dispatch = owl_malloc(sizeof(*dispatch));
     70  dispatch->fd = ZGetFD();
     71  dispatch->cfunc = owl_zephyr_finish_initialization;
     72  dispatch->destroy = (void(*)(owl_dispatch*))owl_free;
     73
     74  owl_select_add_dispatch(dispatch);
     75}
     76
     77void owl_zephyr_finish_initialization(owl_dispatch *d) {
     78  Code_t code;
     79
     80  owl_select_remove_dispatch(d->fd);
     81
     82  ZClosePort();
     83
     84  if ((code = ZInitialize()) != ZERR_NONE) {
     85    owl_function_error("Initializing Zephyr: %s", error_message(code));
     86    return;
     87  }
     88
     89  if ((code = ZOpenPort(NULL)) != ZERR_NONE) {
     90    owl_function_error("Initializing Zephyr: %s", error_message(code));
     91    return;
     92  }
     93
     94  d = owl_malloc(sizeof(owl_dispatch));
     95  d->fd = ZGetFD();
     96  d->cfunc = &owl_zephyr_process_events;
     97  d->destroy = NULL;
     98  owl_select_add_dispatch(d);
     99  owl_global_set_havezephyr(&g);
     100
     101  if(g.load_initial_subs) {
     102    owl_zephyr_load_initial_subs();
     103  }
     104}
     105
     106void owl_zephyr_load_initial_subs() {
     107  int ret, ret2;
     108
     109  owl_function_debugmsg("startup: loading initial zephyr subs");
     110
     111  /* load default subscriptions */
     112  ret = owl_zephyr_loaddefaultsubs();
     113
     114  /* load subscriptions from subs file */
     115  ret2 = owl_zephyr_loadsubs(NULL, 0);
     116
     117  if (ret || ret2) {
     118    owl_function_error("Error loading zephyr subscriptions");
     119  } else if (ret2!=-1) {
     120    owl_global_add_userclue(&g, OWL_USERCLUE_CLASSES);
     121  }
     122
     123  /* load login subscriptions */
     124  if (owl_global_is_loginsubs(&g)) {
     125    owl_function_debugmsg("startup: loading login subs");
     126    owl_function_loadloginsubs(NULL);
     127  }
     128}
     129#else
     130void owl_zephyr_initialize()
     131{
     132}
     133#endif
     134
    100135
    101136int owl_zephyr_shutdown()
Note: See TracChangeset for help on using the changeset viewer.