Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SWP-CM22-Planbased OMPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
felixkhals
SWP-CM22-Planbased OMPI
Merge requests
!2
Fix buffer size specification in function calls
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Fix buffer size specification in function calls
bugfix/buffer_length
into
master
Overview
0
Commits
1
Pipelines
0
Changes
5
Merged
felixkhals
requested to merge
bugfix/buffer_length
into
master
2 years ago
Overview
0
Commits
1
Pipelines
0
Changes
5
Expand
to send(), recv() and snprintf()
0
0
Merge request reports
Compare
master
version 1
9a7c54ce
2 years ago
master (base)
and
version 1
latest version
28950f55
1 commit,
2 years ago
version 1
9a7c54ce
3 commits,
2 years ago
5 files
+
89
−
50
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
5
Search (e.g. *.vue) (Ctrl+P)
ompi/communicator/comm_init.c
+
38
−
18
Options
@@ -96,41 +96,61 @@ static void errorExit(char* msg) {
// TODO: Change int return to size_t!
static
int
getProcessAgentRank
(
uint32_t
jobid
,
uint32_t
vpid
,
size_t
size
)
{
struct
sockaddr_un
strAddr
;
s
ocklen_t
lenAddr
;
int
fdSock
;
if
(
(
fdSock
=
socket
(
PF_UNIX
,
SOCK_STREAM
,
0
))
<
0
)
{
errorExit
(
"
socket
"
);
struct
addrinfo
hints
;
s
truct
addrinfo
*
result
,
*
rp
;
const
char
*
host_ip
=
"localhost"
;
const
char
*
agent_port
=
getenv
(
"DPM_AGENT_PORT"
);
if
(
NULL
==
agent_port
)
{
errorExit
(
"
Could not find DPM_AGENT_PORT env
"
);
}
memset
(
&
hints
,
0
,
sizeof
(
struct
addrinfo
));
hints
.
ai_family
=
AF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
//opting for reliable sequenced socket type
hints
.
ai_flags
=
0
;
hints
.
ai_protocol
=
IPPROTO_TCP
;
int
error_code
=
getaddrinfo
(
host_ip
,
agent_port
,
&
hints
,
&
result
);
if
(
0
!=
error_code
)
{
errorExit
(
"Could not get addrinfo!"
);
}
int
socket_fd
=
0
;
for
(
rp
=
result
;
rp
!=
NULL
;
rp
=
rp
->
ai_next
)
{
socket_fd
=
socket
(
rp
->
ai_family
,
rp
->
ai_socktype
,
rp
->
ai_protocol
);
if
(
socket_fd
==
-
1
)
{
continue
;
}
strAddr
.
sun_family
=
AF_LOCAL
;
/* Unix domain */
const
char
*
socket_path
=
getenv
(
"DPM_AGENT_SOCKET"
);
// check for success
if
(
NULL
==
socket_path
)
{
errorExit
(
"Could not find DPM_AGENT_SOCKET env"
);
if
(
0
==
connect
(
socket_fd
,
rp
->
ai_addr
,
rp
->
ai_addrlen
))
{
break
;
//successfully connected
}
else
{
close
(
socket_fd
);
//close socket when we cannot connect
}
}
strcpy
(
strAddr
.
sun_path
,
socket_path
);
lenAddr
=
sizeof
(
strAddr
.
sun_family
)
+
strlen
(
strAddr
.
sun_path
);
if
(
connect
(
fdSock
,
(
struct
sockaddr
*
)
&
strAddr
,
lenAddr
)
!=
0
)
{
errorExit
(
"connect"
);
freeaddrinfo
(
result
);
//free result
// exit if the result-linked-list has been traversed until the end without a successful
// connection
if
(
NULL
==
rp
)
{
errorExit
(
"Could not connect to host. Host not available or host/port invalid."
);
}
pid_t
pid
=
getpid
();
char
info_to_send
[
BUFFLEN
];
snprintf
(
info_to_send
,
BUFFLEN
+
1
,
snprintf
(
info_to_send
,
BUFFLEN
,
"%d,%u,%u,%zu"
,
pid
,
vpid
,
jobid
,
size
);
if
(
send
(
fdSock
,
info_to_send
,
BUFFLEN
+
1
,
0
)
<
0
)
{
if
(
send
(
socket_fd
,
info_to_send
,
BUFFLEN
,
0
)
<
0
)
{
errorExit
(
"send"
);
}
char
rank_to_recv
[
BUFFLEN
];
recv
(
fdSock
,
rank_to_recv
,
BUFFLEN
+
1
,
0
);
recv
(
socket_fd
,
rank_to_recv
,
BUFFLEN
,
0
);
int
received_rank
=
(
int
)
strtol
(
rank_to_recv
,
NULL
,
0
);
printf
(
"Received from server: %d
\n
"
,
received_rank
);
close
(
fdSock
);
close
(
socket_fd
);
return
received_rank
;
}
Loading