fcoeadm should also be using abstract sockets as the filesystem might not be present by the time fcoemon is started.
Signed-off-by: Hannes Reinecke <[email protected]> --- fcoe_clif.h | 2 -- fcoeadm.c | 27 ++++++++++++++++++--------- fcoemon.c | 43 ++++++++++--------------------------------- 3 files changed, 28 insertions(+), 44 deletions(-) diff --git a/fcoe_clif.h b/fcoe_clif.h index e375de2..d67b75f 100644 --- a/fcoe_clif.h +++ b/fcoe_clif.h @@ -27,9 +27,7 @@ */ -#define FCM_SRV_DIR "/var/run/fcm" #define CLIF_IFNAME "fcm_clif" -#define CLIF_SOCK_FILE FCM_SRV_DIR "/" CLIF_IFNAME #define CLIF_PID_FILE _PATH_VARRUN "fcoemon.pid" diff --git a/fcoeadm.c b/fcoeadm.c index 795b12a..6ee17cb 100644 --- a/fcoeadm.c +++ b/fcoeadm.c @@ -134,24 +134,33 @@ static inline void fcoeadm_close_cli(struct clif_sock_info *clif_info) static enum fcoe_status fcoeadm_open_cli(struct clif_sock_info *clif_info) { enum fcoe_status rc = SUCCESS; + struct sockaddr_un *lp; + socklen_t addrlen; - clif_info->socket_fd = socket(PF_UNIX, SOCK_DGRAM, 0); + clif_info->socket_fd = socket(AF_LOCAL, SOCK_DGRAM, 0); if (clif_info->socket_fd < 0) return ENOMONCONN; - clif_info->local.sun_family = AF_UNIX; - if (bind(clif_info->socket_fd, (struct sockaddr *)&clif_info->local, - sizeof(clif_info->local.sun_family)) < 0) { + lp = &clif_info->local; + memset(lp, 0, sizeof(*lp)); + lp->sun_family = AF_LOCAL; + lp->sun_path[0] = '\0'; + snprintf(&lp->sun_path[1], sizeof(lp->sun_path) - 1, + "%s/%d", CLIF_IFNAME, getpid); + addrlen = sizeof(sa_family_t) + strlen(lp->sun_path + 1) + 1; + if (bind(clif_info->socket_fd, (struct sockaddr *)lp, addrlen) < 0) { rc = ENOMONCONN; goto err_close; } - clif_info->dest.sun_family = AF_UNIX; - strncpy(clif_info->dest.sun_path, CLIF_SOCK_FILE, - sizeof(clif_info->dest.sun_path)); - + clif_info->dest.sun_family = AF_LOCAL; + clif_info->dest.sun_path[0] = '\0'; + snprintf(&clif_info->dest.sun_path[1], + sizeof(clif_info->dest.sun_path) - 1, + "%s", CLIF_IFNAME); + addrlen = sizeof(sa_family_t) + strlen(clif_info->dest.sun_path + 1) + 1; if (connect(clif_info->socket_fd, (struct sockaddr *)&clif_info->dest, - sizeof(clif_info->dest)) < 0) { + addrlen) < 0) { rc = ENOMONCONN; goto err_close; } diff --git a/fcoemon.c b/fcoemon.c index 42ed61d..5f60cd9 100644 --- a/fcoemon.c +++ b/fcoemon.c @@ -24,6 +24,7 @@ #include <malloc.h> #include <signal.h> #include <stddef.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <stdint.h> @@ -3197,42 +3198,24 @@ err: static int fcm_srv_create(struct fcm_srv_info *srv_info) { + socklen_t addrlen; struct sockaddr_un addr; int rc = 0; - if (mkdir(FCM_SRV_DIR, S_IRWXU | S_IRWXG) < 0) { - if (errno == EEXIST) { - FCM_LOG_ERR(errno, "Failed to create socket " - "directory %s, this indicates that " - "fcoemon was not shutdown cleanly", - FCM_SRV_DIR); - } else { - rc = errno; - FCM_LOG_ERR(errno, "Failed to create socket " - "directory %s\n", FCM_SRV_DIR); - goto err; - } - } - - srv_info->srv_sock = socket(PF_UNIX, SOCK_DGRAM, 0); + srv_info->srv_sock = socket(AF_LOCAL, SOCK_DGRAM, 0); if (srv_info->srv_sock < 0) { FCM_LOG_ERR(errno, "Failed to create socket\n"); rc = errno; - goto err_rmdir; + goto err; } memset(&addr, 0, sizeof(addr)); - addr.sun_family = AF_UNIX; - strncpy(addr.sun_path, CLIF_SOCK_FILE, sizeof(addr.sun_path)); - - /* - * If there was a previous socket file unlink. If we don't - * then bind will fail. - */ - unlink(CLIF_SOCK_FILE); - - if (bind(srv_info->srv_sock, (struct sockaddr *)&addr, - sizeof(addr)) < 0) { + addr.sun_family = AF_LOCAL; + addr.sun_path[0] = '\0'; + snprintf(&addr.sun_path[1], sizeof(addr.sun_path) -1, + "%s", CLIF_IFNAME); + addrlen = sizeof(sa_family_t) + strlen(addr.sun_path + 1) + 1; + if (bind(srv_info->srv_sock, (struct sockaddr *)&addr, addrlen) < 0) { FCM_LOG_ERR(errno, "Failed to bind socket\n"); rc = errno; goto err_close; @@ -3247,10 +3230,6 @@ static int fcm_srv_create(struct fcm_srv_info *srv_info) err_close: close(srv_info->srv_sock); - unlink(CLIF_SOCK_FILE); - -err_rmdir: - rmdir(FCM_SRV_DIR); err: return rc; @@ -3260,8 +3239,6 @@ static void fcm_srv_destroy(struct fcm_srv_info *srv_info) { FCM_LOG_DBG("Shutdown fcmon server"); close(srv_info->srv_sock); - unlink(CLIF_SOCK_FILE); - rmdir(FCM_SRV_DIR); } int main(int argc, char **argv) -- 1.7.10.4 _______________________________________________ fcoe-devel mailing list [email protected] http://lists.open-fcoe.org/mailman/listinfo/fcoe-devel
