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