Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Z
zafl
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Open Source Software
zafl
Commits
1a54f8a1
Commit
1a54f8a1
authored
5 years ago
by
Anh Nguyen-Tuong
Browse files
Options
Downloads
Patches
Plain Diff
Stash away shared memory utility
parent
cb4a532c
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
util/shm/shmcat.c
+100
-0
100 additions, 0 deletions
util/shm/shmcat.c
with
100 additions
and
0 deletions
util/shm/shmcat.c
0 → 100644
+
100
−
0
View file @
1a54f8a1
/*
* Copyright (c) 2014 Nicholas J. Kain
* Licensed under 2-clause BSD.
* Prints the contents of a SysV shm segment.
*
* Build: gcc -O2 -std=gnu99 shmcat.c -o shmcat
* Usage: shmcat <shmid>
*
* Get the shmid by using 'ipcs -m'.
*/
#include
<stdlib.h>
#include
<stdio.h>
#include
<string.h>
#include
<ctype.h>
#include
<limits.h>
#include
<errno.h>
#include
<sys/types.h>
#include
<sys/ipc.h>
#include
<sys/shm.h>
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
<
2
)
{
printf
(
"Need to specify a shmid as first argument.
\n
"
);
return
-
1
;
}
char
*
eptr
;
long
shmidl
=
strtol
(
argv
[
1
],
&
eptr
,
0
);
if
(((
shmidl
==
LONG_MIN
||
shmidl
==
LONG_MAX
)
&&
errno
==
ERANGE
)
||
eptr
==
argv
[
1
])
{
printf
(
"shmid out of range or not a number: '%s'
\n
"
,
argv
[
1
]);
return
-
1
;
}
if
(
shmidl
<
0
||
shmidl
>
INT_MAX
)
{
printf
(
"shmid out of range: '%lu'
\n
"
,
shmidl
);
return
-
1
;
}
int
shmid
=
shmidl
;
struct
shmid_ds
ds
;
int
err
=
shmctl
(
shmid
,
IPC_STAT
,
&
ds
);
if
(
err
<
0
)
{
printf
(
"shmctl() failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
size_t
shm_bytes
=
ds
.
shm_segsz
;
printf
(
"shmid=%i bytes=%zu
\n
-=-=-=-=-=-
\n
"
,
shmid
,
shm_bytes
);
void
*
s
=
shmat
(
shmid
,
NULL
,
SHM_RDONLY
);
if
(
s
==
(
void
*
)
-
1
)
{
printf
(
"shmat() failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
#ifdef XXX
char
sbuf
[
32
];
memset
(
sbuf
,
0
,
sizeof
sbuf
);
size_t
si
=
0
;
printf
(
"
\n
%8.8zX "
,
si
);
for
(
si
=
0
;
si
<
shm_bytes
;
++
si
)
{
size_t
sis
=
si
%
16
;
if
(
si
&&
si
%
16
==
0
)
{
printf
(
" "
);
for
(
size_t
i
=
0
;
i
<
16
;
++
i
)
{
printf
(
"%c"
,
isprint
(
sbuf
[
i
])
?
sbuf
[
i
]
:
'.'
);
}
memset
(
sbuf
,
0
,
sizeof
sbuf
);
printf
(
"
\n
%8.8zX "
,
si
);
}
sbuf
[
sis
]
=
((
char
*
)
s
)[
si
];
printf
(
"%2.2X "
,
sbuf
[
sis
]);
}
if
(
si
)
{
size_t
sis
=
si
%
16
;
sis
=
sis
?
sis
:
16
;
for
(
size_t
i
=
sis
;
i
<
16
;
++
i
)
printf
(
" "
);
printf
(
" "
);
for
(
size_t
i
=
0
;
i
<
sis
;
++
i
)
{
printf
(
"%c"
,
isprint
(
sbuf
[
i
])
?
sbuf
[
i
]
:
'.'
);
}
memset
(
sbuf
,
0
,
sizeof
sbuf
);
printf
(
"
\n
"
);
}
printf
(
"
\n
"
);
#else
size_t
si
=
0
;
for
(
si
=
0
;
si
<
shm_bytes
;
++
si
)
{
if
(((
char
*
)
s
)[
si
]
!=
0
)
printf
(
"%lx:%u
\n
"
,
si
,
(
unsigned
char
)((
char
*
)
s
)[
si
]);
}
#endif
err
=
shmdt
(
s
);
if
(
err
<
0
)
{
printf
(
"shmdt() failed: %s
\n
"
,
strerror
(
errno
));
return
-
1
;
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment