tools/testing/selftests/prctl/set-process-name.c
Source file repositories/reference/linux-study-clean/tools/testing/selftests/prctl/set-process-name.c
File Facts
- System
- Linux kernel
- Corpus path
tools/testing/selftests/prctl/set-process-name.c- Extension
.c- Size
- 1615 bytes
- Lines
- 95
- 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.
Dependency Surface
errno.hsys/prctl.hstring.hkselftest_harness.h
Detected Declarations
function set_namefunction check_is_name_correctfunction check_null_pointerfunction check_name
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* This test covers the PR_SET_NAME functionality of prctl calls
*/
#include <errno.h>
#include <sys/prctl.h>
#include <string.h>
#include "kselftest_harness.h"
#define CHANGE_NAME "changename"
#define EMPTY_NAME ""
#define TASK_COMM_LEN 16
#define MAX_PATH_LEN 50
int set_name(char *name)
{
int res;
res = prctl(PR_SET_NAME, name, NULL, NULL, NULL);
if (res < 0)
return -errno;
return res;
}
int check_is_name_correct(char *check_name)
{
char name[TASK_COMM_LEN];
int res;
res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
if (res < 0)
return -errno;
return !strcmp(name, check_name);
}
int check_null_pointer(char *check_name)
{
char *name = NULL;
int res;
res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
return res;
}
int check_name(void)
{
int pid;
pid = getpid();
FILE *fptr = NULL;
char path[MAX_PATH_LEN] = {};
char name[TASK_COMM_LEN] = {};
char output[TASK_COMM_LEN] = {};
int j;
j = snprintf(path, MAX_PATH_LEN, "/proc/self/task/%d/comm", pid);
fptr = fopen(path, "r");
if (!fptr)
return -EIO;
fscanf(fptr, "%s", output);
if (ferror(fptr))
return -EIO;
int res = prctl(PR_GET_NAME, name, NULL, NULL, NULL);
if (res < 0)
return -errno;
return !strcmp(output, name);
}
TEST(rename_process) {
EXPECT_GE(set_name(CHANGE_NAME), 0);
EXPECT_TRUE(check_is_name_correct(CHANGE_NAME));
EXPECT_GE(set_name(EMPTY_NAME), 0);
EXPECT_TRUE(check_is_name_correct(EMPTY_NAME));
EXPECT_GE(set_name(CHANGE_NAME), 0);
EXPECT_LT(check_null_pointer(CHANGE_NAME), 0);
Annotation
- Immediate include surface: `errno.h`, `sys/prctl.h`, `string.h`, `kselftest_harness.h`.
- Detected declarations: `function set_name`, `function check_is_name_correct`, `function check_null_pointer`, `function check_name`.
- 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.