/* * Close a stream */ void ww_output_close(int output_id) { int i; /* Setup */ if (!initialized) { return; } /* If it's valid, used, enabled, and has an open file descriptor, * free the resources associated with the descriptor */ if (output_id >= 0 && output_id < WW_OUTPUT_MAX_STREAMS && info[output_id].ldi_used && info[output_id].ldi_enabled) { free_descriptor(output_id); /* If no one has the syslog open, we should close it */ for (i = 0; i < WW_OUTPUT_MAX_STREAMS; ++i) { if (info[i].ldi_used && info[i].ldi_syslog) { break; } } #if defined(HAVE_SYSLOG) if (i >= WW_OUTPUT_MAX_STREAMS && syslog_opened) { closelog(); } #endif } }
void wipe_descriptor(DESCRIPTOR_DATA *d) { close(d->socket); d->state = STATE_VOID; d->socket = -1; destroy_d_events(d, EVENT_ALL); unlink_account(d->acc); unlink_descriptor(d); free_account(d->acc); free_descriptor(d); }
void delete_list_table(struct list_table* table) { if(!table) return; struct list_descriptor* current = table->head; while(current) { struct list_descriptor* next = current->next; free_descriptor(current); current = next; } free(table); }
/* * Close a stream */ void opal_output_close(int output_id) { int i; /* Setup */ if (!initialized) { return; } /* If it's valid, used, enabled, and has an open file descriptor, * free the resources associated with the descriptor */ OPAL_THREAD_LOCK(&mutex); if (output_id >= 0 && output_id < OPAL_OUTPUT_MAX_STREAMS && info[output_id].ldi_used && info[output_id].ldi_enabled) { free_descriptor(output_id); /* If no one has the syslog open, we should close it */ for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) { if (info[i].ldi_used && info[i].ldi_syslog) { break; } } #if defined(HAVE_SYSLOG) if (i >= OPAL_OUTPUT_MAX_STREAMS && syslog_opened) { closelog(); } #elif defined(__WINDOWS__) if(info[output_id].ldi_syslog_ident != NULL) { DeregisterEventSource(info[output_id].ldi_syslog_ident); } #endif } /* Somewhat of a hack to free up the temp_str */ if (NULL != temp_str) { free(temp_str); temp_str = NULL; temp_str_len = 0; } OPAL_THREAD_UNLOCK(&mutex); }
void list_deallocate(struct list_table* table, size_t lid) { if(!table) return; struct list_descriptor* current = table->head, *prev = NULL; while(current) { if(current->list_id == lid) { if(prev) // has a previous prev->next = current->next; else // otherwise make point the table_list head on the scnd element table->head = current->next; free_descriptor(current); return; } prev = current; current = current->next; } }
/* * Back-end of open() and reopen(). */ static int do_open(int output_id, ww_output_stream_t * lds) { int i; bool redirect_to_file = false; char *str, *sfx; /* Setup */ if (!initialized) { ww_output_init(); } str = getenv("WW_OUTPUT_REDIRECT"); if (NULL != str && 0 == strcasecmp(str, "file")) { redirect_to_file = true; } sfx = getenv("WW_OUTPUT_SUFFIX"); /* If output_id == -1, find an available stream, or return * WW_ERROR */ if (-1 == output_id) { for (i = 0; i < WW_OUTPUT_MAX_STREAMS; ++i) { if (!info[i].ldi_used) { break; } } if (i >= WW_OUTPUT_MAX_STREAMS) { return WW_ERR_OUT_OF_RESOURCE; } } /* Otherwise, we're reopening, so we need to free all previous * resources, close files, etc. */ else { free_descriptor(output_id); i = output_id; } /* Special case: if we got NULL for lds, then just use the default * verbose */ if (NULL == lds) { lds = &verbose; } /* Got a stream -- now initialize it and open relevant outputs */ info[i].ldi_used = true; info[i].ldi_enabled = lds->lds_is_debugging ? (bool) WW_ENABLE_DEBUG : true; info[i].ldi_verbose_level = lds->lds_verbose_level; #if USE_SYSLOG #if defined(HAVE_SYSLOG) if (ww_output_redirected_to_syslog) { info[i].ldi_syslog = true; info[i].ldi_syslog_priority = ww_output_redirected_syslog_pri; if (NULL != redirect_syslog_ident) { info[i].ldi_syslog_ident = strdup(redirect_syslog_ident); openlog(redirect_syslog_ident, LOG_PID, LOG_USER); } else { info[i].ldi_syslog_ident = NULL; openlog("ww", LOG_PID, LOG_USER); } syslog_opened = true; } else { #endif info[i].ldi_syslog = lds->lds_want_syslog; if (lds->lds_want_syslog) { #if defined(HAVE_SYSLOG) if (NULL != lds->lds_syslog_ident) { info[i].ldi_syslog_ident = strdup(lds->lds_syslog_ident); openlog(lds->lds_syslog_ident, LOG_PID, LOG_USER); } else { info[i].ldi_syslog_ident = NULL; openlog("ww", LOG_PID, LOG_USER); } #endif syslog_opened = true; info[i].ldi_syslog_priority = lds->lds_syslog_priority; } #if defined(HAVE_SYSLOG) } #endif #else info[i].ldi_syslog = false; #endif if (NULL != lds->lds_prefix) { info[i].ldi_prefix = strdup(lds->lds_prefix); info[i].ldi_prefix_len = (int)strlen(lds->lds_prefix); } else { info[i].ldi_prefix = NULL; info[i].ldi_prefix_len = 0; } if (NULL != lds->lds_suffix) { info[i].ldi_suffix = strdup(lds->lds_suffix); info[i].ldi_suffix_len = (int)strlen(lds->lds_suffix); } else { info[i].ldi_suffix = NULL; info[i].ldi_suffix_len = 0; } if (ww_output_redirected_to_syslog) { /* since all is redirected to syslog, ensure * we don't duplicate the output to the std places */ info[i].ldi_stdout = false; info[i].ldi_stderr = false; info[i].ldi_file = false; info[i].ldi_fd = -1; } else { /* since we aren't redirecting to syslog, use what was * given to us */ if (NULL != str && redirect_to_file) { info[i].ldi_stdout = false; info[i].ldi_stderr = false; info[i].ldi_file = true; } else { info[i].ldi_stdout = lds->lds_want_stdout; info[i].ldi_stderr = lds->lds_want_stderr; info[i].ldi_fd = -1; info[i].ldi_file = lds->lds_want_file; } if (NULL != sfx) { info[i].ldi_file_suffix = strdup(sfx); } else { info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL : strdup(lds->lds_file_suffix); } info[i].ldi_file_want_append = lds->lds_want_file_append; info[i].ldi_file_num_lines_lost = 0; } /* Don't open a file in the session directory now -- do that lazily * so that if there's no output, we don't have an empty file */ return i; }
void close_socket (DESCRIPTOR_DATA * d) { DESCRIPTOR_DATA *tmp; char buf[100]; if (d->connected == CON_SOFT_REBOOT) /* Soft reboot sockets. */ return; if (d->character) /* I don't know about this one. . . */ d->character->desc = 0; close (d->hSocketFD); flush_queues (d); if (d->hSocketFD == maxdesc) --maxdesc; if (d->character && d->connected != CON_PLYNG) { unload_pc (d->character); d->character = NULL; } else if (d->character && d->connected == CON_PLYNG) { if (d->character->pc) d->character->pc->last_disconnect = time (0); save_char (d->character, true); /* KLUDGE: If the player is disconnecting is staff, he will get a message about himself disconnecting. However, he will be gone before that message gets to him, and the message will sit around in memory. By saying he isn't connected, the message will not be sent. (connected = -1) */ if (d->original) { d->character = d->original; d->original = NULL; } sprintf (s_buf, "%s has lost link.\n", d->character->tname); d->connected = CON_LINKDEAD; send_to_gods (s_buf); d->connected = CON_PLYNG; if (d->snoop.snooping && d->snoop.snooping->desc) { d->snoop.snooping->desc->snoop.snoop_by = 0; d->snoop.snooping = 0; } if (d->snoop.snoop_by && d->snoop.snoop_by->desc) { d->snoop.snoop_by->desc->snoop.snooping = 0; d->snoop.snoop_by = 0; } if (d->character->pc) d->character->pc->owner = 0; if (IS_MORTAL (d->character) && !IS_SET (d->character->flags, FLAG_GUEST)) { act ("$n has lost link.", true, d->character, 0, 0, TO_ROOM); sprintf (buf, "Closing link to: %s.", GET_NAME (d->character)); system_log (buf, false); d->character->desc = 0; } else if (IS_SET (d->character->flags, FLAG_GUEST)) do_quit (d->character, "", 0); } if (d->acct) delete d->acct; if (next_to_process == d) next_to_process = next_to_process->next; if (d == descriptor_list) { /* this is the head of the list */ descriptor_list = descriptor_list->next; } else { for (tmp = descriptor_list; tmp->next; tmp = tmp->next) if (tmp->next == d) { tmp->next = tmp->next->next; break; } } d->next = NULL; free_descriptor (d); socket_closed = true; }
/* * Back-end of open() and reopen(). Necessary to have it as a * back-end function so that we can do the thread locking properly * (especially upon reopen). */ static int do_open(int output_id, opal_output_stream_t * lds) { int i; /* Setup */ if (!initialized) { opal_output_init(); } /* If output_id == -1, find an available stream, or return * OPAL_ERROR */ if (-1 == output_id) { OPAL_THREAD_LOCK(&mutex); for (i = 0; i < OPAL_OUTPUT_MAX_STREAMS; ++i) { if (!info[i].ldi_used) { break; } } if (i >= OPAL_OUTPUT_MAX_STREAMS) { OPAL_THREAD_UNLOCK(&mutex); return OPAL_ERR_OUT_OF_RESOURCE; } } /* Otherwise, we're reopening, so we need to free all previous * resources, close files, etc. */ else { free_descriptor(output_id); i = output_id; } /* Special case: if we got NULL for lds, then just use the default * verbose */ if (NULL == lds) { lds = &verbose; } /* Got a stream -- now initialize it and open relevant outputs */ info[i].ldi_used = true; if (-1 == output_id) { OPAL_THREAD_UNLOCK(&mutex); } info[i].ldi_enabled = lds->lds_is_debugging ? (bool) OPAL_ENABLE_DEBUG : true; info[i].ldi_verbose_level = lds->lds_verbose_level; #if USE_SYSLOG #if defined(HAVE_SYSLOG) if (opal_output_redirected_to_syslog) { info[i].ldi_syslog = true; info[i].ldi_syslog_priority = opal_output_redirected_syslog_pri; if (NULL != redirect_syslog_ident) { info[i].ldi_syslog_ident = strdup(redirect_syslog_ident); openlog(redirect_syslog_ident, LOG_PID, LOG_USER); } else { info[i].ldi_syslog_ident = NULL; openlog("opal", LOG_PID, LOG_USER); } syslog_opened = true; } else { #endif info[i].ldi_syslog = lds->lds_want_syslog; if (lds->lds_want_syslog) { #if defined(HAVE_SYSLOG) if (NULL != lds->lds_syslog_ident) { info[i].ldi_syslog_ident = strdup(lds->lds_syslog_ident); openlog(lds->lds_syslog_ident, LOG_PID, LOG_USER); } else { info[i].ldi_syslog_ident = NULL; openlog("opal", LOG_PID, LOG_USER); } #elif defined(__WINDOWS__) if (NULL == (info[i].ldi_syslog_ident = RegisterEventSource(NULL, TEXT("opal: ")))) { /* handle the error */ return OPAL_ERROR; } #endif syslog_opened = true; info[i].ldi_syslog_priority = lds->lds_syslog_priority; } #if defined(HAVE_SYSLOG) } #endif #else info[i].ldi_syslog = false; #endif if (NULL != lds->lds_prefix) { info[i].ldi_prefix = strdup(lds->lds_prefix); info[i].ldi_prefix_len = (int)strlen(lds->lds_prefix); } else { info[i].ldi_prefix = NULL; info[i].ldi_prefix_len = 0; } if (NULL != lds->lds_suffix) { info[i].ldi_suffix = strdup(lds->lds_suffix); info[i].ldi_suffix_len = (int)strlen(lds->lds_suffix); } else { info[i].ldi_suffix = NULL; info[i].ldi_suffix_len = 0; } if (opal_output_redirected_to_syslog) { /* since all is redirected to syslog, ensure * we don't duplicate the output to the std places */ info[i].ldi_stdout = false; info[i].ldi_stderr = false; info[i].ldi_file = false; info[i].ldi_fd = -1; } else { /* since we aren't redirecting, use what was * given to us */ info[i].ldi_stdout = lds->lds_want_stdout; info[i].ldi_stderr = lds->lds_want_stderr; info[i].ldi_fd = -1; info[i].ldi_file = lds->lds_want_file; info[i].ldi_file_suffix = (NULL == lds->lds_file_suffix) ? NULL : strdup(lds->lds_file_suffix); info[i].ldi_file_want_append = lds->lds_want_file_append; info[i].ldi_file_num_lines_lost = 0; } /* Don't open a file in the session directory now -- do that lazily * so that if there's no output, we don't have an empty file */ return i; }