Skip to content

Commit c630cb6

Browse files
authored
Merge pull request #1863 from giuseppe/format-contrib-files
contrib: format contrib files
2 parents fa8f56e + 13d4770 commit c630cb6

File tree

4 files changed

+52
-45
lines changed

4 files changed

+52
-45
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ generate-mount_flags.c: src/libcrun/mount_flags.perf
330330

331331
clang-format:
332332
# do not format files that were copied into the source directory.
333-
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
333+
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
334334

335335
shellcheck:
336336
shellcheck autogen.sh build-aux/release.sh tests/run_all_tests.sh tests/*/*.sh contrib/*.sh

contrib/notify-socket-server/notify-socket-server.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
#include <termios.h>
3131
#include <stdio.h>
3232

33-
#define error(status, errno, fmt, ...) do{ \
34-
if (errno) \
35-
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
36-
else \
37-
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
38-
if (status) \
39-
exit (status); \
40-
} while(0)
33+
#define error(status, errno, fmt, ...) \
34+
do \
35+
{ \
36+
if (errno) \
37+
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
38+
else \
39+
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
40+
if (status) \
41+
exit (status); \
42+
} while (0)
4143

4244
static int
4345
open_unix_domain_socket (const char *path)
@@ -46,7 +48,7 @@ open_unix_domain_socket (const char *path)
4648
int ret, fd;
4749
const int one = 1;
4850

49-
fd = socket (AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
51+
fd = socket (AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
5052
if (fd < 0)
5153
error (EXIT_FAILURE, errno, "socket");
5254

@@ -97,7 +99,7 @@ main (int argc, char **argv)
9799
msg.msg_control = ctrl_buf;
98100
msg.msg_controllen = CTRL_SIZE;
99101

100-
ret = recvmsg (fd, &msg, MSG_CMSG_CLOEXEC|MSG_TRUNC);
102+
ret = recvmsg (fd, &msg, MSG_CMSG_CLOEXEC | MSG_TRUNC);
101103
if (ret < 0 && errno == EINTR)
102104
continue;
103105
if (ret < 0)

contrib/seccomp-receiver/seccomp-receiver.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
#include <termios.h>
3131
#include <stdio.h>
3232

33-
#define error(status, errno, fmt, ...) do { \
34-
if (errno) \
35-
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
36-
else \
37-
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
38-
if (status) \
39-
exit (status); \
40-
} while(0)
33+
#define error(status, errno, fmt, ...) \
34+
do \
35+
{ \
36+
if (errno) \
37+
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
38+
else \
39+
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
40+
if (status) \
41+
exit (status); \
42+
} while (0)
4143

4244
static int
4345
open_unix_domain_socket (const char *path)
@@ -47,10 +49,10 @@ open_unix_domain_socket (const char *path)
4749
int fd = socket (AF_UNIX, SOCK_STREAM, 0);
4850
if (fd < 0)
4951
error (EXIT_FAILURE, errno, "error creating UNIX socket");
50-
52+
5153
if (strlen (path) >= sizeof (addr.sun_path))
5254
error (EXIT_FAILURE, 0, "invalid path");
53-
55+
5456
strcpy (addr.sun_path, path);
5557
addr.sun_family = AF_UNIX;
5658
ret = bind (fd, (struct sockaddr *) &addr, sizeof (addr));

contrib/terminal-receiver/terminal-receiver.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,16 @@
3030
#include <signal.h>
3131
#include <stdio.h>
3232

33-
#define error(status, errno, fmt, ...) do { \
34-
if (!errno) \
35-
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
36-
else \
37-
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
38-
if (status) \
39-
exit (status); \
40-
} while(0)
33+
#define error(status, errno, fmt, ...) \
34+
do \
35+
{ \
36+
if (! errno) \
37+
fprintf (stderr, "crun: " fmt, ##__VA_ARGS__); \
38+
else \
39+
fprintf (stderr, "crun: %s:" fmt, strerror (errno), ##__VA_ARGS__); \
40+
if (status) \
41+
exit (status); \
42+
} while (0)
4143

4244
struct termios tset;
4345
int fd;
@@ -52,7 +54,7 @@ open_unix_domain_socket (const char *path)
5254
error (EXIT_FAILURE, errno, "error creating UNIX socket");
5355
if (strlen (path) >= sizeof (addr.sun_path))
5456
error (EXIT_FAILURE, 0, "invalid path");
55-
57+
5658
strcpy (addr.sun_path, path);
5759
addr.sun_family = AF_UNIX;
5860
ret = bind (fd, (struct sockaddr *) &addr, sizeof (addr));
@@ -112,16 +114,16 @@ void
112114
sigint_handler (int s)
113115
{
114116
const char ctrlc = 3;
115-
write(fd, &ctrlc, 1);
117+
write (fd, &ctrlc, 1);
116118
}
117119

118120
void
119-
register_handler (struct sigaction* handler)
121+
register_handler (struct sigaction *handler)
120122
{
121123
handler->sa_handler = sigint_handler;
122-
sigemptyset(&handler->sa_mask);
124+
sigemptyset (&handler->sa_mask);
123125
handler->sa_flags = 0;
124-
sigaction(SIGINT, handler, NULL);
126+
sigaction (SIGINT, handler, NULL);
125127
}
126128

127129
int
@@ -135,7 +137,7 @@ main (int argc, char **argv)
135137

136138
unlink (argv[1]);
137139

138-
register_handler(&ctrl_c_handler);
140+
register_handler (&ctrl_c_handler);
139141

140142
socket = open_unix_domain_socket (argv[1]);
141143
while (1)
@@ -144,7 +146,7 @@ main (int argc, char **argv)
144146
int stdin_flags, term_flags;
145147
int data;
146148

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

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

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

170-
stdin_flags = fcntl(STDIN_FILENO, F_GETFL);
172+
stdin_flags = fcntl (STDIN_FILENO, F_GETFL);
171173
if (stdin_flags == -1)
172174
error (EXIT_FAILURE, errno, "failed to obtain STDIN flags");
173175

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

178-
term_flags = fcntl(fd, F_GETFL);
180+
term_flags = fcntl (fd, F_GETFL);
179181
if (term_flags == -1)
180182
error (EXIT_FAILURE, errno, "failed to obtain terminal flags");
181183

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

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

203-
ret = read (STDIN_FILENO, buf, sizeof(buf));
205+
ret = read (STDIN_FILENO, buf, sizeof (buf));
204206
if (ret > 0)
205207
{
206208
ret = write (fd, buf, ret);
@@ -211,13 +213,14 @@ main (int argc, char **argv)
211213
}
212214
data = 1;
213215
}
214-
if (!data) usleep(10000);
216+
if (! data)
217+
usleep (10000);
215218
}
216219
close (conn);
217-
ret = fcntl(STDIN_FILENO, F_SETFL, stdin_flags);
220+
ret = fcntl (STDIN_FILENO, F_SETFL, stdin_flags);
218221
if (ret == -1)
219222
error (EXIT_FAILURE, errno, "failed to reset STDIN to original setting");
220-
ret = fcntl(fd, F_SETFL, term_flags);
223+
ret = fcntl (fd, F_SETFL, term_flags);
221224
if (ret == -1)
222225
error (EXIT_FAILURE, errno, "failed to reset terminal to original setting");
223226
}

0 commit comments

Comments
 (0)