4545import os
4646import re
4747import stat
48- import subprocess
4948import time
50- import traceback
5149
5250descriptors = []
5351
@@ -120,15 +118,15 @@ def build_block_major_minor_tables():
120118 p2d = {}
121119
122120 # Get values from diskstats file
123- p = subprocess .Popen ("awk '{print $1,$2, $3}' " + DISKSTATS_FILE , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
124- out , err = p .communicate ()
125-
121+ with open (DISKSTATS_FILE , 'r' ) as f :
122+ lines = f .readlines ()
126123 logging .debug ('grabbed diskstat device info' )
127- logging .debug ('diskstat devices: ' + str ( out ))
124+ logging .debug ('diskstat devices: ' + ' \n ' . join ( lines ))
128125
129- for n in out .split ('\n ' ):
130- if n :
131- [maj , min , name ] = n .split ()
126+ for line in lines :
127+ if line :
128+ # read the first three fields from each line
129+ (maj , min , name ) = line .split ()[:3 ]
132130 dnames .append (name )
133131 d2p [name ] = (maj , min )
134132 p2d [(maj , min )] = name
@@ -248,7 +246,6 @@ def update_stats():
248246 logging .debug (' wait ' + str (int (MAX_UPDATE_TIME - (cur_time - last_update ))) + ' seconds' )
249247 return True
250248
251- #####
252249 # Update diskstats
253250 stats = {}
254251
@@ -269,16 +266,18 @@ def update_stats():
269266 if dev not in last_val :
270267 last_val [dev ] = {}
271268
272- # Convert from dmname to devname for use by awk
269+ # Convert from dmname to devname
273270 if device_mapper == 'true' :
274271 olddev = dev
275272 dev = get_devname (dev )
276273
277274 # Get values from diskstats file
278- p = subprocess .Popen ("awk -v dev=" + dev + " '$3 == dev' " + DISKSTATS_FILE , shell = True , stdout = subprocess .PIPE , stderr = subprocess .PIPE )
279- out , err = p .communicate ()
275+ with open (DISKSTATS_FILE , 'r' ) as f :
276+ lines = f .readlines ()
277+ for line in lines :
278+ if dev in line :
279+ vals = line .split ()
280280
281- vals = out .split ()
282281 logging .debug (' vals: ' + str (vals ))
283282
284283 # Reset back to orignal dev name
0 commit comments