Files
RedBear-OS/recipes/tests/sys_socket/unixwrite.c
T
vasilito b9874d0941 feat: USB storage read/write proof + full Red Bear OS tree sync
Add redbear-usb-storage-check in-guest binary that validates USB mass
storage read and write I/O: discovers /scheme/disk/ devices, writes a
test pattern to sector 2048, reads it back, verifies match, restores
original content. Updates test-usb-storage-qemu.sh with write-proof
verification step.

Includes all accumulated Red Bear OS work: kernel patches, relibc
patches, driver infrastructure, DRM/GPU, KDE recipes, firmware,
validation tooling, build system hardening, and documentation.
2026-05-03 23:03:24 +01:00

57 lines
1.5 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <fcntl.h>
#include <errno.h>
#include "test_helpers.h"
// similar to "unixrecv", but this test if write() works before accept().
// "unixrecvfrom" is the similar test to this one, but using SOCK_DGRAM.
// "unixrecvearly" is also the similar test to this one, but using recv().
int main() {
int status;
const char* socket_path = "unix_write.sock";
unlink(socket_path);
int server_fd = socket(AF_UNIX, SOCK_STREAM, 0);
ERROR_IF(socket, server_fd, == -1);
struct sockaddr_un addr = { .sun_family = AF_UNIX };
strncpy(addr.sun_path, socket_path, sizeof(addr.sun_path) - 1);
unlink(socket_path);
status = bind(server_fd, (struct sockaddr*)&addr, sizeof(addr));
ERROR_IF(bind, status, == -1);
status = listen(server_fd, 1);
ERROR_IF(listen, status, == -1);
int client_fd = socket(AF_UNIX, SOCK_STREAM, 0);
ERROR_IF(socket, client_fd, == -1);
status = connect(client_fd, (struct sockaddr*)&addr, sizeof(addr));
ERROR_IF(connect, status, == -1);
char *msg = "yes";
ssize_t ret = write(client_fd, msg, 4);
ERROR_IF(write, ret, == -1);
UNEXP_IF(raise, ret, != 4);
int accepted_fd = accept(server_fd, NULL, NULL);
ERROR_IF(accept, accepted_fd, == -1);
char x[4];
ssize_t amount = read(accepted_fd, x, 4);
ERROR_IF(read, amount, == -1);
close(accepted_fd);
close(client_fd);
close(server_fd);
return 0;
}