예제 #1
0
파일: quorumd.c 프로젝트: dhazen/heartbeat
int
init_stop(const char *pid_file)
{
	long	pid;
	int	rc = LSB_EXIT_OK;

	if (pid_file == NULL) {
		quorum_log(LOG_ERR, "No pid file specified to kill process");
		return LSB_EXIT_GENERIC;
	}
	pid =	cl_read_pidfile(pid_file);

	if (pid > 0) {
		if (CL_KILL((pid_t)pid, SIGTERM) < 0) {
			rc = (errno == EPERM
			      ?	LSB_EXIT_EPERM : LSB_EXIT_GENERIC);
			fprintf(stderr, "Cannot kill pid %ld\n", pid);
		}else{
			quorum_log(LOG_INFO,
			       "Signal sent to pid=%ld,"
			       " waiting for process to exit",
			       pid);

			while (CL_PID_EXISTS(pid)) {
				sleep(1);
			}
		}
	}
	return rc;
}
예제 #2
0
/**
 * This function is called when a client issues a connection message.
 * It occurs after a connection is established.
 *
 * @todo Ensure that the app connecting is appbhd (?)
 * 
 * @return EINVAL if message is not a recoverymgr_connectmsg
 */
static int
recoverymgr_client_connect(recoverymgr_client_t *client, void *Msg, size_t length)
{
        struct recoverymgr_connectmsg* 	msg = Msg;
        int                     	namelen = -1;
        /*uid_t                   	uidlist[1];
        gid_t                   	gidlist[1]; 
        IPC_Auth*               	clientauth;*/

        if (debug >= DBGDETAIL) {
		cl_log(LOG_DEBUG, "recoverymgr_client_connect");
	}

        if (client->appname) {
                return EEXIST;
        }

        if (length < sizeof(*msg)
        ||      (namelen = strnlen(msg->appname, sizeof(msg->appname))) < 1
        ||      namelen >= (int)sizeof(msg->appname)
        ||      strnlen(msg->appinstance, sizeof(msg->appinstance))
        >=      sizeof(msg->appinstance)) {
                return EINVAL;
        }

        if (msg->pid < 2 || (CL_KILL(msg->pid, 0) < 0 && errno != EPERM)
        ||      (client->ch->farside_pid != msg->pid)) {
                return EINVAL;
        }

        client->pid = msg->pid;

#if 0
        /* Make sure client is who they claim to be... */
        uidlist[0] = msg->uid;
        gidlist[0] = msg->gid;
        clientauth = ipc_set_auth(uidlist, gidlist, 1, 1);
        if (client->ch->ops->verify_auth(client->ch, clientauth) != IPC_OK) {
                ipc_destroy_auth(clientauth);
                return EINVAL;
        }
        ipc_destroy_auth(clientauth);
#endif 
        client->appname = g_strdup(msg->appname);
        client->appinst = g_strdup(msg->appinstance);
        client->uid = msg->uid;
        client->gid = msg->gid;
        if (debug >= DBGMIN) {
                cl_log(LOG_DEBUG
                ,       "recoverymgr_client_connect: client: [%s]/[%s] pid %ld"
                " (uid,gid) = (%ld,%ld)\n"
                ,       client->appname
                ,       client->appinst
                ,       (long)client->pid
                ,       (long)client->uid
                ,       (long)client->gid);
        }

        return 0;
}
예제 #3
0
/*
 * Handle SIGHUP to re-open log files
 */
static gboolean
logd_hup_action(int sig, gpointer userdata)
{
	cl_log_close_log_files();
	if (write_process_pid)
		/* do we want to propagate the HUP,
		 * or do we assume that it was a killall anyways? */
		CL_KILL(write_process_pid, SIGHUP);
	else
		cl_log(LOG_INFO, "SIGHUP received, re-opened log files");
	return TRUE;
}
예제 #4
0
static gboolean
logd_term_action(int sig, gpointer userdata)
{      
	GList *log_iter   = logd_client_list;
	GMainLoop *mainloop = (GMainLoop*)userdata;
	ha_logd_client_t *client = NULL;
	
        cl_log(LOG_DEBUG, "logd_term_action: received SIGTERM");
        if (mainloop == NULL){
                cl_log(LOG_ERR, "logd_term_action: invalid arguments");
                return FALSE;
        }

	stop_reading = TRUE;

	while(log_iter != NULL) {
		client = log_iter->data;
		log_iter = log_iter->next;

		cl_log(LOG_DEBUG, "logd_term_action:"
		       " waiting for %d messages to be read for process %s",
		       (int)client->logchan->send_queue->current_qlen,
		       client->app_name);
		
		client->logchan->ops->waitout(client->logchan);
	}

	cl_log(LOG_DEBUG, "logd_term_action"
	": waiting for %d messages to be read by write process"
	,	(int)chanspair[WRITE_PROC_CHAN]->send_queue->current_qlen);
	chanspair[WRITE_PROC_CHAN]->ops->waitout(chanspair[WRITE_PROC_CHAN]);
	
        cl_log(LOG_DEBUG, "logd_term_action: sending SIGTERM to write process");
	if (CL_KILL(write_process_pid, SIGTERM) >= 0){
		
		pid_t pid;
		pid = wait4(write_process_pid, NULL, 0, NULL);
		if (pid < 0){
			cl_log(LOG_ERR, "wait4 for write process failed");
		}
		
	}
	
        g_main_quit(mainloop);
	
        return TRUE;
}