-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tetragon: Add direct-write-tester tester prog
Adding direct-write-tester tester prog to test the bypass of sigkill action in pwrite. It's originally written by Anastasios. Signed-off-by: Jiri Olsa <jolsa@kernel.org>
- Loading branch information
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | ||
// Copyright Authors of Tetragon | ||
|
||
#include <fcntl.h> | ||
#include <sys/syscall.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include <errno.h> | ||
#include <stdio.h> | ||
|
||
#define BLOCKSIZE 4096 | ||
#define O_DIRECT 00040000 | ||
|
||
int main(int argc, char **argv) | ||
{ | ||
char *avd = "NEW_MESSAGE\n"; | ||
void *buffer; | ||
int fd; | ||
|
||
if (argc != 2) | ||
exit(-1); | ||
|
||
fd = open(argv[1], O_WRONLY | O_DIRECT | O_CREAT, S_IRWXU | S_IRWXG); | ||
if (fd == -1) { | ||
perror("open"); | ||
exit(-1); | ||
} | ||
|
||
posix_memalign(&buffer, BLOCKSIZE, BLOCKSIZE); | ||
memset(buffer, 0, BLOCKSIZE); | ||
memcpy(buffer, avd, strlen(avd) + 1); | ||
|
||
ssize_t ret = pwrite(fd, buffer, BLOCKSIZE, 0); | ||
if (ret == -1) { | ||
perror("write"); | ||
exit(-1); | ||
} | ||
|
||
close(fd); | ||
free(buffer); | ||
return 0; | ||
} |