Bump liberty
This commit is contained in:
parent
22e259a680
commit
dce2bb72a2
|
@ -110,15 +110,14 @@ app_context_init (struct app_context *self)
|
||||||
{
|
{
|
||||||
memset (self, 0, sizeof *self);
|
memset (self, 0, sizeof *self);
|
||||||
|
|
||||||
str_map_init (&self->config);
|
self->config = str_map_make (free);
|
||||||
self->config.free = free;
|
|
||||||
simple_config_load_defaults (&self->config, g_config_table);
|
simple_config_load_defaults (&self->config, g_config_table);
|
||||||
|
|
||||||
if (!(self->dpy = XOpenDisplay (NULL)))
|
if (!(self->dpy = XOpenDisplay (NULL)))
|
||||||
exit_fatal ("cannot open display");
|
exit_fatal ("cannot open display");
|
||||||
|
|
||||||
poller_init (&self->poller);
|
poller_init (&self->poller);
|
||||||
poller_fd_init (&self->x_event, &self->poller,
|
self->x_event = poller_fd_make (&self->poller,
|
||||||
ConnectionNumber (self->dpy));
|
ConnectionNumber (self->dpy));
|
||||||
|
|
||||||
self->net_active_window =
|
self->net_active_window =
|
||||||
|
@ -372,8 +371,8 @@ main (int argc, char *argv[])
|
||||||
{ 0, NULL, NULL, 0, NULL }
|
{ 0, NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opt_handler oh;
|
struct opt_handler oh =
|
||||||
opt_handler_init (&oh, argc, argv, opts, NULL, "Activity tracker.");
|
opt_handler_make (argc, argv, opts, NULL, "Activity tracker.");
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = opt_handler_get (&oh)) != -1)
|
while ((c = opt_handler_get (&oh)) != -1)
|
||||||
|
|
|
@ -121,8 +121,7 @@ read_value (int dir, const char *filename, struct error **e)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
|
|
||||||
long value;
|
long value;
|
||||||
if (!read_line (fp, &s)
|
if (!read_line (fp, &s)
|
||||||
|
@ -163,8 +162,7 @@ set_backlight (int dir, long diff, struct error **e)
|
||||||
"%s: %s: %s", "brightness", "openat", strerror (errno));
|
"%s: %s: %s", "brightness", "openat", strerror (errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
str_append_printf (&s, "%ld", req);
|
str_append_printf (&s, "%ld", req);
|
||||||
bool result = write (fd, s.str, s.len) == (ssize_t) s.len;
|
bool result = write (fd, s.str, s.len) == (ssize_t) s.len;
|
||||||
str_free (&s);
|
str_free (&s);
|
||||||
|
|
9
ddc-ci.c
9
ddc-ci.c
|
@ -125,8 +125,7 @@ static bool
|
||||||
ddc_send (int fd, unsigned command, void *args, size_t args_len,
|
ddc_send (int fd, unsigned command, void *args, size_t args_len,
|
||||||
struct error **e)
|
struct error **e)
|
||||||
{
|
{
|
||||||
struct str buf;
|
struct str buf = str_make ();
|
||||||
str_init (&buf);
|
|
||||||
str_pack_u8 (&buf, DDC_ADDRESS_HOST | I2C_READ);
|
str_pack_u8 (&buf, DDC_ADDRESS_HOST | I2C_READ);
|
||||||
str_pack_u8 (&buf, DDC_LENGTH_XOR | (args_len + 1));
|
str_pack_u8 (&buf, DDC_LENGTH_XOR | (args_len + 1));
|
||||||
str_pack_u8 (&buf, command);
|
str_pack_u8 (&buf, command);
|
||||||
|
@ -174,8 +173,7 @@ ddc_read (int fd, unsigned *command, void *out_buf, size_t *n_read,
|
||||||
if (ioctl (fd, I2C_RDWR, &data) < 0)
|
if (ioctl (fd, I2C_RDWR, &data) < 0)
|
||||||
return error_set (e, "%s: %s", "ioctl", strerror (errno));
|
return error_set (e, "%s: %s", "ioctl", strerror (errno));
|
||||||
|
|
||||||
struct msg_unpacker unpacker;
|
struct msg_unpacker unpacker = msg_unpacker_make (buf, sizeof buf);
|
||||||
msg_unpacker_init (&unpacker, buf, sizeof buf);
|
|
||||||
|
|
||||||
uint8_t sender, length, cmd;
|
uint8_t sender, length, cmd;
|
||||||
(void) msg_unpacker_u8 (&unpacker, &sender);
|
(void) msg_unpacker_u8 (&unpacker, &sender);
|
||||||
|
@ -222,8 +220,7 @@ vcp_get_feature (int fd, uint8_t feature, struct vcp_feature_readout *out,
|
||||||
if (command != DDC_GET_VCP_FEATURE_REPLY || len != 7)
|
if (command != DDC_GET_VCP_FEATURE_REPLY || len != 7)
|
||||||
return error_set (e, "invalid response");
|
return error_set (e, "invalid response");
|
||||||
|
|
||||||
struct msg_unpacker unpacker;
|
struct msg_unpacker unpacker = msg_unpacker_make (buf, len);
|
||||||
msg_unpacker_init (&unpacker, buf, len);
|
|
||||||
|
|
||||||
uint8_t result; msg_unpacker_u8 (&unpacker, &result);
|
uint8_t result; msg_unpacker_u8 (&unpacker, &result);
|
||||||
uint8_t vcp_opcode; msg_unpacker_u8 (&unpacker, &vcp_opcode);
|
uint8_t vcp_opcode; msg_unpacker_u8 (&unpacker, &vcp_opcode);
|
||||||
|
|
|
@ -64,8 +64,7 @@ log_message_custom (void *user_data, const char *quote, const char *fmt,
|
||||||
static char *
|
static char *
|
||||||
read_file_cstr (const char *path, struct error **e)
|
read_file_cstr (const char *path, struct error **e)
|
||||||
{
|
{
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
if (read_file (path, &s, e))
|
if (read_file (path, &s, e))
|
||||||
return str_steal (&s);
|
return str_steal (&s);
|
||||||
str_free (&s);
|
str_free (&s);
|
||||||
|
@ -100,11 +99,9 @@ write_file_printf (const char *path, struct error **e, const char *format, ...)
|
||||||
static bool
|
static bool
|
||||||
write_file_printf (const char *path, struct error **e, const char *format, ...)
|
write_file_printf (const char *path, struct error **e, const char *format, ...)
|
||||||
{
|
{
|
||||||
struct str s;
|
|
||||||
str_init (&s);
|
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, format);
|
va_start (ap, format);
|
||||||
|
struct str s = str_make ();
|
||||||
str_append_vprintf (&s, format, ap);
|
str_append_vprintf (&s, format, ap);
|
||||||
va_end (ap);
|
va_end (ap);
|
||||||
|
|
||||||
|
@ -334,8 +331,8 @@ struct pwm_iter
|
||||||
static void
|
static void
|
||||||
pwm_iter_init (struct pwm_iter *self, struct device *device)
|
pwm_iter_init (struct pwm_iter *self, struct device *device)
|
||||||
{
|
{
|
||||||
str_map_iter_init (&self->object_iter,
|
self->object_iter = str_map_iter_make
|
||||||
&config_item_get (device->config, "pwms", NULL)->value.object);
|
(&config_item_get (device->config, "pwms", NULL)->value.object);
|
||||||
self->device = device;
|
self->device = device;
|
||||||
self->paths = NULL;
|
self->paths = NULL;
|
||||||
}
|
}
|
||||||
|
@ -407,7 +404,7 @@ device_create (struct app_context *ctx, const char *path,
|
||||||
self->config = root;
|
self->config = root;
|
||||||
self->path = xstrdup (path);
|
self->path = xstrdup (path);
|
||||||
|
|
||||||
poller_timer_init (&self->timer, &ctx->poller);
|
self->timer = poller_timer_make (&ctx->poller);
|
||||||
self->timer.dispatcher = (poller_timer_fn) device_run;
|
self->timer.dispatcher = (poller_timer_fn) device_run;
|
||||||
self->timer.user_data = self;
|
self->timer.user_data = self;
|
||||||
|
|
||||||
|
@ -463,9 +460,7 @@ check_device_configuration (struct config_item *subtree, struct error **e)
|
||||||
return error_set (e, "no PWMs defined");
|
return error_set (e, "no PWMs defined");
|
||||||
|
|
||||||
// Check regular fields in all PWM subobjects
|
// Check regular fields in all PWM subobjects
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter = str_map_iter_make (&pwms->value.object);
|
||||||
str_map_iter_init (&iter, &pwms->value.object);
|
|
||||||
|
|
||||||
struct config_item *pwm;
|
struct config_item *pwm;
|
||||||
struct error *error = NULL;
|
struct error *error = NULL;
|
||||||
while ((pwm = str_map_iter_next (&iter)))
|
while ((pwm = str_map_iter_next (&iter)))
|
||||||
|
@ -500,8 +495,8 @@ load_configuration (struct app_context *ctx, const char *config_path)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter =
|
||||||
str_map_iter_init (&iter, &(ctx->config = root)->value.object);
|
str_map_iter_make (&(ctx->config = root)->value.object);
|
||||||
|
|
||||||
struct config_item *subtree;
|
struct config_item *subtree;
|
||||||
while ((subtree = str_map_iter_next (&iter)))
|
while ((subtree = str_map_iter_next (&iter)))
|
||||||
|
@ -580,8 +575,8 @@ parse_program_arguments (int argc, char **argv)
|
||||||
{ 0, NULL, NULL, 0, NULL }
|
{ 0, NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opt_handler oh;
|
struct opt_handler oh =
|
||||||
opt_handler_init (&oh, argc, argv, opts, "CONFIG", "Fan controller.");
|
opt_handler_make (argc, argv, opts, "CONFIG", "Fan controller.");
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = opt_handler_get (&oh)) != -1)
|
while ((c = opt_handler_get (&oh)) != -1)
|
||||||
|
@ -628,7 +623,7 @@ main (int argc, char *argv[])
|
||||||
setup_signal_handlers ();
|
setup_signal_handlers ();
|
||||||
|
|
||||||
struct poller_fd signal_event;
|
struct poller_fd signal_event;
|
||||||
poller_fd_init (&signal_event, &ctx.poller, g_signal_pipe[0]);
|
signal_event = poller_fd_make (&ctx.poller, g_signal_pipe[0]);
|
||||||
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
||||||
signal_event.user_data = &ctx;
|
signal_event.user_data = &ctx;
|
||||||
poller_fd_set (&signal_event, POLLIN);
|
poller_fd_set (&signal_event, POLLIN);
|
||||||
|
|
2
liberty
2
liberty
|
@ -1 +1 @@
|
||||||
Subproject commit 17322a368656f99ab25766161c717629da5b6eee
|
Subproject commit 6e9217e5d05d95849fbaa795f92eca4ad86b1507
|
19
priod.c
19
priod.c
|
@ -132,8 +132,7 @@ load_configuration (struct app_context *ctx, const char *config_path)
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter = str_map_iter_make (&root->value.object);
|
||||||
str_map_iter_init (&iter, &root->value.object);
|
|
||||||
ctx->rules = xcalloc (iter.map->len, sizeof *ctx->rules);
|
ctx->rules = xcalloc (iter.map->len, sizeof *ctx->rules);
|
||||||
ctx->rules_len = 0;
|
ctx->rules_len = 0;
|
||||||
|
|
||||||
|
@ -286,10 +285,8 @@ on_exec_name (struct app_context *ctx, int pid, const char *program_name)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str_map set;
|
|
||||||
str_map_init (&set);
|
|
||||||
|
|
||||||
// This has an inherent race condition, but let's give it a try
|
// This has an inherent race condition, but let's give it a try
|
||||||
|
struct str_map set = str_map_make (NULL);
|
||||||
for (size_t retries = 3; retries--; )
|
for (size_t retries = 3; retries--; )
|
||||||
if (reprioritize (pid, program_name, dir, rule, &set))
|
if (reprioritize (pid, program_name, dir, rule, &set))
|
||||||
break;
|
break;
|
||||||
|
@ -303,8 +300,7 @@ on_exec (struct app_context *ctx, int pid)
|
||||||
{
|
{
|
||||||
// This is inherently racy but there seems to be no better way to do it
|
// This is inherently racy but there seems to be no better way to do it
|
||||||
char *path = xstrdup_printf ("/proc/%d/cmdline", pid);
|
char *path = xstrdup_printf ("/proc/%d/cmdline", pid);
|
||||||
struct str cmdline;
|
struct str cmdline = str_make ();
|
||||||
str_init (&cmdline);
|
|
||||||
|
|
||||||
struct error *e = NULL;
|
struct error *e = NULL;
|
||||||
if (read_file (path, &cmdline, &e))
|
if (read_file (path, &cmdline, &e))
|
||||||
|
@ -408,8 +404,7 @@ parse_program_arguments (int argc, char **argv)
|
||||||
{ 0, NULL, NULL, 0, NULL }
|
{ 0, NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opt_handler oh;
|
struct opt_handler oh = opt_handler_make (argc, argv, opts, "CONFIG",
|
||||||
opt_handler_init (&oh, argc, argv, opts, "CONFIG",
|
|
||||||
"Process reprioritizing daemon.");
|
"Process reprioritizing daemon.");
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
@ -498,8 +493,8 @@ main (int argc, char *argv[])
|
||||||
|
|
||||||
setup_signal_handlers ();
|
setup_signal_handlers ();
|
||||||
|
|
||||||
struct poller_fd signal_event;
|
struct poller_fd signal_event =
|
||||||
poller_fd_init (&signal_event, &ctx.poller, g_signal_pipe[0]);
|
poller_fd_make (&ctx.poller, g_signal_pipe[0]);
|
||||||
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
||||||
signal_event.user_data = &ctx;
|
signal_event.user_data = &ctx;
|
||||||
poller_fd_set (&signal_event, POLLIN);
|
poller_fd_set (&signal_event, POLLIN);
|
||||||
|
@ -538,7 +533,7 @@ main (int argc, char *argv[])
|
||||||
if (write (ctx.proc_fd, &subscription, sizeof subscription) < 0)
|
if (write (ctx.proc_fd, &subscription, sizeof subscription) < 0)
|
||||||
exit_fatal ("failed to subscribe for events: %s", strerror (errno));
|
exit_fatal ("failed to subscribe for events: %s", strerror (errno));
|
||||||
|
|
||||||
poller_fd_init (&ctx.proc_event, &ctx.poller, ctx.proc_fd);
|
ctx.proc_event = poller_fd_make (&ctx.poller, ctx.proc_fd);
|
||||||
ctx.proc_event.dispatcher = (poller_fd_fn) on_event;
|
ctx.proc_event.dispatcher = (poller_fd_fn) on_event;
|
||||||
ctx.proc_event.user_data = &ctx;
|
ctx.proc_event.user_data = &ctx;
|
||||||
poller_fd_set (&ctx.proc_event, POLLIN);
|
poller_fd_set (&ctx.proc_event, POLLIN);
|
||||||
|
|
|
@ -33,8 +33,8 @@ parse_program_arguments (int argc, char **argv)
|
||||||
{ 0, NULL, NULL, 0, NULL }
|
{ 0, NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opt_handler oh;
|
struct opt_handler oh =
|
||||||
opt_handler_init (&oh, argc, argv, opts, "CONFIG", "PRNG.");
|
opt_handler_make (argc, argv, opts, "CONFIG", "PRNG.");
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
while ((c = opt_handler_get (&oh)) != -1)
|
while ((c = opt_handler_get (&oh)) != -1)
|
||||||
|
|
122
wmstatus.c
122
wmstatus.c
|
@ -180,10 +180,9 @@ poller_pa_io_new (pa_mainloop_api *api, int fd_, pa_io_event_flags_t events,
|
||||||
self->user_data = userdata;
|
self->user_data = userdata;
|
||||||
|
|
||||||
struct poller_pa *data = api->userdata;
|
struct poller_pa *data = api->userdata;
|
||||||
struct poller_fd *fd = &self->fd;
|
self->fd = poller_fd_make (data->poller, fd_);
|
||||||
poller_fd_init (fd, data->poller, fd_);
|
self->fd.user_data = self;
|
||||||
fd->user_data = self;
|
self->fd.dispatcher = poller_pa_io_dispatcher;
|
||||||
fd->dispatcher = poller_pa_io_dispatcher;
|
|
||||||
|
|
||||||
// FIXME: under x2go PA tries to register twice for the same FD,
|
// FIXME: under x2go PA tries to register twice for the same FD,
|
||||||
// which fails with our curent poller implementation;
|
// which fails with our curent poller implementation;
|
||||||
|
@ -249,10 +248,9 @@ poller_pa_time_new (pa_mainloop_api *api, const struct timeval *tv,
|
||||||
self->user_data = userdata;
|
self->user_data = userdata;
|
||||||
|
|
||||||
struct poller_pa *data = api->userdata;
|
struct poller_pa *data = api->userdata;
|
||||||
struct poller_timer *timer = &self->timer;
|
self->timer = poller_timer_make (data->poller);
|
||||||
poller_timer_init (timer, data->poller);
|
self->timer.user_data = self;
|
||||||
timer->user_data = self;
|
self->timer.dispatcher = poller_pa_time_dispatcher;
|
||||||
timer->dispatcher = poller_pa_time_dispatcher;
|
|
||||||
|
|
||||||
poller_pa_time_restart (self, tv);
|
poller_pa_time_restart (self, tv);
|
||||||
LIST_PREPEND (data->time_list, self);
|
LIST_PREPEND (data->time_list, self);
|
||||||
|
@ -296,12 +294,11 @@ poller_pa_defer_new (pa_mainloop_api *api,
|
||||||
self->user_data = userdata;
|
self->user_data = userdata;
|
||||||
|
|
||||||
struct poller_pa *data = api->userdata;
|
struct poller_pa *data = api->userdata;
|
||||||
struct poller_idle *idle = &self->idle;
|
self->idle = poller_idle_make (data->poller);
|
||||||
poller_idle_init (idle, data->poller);
|
self->idle.user_data = self;
|
||||||
idle->user_data = self;
|
self->idle.dispatcher = poller_pa_defer_dispatcher;
|
||||||
idle->dispatcher = poller_pa_defer_dispatcher;
|
|
||||||
|
|
||||||
poller_idle_set (idle);
|
poller_idle_set (&self->idle);
|
||||||
LIST_PREPEND (data->defer_list, self);
|
LIST_PREPEND (data->defer_list, self);
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
@ -441,8 +438,8 @@ static void
|
||||||
nut_parser_init (struct nut_parser *self)
|
nut_parser_init (struct nut_parser *self)
|
||||||
{
|
{
|
||||||
self->state = NUT_STATE_START_LINE;
|
self->state = NUT_STATE_START_LINE;
|
||||||
str_init (&self->current_field);
|
self->current_field = str_make ();
|
||||||
strv_init (&self->fields);
|
self->fields = strv_make ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -621,12 +618,12 @@ nut_client_init (struct nut_client *self, struct poller *poller)
|
||||||
self->poller = poller;
|
self->poller = poller;
|
||||||
self->socket = -1;
|
self->socket = -1;
|
||||||
|
|
||||||
str_init (&self->read_buffer);
|
self->read_buffer = str_make ();
|
||||||
str_init (&self->write_buffer);
|
self->write_buffer = str_make ();
|
||||||
|
|
||||||
nut_parser_init (&self->parser);
|
nut_parser_init (&self->parser);
|
||||||
|
|
||||||
poller_fd_init (&self->socket_event, poller, -1);
|
self->socket_event = poller_fd_make (poller, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -751,8 +748,7 @@ nut_client_dispatch (struct nut_client *self, struct nut_response *response)
|
||||||
static bool
|
static bool
|
||||||
nut_client_parse_line (struct nut_client *self)
|
nut_client_parse_line (struct nut_client *self)
|
||||||
{
|
{
|
||||||
struct str reconstructed;
|
struct str reconstructed = str_make ();
|
||||||
str_init (&reconstructed);
|
|
||||||
nut_client_serialize (self->parser.fields.vector, &reconstructed);
|
nut_client_serialize (self->parser.fields.vector, &reconstructed);
|
||||||
print_debug ("NUT >> %s", reconstructed.str);
|
print_debug ("NUT >> %s", reconstructed.str);
|
||||||
str_free (&reconstructed);
|
str_free (&reconstructed);
|
||||||
|
@ -772,7 +768,7 @@ nut_client_parse_line (struct nut_client *self)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct nut_line *line = xcalloc (1, sizeof *line);
|
struct nut_line *line = xcalloc (1, sizeof *line);
|
||||||
strv_init (&line->fields);
|
line->fields = strv_make ();
|
||||||
strv_append_vector (&line->fields, fields->vector);
|
strv_append_vector (&line->fields, fields->vector);
|
||||||
LIST_APPEND_WITH_TAIL (self->data, self->data_tail, line);
|
LIST_APPEND_WITH_TAIL (self->data, self->data_tail, line);
|
||||||
}
|
}
|
||||||
|
@ -861,8 +857,7 @@ static void nut_client_send_command
|
||||||
static void
|
static void
|
||||||
nut_client_send_commandv (struct nut_client *self, char **commands)
|
nut_client_send_commandv (struct nut_client *self, char **commands)
|
||||||
{
|
{
|
||||||
struct str line;
|
struct str line = str_make ();
|
||||||
str_init (&line);
|
|
||||||
nut_client_serialize (commands, &line);
|
nut_client_serialize (commands, &line);
|
||||||
|
|
||||||
print_debug ("NUT << %s", line.str);
|
print_debug ("NUT << %s", line.str);
|
||||||
|
@ -876,8 +871,7 @@ nut_client_send_commandv (struct nut_client *self, char **commands)
|
||||||
static void
|
static void
|
||||||
nut_client_send_command (struct nut_client *self, const char *command, ...)
|
nut_client_send_command (struct nut_client *self, const char *command, ...)
|
||||||
{
|
{
|
||||||
struct strv v;
|
struct strv v = strv_make ();
|
||||||
strv_init (&v);
|
|
||||||
|
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start (ap, command);
|
va_start (ap, command);
|
||||||
|
@ -898,7 +892,7 @@ nut_client_finish_connection (struct nut_client *self, int socket)
|
||||||
self->socket = socket;
|
self->socket = socket;
|
||||||
self->state = NUT_CONNECTED;
|
self->state = NUT_CONNECTED;
|
||||||
|
|
||||||
poller_fd_init (&self->socket_event, self->poller, self->socket);
|
self->socket_event = poller_fd_make (self->poller, self->socket);
|
||||||
self->socket_event.dispatcher = nut_client_on_ready;
|
self->socket_event.dispatcher = nut_client_on_ready;
|
||||||
self->socket_event.user_data = self;
|
self->socket_event.user_data = self;
|
||||||
|
|
||||||
|
@ -1026,7 +1020,7 @@ backend_dwm_new (Display *dpy)
|
||||||
self->super.flush = backend_dwm_flush;
|
self->super.flush = backend_dwm_flush;
|
||||||
|
|
||||||
self->dpy = dpy;
|
self->dpy = dpy;
|
||||||
strv_init (&self->items);
|
self->items = strv_make ();
|
||||||
return &self->super;
|
return &self->super;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1116,7 +1110,7 @@ backend_i3_new (void)
|
||||||
self->super.add = backend_i3_add;
|
self->super.add = backend_i3_add;
|
||||||
self->super.flush = backend_i3_flush;
|
self->super.flush = backend_i3_flush;
|
||||||
|
|
||||||
strv_init (&self->items);
|
self->items = strv_make ();
|
||||||
return &self->super;
|
return &self->super;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1253,8 +1247,7 @@ app_context_init (struct app_context *self)
|
||||||
{
|
{
|
||||||
memset (self, 0, sizeof *self);
|
memset (self, 0, sizeof *self);
|
||||||
|
|
||||||
str_map_init (&self->config);
|
self->config = str_map_make (free);
|
||||||
self->config.free = free;
|
|
||||||
simple_config_load_defaults (&self->config, g_config_table);
|
simple_config_load_defaults (&self->config, g_config_table);
|
||||||
|
|
||||||
if (!(self->dpy = XkbOpenDisplay
|
if (!(self->dpy = XkbOpenDisplay
|
||||||
|
@ -1264,15 +1257,15 @@ app_context_init (struct app_context *self)
|
||||||
poller_init (&self->poller);
|
poller_init (&self->poller);
|
||||||
self->api = poller_pa_new (&self->poller);
|
self->api = poller_pa_new (&self->poller);
|
||||||
|
|
||||||
strv_init (&self->command_current);
|
self->command_current = strv_make ();
|
||||||
self->command_pid = -1;
|
self->command_pid = -1;
|
||||||
self->command_fd = -1;
|
self->command_fd = -1;
|
||||||
poller_fd_init (&self->command_event, &self->poller, -1);
|
self->command_event = poller_fd_make (&self->poller, -1);
|
||||||
str_init (&self->command_buffer);
|
self->command_buffer = str_make ();
|
||||||
|
|
||||||
set_cloexec (ConnectionNumber (self->dpy));
|
set_cloexec (ConnectionNumber (self->dpy));
|
||||||
poller_fd_init (&self->x_event, &self->poller,
|
self->x_event =
|
||||||
ConnectionNumber (self->dpy));
|
poller_fd_make (&self->poller, ConnectionNumber (self->dpy));
|
||||||
|
|
||||||
app_context_init_xsync (self);
|
app_context_init_xsync (self);
|
||||||
|
|
||||||
|
@ -1286,13 +1279,12 @@ app_context_init (struct app_context *self)
|
||||||
dbus_error_free (&err);
|
dbus_error_free (&err);
|
||||||
}
|
}
|
||||||
|
|
||||||
mpd_client_init (&self->mpd_client, &self->poller);
|
self->mpd_client = mpd_client_make (&self->poller);
|
||||||
|
|
||||||
nut_client_init (&self->nut_client, &self->poller);
|
nut_client_init (&self->nut_client, &self->poller);
|
||||||
str_map_init (&self->nut_ups_info);
|
self->nut_ups_info = str_map_make (str_map_destroy);
|
||||||
self->nut_ups_info.free = str_map_destroy;
|
|
||||||
|
|
||||||
strv_init (&self->sink_ports);
|
self->sink_ports = strv_make ();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1355,8 +1347,7 @@ read_value (int dir, const char *filename, struct error **e)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
bool success = read_line (fp, &s);
|
bool success = read_line (fp, &s);
|
||||||
fclose (fp);
|
fclose (fp);
|
||||||
|
|
||||||
|
@ -1400,8 +1391,7 @@ read_battery_status (int dir, struct error **e)
|
||||||
error_propagate (e, error);
|
error_propagate (e, error);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
str_append (&s, status);
|
str_append (&s, status);
|
||||||
|
|
||||||
// Dell is being unreasonable and seems to set charge_now
|
// Dell is being unreasonable and seems to set charge_now
|
||||||
|
@ -1509,8 +1499,7 @@ make_volume_status (struct app_context *ctx)
|
||||||
if (!ctx->sink_volume.channels)
|
if (!ctx->sink_volume.channels)
|
||||||
return xstrdup ("");
|
return xstrdup ("");
|
||||||
|
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
if (ctx->sink_muted)
|
if (ctx->sink_muted)
|
||||||
str_append (&s, "Muted ");
|
str_append (&s, "Muted ");
|
||||||
|
|
||||||
|
@ -1750,7 +1739,7 @@ on_command_start (void *user_data)
|
||||||
ctx->command_pid = pid;
|
ctx->command_pid = pid;
|
||||||
str_reset (&ctx->command_buffer);
|
str_reset (&ctx->command_buffer);
|
||||||
|
|
||||||
poller_fd_init (&ctx->command_event, &ctx->poller,
|
ctx->command_event = poller_fd_make (&ctx->poller,
|
||||||
(ctx->command_fd = output_pipe[PIPE_READ]));
|
(ctx->command_fd = output_pipe[PIPE_READ]));
|
||||||
ctx->command_event.dispatcher = on_command_ready;
|
ctx->command_event.dispatcher = on_command_ready;
|
||||||
ctx->command_event.user_data = ctx;
|
ctx->command_event.user_data = ctx;
|
||||||
|
@ -1763,9 +1752,8 @@ on_command_start (void *user_data)
|
||||||
static void
|
static void
|
||||||
mpd_vector_to_map (const struct strv *data, struct str_map *map)
|
mpd_vector_to_map (const struct strv *data, struct str_map *map)
|
||||||
{
|
{
|
||||||
str_map_init (map);
|
*map = str_map_make (free);
|
||||||
map->key_xfrm = tolower_ascii_strxfrm;
|
map->key_xfrm = tolower_ascii_strxfrm;
|
||||||
map->free = free;
|
|
||||||
|
|
||||||
char *key, *value;
|
char *key, *value;
|
||||||
for (size_t i = 0; i < data->len; i++)
|
for (size_t i = 0; i < data->len; i++)
|
||||||
|
@ -1795,8 +1783,7 @@ mpd_on_info_response (const struct mpd_response *response,
|
||||||
free (ctx->mpd_status);
|
free (ctx->mpd_status);
|
||||||
ctx->mpd_status = NULL;
|
ctx->mpd_status = NULL;
|
||||||
|
|
||||||
struct str s;
|
struct str s = str_make ();
|
||||||
str_init (&s);
|
|
||||||
|
|
||||||
const char *value;
|
const char *value;
|
||||||
if ((value = str_map_find (&map, "state")))
|
if ((value = str_map_find (&map, "state")))
|
||||||
|
@ -1996,13 +1983,10 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
|
||||||
if (!soft_assert (xstrtoul (&runtime_sec, runtime, 10)))
|
if (!soft_assert (xstrtoul (&runtime_sec, runtime, 10)))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct strv items;
|
struct strv items = strv_make ();
|
||||||
strv_init (&items);
|
|
||||||
|
|
||||||
bool running_on_batteries = false;
|
bool running_on_batteries = false;
|
||||||
|
|
||||||
struct strv v;
|
struct strv v = strv_make ();
|
||||||
strv_init (&v);
|
|
||||||
cstr_split (status, " ", true, &v);
|
cstr_split (status, " ", true, &v);
|
||||||
for (size_t i = 0; i < v.len; i++)
|
for (size_t i = 0; i < v.len; i++)
|
||||||
{
|
{
|
||||||
|
@ -2027,8 +2011,7 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
|
||||||
&& xstrtoul (&threshold_n, threshold, 10)
|
&& xstrtoul (&threshold_n, threshold, 10)
|
||||||
&& load_n >= threshold_n)
|
&& load_n >= threshold_n)
|
||||||
{
|
{
|
||||||
struct str item;
|
struct str item = str_make ();
|
||||||
str_init (&item);
|
|
||||||
str_append_printf (&item, "load %s%%", load);
|
str_append_printf (&item, "load %s%%", load);
|
||||||
|
|
||||||
const char *power = str_map_find (dict, "ups.realpower.nominal");
|
const char *power = str_map_find (dict, "ups.realpower.nominal");
|
||||||
|
@ -2043,10 +2026,8 @@ nut_process_ups (struct app_context *ctx, struct strv *ups_list,
|
||||||
strv_append_owned (&items, str_steal (&item));
|
strv_append_owned (&items, str_steal (&item));
|
||||||
}
|
}
|
||||||
|
|
||||||
struct str result;
|
struct str result = str_make ();
|
||||||
str_init (&result);
|
|
||||||
str_append (&result, "UPS: ");
|
str_append (&result, "UPS: ");
|
||||||
|
|
||||||
for (size_t i = 0; i < items.len; i++)
|
for (size_t i = 0; i < items.len; i++)
|
||||||
{
|
{
|
||||||
if (i) str_append (&result, "; ");
|
if (i) str_append (&result, "; ");
|
||||||
|
@ -2063,11 +2044,9 @@ nut_on_logout_response (const struct nut_response *response, void *user_data)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
struct app_context *ctx = user_data;
|
struct app_context *ctx = user_data;
|
||||||
struct strv ups_list;
|
struct strv ups_list = strv_make ();
|
||||||
strv_init (&ups_list);
|
|
||||||
|
|
||||||
struct str_map_iter iter;
|
struct str_map_iter iter = str_map_iter_make (&ctx->nut_ups_info);
|
||||||
str_map_iter_init (&iter, &ctx->nut_ups_info);
|
|
||||||
struct str_map *dict;
|
struct str_map *dict;
|
||||||
while ((dict = str_map_iter_next (&iter)))
|
while ((dict = str_map_iter_next (&iter)))
|
||||||
nut_process_ups (ctx, &ups_list, iter.link->key, dict);
|
nut_process_ups (ctx, &ups_list, iter.link->key, dict);
|
||||||
|
@ -2077,8 +2056,7 @@ nut_on_logout_response (const struct nut_response *response, void *user_data)
|
||||||
|
|
||||||
if (ups_list.len)
|
if (ups_list.len)
|
||||||
{
|
{
|
||||||
struct str status;
|
struct str status = str_make ();
|
||||||
str_init (&status);
|
|
||||||
str_append (&status, ups_list.vector[0]);
|
str_append (&status, ups_list.vector[0]);
|
||||||
for (size_t i = 1; i < ups_list.len; i++)
|
for (size_t i = 1; i < ups_list.len; i++)
|
||||||
str_append_printf (&status, " %s", ups_list.vector[0]);
|
str_append_printf (&status, " %s", ups_list.vector[0]);
|
||||||
|
@ -2097,8 +2075,8 @@ nut_store_var (struct app_context *ctx,
|
||||||
struct str_map *map;
|
struct str_map *map;
|
||||||
if (!(map = str_map_find (&ctx->nut_ups_info, ups_name)))
|
if (!(map = str_map_find (&ctx->nut_ups_info, ups_name)))
|
||||||
{
|
{
|
||||||
str_map_init ((map = xcalloc (1, sizeof *map)));
|
map = xmalloc (sizeof *map);
|
||||||
map->free = free;
|
*map = str_map_make (free);
|
||||||
str_map_set (&ctx->nut_ups_info, ups_name, map);
|
str_map_set (&ctx->nut_ups_info, ups_name, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2777,7 +2755,7 @@ setup_signal_handlers (struct app_context *ctx)
|
||||||
if (sigaction (SIGCHLD, &sa, NULL) == -1)
|
if (sigaction (SIGCHLD, &sa, NULL) == -1)
|
||||||
print_error ("%s: %s", "sigaction", strerror (errno));
|
print_error ("%s: %s", "sigaction", strerror (errno));
|
||||||
|
|
||||||
poller_fd_init (&g_signal_event, &ctx->poller, g_signal_pipe[PIPE_READ]);
|
g_signal_event = poller_fd_make (&ctx->poller, g_signal_pipe[PIPE_READ]);
|
||||||
g_signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
g_signal_event.dispatcher = (poller_fd_fn) on_signal_pipe_readable;
|
||||||
g_signal_event.user_data = ctx;
|
g_signal_event.user_data = ctx;
|
||||||
poller_fd_set (&g_signal_event, POLLIN);
|
poller_fd_set (&g_signal_event, POLLIN);
|
||||||
|
@ -2787,7 +2765,7 @@ static void
|
||||||
poller_timer_init_and_set (struct poller_timer *self, struct poller *poller,
|
poller_timer_init_and_set (struct poller_timer *self, struct poller *poller,
|
||||||
poller_timer_fn cb, void *user_data)
|
poller_timer_fn cb, void *user_data)
|
||||||
{
|
{
|
||||||
poller_timer_init (self, poller);
|
*self = poller_timer_make (poller);
|
||||||
self->dispatcher = cb;
|
self->dispatcher = cb;
|
||||||
self->user_data = user_data;
|
self->user_data = user_data;
|
||||||
|
|
||||||
|
@ -2811,8 +2789,8 @@ main (int argc, char *argv[])
|
||||||
{ 0, NULL, NULL, 0, NULL }
|
{ 0, NULL, NULL, 0, NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct opt_handler oh;
|
struct opt_handler oh =
|
||||||
opt_handler_init (&oh, argc, argv, opts, NULL, "Set root window name.");
|
opt_handler_make (argc, argv, opts, NULL, "Set root window name.");
|
||||||
bool i3bar = false;
|
bool i3bar = false;
|
||||||
|
|
||||||
int c;
|
int c;
|
||||||
|
|
Loading…
Reference in New Issue