-
Notifications
You must be signed in to change notification settings - Fork 28
NetBSD support #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
NetBSD support #36
Changes from all commits
568754d
3d61a5a
6c24e99
5c5afcc
fe4443e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,8 +27,9 @@ | |
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <poll.h> | ||
| #include <sys/signalfd.h> | ||
| #include <time.h> | ||
| #include <fcntl.h> | ||
| #include <unistd.h> | ||
| #include <wayland-client.h> | ||
| #include <wld/wayland.h> | ||
| #include <wld/wld.h> | ||
|
|
@@ -172,6 +173,7 @@ static bool running, need_draw; | |
| static char clock_text[32]; | ||
| static struct item_data divider_data = {.width = 14 }; | ||
| static struct text_item_data clock_data = {.text = clock_text }; | ||
| static int pfd[2]; | ||
|
|
||
| static void __attribute__((noreturn)) die(const char *const format, ...) | ||
| { | ||
|
|
@@ -504,32 +506,74 @@ setup(void) | |
| wl_display_flush(display); | ||
| } | ||
|
|
||
| static void | ||
| sigalrm_handler(int sig) | ||
| { | ||
| int p_errno = errno; /* Preserve errno */ | ||
| int ret; | ||
|
|
||
| if ((ret = write(pfd[1], ".", 1)) != 1) | ||
| die("self-pipe write failed\n"); | ||
| errno = p_errno; | ||
| } | ||
|
|
||
| static int | ||
| set_nonblock(int fd) | ||
| { | ||
| int flags; | ||
|
|
||
| if ((flags = fcntl(fd, F_GETFL)) == -1) { | ||
| return -1; | ||
| } | ||
|
|
||
| if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) { | ||
| return -1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
| static void | ||
| run(void) | ||
| { | ||
| sigset_t signals; | ||
| struct itimerspec timer_value = { | ||
| .it_interval = { 1, 0 }, | ||
| .it_value = { 0, 1 } | ||
| }; | ||
| struct pollfd fds[2]; | ||
| struct screen *screen; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of using a separate event loop for kqueue, I think we should just avoid
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've updated this to use the self-pipe trick but I'm not seeing the signal being fired more than once. Not sure what I'm doing wrong.
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's working for me on Linux, so I'm not really sure. If you're not getting the signal, it sounds like it has something to do with the timer. Unfortunately, I don't have any ideas about what might be wrong. |
||
| struct sigaction sa = {0}; | ||
|
|
||
| if (pipe(pfd) == -1) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does NetBSD have It is accepted for the next version of POSIX: |
||
| die("creating pipe failed: %s\n", strerror(errno)); | ||
|
|
||
| if (set_nonblock(pfd[0]) == -1) | ||
| die("could not set O_NONBLOCK on pipe fd: %s\n", strerror(errno)); | ||
|
|
||
| if (set_nonblock(pfd[1]) == -1) | ||
| die("could not set O_NONBLOCK on pipe fd\n", strerror(errno)); | ||
|
|
||
| sa.sa_flags = SA_RESTART; | ||
| sa.sa_handler = sigalrm_handler; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd just move these to the initializer. |
||
|
|
||
| sigemptyset(&signals); | ||
| sigaddset(&signals, SIGALRM); | ||
| sigprocmask(SIG_BLOCK, &signals, NULL); | ||
| if (sigaction(SIGALRM, &sa, NULL) == -1) | ||
| die("sigaction failed\n", strerror(errno)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error format string is missing a Let's just use |
||
|
|
||
| fds[0].fd = wl_display_get_fd(display); | ||
| fds[0].events = POLLIN; | ||
| fds[1].fd = signalfd(-1, &signals, SFD_CLOEXEC); | ||
| fds[1].fd = pfd[0]; | ||
| fds[1].events = POLLIN; | ||
|
|
||
| timer_settime(timer, 0, &timer_value, NULL); | ||
| running = true; | ||
|
|
||
| while (true) { | ||
| if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) == -1) | ||
| break; | ||
| if (poll(fds, 2, -1) == -1) { | ||
| if (errno != EINTR) { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's leave Also, I'd combine these two if-statements: if (poll(fds, sizeof(fds) / sizeof(fds[0]), -1) == -1 && errno != EINTR) {
perror("poll");
break;
} |
||
| perror("poll"); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (fds[0].revents & POLLIN) { | ||
| if (wl_display_dispatch(display) == -1) { | ||
|
|
@@ -539,11 +583,14 @@ run(void) | |
| } | ||
| } | ||
| if (fds[1].revents & POLLIN) { | ||
| time_t raw_time = time(NULL); | ||
| struct tm *local_time = localtime(&raw_time); | ||
|
|
||
| sigwaitinfo(&signals, NULL); | ||
|
|
||
| uint8_t discard; | ||
| time_t raw_time; | ||
| struct tm *local_time; | ||
| int nbytes; | ||
|
|
||
| while ((nbytes = read(pfd[0], &discard, 1)) > 0); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No reason to save the return value Also, let's move the semicolon to its own line to make it clear that the loop has an empty body. |
||
| raw_time = time(NULL); | ||
| local_time = localtime(&raw_time); | ||
| strftime(clock_text, sizeof(clock_text), "%A %T %F", local_time); | ||
| update_text_item_data(&clock_data); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAVE_KQUEUEshould not longer be needed with the self-pipe, right?