Get rid of all global variables

This commit is contained in:
Utkarsh Verma
2023-10-25 20:00:08 +05:30
parent bc84d094cd
commit 10f7d9b8db
13 changed files with 121 additions and 69 deletions

View File

@@ -5,9 +5,19 @@
#include <stdio.h>
#include <sys/poll.h>
#include "main.h"
#include "block.h"
#include "util.h"
watcher watcher_new(const block* const blocks,
const unsigned short block_count) {
watcher watcher = {
.blocks = blocks,
.block_count = block_count,
};
return watcher;
}
int watcher_init(watcher* const watcher, const int signal_fd) {
if (signal_fd == -1) {
fprintf(stderr,
@@ -19,8 +29,8 @@ int watcher_init(watcher* const watcher, const int signal_fd) {
fd->fd = signal_fd;
fd->events = POLLIN;
for (unsigned short i = 0; i < LEN(blocks); ++i) {
const int block_fd = blocks[i].pipe[READ_END];
for (unsigned short i = 0; i < watcher->block_count; ++i) {
const int block_fd = watcher->blocks[i].pipe[READ_END];
if (block_fd == -1) {
fprintf(
stderr,