@@ -21,6 +21,7 @@ in the source distribution for its full text.
2121#include "CRT.h"
2222#include "Macros.h"
2323#include "Object.h"
24+ #include "ProgramLauncher.h"
2425#include "RichString.h"
2526#include "Settings.h"
2627#include "XUtils.h"
@@ -68,6 +69,8 @@ typedef struct SystemdMeterContext {
6869static SystemdMeterContext_t ctx_system ;
6970static SystemdMeterContext_t ctx_user ;
7071
72+ static ProgramLauncher SystemdMeter_programLauncher ;
73+
7174static void SystemdMeter_done (ATTR_UNUSED Meter * this ) {
7275 SystemdMeterContext_t * ctx = String_eq (Meter_name (this ), "SystemdUser" ) ? & ctx_user : & ctx_system ;
7376
@@ -217,6 +220,10 @@ static void updateViaExec(bool user) {
217220 if (Settings_isReadonly ())
218221 return ;
219222
223+ ProgramLauncher_setPath (& SystemdMeter_programLauncher , "systemctl" );
224+ if (SystemdMeter_programLauncher .lastErrno != 0 )
225+ return ;
226+
220227 int fdpair [2 ] = {-1 , -1 };
221228 if (pipe (fdpair ) < 0 )
222229 return ;
@@ -237,19 +244,20 @@ static void updateViaExec(bool user) {
237244 exit (1 );
238245 dup2 (fdnull , STDERR_FILENO );
239246 close (fdnull );
240- // Use of NULL in variadic functions must have a pointer cast.
241- // The NULL constant is not required by standard to have a pointer type.
242- execlp (
243- "systemctl" ,
247+
248+ const char * argv [] = {
244249 "systemctl" ,
245250 "show" ,
246- user ? "--user" : "--system" ,
251+ ( user ? "--user" : "--system" ) ,
247252 "--property=SystemState" ,
248253 "--property=NFailedUnits" ,
249254 "--property=NNames" ,
250255 "--property=NJobs" ,
251256 "--property=NInstalledJobs" ,
252- (char * )NULL );
257+ NULL
258+ };
259+ ProgramLauncher_execv_const (& SystemdMeter_programLauncher , argv );
260+
253261 exit (127 );
254262 }
255263 close (fdpair [1 ]);
0 commit comments