return ustcomm_init_app(getpid(), &ustcomm_app);
}
-/* FIXME: reenable this to delete socket file. */
-
-#if 0
-static void destroy_socket(void)
-{
- int result;
-
- if(mysocketfile[0] == '\0')
- return;
-
- result = unlink(mysocketfile);
- if(result == -1) {
- PERROR("unlink");
- }
-}
-#endif
-
static int init_signal_handler(void)
{
/* Attempt to handler SIGIO. If the main program wants to
#include <sys/un.h>
#include <unistd.h>
#include <poll.h>
+#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
}
if(path_out) {
- *path_out = "";
- *path_out = strdupa(addr.sun_path);
+ *path_out = strdup(addr.sun_path);
}
return fd;
return retval;
}
+void ustcomm_fini_app(struct ustcomm_app *handle)
+{
+ int result;
+ struct stat st;
+
+ /* Destroy socket */
+ ERR("socket path is: %s", handle->server.socketpath);
+ 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");
+ }
+}
+
static char *find_tok(char *str)
{
while(*str == ' ') {
extern int ustcomm_app_recv_message(struct ustcomm_app *app, char **msg, struct ustcomm_source *src, int timeout);
extern int ustcomm_init_app(pid_t pid, struct ustcomm_app *handle);
+extern void ustcomm_fini_app(struct ustcomm_app *handle);
extern int ustcomm_init_ustd(struct ustcomm_ustd *handle, const char *sock_path);