diff options
author | Thomas Adam <thomas@xteddy.org> | 2015-10-29 10:01:09 +0000 |
---|---|---|
committer | Thomas Adam <thomas@xteddy.org> | 2015-10-29 10:01:09 +0000 |
commit | e8bb385d6d9d8a91b5fa78e906531afc02320b80 (patch) | |
tree | a8da864a21b2ba4fdaa6c5cb843c6a864e24de82 /proc.c | |
parent | a5e4d3a2d8c2fb288488ee5922a561a4a9e6803a (diff) | |
parent | 45f3cea263d1f99912cd6b353c91ccb872c26a71 (diff) |
Merge branch 'obsd-master'
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 31 |
1 files changed, 21 insertions, 10 deletions
@@ -48,7 +48,8 @@ struct tmuxpeer { void *arg; }; -static void proc_update_event(struct tmuxpeer *); +static int peer_check_version(struct tmuxpeer *, struct imsg *); +static void proc_update_event(struct tmuxpeer *); static void proc_event_cb(unused int fd, short events, void *arg) @@ -56,7 +57,6 @@ proc_event_cb(unused int fd, short events, void *arg) struct tmuxpeer *peer = arg; ssize_t n; struct imsg imsg; - int v; if (!(peer->flags & PEER_BAD) && (events & EV_READ)) { if ((n = imsg_read(&peer->ibuf)) == -1 || n == 0) { @@ -72,14 +72,7 @@ proc_event_cb(unused int fd, short events, void *arg) break; log_debug("peer %p message %d", peer, imsg.hdr.type); - v = imsg.hdr.peerid; - if (imsg.hdr.type != MSG_VERSION && - v != PROTOCOL_VERSION) { - log_debug("peer %p bad version %d", peer, v); - - proc_send(peer, MSG_VERSION, -1, NULL, 0); - peer->flags |= PEER_BAD; - + if (peer_check_version(peer, &imsg) != 0) { if (imsg.fd != -1) close(imsg.fd); imsg_free(&imsg); @@ -114,6 +107,24 @@ proc_signal_cb(int signo, unused short events, void *arg) tp->signalcb(signo); } +static int +peer_check_version(struct tmuxpeer *peer, struct imsg *imsg) +{ + int version; + + version = imsg->hdr.peerid & 0xff; + if (imsg->hdr.type != MSG_VERSION && version != PROTOCOL_VERSION) { + log_debug("peer %p bad version %d", peer, version); + + proc_send(peer, MSG_VERSION, -1, NULL, 0); + peer->flags |= PEER_BAD; + + return (-1); + } + imsg->hdr.peerid >>= 8; + return (0); +} + static void proc_update_event(struct tmuxpeer *peer) { |