From 83afdf79df7ef3bd5c4557fdacc58e4513d76438 Mon Sep 17 00:00:00 2001 From: kshithijiyer Date: Fri, 24 Apr 2020 18:46:14 +0530 Subject: [Libfix] Fix get_brick_processes_count() to use pgrep Problem: On latest platforms pidof command is returning multiple pids as shown below: 27190 27078 26854 This is becasue it was returning glusterd,glusterfsd and glusterfs processes as well. The problem is that /usr/sbin/glusterd is a link to glusterfsd. 'pidof' has a new feature that pidof searches for the pattern in /proc/PID/cmdline, /proc/PID/stat and finally /proc/PID/exe. Hence pidof matches realpath of /proc//exe as /usr/sbin/glusterfsd and results in glusterd, glusterfs and glusterfsd pids being returned in output. Fix: Use pgrep instead of pidof to get glusterfsd pids. And change the split logic accordingly. Change-Id: Ie215734387989f2d8cb19e4b4f7cddc73d2a5608 Signed-off-by: kshithijiyer --- glustolibs-gluster/glustolibs/gluster/brickmux_ops.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'glustolibs-gluster') diff --git a/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py b/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py index eeb4e2a50..3defdba8a 100755 --- a/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py +++ b/glustolibs-gluster/glustolibs/gluster/brickmux_ops.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -# Copyright (C) 2017-2019 Red Hat, Inc. +# Copyright (C) 2017-2020 Red Hat, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -149,8 +149,10 @@ def get_brick_processes_count(mnode): int: Number of brick processes running on the node. None: If the command fails to execute. """ - ret, out, _ = g.run(mnode, "pidof glusterfsd") + ret, out, _ = g.run(mnode, "pgrep -x glusterfsd") if not ret: - return len(out.split(" ")) + list_of_pids = out.split("\n") + list_of_pids.pop() + return len(list_of_pids) else: return None -- cgit