~ubuntu-branches/ubuntu/trusty/keepalived/trusty

« back to all changes in this revision

Viewing changes to keepalived/core/pidfile.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2009-05-12 20:26:15 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090512202615-k850bw35qpuvpq4p
Tags: 1.1.17-1ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/rules: DEB_UPDATE_RCD_PARAMS := expicit init start/stop
    parameters (don't stop at 0 and 6)
  - debian/init.d: init script header adapted to stop rule
  - debian/keepalived.postinst: Remove shutdown and reboot links

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 *
6
6
 * Part:        pidfile utility.
7
7
 *
8
 
 * Version:     $Id: pidfile.c,v 1.1.15 2007/09/15 04:07:41 acassen Exp $
 
8
 * Version:     $Id: pidfile.c,v 1.1.17 2009/03/05 01:31:12 acassen Exp $
9
9
 *
10
10
 * Author:      Alexandre Cassen, <acassen@linux-vs.org>
11
11
 *
19
19
 *              as published by the Free Software Foundation; either version
20
20
 *              2 of the License, or (at your option) any later version.
21
21
 *
22
 
 * Copyright (C) 2001-2007 Alexandre Cassen, <acassen@freebox.fr>
 
22
 * Copyright (C) 2001-2009 Alexandre Cassen, <acassen@freebox.fr>
23
23
 */
24
24
 
 
25
#include "logger.h"
25
26
#include "pidfile.h"
 
27
extern char *main_pidfile;
 
28
extern char *checkers_pidfile;
 
29
extern char *vrrp_pidfile;
26
30
 
27
31
/* Create the runnnig daemon pidfile */
28
32
int
31
35
        FILE *pidfile = fopen(pid_file, "w");
32
36
 
33
37
        if (!pidfile) {
34
 
                syslog(LOG_INFO, "pidfile_write : Can not open %s pidfile",
 
38
                log_message(LOG_INFO, "pidfile_write : Can not open %s pidfile",
35
39
                       pid_file);
36
40
                return 0;
37
41
        }
63
67
 
64
68
        /* If no process is attached to pidfile, remove it */
65
69
        if (kill(pid, 0)) {
66
 
                syslog(LOG_INFO, "Remove a zombie pid file %s", pid_file);
 
70
                log_message(LOG_INFO, "Remove a zombie pid file %s", pid_file);
67
71
                pidfile_rm(pid_file);
68
72
                return 0;
69
73
        }
75
79
int
76
80
keepalived_running(int mode)
77
81
{
78
 
        if (process_running(KEEPALIVED_PID_FILE))
 
82
        if (process_running(main_pidfile))
79
83
                return 1;
80
84
        else if (mode & 1 || mode & 2)
81
 
                return process_running((mode & 1) ? KEEPALIVED_VRRP_PID_FILE :
82
 
                                       KEEPALIVED_CHECKERS_PID_FILE);
 
85
                return process_running((mode & 1) ? vrrp_pidfile :
 
86
                                       checkers_pidfile);
83
87
 
84
 
        if (process_running(KEEPALIVED_VRRP_PID_FILE) ||
85
 
            process_running(KEEPALIVED_CHECKERS_PID_FILE))
 
88
        if (process_running(vrrp_pidfile) ||
 
89
            process_running(checkers_pidfile))
86
90
                return 1;
87
91
        return 0;
88
92
}
91
95
int
92
96
vrrp_running(void)
93
97
{
94
 
        return process_running(VRRP_PID_FILE);
 
98
        return process_running(vrrp_pidfile);
95
99
}
96
100
 
97
101
/* Return VRRP child process state */
98
102
int
99
103
checkers_running(void)
100
104
{
101
 
        return process_running(CHECKERS_PID_FILE);
 
105
        return process_running(checkers_pidfile);
102
106
}