Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/TestConfig/scripts/tools/sysvcleanup.pl
6004 views
1
#!/usr/bin/perl
2
##############################################################################
3
# Copyright (c) 2016, 2019 IBM Corp. and others
4
#
5
# This program and the accompanying materials are made available under
6
# the terms of the Eclipse Public License 2.0 which accompanies this
7
# distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
# or the Apache License, Version 2.0 which accompanies this distribution and
9
# is available at https://www.apache.org/licenses/LICENSE-2.0.
10
#
11
# This Source Code may also be made available under the following
12
# Secondary Licenses when the conditions for such availability set
13
# forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
# General Public License, version 2 with the GNU Classpath
15
# Exception [1] and GNU General Public License, version 2 with the
16
# OpenJDK Assembly Exception [2].
17
#
18
# [1] https://www.gnu.org/software/classpath/license.html
19
# [2] http://openjdk.java.net/legal/assembly-exception.html
20
#
21
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
##############################################################################
23
24
use strict;
25
26
#
27
# This script cleans up SysV memory and semaphores.
28
#
29
30
my $numargs = @ARGV;
31
if ($numargs > 2) {
32
print("Error: incorrect usage!\n");
33
print("\tscriptname.pl userid zos\n");
34
print("\t\tuserid: user you wish to clean up SysV objects for\n");
35
print("\t\tzos: set this if your cleaning up on zos\n");
36
}
37
38
#
39
# The user we are cleaning up ipcs for ...
40
#
41
42
my $cleanupuser = "j9build";
43
# a1 is for Attach API, ad is for shared classes, 0a is for pltest (and for cloud at one time)
44
my $semaphoreProjid = "(0xad|0xa1|0x41|0x42|0x43|0x44|0x45|0x46|0x47|0x48|0x49|0x4a|0x4b|0x4c|0x4d|0x4e|0x4f|0x50|0x51|0x52|0x53|0x54|".
45
"0x81|0x81|0x82|0x83|0x84|0x85|0x86|0x87|0x88|0x89|0x8a|0x8b|0x8c|0x8d|0x8e|0x8f|0x90|0x91|0x92|0x93|0x94|0x0a)";
46
47
my $memoryProjid = "(0xde|0x21|0x22|0x23|0x24|0x25|0x26|0x27|0x28|0x29|0x2a|0x2b|0x2c|0x2d|0x2e|0x2f|0x30|0x31|0x32|0x33|0x34|".
48
"0x61|0x61|0x62|0x63|0x64|0x65|0x66|0x67|0x68|0x69|0x6a|0x6b|0x6c|0x6d|0x6e|0x6f|0x70|0x71|0x72|0x73|0x74)";
49
50
my $keyindex = 0;
51
my $idindex = 1;
52
my $ownerindex = 2;
53
54
my @stdoutvar = ();
55
my $iter = "";
56
my $foundSemaphoreHeader = 0;
57
my $foundMemoryHeader = 0;
58
59
my $memsremoved=0;
60
my $semsremoved=0;
61
62
if ($numargs>0) {
63
$cleanupuser=$ARGV[0];
64
}
65
if (($numargs>1) && ($ARGV[1] =~ /zos/))
66
{
67
$keyindex=2;
68
$idindex=1;
69
$ownerindex=4;
70
}
71
72
if (($numargs>1) && ($ARGV[1] =~ /aix/))
73
{
74
$keyindex=2;
75
$idindex=1;
76
$ownerindex=4;
77
}
78
79
80
printf("Start SysV clean up for user:".$cleanupuser." ".$ARGV[1]."\n");
81
82
#
83
# 1.) LIST MEMORY:
84
# - Call ipcs and store stdout in a local variable.
85
# - If the command fails we exit ASAP
86
#
87
@stdoutvar = `ipcs -m` or die("Error: could not execute ipcs!");
88
89
#
90
# 2.) CLEAN UP SYSV MEMORY
91
# Loop through stdout and perform clean up of semaphores owned by 'user'
92
#
93
$iter = "";
94
$foundSemaphoreHeader = 0;
95
$foundMemoryHeader = 0;
96
foreach $iter (@stdoutvar) {
97
98
if ($iter =~ /Shared Memory/) {
99
$foundMemoryHeader=1;
100
}
101
if (($iter =~ /$memoryProjid/) && ($foundMemoryHeader==1)) {
102
#remove any sequence of whitespace and insert a :
103
$iter =~s/[\s]+/:/g;
104
105
#split the string around :
106
my @vals = split(/:/,$iter);
107
108
#we expect 3 entries in this row ... the 1st three are kei,id,owner ...
109
#the rest are don't cares ...
110
if (@vals<3) {
111
die("ipcs did not return expected output");
112
}
113
114
my $key = $vals[$keyindex];
115
my $id = $vals[$idindex];
116
my $owner = $vals[$ownerindex];
117
if (($owner =~ /$cleanupuser/) || ($cleanupuser =~ /all/)) {
118
my $cleanmem = "ipcrm -m $id";
119
my $out = `$cleanmem`;
120
print($out);
121
$memsremoved = $memsremoved + 1;
122
}
123
}
124
}
125
126
#
127
# 3.) LIST SEMAPHORES:
128
# - Call ipcs and store stdout in a local variable.
129
# - If the command fails we exit ASAP
130
#
131
@stdoutvar = `ipcs -s` or die("Error: could not execute ipcs!");
132
133
#
134
# 4.) CLEAN UP SYSV MEMORY
135
# Loop through stdout and perform clean up of semaphores owned by 'user'
136
#
137
$iter = "";
138
$foundSemaphoreHeader = 0;
139
$foundMemoryHeader = 0;
140
foreach $iter (@stdoutvar) {
141
142
if ($iter =~ /Semaphore/) {
143
$foundSemaphoreHeader=1;
144
}
145
if (($iter =~ /$semaphoreProjid/) && ($foundSemaphoreHeader==1)) {
146
#remove any sequence of whitespace and insert a :
147
$iter =~s/[\s]+/:/g;
148
149
#split the string around :
150
my @vals = split(/:/,$iter);
151
152
#we expect 3 entries in this row ... the 1st three are kei,id,owner ...
153
#the rest are don't cares ...
154
if (@vals<3) {
155
die("ipcs did not return expected output");
156
}
157
my $key = $vals[$keyindex];
158
my $id = $vals[$idindex];
159
my $owner = $vals[$ownerindex];
160
if (($owner =~ /$cleanupuser/) || ($cleanupuser =~ /all/)) {
161
my $cleansem = "ipcrm -s $id";
162
my $out = `$cleansem`;
163
print($out);
164
$semsremoved = $semsremoved + 1;
165
}
166
}
167
}
168
169
printf("Clean up is finished:\n");
170
printf("\tShared Memory Segments Removed:".$memsremoved."\n");
171
printf("\tShared Semaphores Removed:".$semsremoved."\n");
172
173
0;
174
175
176