Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/ggate/ggated/ggated.c
Show First 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | if ((cinit->gc_flags & GGATE_FLAG_RDONLY) != 0) { | ||||
} | } | ||||
} | } | ||||
if ((conn->c_flags & GGATE_FLAG_RDONLY) != 0) | if ((conn->c_flags & GGATE_FLAG_RDONLY) != 0) | ||||
flags = O_RDONLY; | flags = O_RDONLY; | ||||
else if ((conn->c_flags & GGATE_FLAG_WRONLY) != 0) | else if ((conn->c_flags & GGATE_FLAG_WRONLY) != 0) | ||||
flags = O_WRONLY; | flags = O_WRONLY; | ||||
else | else | ||||
flags = O_RDWR; | flags = O_RDWR; | ||||
if (conn->c_diskfd != -1) { | |||||
if (strcmp(conn->c_path, ex->e_path) != 0) { | |||||
g_gate_log(LOG_ERR, "old %s and new %s: " | |||||
"Path mismatch during handshakes.", | |||||
conn->c_path, ex->e_path); | |||||
return (EPERM); | |||||
} | |||||
return (0); | |||||
} | |||||
conn->c_diskfd = open(ex->e_path, flags); | conn->c_diskfd = open(ex->e_path, flags); | ||||
if (conn->c_diskfd == -1) { | if (conn->c_diskfd == -1) { | ||||
error = errno; | error = errno; | ||||
g_gate_log(LOG_ERR, "Cannot open %s: %s.", ex->e_path, | g_gate_log(LOG_ERR, "Cannot open %s: %s.", ex->e_path, | ||||
strerror(error)); | strerror(error)); | ||||
return (error); | return (error); | ||||
} | } | ||||
return (0); | return (0); | ||||
▲ Show 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | connection_new(struct g_gate_cinit *cinit, struct sockaddr *s, int sfd) | ||||
conn->c_path = strdup(cinit->gc_path); | conn->c_path = strdup(cinit->gc_path); | ||||
if (conn->c_path == NULL) { | if (conn->c_path == NULL) { | ||||
free(conn); | free(conn); | ||||
return (NULL); | return (NULL); | ||||
} | } | ||||
conn->c_token = cinit->gc_token; | conn->c_token = cinit->gc_token; | ||||
ip = htonl(((struct sockaddr_in *)(void *)s)->sin_addr.s_addr); | ip = htonl(((struct sockaddr_in *)(void *)s)->sin_addr.s_addr); | ||||
conn->c_srcip = ip; | conn->c_srcip = ip; | ||||
conn->c_sendfd = conn->c_recvfd = -1; | conn->c_diskfd = conn->c_sendfd = conn->c_recvfd = -1; | ||||
if ((cinit->gc_flags & GGATE_FLAG_SEND) != 0) | if ((cinit->gc_flags & GGATE_FLAG_SEND) != 0) | ||||
conn->c_sendfd = sfd; | conn->c_sendfd = sfd; | ||||
else | else | ||||
conn->c_recvfd = sfd; | conn->c_recvfd = sfd; | ||||
conn->c_mediasize = 0; | conn->c_mediasize = 0; | ||||
conn->c_sectorsize = 0; | conn->c_sectorsize = 0; | ||||
time(&conn->c_birthtime); | time(&conn->c_birthtime); | ||||
conn->c_flags = cinit->gc_flags; | conn->c_flags = cinit->gc_flags; | ||||
Show All 38 Lines | |||||
*/ | */ | ||||
static void | static void | ||||
connection_remove(struct ggd_connection *conn) | connection_remove(struct ggd_connection *conn) | ||||
{ | { | ||||
LIST_REMOVE(conn, c_next); | LIST_REMOVE(conn, c_next); | ||||
g_gate_log(LOG_DEBUG, "Connection removed [%s %s].", | g_gate_log(LOG_DEBUG, "Connection removed [%s %s].", | ||||
ip2str(conn->c_srcip), conn->c_path); | ip2str(conn->c_srcip), conn->c_path); | ||||
if (conn->c_diskfd != -1) | |||||
close(conn->c_diskfd); | |||||
if (conn->c_sendfd != -1) | if (conn->c_sendfd != -1) | ||||
close(conn->c_sendfd); | close(conn->c_sendfd); | ||||
if (conn->c_recvfd != -1) | if (conn->c_recvfd != -1) | ||||
close(conn->c_recvfd); | close(conn->c_recvfd); | ||||
free(conn->c_path); | free(conn->c_path); | ||||
free(conn); | free(conn); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 548 Lines • Show Last 20 Lines |