tools/testing/selftests/mqueue/mq_open_tests.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/mqueue/mq_open_tests.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/mqueue/mq_open_tests.c- Extension
.c- Size
- 15882 bytes
- Lines
- 503
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
stdio.hstdlib.hunistd.hfcntl.hstring.hlimits.herrno.hsys/types.hsys/time.hsys/resource.hsys/stat.hmqueue.herror.hkselftest.h
Detected Declarations
function __setfunction shutdownfunction getfunction setfunction getrfunction setrfunction validate_current_settingsfunction test_queuefunction test_queue_failfunction main
Annotated Snippet
if (rlim_needed > cur_limits.rlim_cur) {
printf("Temporarily lowering default queue parameters "
"to something that will work\n"
"with the current rlimit values.\n\n");
set(def_msgs, 10);
cur_def_msgs = 10;
set(def_msgsize, 128);
cur_def_msgsize = 128;
}
} else {
rlim_needed = (cur_max_msgs + 1) * (cur_max_msgsize + 1 +
2 * sizeof(void *));
if (rlim_needed > cur_limits.rlim_cur) {
printf("Temporarily lowering maximum queue parameters "
"to something that will work\n"
"with the current rlimit values in case this is "
"a kernel that ties the default\n"
"queue parameters to the maximum queue "
"parameters.\n\n");
set(max_msgs, 10);
cur_max_msgs = 10;
set(max_msgsize, 128);
cur_max_msgsize = 128;
}
}
}
/*
* test_queue - Test opening a queue, shutdown if we fail. This should
* only be called in situations that should never fail. We clean up
* after ourselves and return the queue attributes in *result.
*/
static inline void test_queue(struct mq_attr *attr, struct mq_attr *result)
{
int flags = O_RDWR | O_EXCL | O_CREAT;
int perms = DEFFILEMODE;
if ((queue = mq_open(queue_path, flags, perms, attr)) == -1)
shutdown(1, "mq_open()", __LINE__);
if (mq_getattr(queue, result))
shutdown(1, "mq_getattr()", __LINE__);
if (mq_close(queue))
shutdown(1, "mq_close()", __LINE__);
queue = -1;
if (mq_unlink(queue_path))
shutdown(1, "mq_unlink()", __LINE__);
}
/*
* Same as test_queue above, but failure is not fatal.
* Returns:
* 0 - Failed to create a queue
* 1 - Created a queue, attributes in *result
*/
static inline int test_queue_fail(struct mq_attr *attr, struct mq_attr *result)
{
int flags = O_RDWR | O_EXCL | O_CREAT;
int perms = DEFFILEMODE;
if ((queue = mq_open(queue_path, flags, perms, attr)) == -1)
return 0;
if (mq_getattr(queue, result))
shutdown(1, "mq_getattr()", __LINE__);
if (mq_close(queue))
shutdown(1, "mq_close()", __LINE__);
queue = -1;
if (mq_unlink(queue_path))
shutdown(1, "mq_unlink()", __LINE__);
return 1;
}
int main(int argc, char *argv[])
{
struct mq_attr attr, result;
if (argc != 2) {
printf("Using Default queue path - %s\n", default_queue_path);
queue_path = default_queue_path;
} else {
/*
* Although we can create a msg queue with a non-absolute path name,
* unlink will fail. So, if the name doesn't start with a /, add one
* when we save it.
*/
if (*argv[1] == '/')
queue_path = strdup(argv[1]);
else {
queue_path = malloc(strlen(argv[1]) + 2);
if (!queue_path) {
Annotation
- Immediate include surface: `stdio.h`, `stdlib.h`, `unistd.h`, `fcntl.h`, `string.h`, `limits.h`, `errno.h`, `sys/types.h`.
- Detected declarations: `function __set`, `function shutdown`, `function get`, `function set`, `function getr`, `function setr`, `function validate_current_settings`, `function test_queue`, `function test_queue_fail`, `function main`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.