Commit 4432c644 authored by Cyrill Gorcunov's avatar Cyrill Gorcunov

net: sockets -- A few style tuneups

To follow rest of code

 - use !x for xalloc result tests
 - structure members are tab aligned
 - multiline assignments over structure members are aligned as well
Signed-off-by: 's avatarCyrill Gorcunov <gorcunov@openvz.org>
parent bc3370fc
......@@ -42,7 +42,6 @@ struct socket_desc {
struct unix_sk_desc {
struct socket_desc sd;
unsigned int type;
unsigned int state;
unsigned int peer_ino;
......@@ -72,7 +71,9 @@ static int sk_collect_one(int ino, int family, struct socket_desc *d)
d->ino = ino;
d->family = family;
d->next = sockets[ino % SK_HASH_SIZE];
sockets[ino % SK_HASH_SIZE] = d;
return 0;
}
......@@ -175,9 +176,9 @@ err:
int try_dump_socket(char *dir, char *fd, struct cr_fdset *cr_fdset)
{
struct socket_desc *sk;
struct statfs fst;
struct stat st;
struct socket_desc *sk;
snprintf(buf, sizeof(buf), "%s/%s", dir, fd);
if (statfs(buf, &fst)) {
......@@ -194,7 +195,7 @@ int try_dump_socket(char *dir, char *fd, struct cr_fdset *cr_fdset)
return 1; /* not a socket, proceed with caller error */
sk = lookup_socket(st.st_ino);
if (sk == NULL) {
if (!sk) {
pr_err("Uncollected socket %d\n", st.st_ino);
return -1;
}
......@@ -213,20 +214,19 @@ static int unix_collect_one(struct unix_diag_msg *m, struct rtattr **tb)
struct unix_sk_desc *d, **h;
d = xzalloc(sizeof(*d));
if (d == NULL)
if (!d)
return -1;
d->type = m->udiag_type;
d->state = m->udiag_state;
d->state= m->udiag_state;
if (tb[UNIX_DIAG_PEER])
d->peer_ino = *(int *)RTA_DATA(tb[UNIX_DIAG_PEER]);
if (tb[UNIX_DIAG_NAME]) {
int len = RTA_PAYLOAD(tb[UNIX_DIAG_NAME]);
char *name;
char *name = xmalloc(len + 1);
name = xmalloc(len + 1);
if (!name)
goto err;
......@@ -325,7 +325,7 @@ static int collect_unix_sockets(int nl)
msg.msg_iovlen = 1;
memset(&nladdr, 0, sizeof(nladdr));
nladdr.nl_family = AF_NETLINK;
nladdr.nl_family= AF_NETLINK;
iov.iov_base = &req;
iov.iov_len = sizeof(req);
......@@ -333,15 +333,16 @@ static int collect_unix_sockets(int nl)
memset(&req, 0, sizeof(req));
req.hdr.nlmsg_len = sizeof(req);
req.hdr.nlmsg_type = SOCK_DIAG_BY_FAMILY;
req.hdr.nlmsg_flags = NLM_F_ROOT|NLM_F_MATCH|NLM_F_REQUEST;
req.hdr.nlmsg_flags = NLM_F_ROOT | NLM_F_MATCH | NLM_F_REQUEST;
req.hdr.nlmsg_seq = CR_NLMSG_SEQ;
req.r.sdiag_family = AF_UNIX;
req.r.udiag_states = -1; /* All */
req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_VFS | UDIAG_SHOW_PEER | UDIAG_SHOW_ICONS | UDIAG_SHOW_RQLEN;
req.r.udiag_show = UDIAG_SHOW_NAME | UDIAG_SHOW_VFS | UDIAG_SHOW_PEER |
UDIAG_SHOW_ICONS | UDIAG_SHOW_RQLEN;
if (sendmsg(nl, &msg, 0) < 0) {
pr_perror("Can't send request message\n");
goto out_err;
goto err;
}
iov.iov_base = buf;
......@@ -360,24 +361,23 @@ static int collect_unix_sockets(int nl)
if (err < 0) {
if (errno == EINTR)
continue;
goto out_err;
else
goto err;
}
if (err == 0)
break;
err = nlmsg_receive(buf, err, unix_receive_one);
if (err < 0)
goto out_err;
goto err;
if (err == 0)
break;
}
return 0;
out_err:
err:
return -1;
}
int collect_sockets(void)
......@@ -392,8 +392,8 @@ int collect_sockets(void)
}
err = collect_unix_sockets(nl);
close(nl);
return err;
}
......@@ -416,7 +416,7 @@ static int run_connect_jobs(void)
struct unix_conn_job *cj, *next;
cj = conn_jobs;
while (cj != NULL) {
while (cj) {
int attempts = 8;
unix_show_job("Run conn", cj->fd, -1);
......@@ -452,7 +452,7 @@ static int run_accept_jobs(void)
struct unix_accept_job *aj, *next;
aj = accept_jobs;
while (aj != NULL) {
while (aj) {
int fd;
unix_show_job("Run acc", aj->fd, -1);
......@@ -477,7 +477,9 @@ static void prep_conn_addr(int id, struct sockaddr_un *addr, int *addrlen)
{
addr->sun_family = AF_UNIX;
addr->sun_path[0] = '\0';
snprintf(addr->sun_path + 1, UNIX_PATH_MAX - 1, "crtools-sk-%10d", id);
*addrlen = sizeof(addr->sun_family) + sizeof("crtools-sk-") - 1 + 10;
}
......@@ -560,7 +562,7 @@ static int open_unix_sk(struct unix_sk_entry *ue, int *img_fd)
*/
cj = xmalloc(sizeof(*cj));
if (cj == NULL)
if (!cj)
goto err;
prep_conn_addr(ue->peer, &cj->addr, &cj->addrlen);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment