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
unix
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
tu-wien
unix
Commits
833c5606
Commit
833c5606
authored
Jan 11, 2019
by
Ivaylo Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add input check to generator
parent
9a652f4d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
7 deletions
+23
-7
fb_arc_set/generator.c
fb_arc_set/generator.c
+18
-2
fb_arc_set/shared/shm.c
fb_arc_set/shared/shm.c
+5
-5
No files found.
fb_arc_set/generator.c
View file @
833c5606
...
...
@@ -27,13 +27,29 @@
*
**/
#include "shared/shm.c"
#include <regex.h>
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
>
1
)
{
fprintf
(
stderr
,
"ERROR: Command takes no arguments"
);
if
(
argc
<
2
)
{
fprintf
(
stderr
,
"ERROR: Command takes at least one argument.
\n
"
);
puts
(
"Usage:
\n
generator EDGE1 EDGE2 ..."
);
exit
(
EXIT_FAILURE
);
}
regex_t
regex
;
if
(
regcomp
(
&
regex
,
"^[0-9]*-[0-9]*$"
,
REG_EXTENDED
|
REG_NOSUB
))
{
fprintf
(
stderr
,
"ERROR: Could not compile regex
\n
"
);
exit
(
EXIT_FAILURE
);
}
for
(
int
i
=
1
;
i
<=
argc
-
1
;
i
++
)
{
if
(
regexec
(
&
regex
,
argv
[
i
],
0
,
NULL
,
0
)
==
REG_NOMATCH
)
{
fprintf
(
stderr
,
"ERROR: Incorrect input found
\n
"
);
puts
(
"Usage:
\n
generator EDGE1 EDGE2 ..."
);
exit
(
EXIT_FAILURE
);
}
}
void
*
terminate_shm
=
open_shm
(
TERMINATE_SHM
,
TERMINATE_SHM_SIZE
);
write_to_shm
(
terminate_shm
,
"1"
,
TERMINATE_SHM_SIZE
);
...
...
fb_arc_set/shared/shm.c
View file @
833c5606
...
...
@@ -13,12 +13,12 @@
void
*
open_shm
(
char
*
shm_name
,
size_t
shm_size
)
{
int
shmfd
=
shm_open
(
shm_name
,
O_RDWR
|
O_CREAT
,
0600
);
if
(
shmfd
==
-
1
)
{
fprintf
(
stderr
,
"ERROR: Failed creating shared memory object"
);
fprintf
(
stderr
,
"ERROR: Failed creating shared memory object
\n
"
);
exit
(
EXIT_FAILURE
);
}
if
(
ftruncate
(
shmfd
,
shm_size
)
<
0
)
{
fprintf
(
stderr
,
"ERROR: Failed truncating shared memory object"
);
fprintf
(
stderr
,
"ERROR: Failed truncating shared memory object
\n
"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -26,7 +26,7 @@ void* open_shm(char *shm_name, size_t shm_size) {
shm
=
mmap
(
NULL
,
shm_size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
,
shmfd
,
0
);
if
(
shm
==
MAP_FAILED
)
{
fprintf
(
stderr
,
"ERROR: Failed mapping shared memory object"
);
fprintf
(
stderr
,
"ERROR: Failed mapping shared memory object
\n
"
);
exit
(
EXIT_FAILURE
);
}
...
...
@@ -39,14 +39,14 @@ void write_to_shm(void* shm, char *message, size_t message_size) {
void
close_shm
(
void
*
shm
,
size_t
shm_size
)
{
if
(
munmap
(
shm
,
shm_size
)
==
-
1
)
{
fprintf
(
stderr
,
"ERROR: Failed unmapping shared memory object"
);
fprintf
(
stderr
,
"ERROR: Failed unmapping shared memory object
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
void
destroy_shm
(
char
*
shm_name
)
{
if
(
shm_unlink
(
shm_name
)
==
-
1
)
{
fprintf
(
stderr
,
"ERROR: Failed unlinking shared memory object"
);
fprintf
(
stderr
,
"ERROR: Failed unlinking shared memory object
\n
"
);
exit
(
EXIT_FAILURE
);
}
}
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