aboutsummaryrefslogtreecommitdiffstats
path: root/sway/swaynag.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/swaynag.c')
-rw-r--r--sway/swaynag.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/sway/swaynag.c b/sway/swaynag.c
index db5a919a..bc5e23ea 100644
--- a/sway/swaynag.c
+++ b/sway/swaynag.c
@@ -1,4 +1,3 @@
1#define _POSIX_C_SOURCE 200809L
2#include <signal.h> 1#include <signal.h>
3#include <stdbool.h> 2#include <stdbool.h>
4#include <stdlib.h> 3#include <stdlib.h>
@@ -64,6 +63,8 @@ bool swaynag_spawn(const char *swaynag_command,
64 sway_log(SWAY_ERROR, "Failed to create fork for swaynag"); 63 sway_log(SWAY_ERROR, "Failed to create fork for swaynag");
65 goto failed; 64 goto failed;
66 } else if (pid == 0) { 65 } else if (pid == 0) {
66 restore_nofile_limit();
67
67 pid = fork(); 68 pid = fork();
68 if (pid < 0) { 69 if (pid < 0) {
69 sway_log_errno(SWAY_ERROR, "fork failed"); 70 sway_log_errno(SWAY_ERROR, "fork failed");
@@ -87,8 +88,8 @@ bool swaynag_spawn(const char *swaynag_command,
87 size_t length = strlen(swaynag_command) + strlen(swaynag->args) + 2; 88 size_t length = strlen(swaynag_command) + strlen(swaynag->args) + 2;
88 char *cmd = malloc(length); 89 char *cmd = malloc(length);
89 snprintf(cmd, length, "%s %s", swaynag_command, swaynag->args); 90 snprintf(cmd, length, "%s %s", swaynag_command, swaynag->args);
90 execl("/bin/sh", "/bin/sh", "-c", cmd, NULL); 91 execlp("sh", "sh", "-c", cmd, NULL);
91 sway_log_errno(SWAY_ERROR, "execl failed"); 92 sway_log_errno(SWAY_ERROR, "execlp failed");
92 _exit(EXIT_FAILURE); 93 _exit(EXIT_FAILURE);
93 } 94 }
94 _exit(EXIT_SUCCESS); 95 _exit(EXIT_SUCCESS);
@@ -143,22 +144,16 @@ void swaynag_log(const char *swaynag_command, struct swaynag_instance *swaynag,
143 144
144 va_list args; 145 va_list args;
145 va_start(args, fmt); 146 va_start(args, fmt);
146 size_t length = vsnprintf(NULL, 0, fmt, args) + 1; 147 char *str = vformat_str(fmt, args);
147 va_end(args); 148 va_end(args);
148 149 if (!str) {
149 char *temp = malloc(length + 1);
150 if (!temp) {
151 sway_log(SWAY_ERROR, "Failed to allocate buffer for swaynag log entry."); 150 sway_log(SWAY_ERROR, "Failed to allocate buffer for swaynag log entry.");
152 return; 151 return;
153 } 152 }
154 153
155 va_start(args, fmt); 154 write(swaynag->fd[1], str, strlen(str));
156 vsnprintf(temp, length, fmt, args);
157 va_end(args);
158
159 write(swaynag->fd[1], temp, length);
160 155
161 free(temp); 156 free(str);
162} 157}
163 158
164void swaynag_show(struct swaynag_instance *swaynag) { 159void swaynag_show(struct swaynag_instance *swaynag) {