4
0
Эх сурвалжийг харах

Merge trunk revision 2753:
r2753 | honzaf | 2010-04-01 05:51:07 -0700 (Thu, 01 Apr 2010) | 5 lines

Support for user configurable warning signal

Allow developer configure a signal to be send as a warning signal
before real SIGKILL.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2777 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 16 жил өмнө
parent
commit
53557fec6d

+ 13 - 1
include/corosync/sam.h

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009-2010 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -102,6 +102,18 @@ cs_error_t sam_start (void);
  */
 cs_error_t sam_stop (void);
 
+/*
+ * Set warning signal to be send. Default signal is SIGTERM. You can
+ * use SIGKILL to emulate NOT sending warning signal and just send
+ * SIGKILL.
+ *
+ * @return
+ * - CS_OK in case no problem appeared
+ * - CS_ERR_BAD_HANDLE library was not initialized by #sam_initialize or
+ *   is finalized
+ */
+cs_error_t sam_warn_signal_set (int warn_signal);
+
 /*
  * Register application. This is one of most crucial function. In case, your
  * application will be restarted, you will always return to point after calling

+ 1 - 1
lib/libsam.verso

@@ -1 +1 @@
-4.0.0
+4.1.0

+ 18 - 4
lib/sam.c

@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009 Red Hat, Inc.
+ * Copyright (c) 2009-2010 Red Hat, Inc.
  *
  * All rights reserved.
  *
@@ -87,6 +87,7 @@ static struct {
 	unsigned int instance_id;
 	int parent_fd;
 	int term_send;
+	int warn_signal;
 
 	sam_hc_callback_t hc_callback;
 	pthread_t cb_thread;
@@ -112,6 +113,8 @@ cs_error_t sam_initialize (
 
 	sam_internal_data.internal_status = SAM_INTERNAL_STATUS_INITIALIZED;
 
+	sam_internal_data.warn_signal = SIGTERM;
+
 	return (CS_OK);
 }
 
@@ -225,6 +228,18 @@ exit_error:
 }
 
 
+cs_error_t sam_warn_signal_set (int warn_signal)
+{
+	if (sam_internal_data.internal_status != SAM_INTERNAL_STATUS_INITIALIZED &&
+		sam_internal_data.internal_status != SAM_INTERNAL_STATUS_REGISTERED &&
+		sam_internal_data.internal_status != SAM_INTERNAL_STATUS_STARTED) {
+		return (CS_ERR_BAD_HANDLE);
+	}
+
+	sam_internal_data.warn_signal = warn_signal;
+
+	return (CS_OK);
+}
 
 static enum sam_parent_action_t sam_parent_handler (int pipe_fd, pid_t child_pid)
 {
@@ -275,10 +290,9 @@ static enum sam_parent_action_t sam_parent_handler (int pipe_fd, pid_t child_pid
 				 */
 				if (!sam_internal_data.term_send) {
 					/*
-					 * We didn't send SIGTERM (warning) yet.
+					 * We didn't send warn_signal yet.
 					 */
-
-					kill (child_pid, SIGTERM);
+					kill (child_pid, sam_internal_data.warn_signal);
 
 					sam_internal_data.term_send = 1;
 				} else {

+ 2 - 1
man/Makefile.am

@@ -107,7 +107,8 @@ dist_man_MANS = \
 	sam_overview.8 \
 	sam_register.3 \
 	sam_start.3 \
-	sam_stop.3
+	sam_stop.3 \
+	sam_warn_signal_set.3
 	
 if BUILD_HTML_DOCS
 

+ 4 - 3
man/sam_overview.8

@@ -50,8 +50,8 @@ the \fBfork(3)\fR system call.  This duplicate process copy contains the logic
 for executing the SAM server.  The SAM server is responsible for requesting
 healthchecks from the active process, and controlling the lifecycle of the
 active process when it fails.  If the active process fails to respond to the
-healthcheck request sent by the SAM server, it will be sent a SIGTERM signal
-to request shutdown of the application.  After a configured time interval, the
+healthcheck request sent by the SAM server, it will be sent a user configurable
+signal (default SIGTERM) to request shutdown of the application.  After a configured time interval, the
 process will be forcibly killed by being sent a SIGKILL signal.  Once the
 active process terminates, the SAM server will create a new active process.
 
@@ -85,7 +85,7 @@ then once has undefined results and is not recommended or tested.
 
 .SH Setting warning callback
 .P
-A \fISIGTERM\fR signal is sent to the application when a recovery action is
+User configurable signal (default \fISIGTERM\fR) is sent to the application when a recovery action is
 planned.  The application can use the \fBsignal(3)\fR system call to monitor
 for this signal.
 
@@ -122,5 +122,6 @@ the \fBsam_hc_callback_register(3)\fR function should be executed.
 .BR sam_start (3),
 .BR sam_stop (3),
 .BR sam_register (3),
+.BR sam_warn_signal_set (3),
 .BR sam_hc_send (3),
 .BR sam_hc_callback_register (3)

+ 63 - 0
man/sam_warn_signal_set.3

@@ -0,0 +1,63 @@
+.\"/*
+.\" * Copyright (c) 2010 Red Hat, Inc.
+.\" *
+.\" * All rights reserved.
+.\" *
+.\" * Author: Jan Friesse (jfriesse@redhat.com)
+.\" *
+.\" * This software licensed under BSD license, the text of which follows:
+.\" *
+.\" * Redistribution and use in source and binary forms, with or without
+.\" * modification, are permitted provided that the following conditions are met:
+.\" *
+.\" * - Redistributions of source code must retain the above copyright notice,
+.\" *   this list of conditions and the following disclaimer.
+.\" * - Redistributions in binary form must reproduce the above copyright notice,
+.\" *   this list of conditions and the following disclaimer in the documentation
+.\" *   and/or other materials provided with the distribution.
+.\" * - Neither the name of the Red Hat, Inc. nor the names of its
+.\" *   contributors may be used to endorse or promote products derived from this
+.\" *   software without specific prior written permission.
+.\" *
+.\" * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+.\" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+.\" * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+.\" * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+.\" * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+.\" * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+.\" * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+.\" * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+.\" * THE POSSIBILITY OF SUCH DAMAGE.
+.\" */
+.TH "SAM_WARN_SIGNAL_SET" 3 "03/11/2010" "corosync Man Page" "Corosync Cluster Engine Programmer's Manual"
+
+.SH NAME
+.P
+sam_warn_signal_set \- Set warn signal
+
+.SH SYNOPSIS
+.P
+\fB#include <corosync/sam.h>\fR
+
+.P
+\fBcs_error_t sam_warn_signal_set (int warn_signal);\fR
+
+.SH DESCRIPTION
+.P
+The \fBsam_warn_signal_set\fR function is used to configure warning signal
+sent before real killing of unresponsive application. Default value is
+SIGTERM. SIGKILL can be used to emulate "not warning signal send" behaviour.
+
+.SH RETURN VALUE
+.P
+This call return CS_OK value if successful, otherwise and error is returned.
+
+.SH ERRORS
+.TP
+CS_ERR_BAD_HANDLE
+component was not initialized by calling \fBsam_initialize(3)\fR or it was finalized.
+
+.SH "SEE ALSO"
+.BR sam_initialize (3)