-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;
-}
-
-void ustcomm_fini_app(struct ustcomm_app *handle)
-{
- int result;
- struct stat st;
-
- /* Destroy socket */
- result = stat(handle->server.socketpath, &st);
- if(result == -1) {
- PERROR("stat (%s)", handle->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(handle->server.socketpath);
- if(result == -1) {
- PERROR("unlink");
- }
-}