X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=send_common.c;h=26502cabd08376673b2c46b61ccffae400344274;hb=9055c71be97f1095dcdbd83da305b600f204f763;hp=f7770a01394e9b0089ff4b5dc20b2befcf54e5bb;hpb=4fbe16430b4776814128d7110682c69d1b047c57;p=paraslash.git diff --git a/send_common.c b/send_common.c index f7770a01..26502cab 100644 --- a/send_common.c +++ b/send_common.c @@ -21,10 +21,10 @@ #include "afs.h" #include "server.h" #include "acl.h" +#include "sched.h" #include "send.h" #include "close_on_fork.h" #include "chunk_queue.h" -#include "sched.h" #include "vss.h" /** Clients will be kicked if there are more than that many bytes pending. */ @@ -44,10 +44,12 @@ */ void shutdown_client(struct sender_client *sc, struct sender_status *ss) { - PARA_INFO_LOG("shutting down %s on fd %d\n", sc->name, sc->fd); + if (!process_is_command_handler()) { + PARA_INFO_LOG("shutting down %s on fd %d\n", sc->name, sc->fd); + close(sc->fd); + del_close_on_fork_list(sc->fd); + } free(sc->name); - close(sc->fd); - del_close_on_fork_list(sc->fd); cq_destroy(sc->cq); list_del(&sc->node); free(sc->private_data); @@ -118,14 +120,14 @@ void init_sender_status(struct sender_status *ss, if (n == 0) { ss->num_listen_fds = 1; - ss->listen_addresses = para_malloc(sizeof(char *)); + ss->listen_addresses = alloc(sizeof(char *)); ss->listen_addresses[0] = NULL; - ss->listen_fds = para_malloc(sizeof(int)); + ss->listen_fds = alloc(sizeof(int)); ss->listen_fds[0] = -1; } else { ss->num_listen_fds = n; - ss->listen_addresses = para_malloc(n * sizeof(char *)); - ss->listen_fds = para_malloc(n * sizeof(int)); + ss->listen_addresses = alloc(n * sizeof(char *)); + ss->listen_fds = alloc(n * sizeof(int)); FOR_EACH_LISTEN_FD(i, ss) { ss->listen_addresses[i] = para_strdup(lls_string_val(i, listen_address_opt_result)); @@ -134,9 +136,9 @@ void init_sender_status(struct sender_status *ss, } ss->default_port = default_port; - INIT_LIST_HEAD(&ss->client_list); + init_list_head(&ss->client_list); /* Initialize an access control list */ - INIT_LIST_HEAD(&ss->acl); + init_list_head(&ss->acl); for (i = 0; i < lls_opt_given(acl_opt_result); i++) { const char *arg = lls_string_val(i, acl_opt_result); char addr[16]; @@ -152,6 +154,25 @@ void init_sender_status(struct sender_status *ss, ss->default_deny = default_deny; } +/** + * Deallocate all resources allocated in \ref init_sender_status(). + * + * \param ss The structure whose components should be freed. + * + * This frees the dynamically allocated parts of the structure which was + * initialized by an earlier call to \ref init_sender_status(). It does *not* + * call free(ss), though. + */ +void free_sender_status(const struct sender_status *ss) +{ + int i; + + free(ss->listen_fds); + FOR_EACH_LISTEN_FD(i, ss) + free(ss->listen_addresses[i]); + free(ss->listen_addresses); +} + /** * Return a string containing the current status of a sender. * @@ -217,6 +238,22 @@ void generic_com_allow(struct sender_command_data *scd, acl_allow(scd->host, scd->netmask, &ss->acl, ss->default_deny); } +/** + * Empty the access control list of a sender. + * + * \param acl The access control list of the sender. + * + * This is called from the ->shutdown methods of the http and the dccp sender. + */ +void generic_acl_deplete(struct list_head *acl) +{ + /* + * Since default_deny is false, the ACL is considered a blacklist. A + * netmask of zero matches any IP address, so this call empties the ACL. + */ + acl_allow("0.0.0.0", 0 /* netmask */, acl, 0 /* default_deny */); +} + /** * Deny connections from the given range of IP addresses. * @@ -306,7 +343,6 @@ void generic_com_off(struct sender_status *ss) * Accept a connection on the socket(s) this server is listening on. * * \param ss The sender whose listening fd is ready for reading. - * \param rfds Passed to para_accept(), * * This accepts incoming connections on any of the listening sockets of the * server. If there is a connection pending, the function @@ -330,7 +366,7 @@ void generic_com_off(struct sender_status *ss) * \sa \ref para_accept(), \ref mark_fd_nonblocking(), \ref acl_check_access(), * \ref cq_new(), \ref add_close_on_fork_list(). */ -struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfds) +struct sender_client *accept_sender_client(struct sender_status *ss) { struct sender_client *sc; int fd, ret; @@ -339,7 +375,7 @@ struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfd FOR_EACH_LISTEN_FD(n, ss) { if (ss->listen_fds[n] < 0) continue; - ret = para_accept(ss->listen_fds[n], rfds, NULL, 0, &fd); + ret = para_accept(ss->listen_fds[n], NULL, 0, &fd); if (ret < 0) goto warn; if (ret == 0) @@ -354,7 +390,7 @@ struct sender_client *accept_sender_client(struct sender_status *ss, fd_set *rfd if (ret < 0) goto close_fd_and_warn; ss->num_clients++; - sc = para_calloc(sizeof(*sc)); + sc = zalloc(sizeof(*sc)); sc->fd = fd; sc->name = para_strdup(remote_name(fd)); sc->cq = cq_new(MAX_CQ_BYTES);