- Timestamp:
- Feb 16, 2009, 2:48:16 PM (16 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
zephyr.c
re2a620b r52a0f14 13 13 #endif 14 14 15 int owl_zephyr_initialize() 16 { 17 #ifdef HAVE_LIBZEPHYR 15 #define HM_SVC_FALLBACK htons((unsigned short) 2104) 16 17 #ifdef HAVE_LIBZEPHYR 18 void owl_zephyr_initialize() 19 { 18 20 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(¬ice)) != 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 #endif39 return(0);40 }41 42 #ifdef HAVE_LIBZEPHYR43 #define HM_SVC_FALLBACK htons((unsigned short) 2104)44 45 /*46 * Code modified from libzephyr's ZhmStat.c47 *48 * Modified to only wait one second to time out if there is no49 * hostmanager present, rather than a rather excessive 10 seconds.50 */51 Code_t owl_zhm_stat(ZNotice_t *notice) {52 21 struct servent *sp; 53 22 struct sockaddr_in sin; 54 23 ZNotice_t req; 55 24 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 } 58 38 59 39 (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in)); … … 76 56 req.z_default_format = ""; 77 57 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 77 void 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 106 void 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 130 void owl_zephyr_initialize() 131 { 132 } 133 #endif 134 100 135 101 136 int owl_zephyr_shutdown()
Note: See TracChangeset
for help on using the changeset viewer.