-int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path)
-{
- char *name;
- int retval = 0;
-
- if(sock_path) {
- asprintf(&name, "%s", sock_path);
- }
- else {
- int result;
-
- /* Only check if socket dir exists if we are using the default directory */
- result = ensure_dir_exists(SOCK_DIR);
- if(result == -1) {
- ERR("Unable to create socket directory %s", SOCK_DIR);
- return -1;
- }
-
- asprintf(&name, "%s/%s", SOCK_DIR, "ustd");
- }
-
- handle->server.listen_fd = init_named_socket(name, &handle->server.socketpath);
- if(handle->server.listen_fd < 0) {
- ERR("error initializing named socket at %s", name);
- retval = -1;
- goto free_name;
- }
-
- INIT_LIST_HEAD(&handle->server.connections);
-
-free_name:
- free(name);
-
- return retval;
-}
-
-static void ustcomm_fini_server(struct ustcomm_server *server, int keep_socket_file)
-{
- int result;
- struct stat st;
-
- if(!keep_socket_file) {
- /* Destroy socket */
- result = stat(server->socketpath, &st);
- if(result == -1) {
- PERROR("stat (%s)", server->socketpath);
- return;
- }
-
- /* Paranoid check before deleting. */
- result = S_ISSOCK(st.st_mode);
- if(!result) {
- ERR("The socket we are about to delete is not a socket.");
- return;
- }
-
- result = unlink(server->socketpath);
- if(result == -1) {
- PERROR("unlink");
- }
- }
-
- free(server->socketpath);
-
- result = close(server->listen_fd);
- if(result == -1) {
- PERROR("close");
- return;
- }
-}
-
-/* Free a traceable application server */
-
-void ustcomm_fini_app(struct ustcomm_app *handle, int keep_socket_file)
-{
- ustcomm_fini_server(&handle->server, keep_socket_file);
-}
-
-/* Free a ustd server */
-
-void ustcomm_fini_ustd(struct ustcomm_ustd *handle)
-{
- ustcomm_fini_server(&handle->server, 0);
-}