summaryrefslogtreecommitdiff
path: root/swaynag/swaynag.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaynag/swaynag.c')
-rw-r--r--swaynag/swaynag.c27
1 files changed, 11 insertions, 16 deletions
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index 5620155d..9b57d578 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -28,13 +28,8 @@ static bool terminal_execute(char *terminal, char *command) {
fprintf(tmp, "#!/bin/sh\nrm %s\n%s", fname, command);
fclose(tmp);
chmod(fname, S_IRUSR | S_IWUSR | S_IXUSR);
- size_t cmd_size = strlen(terminal) + strlen(" -e ") + strlen(fname) + 1;
- char *cmd = malloc(cmd_size);
- if (!cmd) {
- perror("malloc");
- return false;
- }
- snprintf(cmd, cmd_size, "%s -e %s", terminal, fname);
+ char *cmd = malloc(sizeof(char) * (strlen(terminal) + strlen(" -e ") + strlen(fname) + 1));
+ sprintf(cmd, "%s -e %s", terminal, fname);
execlp("sh", "sh", "-c", cmd, NULL);
sway_log_errno(SWAY_ERROR, "Failed to run command, execlp() returned.");
free(cmd);
@@ -63,7 +58,7 @@ static void swaynag_button_execute(struct swaynag *swaynag,
} else if (pid == 0) {
// Child of the child. Will be reparented to the init process
char *terminal = getenv("TERMINAL");
- if (button->terminal && terminal && *terminal) {
+ if (button->terminal && terminal && strlen(terminal)) {
sway_log(SWAY_DEBUG, "Found $TERMINAL: %s", terminal);
if (!terminal_execute(terminal, button->action)) {
swaynag_destroy(swaynag);
@@ -143,7 +138,7 @@ static void update_cursor(struct swaynag_seat *seat) {
const char *cursor_theme = getenv("XCURSOR_THEME");
unsigned cursor_size = 24;
const char *env_cursor_size = getenv("XCURSOR_SIZE");
- if (env_cursor_size && *env_cursor_size) {
+ if (env_cursor_size && strlen(env_cursor_size) > 0) {
errno = 0;
char *end;
unsigned size = strtoul(env_cursor_size, &end, 10);
@@ -344,7 +339,6 @@ static void handle_global(void *data, struct wl_registry *registry,
struct swaynag_seat *seat =
calloc(1, sizeof(struct swaynag_seat));
if (!seat) {
- perror("calloc");
return;
}
@@ -362,10 +356,6 @@ static void handle_global(void *data, struct wl_registry *registry,
if (!swaynag->output) {
struct swaynag_output *output =
calloc(1, sizeof(struct swaynag_output));
- if (!output) {
- perror("calloc");
- return;
- }
output->wl_output = wl_registry_bind(registry, name,
&wl_output_interface, 4);
output->wl_name = name;
@@ -521,8 +511,13 @@ void swaynag_destroy(struct swaynag *swaynag) {
swaynag_seat_destroy(seat);
}
- destroy_buffer(&swaynag->buffers[0]);
- destroy_buffer(&swaynag->buffers[1]);
+ if (&swaynag->buffers[0]) {
+ destroy_buffer(&swaynag->buffers[0]);
+ }
+
+ if (&swaynag->buffers[1]) {
+ destroy_buffer(&swaynag->buffers[1]);
+ }
if (swaynag->outputs.prev || swaynag->outputs.next) {
struct swaynag_output *output, *temp;