control.c (228542) | control.c (229945) |
---|---|
1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2009-2010 The FreeBSD Foundation 3 * All rights reserved. 4 * 5 * This software was developed by Pawel Jakub Dawidek under sponsorship from 6 * the FreeBSD Foundation. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 14 unchanged lines hidden (view full) --- 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sbin/hastd/control.c 228542 2011-12-15 22:01:34Z pjd $"); | 31__FBSDID("$FreeBSD: head/sbin/hastd/control.c 229945 2012-01-10 22:39:07Z pjd $"); |
32 33#include <sys/types.h> 34#include <sys/wait.h> 35 36#include <errno.h> 37#include <pthread.h> 38#include <signal.h> 39#include <stdio.h> --- 70 unchanged lines hidden (view full) --- 110 res->hr_role = role; 111 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); 112 113 /* 114 * If previous role was primary or secondary we have to kill process 115 * doing that work. 116 */ 117 if (res->hr_workerpid != 0) { | 32 33#include <sys/types.h> 34#include <sys/wait.h> 35 36#include <errno.h> 37#include <pthread.h> 38#include <signal.h> 39#include <stdio.h> --- 70 unchanged lines hidden (view full) --- 110 res->hr_role = role; 111 pjdlog_prefix_set("[%s] (%s) ", res->hr_name, role2str(res->hr_role)); 112 113 /* 114 * If previous role was primary or secondary we have to kill process 115 * doing that work. 116 */ 117 if (res->hr_workerpid != 0) { |
118 if (kill(res->hr_workerpid, SIGTERM) < 0) { | 118 if (kill(res->hr_workerpid, SIGTERM) == -1) { |
119 pjdlog_errno(LOG_WARNING, 120 "Unable to kill worker process %u", 121 (unsigned int)res->hr_workerpid); 122 } else if (waitpid(res->hr_workerpid, NULL, 0) != 123 res->hr_workerpid) { 124 pjdlog_errno(LOG_WARNING, 125 "Error while waiting for worker process %u", 126 (unsigned int)res->hr_workerpid); --- 35 unchanged lines hidden (view full) --- 162 cnvout = nv_alloc(); 163 nv_add_uint8(cnvout, CONTROL_STATUS, "cmd"); 164 error = nv_error(cnvout); 165 if (error != 0) { 166 pjdlog_common(LOG_ERR, 0, error, 167 "Unable to prepare control header"); 168 goto end; 169 } | 119 pjdlog_errno(LOG_WARNING, 120 "Unable to kill worker process %u", 121 (unsigned int)res->hr_workerpid); 122 } else if (waitpid(res->hr_workerpid, NULL, 0) != 123 res->hr_workerpid) { 124 pjdlog_errno(LOG_WARNING, 125 "Error while waiting for worker process %u", 126 (unsigned int)res->hr_workerpid); --- 35 unchanged lines hidden (view full) --- 162 cnvout = nv_alloc(); 163 nv_add_uint8(cnvout, CONTROL_STATUS, "cmd"); 164 error = nv_error(cnvout); 165 if (error != 0) { 166 pjdlog_common(LOG_ERR, 0, error, 167 "Unable to prepare control header"); 168 goto end; 169 } |
170 if (hast_proto_send(res, res->hr_ctrl, cnvout, NULL, 0) < 0) { | 170 if (hast_proto_send(res, res->hr_ctrl, cnvout, NULL, 0) == -1) { |
171 error = errno; 172 pjdlog_errno(LOG_ERR, "Unable to send control header"); 173 goto end; 174 } 175 176 /* 177 * Receive response. 178 */ | 171 error = errno; 172 pjdlog_errno(LOG_ERR, "Unable to send control header"); 173 goto end; 174 } 175 176 /* 177 * Receive response. 178 */ |
179 if (hast_proto_recv_hdr(res->hr_ctrl, &cnvin) < 0) { | 179 if (hast_proto_recv_hdr(res->hr_ctrl, &cnvin) == -1) { |
180 error = errno; 181 pjdlog_errno(LOG_ERR, "Unable to receive control header"); 182 goto end; 183 } 184 185 error = nv_get_int16(cnvin, "error"); 186 if (error != 0) 187 goto end; --- 100 unchanged lines hidden (view full) --- 288{ 289 struct proto_conn *conn; 290 struct nv *nvin, *nvout; 291 unsigned int ii; 292 const char *str; 293 uint8_t cmd, role; 294 int error; 295 | 180 error = errno; 181 pjdlog_errno(LOG_ERR, "Unable to receive control header"); 182 goto end; 183 } 184 185 error = nv_get_int16(cnvin, "error"); 186 if (error != 0) 187 goto end; --- 100 unchanged lines hidden (view full) --- 288{ 289 struct proto_conn *conn; 290 struct nv *nvin, *nvout; 291 unsigned int ii; 292 const char *str; 293 uint8_t cmd, role; 294 int error; 295 |
296 if (proto_accept(cfg->hc_controlconn, &conn) < 0) { | 296 if (proto_accept(cfg->hc_controlconn, &conn) == -1) { |
297 pjdlog_errno(LOG_ERR, "Unable to accept control connection"); 298 return; 299 } 300 301 cfg->hc_controlin = conn; 302 nvin = nvout = NULL; 303 role = HAST_ROLE_UNDEF; 304 | 297 pjdlog_errno(LOG_ERR, "Unable to accept control connection"); 298 return; 299 } 300 301 cfg->hc_controlin = conn; 302 nvin = nvout = NULL; 303 role = HAST_ROLE_UNDEF; 304 |
305 if (hast_proto_recv_hdr(conn, &nvin) < 0) { | 305 if (hast_proto_recv_hdr(conn, &nvin) == -1) { |
306 pjdlog_errno(LOG_ERR, "Unable to receive control header"); 307 nvin = NULL; 308 goto close; 309 } 310 311 /* Obtain command code. 0 means that nv_get_uint8() failed. */ 312 cmd = nv_get_uint8(nvin, "cmd"); 313 if (cmd == 0) { --- 76 unchanged lines hidden (view full) --- 390 } 391 } 392 if (nv_error(nvout) != 0) 393 goto close; 394fail: 395 if (error != 0) 396 nv_add_int16(nvout, error, "error"); 397 | 306 pjdlog_errno(LOG_ERR, "Unable to receive control header"); 307 nvin = NULL; 308 goto close; 309 } 310 311 /* Obtain command code. 0 means that nv_get_uint8() failed. */ 312 cmd = nv_get_uint8(nvin, "cmd"); 313 if (cmd == 0) { --- 76 unchanged lines hidden (view full) --- 390 } 391 } 392 if (nv_error(nvout) != 0) 393 goto close; 394fail: 395 if (error != 0) 396 nv_add_int16(nvout, error, "error"); 397 |
398 if (hast_proto_send(NULL, conn, nvout, NULL, 0) < 0) | 398 if (hast_proto_send(NULL, conn, nvout, NULL, 0) == -1) |
399 pjdlog_errno(LOG_ERR, "Unable to send control response"); 400close: 401 if (nvin != NULL) 402 nv_free(nvin); 403 if (nvout != NULL) 404 nv_free(nvout); 405 proto_close(conn); 406 cfg->hc_controlin = NULL; --- 5 unchanged lines hidden (view full) --- 412void * 413ctrl_thread(void *arg) 414{ 415 struct hast_resource *res = arg; 416 struct nv *nvin, *nvout; 417 uint8_t cmd; 418 419 for (;;) { | 399 pjdlog_errno(LOG_ERR, "Unable to send control response"); 400close: 401 if (nvin != NULL) 402 nv_free(nvin); 403 if (nvout != NULL) 404 nv_free(nvout); 405 proto_close(conn); 406 cfg->hc_controlin = NULL; --- 5 unchanged lines hidden (view full) --- 412void * 413ctrl_thread(void *arg) 414{ 415 struct hast_resource *res = arg; 416 struct nv *nvin, *nvout; 417 uint8_t cmd; 418 419 for (;;) { |
420 if (hast_proto_recv_hdr(res->hr_ctrl, &nvin) < 0) { | 420 if (hast_proto_recv_hdr(res->hr_ctrl, &nvin) == -1) { |
421 if (sigexit_received) 422 pthread_exit(NULL); 423 pjdlog_errno(LOG_ERR, 424 "Unable to receive control message"); 425 kill(getpid(), SIGTERM); 426 pthread_exit(NULL); 427 } 428 cmd = nv_get_uint8(nvin, "cmd"); --- 47 unchanged lines hidden (view full) --- 476 break; 477 } 478 nv_free(nvin); 479 if (nv_error(nvout) != 0) { 480 pjdlog_error("Unable to create answer on control message."); 481 nv_free(nvout); 482 continue; 483 } | 421 if (sigexit_received) 422 pthread_exit(NULL); 423 pjdlog_errno(LOG_ERR, 424 "Unable to receive control message"); 425 kill(getpid(), SIGTERM); 426 pthread_exit(NULL); 427 } 428 cmd = nv_get_uint8(nvin, "cmd"); --- 47 unchanged lines hidden (view full) --- 476 break; 477 } 478 nv_free(nvin); 479 if (nv_error(nvout) != 0) { 480 pjdlog_error("Unable to create answer on control message."); 481 nv_free(nvout); 482 continue; 483 } |
484 if (hast_proto_send(NULL, res->hr_ctrl, nvout, NULL, 0) < 0) { | 484 if (hast_proto_send(NULL, res->hr_ctrl, nvout, NULL, 0) == -1) { |
485 pjdlog_errno(LOG_ERR, 486 "Unable to send reply to control message"); 487 } 488 nv_free(nvout); 489 } 490 /* NOTREACHED */ 491 return (NULL); 492} | 485 pjdlog_errno(LOG_ERR, 486 "Unable to send reply to control message"); 487 } 488 nv_free(nvout); 489 } 490 /* NOTREACHED */ 491 return (NULL); 492} |