void manager_free(Manager *m) { Network *network; NetDev *netdev; Link *link; if (!m) return; udev_monitor_unref(m->udev_monitor); udev_unref(m->udev); sd_bus_unref(m->bus); sd_event_source_unref(m->udev_event_source); sd_event_source_unref(m->sigterm_event_source); sd_event_source_unref(m->sigint_event_source); sd_event_unref(m->event); while ((network = m->networks)) network_free(network); while ((link = hashmap_first(m->links))) link_free(link); hashmap_free(m->links); while ((netdev = hashmap_first(m->netdevs))) netdev_free(netdev); hashmap_free(m->netdevs); sd_rtnl_unref(m->rtnl); free(m); }
void manager_free(Manager *m) { Network *network; Bridge *bridge; Link *link; udev_monitor_unref(m->udev_monitor); udev_unref(m->udev); sd_bus_unref(m->bus); sd_event_source_unref(m->udev_event_source); sd_event_unref(m->event); while ((network = m->networks)) network_free(network); while ((link = hashmap_first(m->links))) link_free(link); hashmap_free(m->links); while ((bridge = hashmap_first(m->bridges))) bridge_free(bridge); hashmap_free(m->bridges); sd_rtnl_unref(m->rtnl); free(m); }
void manager_free(Manager *m) { Machine *machine; Image *i; assert(m); while ((machine = hashmap_first(m->machines))) machine_free(machine); hashmap_free(m->machines); hashmap_free(m->machine_units); hashmap_free(m->machine_leaders); while ((i = hashmap_steal_first(m->image_cache))) image_unref(i); hashmap_free(m->image_cache); sd_event_source_unref(m->image_cache_defer_event); bus_verify_polkit_async_registry_free(m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); free(m); }
void manager_free(Manager *m) { Machine *machine; assert(m); while (m->operations) operation_free(m->operations); assert(m->n_operations == 0); while ((machine = hashmap_first(m->machines))) machine_free(machine); hashmap_free(m->machines); hashmap_free(m->machine_units); hashmap_free(m->machine_leaders); hashmap_free_with_destructor(m->image_cache, image_unref); sd_event_source_unref(m->image_cache_defer_event); bus_verify_polkit_async_registry_free(m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); free(m); }
void manager_free(Manager *m) { Machine *machine; assert(m); while ((machine = hashmap_first(m->machines))) machine_free(machine); hashmap_free(m->machines); hashmap_free(m->machine_units); if (m->bus) { dbus_connection_flush(m->bus); dbus_connection_close(m->bus); dbus_connection_unref(m->bus); } if (m->bus_fd >= 0) close_nointr_nofail(m->bus_fd); if (m->epoll_fd >= 0) close_nointr_nofail(m->epoll_fd); free(m); }
static void lldp_flush_neighbors(sd_lldp *lldp) { sd_lldp_neighbor *n; assert(lldp); while ((n = hashmap_first(lldp->neighbor_by_id))) lldp_neighbor_unlink(n); }
void manager_free(Manager *m) { Machine *machine; assert(m); while ((machine = hashmap_first(m->machines))) machine_free(machine); hashmap_free(m->machines); hashmap_free(m->machine_units); hashmap_free(m->machine_leaders); sd_bus_unref(m->bus); sd_event_unref(m->event); free(m); }
static void client_free(Client *c) { Match *m; if (!c) return; if (c->context) { if (c->watch) sd_bus_remove_match(c->context->bus, c->watch, on_name_owner_changed, c); assert_se(hashmap_remove(c->context->clients, &c->id) == c); } while ((m = hashmap_first(c->matches))) match_free(m); hashmap_free(c->matches); free(c->watch); free(c); }
void* set_first(Set *s) { return hashmap_first(MAKE_HASHMAP(s)); }
static void manager_free(Manager *m) { Session *session; User *u; Device *d; Seat *s; Inhibitor *i; Button *b; assert(m); while ((session = hashmap_first(m->sessions))) session_free(session); while ((u = hashmap_first(m->users))) user_free(u); while ((d = hashmap_first(m->devices))) device_free(d); while ((s = hashmap_first(m->seats))) seat_free(s); while ((i = hashmap_first(m->inhibitors))) inhibitor_free(i); while ((b = hashmap_first(m->buttons))) button_free(b); hashmap_free(m->devices); hashmap_free(m->seats); hashmap_free(m->sessions); hashmap_free(m->users); hashmap_free(m->inhibitors); hashmap_free(m->buttons); hashmap_free(m->user_units); hashmap_free(m->session_units); sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->inhibit_timeout_source); sd_event_source_unref(m->scheduled_shutdown_timeout_source); sd_event_source_unref(m->nologin_timeout_source); sd_event_source_unref(m->wall_message_timeout_source); sd_event_source_unref(m->console_active_event_source); sd_event_source_unref(m->udev_seat_event_source); sd_event_source_unref(m->udev_device_event_source); sd_event_source_unref(m->udev_vcsa_event_source); sd_event_source_unref(m->udev_button_event_source); sd_event_source_unref(m->lid_switch_ignore_event_source); safe_close(m->console_active_fd); udev_monitor_unref(m->udev_seat_monitor); udev_monitor_unref(m->udev_device_monitor); udev_monitor_unref(m->udev_vcsa_monitor); udev_monitor_unref(m->udev_button_monitor); udev_unref(m->udev); if (m->unlink_nologin) (void) unlink("/run/nologin"); bus_verify_polkit_async_registry_free(m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); safe_close(m->reserve_vt_fd); strv_free(m->kill_only_users); strv_free(m->kill_exclude_users); free(m->scheduled_shutdown_type); free(m->scheduled_shutdown_tty); free(m->wall_message); free(m->action_job); free(m); }
/* * Loop through all the headers (including the response code) from the * server. */ static int process_server_headers(struct conn_s *connptr) { static char *skipheaders[] = { "keep-alive", "proxy-authenticate", "proxy-authorization", "proxy-connection", "transfer-encoding", }; char *response_line; hashmap_t hashofheaders; hashmap_iter iter; char *data, *header; ssize_t len; int i; int ret; /* FIXME: Remember to handle a "simple_req" type */ /* Get the response line from the remote server. */ retry: len = readline(connptr->server_fd, &response_line); if (len <= 0) return -1; /* * Strip the new line and character return from the string. */ if (chomp(response_line, len) == len) { /* * If the number of characters removed is the same as the * length then it was a blank line. Free the buffer and * try again (since we're looking for a request line.) */ safefree(response_line); goto retry; } hashofheaders = hashmap_create(HEADER_BUCKETS); if (!hashofheaders) { safefree(response_line); return -1; } /* * Get all the headers from the remote server in a big hash */ if (get_all_headers(connptr->server_fd, hashofheaders) < 0) { log_message(LOG_WARNING, "Could not retrieve all the headers from the remote server."); hashmap_delete(hashofheaders); safefree(response_line); indicate_http_error(connptr, 503, "Could not retrieve all the headers", "detail", PACKAGE " was unable to retrieve and process headers from the remote web server.", NULL); return -1; } /* Send the saved response line first */ ret = write_message(connptr->client_fd, "%s\r\n", response_line); safefree(response_line); if (ret < 0) goto ERROR_EXIT; /* * If there is a "Content-Length" header, retrieve the information * from it for later use. */ connptr->content_length.server = get_content_length(hashofheaders); /* * See if there is a connection header. If so, we need to to a bit of * processing. */ remove_connection_headers(hashofheaders); /* * Delete the headers listed in the skipheaders list */ for (i = 0; i != (sizeof(skipheaders) / sizeof(char *)); i++) { hashmap_remove(hashofheaders, skipheaders[i]); } /* Send, or add the Via header */ ret = write_via_header(connptr->client_fd, hashofheaders, connptr->protocol.major, connptr->protocol.minor); if (ret < 0) goto ERROR_EXIT; /* * All right, output all the remaining headers to the client. */ iter = hashmap_first(hashofheaders); if (iter >= 0) { for ( ; !hashmap_is_end(hashofheaders, iter); ++iter) { hashmap_return_entry(hashofheaders, iter, &data, (void **)&header); ret = write_message(connptr->client_fd, "%s: %s\r\n", data, header); if (ret < 0) goto ERROR_EXIT; } } hashmap_delete(hashofheaders); /* Write the final blank line to signify the end of the headers */ if (safe_write(connptr->client_fd, "\r\n", 2) < 0) return -1; return 0; ERROR_EXIT: hashmap_delete(hashofheaders); return -1; }
/* * Here we loop through all the headers the client is sending. If we * are running in anonymous mode, we will _only_ send the headers listed * (plus a few which are required for various methods). * - rjkaes */ static int process_client_headers(struct conn_s *connptr, hashmap_t hashofheaders) { static char *skipheaders[] = { "host", "keep-alive", "proxy-authenticate", "proxy-authorization", "proxy-connection", "te", "trailers", "transfer-encoding", "upgrade" }; int i; hashmap_iter iter; int ret = 0; char *data, *header; /* * Don't send headers if there's already an error, if the request was * a stats request, or if this was a CONNECT method (unless upstream * proxy is in use.) */ if (connptr->server_fd == -1 || connptr->show_stats || (connptr->connect_method && (connptr->upstream_proxy == NULL))) { log_message(LOG_INFO, "Not sending client headers to remote machine"); return 0; } /* * See if there is a "Content-Length" header. If so, again we need * to do a bit of processing. */ connptr->content_length.client = get_content_length(hashofheaders); /* * See if there is a "Connection" header. If so, we need to do a bit * of processing. :) */ remove_connection_headers(hashofheaders); /* * Delete the headers listed in the skipheaders list */ for (i = 0; i != (sizeof(skipheaders) / sizeof(char *)); i++) { hashmap_remove(hashofheaders, skipheaders[i]); } /* Send, or add the Via header */ ret = write_via_header(connptr->server_fd, hashofheaders, connptr->protocol.major, connptr->protocol.minor); if (ret < 0) { indicate_http_error(connptr, 503, "Could not send data to remote server", "detail", "A network error occurred while trying to write data to the remote web server.", NULL); goto PULL_CLIENT_DATA; } /* * Output all the remaining headers to the remote machine. */ iter = hashmap_first(hashofheaders); if (iter >= 0) { for ( ; !hashmap_is_end(hashofheaders, iter); ++iter) { hashmap_return_entry(hashofheaders, iter, &data, (void**)&header); if (!is_anonymous_enabled() || anonymous_search(data) > 0) { ret = write_message(connptr->server_fd, "%s: %s\r\n", data, header); if (ret < 0) { indicate_http_error(connptr, 503, "Could not send data to remote server", "detail", "A network error occurred while trying to write data to the remote web server.", NULL); goto PULL_CLIENT_DATA; } } } } #if defined(XTINYPROXY_ENABLE) if (config.my_domain) add_xtinyproxy_header(connptr); #endif /* Write the final "blank" line to signify the end of the headers */ if (safe_write(connptr->server_fd, "\r\n", 2) < 0) return -1; /* * Spin here pulling the data from the client. */ PULL_CLIENT_DATA: if (connptr->content_length.client > 0) return pull_client_data(connptr, connptr->content_length.client); else return ret; }
void manager_free(Manager *m) { Session *session; User *u; Device *d; Seat *s; Inhibitor *i; Button *b; assert(m); while ((session = hashmap_first(m->sessions))) session_free(session); while ((u = hashmap_first(m->users))) user_free(u); while ((d = hashmap_first(m->devices))) device_free(d); while ((s = hashmap_first(m->seats))) seat_free(s); while ((i = hashmap_first(m->inhibitors))) inhibitor_free(i); while ((b = hashmap_first(m->buttons))) button_free(b); hashmap_free(m->devices); hashmap_free(m->seats); hashmap_free(m->sessions); hashmap_free(m->users); hashmap_free(m->inhibitors); hashmap_free(m->buttons); hashmap_free(m->user_units); hashmap_free(m->session_units); set_free_free(m->busnames); sd_event_source_unref(m->idle_action_event_source); sd_event_source_unref(m->console_active_event_source); sd_event_source_unref(m->udev_seat_event_source); sd_event_source_unref(m->udev_device_event_source); sd_event_source_unref(m->udev_vcsa_event_source); sd_event_source_unref(m->udev_button_event_source); sd_event_source_unref(m->lid_switch_ignore_event_source); safe_close(m->console_active_fd); if (m->udev_seat_monitor) udev_monitor_unref(m->udev_seat_monitor); if (m->udev_device_monitor) udev_monitor_unref(m->udev_device_monitor); if (m->udev_vcsa_monitor) udev_monitor_unref(m->udev_vcsa_monitor); if (m->udev_button_monitor) udev_monitor_unref(m->udev_button_monitor); if (m->udev) udev_unref(m->udev); bus_verify_polkit_async_registry_free(m->bus, m->polkit_registry); sd_bus_unref(m->bus); sd_event_unref(m->event); safe_close(m->reserve_vt_fd); strv_free(m->kill_only_users); strv_free(m->kill_exclude_users); free(m->action_job); free(m); }