Low: pgsql: change pgsql-status into UNKNOWN when validation is failed on stop

Change pgsql-status into UNKNOWN when validation is failed on stop.
Because pgsql-status remains in HS even though validation failure
means stop succeeded in pgsql RA.
Low: tools/findif: fix comment typos

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: make ConvertQuadToInt use netmask_bits fnc

This is not only to simplify ConvertQuadToInt and practice DRY
principle, but also to make it a little bit safer.  Because
of vague data types involved (instead of uint32_t at al.),
this at least adds one assurance and that is that the logic
will not get broken on architecture with 16bit int
(provided that long has still 32bit, which is not guaranteed
either).

Newly, failure of inet_pton (especially, malformed IP address
format) is indicated via -1 return value.  Previously, such
case was not handled safely.

The patch also unifies tab usage (ConvertQuadToInt was the only
function using spaces for indentation).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: split ValidateNetmaskBits (conv.+valid.)

This commits moves conversion logic from ValidateNetmaskBits into
a separate function (ConvertNetmaskBitsToInt).  This way, we can
validate resulting number of netmask's bits, no matter if the original
string specified netmask as IP expression (via ConvertQuadToInt) or
directly as number of its bits (via ConvertNetmaskBitsToInt).

In turn, we are reaching the original goal to remove ill-advised
reuse of the storage with a string obtained by getenv call
(see netmaskbits, its initialization and rewrite using snprintf).

Strictly viewed, pointer to string returned by getenv should rather
not be stored at all (see [1]), but at least, this patch makes
the program conform to "[t]he application shall ensure that it does
not modify the string pointed to by the getenv() function" part
of getent POSIX documentation (per [1], C standard ditto).

[1] https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=1703960

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: remove superfluous string termination

The string is already terminated at that position
(see "man fgets strlen").

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: sanitize SearchUsingRouteCmd a bit

Not knowing how the input SearchUsingRouteCmd generates and subsequently
processing [*], only the most conservative changes are contained in this
patch.

First, there was a futile assigment that would only be valid if
commented out strsep calls were in effect.  Due to this, the assigment
was also only commented out.

Next, return value used to be taken from the first strtok in sequence,
only to be overwritten by another one.

Finally, if strtok unexpectedly returned NULL (due to input format other
than expected), it was not handled gracefully.

[*] "route -n get <addr>" is not supported in RHEL neither in Fedora

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/sfex_init.c: fix unchecked return value

Suggested-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/send_arp.linux.c: clarify fall-through in switch

Reported-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: add test-findif.sh

Basically, this validates previous findif changes.

As can be seen, the patches do not introduce regression (at least in the
tested cases), but additionally fix cases where netmask is specified
in the IP-like but broken form.

Before the changes:

[...]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (missing last item in quad)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=255.255.255.
Converted dotted-quad netmask to CIDR as: 6
FAIL exit code: 0 vs 6
[FAIL]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (random string containing dot)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=foo.bar
Converted dotted-quad netmask to CIDR as: 6
FAIL exit code: 0 vs 6
[FAIL]
--- TOTAL ---
[FAIL] 2
[...]

After the changes:

[...]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (missing last item in
quad)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=255.255.255.
Converted dotted-quad netmask to CIDR as: -1
Invalid netmask specification [255.255.255.]
[ OK ]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (random string
containing dot)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=foo.bar
Converted dotted-quad netmask to CIDR as: -1
Invalid netmask specification [foo.bar]
[ OK ]
--- TOTAL ---
[ OK ]
[...]

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Merge pull request #143 from jnpkrn/patches

 Low: tools/findif: various cleanups
LVM Agents:  Warn instead of fail if initrd is newer than lvm.conf

There are many reasons why a user may change the lvm.conf file.  They might
change filters or default segment types, etc.  Making the HA LVM scripts
error our every time the lvm.conf file is newer than the initrd, can cause
serious problems.  For example, if a service is running and lvm.conf is
changed, a subsequent fail-over would not work because the HA LVM script
would abort on this condition.

Instead of making things potentially worse, we have the scripts warn the
user (rather than failing) whenever this condition is hit.  That way,
the user isn't suddenly surprised by things not working.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
LVM Agents:  Add quotes around expressions used in conditionals

When variables have the possibility of expanding to more than one word,
we must have quotes around them or we will get errors, like:
	"line 46: [: too many arguments"

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Merge pull request #145 from jnpkrn/patches3

Low: tools: little cleanup
Merge pull request #146 from jbrassow/master

Bug fixes for HA LVM resource agents
resource-agents: Fix return code in fslib.sh

Patch from John Ruemker <jruemker@redhat.com>:

When you have an fs resource that depends on an lvm resource in a service,
and that lvm resource fails to start, the subsequent attempt to stop the fs
resource will fail because the device doesn't exist (since the logical
volume was never activated).

Because we're stopping a resource that is not actually running
(the fs isn't mounted), the operation should succeed here. Instead it
fails, preventing recovery.

Resolves: rhbz#853249
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
resource-agents: Fix for reading /proc/mounts in fs-lib.sh

This patch fixes a problem with the fs resource agent
that caused status checks to mistakenly fail as a result
of /proc/mounts changing while it was being read.

Original patch from John Ruemker <jruemker@redhat.com>

Resolves rhbz#853249

Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
resource-agents: Add debugging output to fs-lib.sh

Add debugging output to the status/monitor operation in
fs-lib.sh analagous to what other agents do.

Resolves: rhbz#714156

Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
resource-agents: Set restart retries to 0 for oracledb.sh

Per the suggestion of Chris Phillips <cphillip@redhat.com> change
the setting of RESTART_RETRIES to 0 from 3 to prevent rgmanager from
attempting to restart the database during the status operation so that
failures are properly counted.

Resolves: rhbz#817550

Signed-off-by: Ryan McCabe <rmccabe@redhat.com>
LVM agents:  Deactivate remotely active LVs before attempting EX activation

These changes address rhbz729812.  When a clustered volume group is part of
an HA LVM setup (an active/passive installation), the LVs that are activated
as part of the 'clvmd' startup may cause problems with the initialization of
HA LVM.  This is because HA LVM requires that logical volumes be active
exclusively.  If a remote machine activates the LVs via the 'clvmd' init
script before the local machine runs the service manager, it will be
impossible to activate the LVs exclusively.

Should the exclusive activation fail, the solution is to first attempt to
deactivate the LVs cluster-wide (unless the LVs are open - in which case
a deactivation would obviously fail).  If the deactivation is successful,
then another attempt can be made to activate exclusively.

This isn't a perfect solution.  It is still possible for yet another machine
to attempt a 'clvmd' activation between the time we deactivate and try again
for the exclusive activation.  This does substantially close the gap for
problems though.  If this solution proves to be insufficient, then 'lvs' or
some other command will need to be given the capabilities to report whether
an LV is active remotely or not.  This would give us the ability to distiguish
between a activation that fails because '--partial' was not used and an
exclusive activation that failed because another machine has the LV open
remotely.
resource-agents: Fix tomcat-6 startup

The /usr/sbin/tomcat6 script no longer parses the configuration file
and sets shell variables before trying to start tomcat6. Do that manually
so that we can actually run.

Resolves: rhbz#757632
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>