~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to crmd/subsystems.c

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-07-16 16:40:24 UTC
  • mfrom: (1.1.11) (2.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20130716164024-lvwrf4xivk1wdr3c
Tags: 1.1.9+git20130321-1ubuntu1
* Resync from debian expiremental.
* debian/control:
  - Use lower version for Build-Depends on libcorosync-dev
    and libqb-dev.
  - Build-Depends on libcfg-dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
#include <crmd.h>
45
45
#include <crm/common/util.h>
46
 
#include <clplumbing/proctrack.h>
47
 
 
48
 
static void
49
 
crmdManagedChildRegistered(ProcTrack * p)
50
 
{
51
 
    struct crm_subsystem_s *the_subsystem = p->privatedata;
52
 
 
53
 
    the_subsystem->pid = p->pid;
54
 
}
55
 
 
56
 
static void
57
 
crmdManagedChildDied(ProcTrack * p, int status, int signo, int exitcode, int waslogged)
58
 
{
59
 
    struct crm_subsystem_s *the_subsystem = p->privatedata;
60
 
 
61
 
    crm_info("Process %s:[%d] exited (signal=%d, exitcode=%d)",
62
 
             the_subsystem->name, the_subsystem->pid, signo, exitcode);
63
 
 
64
 
#if 0
65
 
    /* everything below is now handled in pe_connection_destroy() */
66
 
    the_subsystem->pid = -1;
67
 
    the_subsystem->ipc = NULL;
68
 
    clear_bit_inplace(fsa_input_register, the_subsystem->flag_connected);
69
 
 
70
 
    crm_trace("Triggering FSA: %s", __FUNCTION__);
71
 
    mainloop_set_trigger(fsa_source);
72
 
 
73
 
    if (is_set(fsa_input_register, the_subsystem->flag_required)) {
74
 
        /* this wasnt supposed to happen */
75
 
        crm_warn("The %s subsystem terminated unexpectedly", the_subsystem->name);
76
 
 
77
 
        if (the_subsystem->flag_connected == R_PE_CONNECTED) {
78
 
            int rc = cib_ok;
79
 
            char *pid = crm_itoa(the_subsystem->pid);
80
 
 
81
 
            /* the PE died...
82
 
             * save the current CIB so that we have a chance of
83
 
             * figuring out what killed it
84
 
             */
85
 
            rc = fsa_cib_conn->cmds->query(fsa_cib_conn, NULL, NULL, cib_scope_local);
86
 
            add_cib_op_callback(fsa_cib_conn, rc, TRUE, pid, save_cib_contents);
87
 
        }
88
 
 
89
 
        register_fsa_input_before(C_FSA_INTERNAL, I_ERROR, NULL);
 
46
 
 
47
static void
 
48
crmdManagedChildDied(GPid pid, gint status, gpointer user_data)
 
49
{
 
50
    struct crm_subsystem_s *the_subsystem = user_data;
 
51
 
 
52
    if (WIFSIGNALED(status)) {
 
53
        int signo = WTERMSIG(status);
 
54
        int core = WCOREDUMP(status);
 
55
 
 
56
        crm_notice("Child process %s terminated with signal %d (pid=%d, core=%d)",
 
57
                   the_subsystem->name, signo, the_subsystem->pid, core);
 
58
 
 
59
    } else if (WIFEXITED(status)) {
 
60
        int exitcode = WEXITSTATUS(status);
 
61
 
 
62
        do_crm_log(exitcode == 0 ? LOG_INFO : LOG_ERR,
 
63
                   "Child process %s exited (pid=%d, rc=%d)", the_subsystem->name,
 
64
                   the_subsystem->pid, exitcode);
 
65
 
 
66
    } else {
 
67
        crm_err("Process %s:[%d] exited?", the_subsystem->name, the_subsystem->pid);
90
68
    }
91
 
#endif
92
 
    p->privatedata = NULL;
93
 
}
94
 
 
95
 
static const char *
96
 
crmdManagedChildName(ProcTrack * p)
97
 
{
98
 
    struct crm_subsystem_s *the_subsystem = p->privatedata;
99
 
 
100
 
    return the_subsystem->name;
101
 
}
102
 
 
103
 
static ProcTrack_ops crmd_managed_child_ops = {
104
 
    crmdManagedChildDied,
105
 
    crmdManagedChildRegistered,
106
 
    crmdManagedChildName
107
 
};
 
69
}
108
70
 
109
71
gboolean
110
72
stop_subsystem(struct crm_subsystem_s *the_subsystem, gboolean force_quit)
112
74
    int quit_signal = SIGTERM;
113
75
 
114
76
    crm_trace("Stopping sub-system \"%s\"", the_subsystem->name);
115
 
    clear_bit_inplace(fsa_input_register, the_subsystem->flag_required);
 
77
    clear_bit(fsa_input_register, the_subsystem->flag_required);
116
78
 
117
79
    if (the_subsystem->pid <= 0) {
118
80
        crm_trace("Client %s not running", the_subsystem->name);
156
118
    const char *devnull = "/dev/null";
157
119
 
158
120
    crm_info("Starting sub-system \"%s\"", the_subsystem->name);
159
 
    set_bit_inplace(fsa_input_register, the_subsystem->flag_required);
160
121
 
161
122
    if (the_subsystem->pid > 0) {
162
123
        crm_warn("Client %s already running as pid %d",
189
150
            return FALSE;
190
151
 
191
152
        default:               /* Parent */
192
 
            NewTrackedProc(pid, 0, PT_LOGNORMAL, the_subsystem, &crmd_managed_child_ops);
 
153
            g_child_watch_add(pid, crmdManagedChildDied, the_subsystem);
193
154
            crm_trace("Client %s is has pid: %d", the_subsystem->name, pid);
194
155
            the_subsystem->pid = pid;
195
156
            return TRUE;
216
177
    (void)open(devnull, O_WRONLY);      /* Stderr: fd 2 */
217
178
 
218
179
    {
219
 
        char *opts[] = { crm_strdup(the_subsystem->command), NULL };
 
180
        char *opts[] = { strdup(the_subsystem->command), NULL };
 
181
        /* coverity[toctou] The call to stat() is a fail-fast, not a race */
220
182
        (void)execvp(the_subsystem->command, opts);
221
183
    }
222
184
 
223
185
    /* Should not happen */
224
186
    crm_perror(LOG_ERR, "FATAL: Cannot exec %s", the_subsystem->command);
225
187
 
226
 
    exit(100);                  /* Suppress respawning */
 
188
    crmd_exit(100);             /* Suppress respawning */
227
189
    return TRUE;                /* never reached */
228
190
}