@@ -132,8 +132,6 @@ void log_sample(int sample, struct list_sample_data **ptr) {
132132 struct list_sample_data * sampledata ;
133133 struct ps_sched_struct * ps_prev = NULL ;
134134
135-
136-
137135 sampledata = * ptr ;
138136
139137 /* all the per-process stuff goes here */
@@ -151,8 +149,8 @@ void log_sample(int sample, struct list_sample_data **ptr) {
151149 /* block stuff */
152150 vmstat = openat (procfd , "vmstat" , O_RDONLY );
153151 if (vmstat == -1 ) {
154- perror ( " open /proc/vmstat" );
155- exit (EXIT_FAILURE );
152+ log_error ( "Failed to open /proc/vmstat: %m " );
153+ exit (EXIT_FAILURE );
156154 }
157155 }
158156
@@ -183,8 +181,8 @@ void log_sample(int sample, struct list_sample_data **ptr) {
183181 /* overall CPU utilization */
184182 schedstat = openat (procfd , "schedstat" , O_RDONLY );
185183 if (schedstat == -1 ) {
186- perror ( " open /proc/schedstat" );
187- exit (EXIT_FAILURE );
184+ log_error ( "Failed to open /proc/schedstat: %m " );
185+ exit (EXIT_FAILURE );
188186 }
189187 }
190188
@@ -257,17 +255,17 @@ void log_sample(int sample, struct list_sample_data **ptr) {
257255 char t [32 ];
258256 struct ps_struct * parent ;
259257
260- ps -> next_ps = calloc ( 1 , sizeof ( struct ps_struct ) );
258+ ps -> next_ps = new0 ( struct ps_struct , 1 );
261259 if (!ps -> next_ps ) {
262- perror ( "calloc(ps_struct)" );
260+ log_oom ( );
263261 exit (EXIT_FAILURE );
264262 }
265263 ps = ps -> next_ps ;
266264 ps -> pid = pid ;
267265
268- ps -> sample = calloc ( 1 , sizeof ( struct ps_sched_struct ) );
266+ ps -> sample = new0 ( struct ps_sched_struct , 1 );
269267 if (!ps -> sample ) {
270- perror ( "calloc(ps_struct)" );
268+ log_oom ( );
271269 exit (EXIT_FAILURE );
272270 }
273271 ps -> sample -> sampledata = sampledata ;
@@ -393,10 +391,10 @@ void log_sample(int sample, struct list_sample_data **ptr) {
393391 if (!sscanf (buf , "%s %s %*s" , rt , wt ))
394392 continue ;
395393
396- ps -> sample -> next = calloc ( 1 , sizeof ( struct ps_sched_struct ) );
394+ ps -> sample -> next = new0 ( struct ps_sched_struct , 1 );
397395 if (!ps -> sample ) {
398- perror ( "calloc(ps_struct)" );
399- exit (EXIT_FAILURE );
396+ log_oom ( );
397+ exit (EXIT_FAILURE );
400398 }
401399 ps -> sample -> next -> prev = ps -> sample ;
402400 ps -> sample = ps -> sample -> next ;
0 commit comments