X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=libustcomm%2Fustcomm.c;h=f2b7a03b9ea67f8daee033099d0dc2faea9ead1b;hb=7032c7d350bfa093db533713df8a14df37360bdc;hp=155dfd0087c53aaba52fa866f87f9eca7a1c457d;hpb=f05eefd81e6ddc4911529b2c3a754aa68e713ca7;p=ust.git diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index 155dfd0..f2b7a03 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -15,6 +15,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +/* API used by UST components to communicate with each other via sockets. */ + #define _GNU_SOURCE #include #include @@ -44,14 +46,16 @@ static int mkdir_p(const char *path, mode_t mode) int retval = 0; int result; + mode_t old_umask; - tmp = malloc(strlen(path) + 1); + tmp = zmalloc(strlen(path) + 1); if (tmp == NULL) return -1; /* skip first / */ path_p = path+1; + old_umask = umask(0); for(;;) { while (*path_p != '/') { if(*path_p == 0) @@ -83,6 +87,7 @@ static int mkdir_p(const char *path, mode_t mode) } free(tmp); + umask(old_umask); return retval; } @@ -327,15 +332,15 @@ int ustcomm_recv_message(struct ustcomm_server *server, char **msg, struct ustco n_fds++; } - fds = (struct pollfd *) malloc(n_fds * sizeof(struct pollfd)); + fds = (struct pollfd *) zmalloc(n_fds * sizeof(struct pollfd)); if(fds == NULL) { - ERR("malloc returned NULL"); + ERR("zmalloc returned NULL"); return -1; } - conn_table = (struct ustcomm_connection **) malloc(n_fds * sizeof(struct ustcomm_connection *)); + conn_table = (struct ustcomm_connection **) zmalloc(n_fds * sizeof(struct ustcomm_connection *)); if(conn_table == NULL) { - ERR("malloc returned NULL"); + ERR("zmalloc returned NULL"); retval = -1; goto free_fds_return; } @@ -379,9 +384,9 @@ int ustcomm_recv_message(struct ustcomm_server *server, char **msg, struct ustco goto free_conn_table_return; } - newconn = (struct ustcomm_connection *) malloc(sizeof(struct ustcomm_connection)); + newconn = (struct ustcomm_connection *) zmalloc(sizeof(struct ustcomm_connection)); if(newconn == NULL) { - ERR("malloc returned NULL"); + ERR("zmalloc returned NULL"); return -1; } @@ -643,7 +648,8 @@ static int ensure_dir_exists(const char *dir) /* ENOENT */ int result; - result = mkdir_p(dir, 0777); + /* mkdir mode to 0777 */ + result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO); if(result != 0) { ERR("executing in recursive creation of directory %s", dir); return -1; @@ -880,9 +886,9 @@ static int process_mp_incoming_conn(void *priv, int fd, short events) return -1; } - newconn = (struct ustcomm_connection *) malloc(sizeof(struct ustcomm_connection)); + newconn = (struct ustcomm_connection *) zmalloc(sizeof(struct ustcomm_connection)); if(newconn == NULL) { - ERR("malloc returned NULL"); + ERR("zmalloc returned NULL"); return -1; } @@ -942,7 +948,7 @@ void ustcomm_mp_add_app_clients(struct mpentries *ent, struct ustcomm_app *app, multipoll_add(ent, app->server.listen_fd, POLLIN, process_mp_incoming_conn, &app->server, NULL); list_for_each_entry(conn, &app->server.connections, list) { - struct ustcomm_multipoll_conn_info *mpinfo = (struct ustcomm_multipoll_conn_info *) malloc(sizeof(struct ustcomm_multipoll_conn_info)); + struct ustcomm_multipoll_conn_info *mpinfo = (struct ustcomm_multipoll_conn_info *) zmalloc(sizeof(struct ustcomm_multipoll_conn_info)); mpinfo->conn = conn; mpinfo->cb = cb; multipoll_add(ent, conn->fd, POLLIN, process_mp_conn_msg, mpinfo, free_ustcomm_client_poll);