Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ generate-mount_flags.c: src/libcrun/mount_flags.perf

clang-format:
# do not format files that were copied into the source directory.
git ls-files src tests | grep -E "\\.[hc]" | grep -v "blake3\|chroot_realpath.c\|cloned_binary.c\|signals.c\|mount_flags.c" | xargs clang-format -style=file -i
git ls-files contrib src tests | grep -E "\\.[hc]" | grep -v "blake3\|chroot_realpath.c\|cloned_binary.c\|signals.c\|mount_flags.c" | xargs clang-format -style=file -i

shellcheck:
shellcheck autogen.sh build-aux/release.sh tests/run_all_tests.sh tests/*/*.sh contrib/*.sh
Expand Down
22 changes: 12 additions & 10 deletions contrib/notify-socket-server/notify-socket-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
#include <termios.h>
#include <stdio.h>

#define error(status, errno, fmt, ...) do{ \
if (errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while(0)
#define error(status, errno, fmt, ...) \
do \
{ \
if (errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while (0)

static int
open_unix_domain_socket (const char *path)
Expand All @@ -46,7 +48,7 @@ open_unix_domain_socket (const char *path)
int ret, fd;
const int one = 1;

fd = socket (AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
if (fd < 0)
error (EXIT_FAILURE, errno, "socket");

Expand Down Expand Up @@ -97,7 +99,7 @@ main (int argc, char **argv)
msg.msg_control = ctrl_buf;
msg.msg_controllen = CTRL_SIZE;

ret = recvmsg (fd, &msg, MSG_CMSG_CLOEXEC|MSG_TRUNC);
ret = recvmsg (fd, &msg, MSG_CMSG_CLOEXEC | MSG_TRUNC);
if (ret < 0 && errno == EINTR)
continue;
if (ret < 0)
Expand Down
22 changes: 12 additions & 10 deletions contrib/seccomp-receiver/seccomp-receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
#include <termios.h>
#include <stdio.h>

#define error(status, errno, fmt, ...) do { \
if (errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while(0)
#define error(status, errno, fmt, ...) \
do \
{ \
if (errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while (0)

static int
open_unix_domain_socket (const char *path)
Expand All @@ -47,10 +49,10 @@ open_unix_domain_socket (const char *path)
int fd = socket (AF_UNIX, SOCK_STREAM, 0);
if (fd < 0)
error (EXIT_FAILURE, errno, "error creating UNIX socket");

if (strlen (path) >= sizeof (addr.sun_path))
error (EXIT_FAILURE, 0, "invalid path");

strcpy (addr.sun_path, path);
addr.sun_family = AF_UNIX;
ret = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
Expand Down
51 changes: 27 additions & 24 deletions contrib/terminal-receiver/terminal-receiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@
#include <signal.h>
#include <stdio.h>

#define error(status, errno, fmt, ...) do { \
if (!errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while(0)
#define error(status, errno, fmt, ...) \
do \
{ \
if (! errno) \
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
else \
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
if (status) \
exit (status); \
} while (0)

struct termios tset;
int fd;
Expand All @@ -52,7 +54,7 @@ open_unix_domain_socket (const char *path)
error (EXIT_FAILURE, errno, "error creating UNIX socket");
if (strlen (path) >= sizeof (addr.sun_path))
error (EXIT_FAILURE, 0, "invalid path");

strcpy (addr.sun_path, path);
addr.sun_family = AF_UNIX;
ret = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
Expand Down Expand Up @@ -112,16 +114,16 @@ void
sigint_handler (int s)
{
const char ctrlc = 3;
write(fd, &ctrlc, 1);
write (fd, &ctrlc, 1);
}

void
register_handler (struct sigaction* handler)
register_handler (struct sigaction *handler)
{
handler->sa_handler = sigint_handler;
sigemptyset(&handler->sa_mask);
sigemptyset (&handler->sa_mask);
handler->sa_flags = 0;
sigaction(SIGINT, handler, NULL);
sigaction (SIGINT, handler, NULL);
}

int
Expand All @@ -135,7 +137,7 @@ main (int argc, char **argv)

unlink (argv[1]);

register_handler(&ctrl_c_handler);
register_handler (&ctrl_c_handler);

socket = open_unix_domain_socket (argv[1]);
while (1)
Expand All @@ -144,7 +146,7 @@ main (int argc, char **argv)
int stdin_flags, term_flags;
int data;

printf("Press 'Ctrl \\' to exit.\nWaiting for connection ...\n");
printf ("Press 'Ctrl \\' to exit.\nWaiting for connection ...\n");
do
conn = accept (socket, NULL, NULL);
while (conn < 0 && errno == EINTR);
Expand All @@ -158,7 +160,7 @@ main (int argc, char **argv)
continue;
}

if (tcgetattr(fd, &tset) == -1)
if (tcgetattr (fd, &tset) == -1)
error (0, errno, "failed to get console terminal settings");

tset.c_oflag |= ONLCR;
Expand All @@ -167,19 +169,19 @@ main (int argc, char **argv)
if (tcsetattr (fd, TCSANOW, &tset) == -1)
error (0, errno, "failed to set console terminal settings");

stdin_flags = fcntl(STDIN_FILENO, F_GETFL);
stdin_flags = fcntl (STDIN_FILENO, F_GETFL);
if (stdin_flags == -1)
error (EXIT_FAILURE, errno, "failed to obtain STDIN flags");

ret = fcntl(STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
ret = fcntl (STDIN_FILENO, F_SETFL, stdin_flags | O_NONBLOCK);
if (ret == -1)
error (EXIT_FAILURE, errno, "failed to set STDIN to non-blocking");

term_flags = fcntl(fd, F_GETFL);
term_flags = fcntl (fd, F_GETFL);
if (term_flags == -1)
error (EXIT_FAILURE, errno, "failed to obtain terminal flags");

ret = fcntl(fd, F_SETFL, term_flags | O_NONBLOCK);
ret = fcntl (fd, F_SETFL, term_flags | O_NONBLOCK);
if (ret == -1)
error (EXIT_FAILURE, errno, "failed to set terminal to non-blocking");

Expand All @@ -200,7 +202,7 @@ main (int argc, char **argv)
data = 1;
}

ret = read (STDIN_FILENO, buf, sizeof(buf));
ret = read (STDIN_FILENO, buf, sizeof (buf));
if (ret > 0)
{
ret = write (fd, buf, ret);
Expand All @@ -211,13 +213,14 @@ main (int argc, char **argv)
}
data = 1;
}
if (!data) usleep(10000);
if (! data)
usleep (10000);
}
close (conn);
ret = fcntl(STDIN_FILENO, F_SETFL, stdin_flags);
ret = fcntl (STDIN_FILENO, F_SETFL, stdin_flags);
if (ret == -1)
error (EXIT_FAILURE, errno, "failed to reset STDIN to original setting");
ret = fcntl(fd, F_SETFL, term_flags);
ret = fcntl (fd, F_SETFL, term_flags);
if (ret == -1)
error (EXIT_FAILURE, errno, "failed to reset terminal to original setting");
}
Expand Down