Skip to content

Commit 8470d79

Browse files
committed
Added env var pid override in proc-net acceptance test
To align with change to reading /proc/<pid>/... Ticket: CFE-3429 Changelog: none
1 parent 628055f commit 8470d79

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

libenv/unix_iface.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,7 +1395,7 @@ JsonElement* GetProcFileInfo(EvalContext *ctx, const char* filename, const char*
13951395
void GetNetworkingInfo(EvalContext *ctx)
13961396
{
13971397
const char *procdir_root = GetRelocatedProcdirRoot();
1398-
int promiser_pid = (int) getpid();
1398+
int promiser_pid = GetProcdirPid();
13991399

14001400
Buffer *pbuf = BufferNew();
14011401

@@ -1549,7 +1549,7 @@ void GetNetworkingInfo(EvalContext *ctx)
15491549
JsonElement* GetNetworkingConnections(EvalContext *ctx)
15501550
{
15511551
const char *procdir_root = GetRelocatedProcdirRoot();
1552-
int promiser_pid = (int) getpid();
1552+
int promiser_pid = GetProcdirPid();
15531553
JsonElement *json = JsonObjectCreate(5);
15541554
const char* ports_regex = "^\\s*\\d+:\\s+(?<raw_local>[0-9A-F:]+)\\s+(?<raw_remote>[0-9A-F:]+)\\s+(?<raw_state>[0-9]+)";
15551555

tests/acceptance/00_basics/environment/proc-net-functions.cf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,35 @@ body common control
77

88
###########################################################
99

10+
bundle agent init
11+
{
12+
vars:
13+
"pid_for_testing" int => "11";
14+
15+
methods:
16+
"" usebundle => dir_sync(
17+
"$(this.promise_dirname)/proc",
18+
"$(G.testdir)/proc"
19+
);
20+
21+
commands:
22+
"
23+
cd $(G.testdir)/proc/proc
24+
mkdir $(pid_for_testing)
25+
mv net $(pid_for_testing)/
26+
ln -s $(pid_for_testing) self
27+
ln -s self/net net
28+
"
29+
comment => "Create a semi-real structure with symlinks and a pid dir",
30+
contain => in_shell;
31+
}
32+
33+
1034
bundle agent test
1135
{
1236
meta:
1337
"test_skip_unsupported" string => "!linux";
1438

1539
commands:
16-
"$(G.env) CFENGINE_TEST_OVERRIDE_PROCDIR=$(this.promise_dirname)/proc $(sys.cf_agent) -DAUTO -f $(this.promise_filename).sub";
40+
"$(G.env) CFENGINE_TEST_OVERRIDE_PROCPID=$(init.pid_for_testing) CFENGINE_TEST_OVERRIDE_PROCDIR=$(G.testdir)/proc $(sys.cf_agent) -DAUTO -f $(this.promise_filename).sub";
1741
}

tests/acceptance/00_basics/environment/proc-net.cf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,34 @@ body common control
77

88
###########################################################
99

10+
bundle agent init
11+
{
12+
vars:
13+
"pid_for_testing" int => "11";
14+
15+
methods:
16+
"" usebundle => dir_sync(
17+
"$(this.promise_dirname)/proc",
18+
"$(G.testdir)/proc"
19+
);
20+
21+
commands:
22+
"
23+
cd $(G.testdir)/proc/proc
24+
mkdir $(pid_for_testing)
25+
mv net $(pid_for_testing)/
26+
ln -s $(pid_for_testing) self
27+
ln -s self/net net
28+
"
29+
comment => "Create a semi-real structure with symlinks and a pid dir",
30+
contain => in_shell;
31+
}
32+
1033
bundle agent test
1134
{
1235
meta:
1336
"test_skip_unsupported" string => "!linux";
1437

1538
commands:
16-
"$(G.env) CFENGINE_TEST_OVERRIDE_PROCDIR=$(this.promise_dirname)/proc $(sys.cf_agent) -DAUTO -f $(this.promise_filename).sub";
39+
"$(G.env) CFENGINE_TEST_OVERRIDE_PROCPID=$(init.pid_for_testing) CFENGINE_TEST_OVERRIDE_PROCDIR=$(G.testdir)/proc $(sys.cf_agent) -DAUTO -f $(this.promise_filename).sub";
1740
}

0 commit comments

Comments
 (0)