Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
DiSL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
5
Issues
5
List
Boards
Labels
Service Desk
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DiSL
DiSL
Commits
44c2607d
Verified
Commit
44c2607d
authored
Nov 26, 2018
by
Vít Kabele
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sessions.c: JAR loading extracted to standalone method
parent
8b709571
Pipeline
#3524
passed with stages
in 3 minutes and 13 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
29 deletions
+49
-29
src-disl-agent/sessions.c
src-disl-agent/sessions.c
+49
-29
No files found.
src-disl-agent/sessions.c
View file @
44c2607d
...
...
@@ -23,7 +23,10 @@
* Send client message to socket.
*/
void
send_client_message
(
const
ClientMessage
message
,
struct
connection
*
restrict
conn
)
{
send_client_message
(
const
ClientMessage
message
,
struct
connection
*
restrict
conn
)
{
void
*
buffer
;
size_t
send_size
=
client_message__get_packed_size
(
&
message
);
buffer
=
malloc
(
send_size
);
// FREE!
...
...
@@ -50,57 +53,74 @@ receive_server_message(struct connection * restrict conn) {
return
(
response
);
}
/*
* Instrumentation jar structure
*/
struct
inst_jar
{
char
*
name
;
FILE
*
file
;
long
filesize
;
char
*
name
;
void
*
buffer
;
size_t
filesize
;
};
/*
* Get filesize
*/
static
long
get_filesize
(
const
char
*
filename
){
get_filesize
(
const
char
*
filename
)
{
struct
stat
buffer
;
int
status
;
status
=
stat
(
filename
,
&
buffer
);
return
buffer
.
st_size
;
return
(
buffer
.
st_size
)
;
}
/**
/*
* Load the files to the buffers.
* @return
*/
static
void
load_files_to_buffers
(
struct
inst_jar
*
jars
,
const
size_t
count
)
{
FILE
*
file
;
// Open the files and ensure that all of them exists
for
(
size_t
i
=
0
;
i
<
count
;
++
i
)
{
file
=
fopen
(
jars
[
i
].
name
,
"r"
);
assert
(
file
!=
NULL
);
jars
[
i
].
filesize
=
(
size_t
)
get_filesize
(
jars
[
i
].
name
);
jars
[
i
].
buffer
=
malloc
(
jars
[
i
].
filesize
);
fread
(
jars
[
i
].
buffer
,
1
,
jars
[
i
].
filesize
,
file
);
fclose
(
file
);
}
}
/*
* Instrumentation delivery message build
* @param config
* @return
*/
static
InstrumentationDelivery
instrumentationDeliveryInit
(
struct
config
*
config
){
instrumentationDeliveryInit
(
struct
config
*
config
)
{
InstrumentationDelivery
delivery
=
INSTRUMENTATION_DELIVERY__INIT
;
size_t
tokens
=
config
->
jar_count
;
char
**
arr
=
config
->
instrumentation_jars
;
struct
inst_jar
*
jars
=
malloc
(
tokens
*
sizeof
(
struct
inst_jar
));
size_t
jarCount
=
config
->
jar_count
;
size_t
total_size
=
0
;
delivery
.
n_sizes
=
tokens
;
delivery
.
sizes
=
malloc
(
tokens
*
sizeof
(
int32_t
));
struct
inst_jar
*
jars
=
malloc
(
jarCount
*
sizeof
(
struct
inst_jar
));
for
(
size_t
i
=
0
;
i
<
tokens
;
++
i
){
jars
[
i
].
name
=
arr
[
i
];
}
delivery
.
n_sizes
=
jarCount
;
delivery
.
sizes
=
malloc
(
jarCount
*
sizeof
(
int32_t
));
free
(
arr
);
for
(
size_t
i
=
0
;
i
<
jarCount
;
++
i
)
{
jars
[
i
].
name
=
config
->
instrumentation_jars
[
i
];
}
// Silent fallback to backward compatibility.
if
(
tokens
==
0
)
return
delivery
;
load_files_to_buffers
(
jars
,
jarCount
);
// Open the files and ensure that all of them exists
for
(
size_t
i
=
0
;
i
<
tokens
;
++
i
){
jars
[
i
].
file
=
fopen
(
jars
[
i
].
name
,
"r"
);
assert
(
jars
[
i
].
file
!=
NULL
);
jars
[
i
].
filesize
=
get_filesize
(
jars
[
i
].
name
);
total_size
+=
jars
[
i
].
filesize
;
delivery
.
sizes
[
i
]
=
(
int32_t
)
jars
[
i
].
filesize
;
// Crop conversion size_t -> int32_t
for
(
size_t
i
=
0
;
i
<
jarCount
;
++
i
)
{
delivery
.
sizes
[
i
]
=
(
int32_t
)
jars
[
i
].
filesize
;
total_size
+=
delivery
.
sizes
[
i
];
}
assert
(
total_size
>
0
);
...
...
@@ -109,10 +129,10 @@ instrumentationDeliveryInit(struct config * config){
delivery
.
instrumentation
.
data
=
malloc
(
total_size
);
void
*
buffer
=
delivery
.
instrumentation
.
data
;
for
(
size_t
i
=
0
;
i
<
tokens
;
++
i
)
{
fread
(
buffer
,
1
,
(
size_t
)
jars
[
i
].
filesize
,
jars
[
i
].
fil
e
);
for
(
size_t
i
=
0
;
i
<
jarCount
;
++
i
)
{
memcpy
(
buffer
,
jars
[
i
].
buffer
,
jars
[
i
].
filesiz
e
);
buffer
+=
jars
[
i
].
filesize
;
f
close
(
jars
[
i
].
file
);
f
ree
(
jars
[
i
].
buffer
);
}
free
(
jars
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment