aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/log.c20
-rw-r--r--common/readline.c27
-rw-r--r--include/readline.h1
-rw-r--r--swaylock/main.c28
4 files changed, 64 insertions, 12 deletions
diff --git a/common/log.c b/common/log.c
index f9242bf4..0c0ecf89 100644
--- a/common/log.c
+++ b/common/log.c
@@ -1,5 +1,6 @@
1#include "log.h" 1#include "log.h"
2#include "sway.h" 2#include "sway.h"
3#include "readline.h"
3#include <stdarg.h> 4#include <stdarg.h>
4#include <stdio.h> 5#include <stdio.h>
5#include <stdlib.h> 6#include <stdlib.h>
@@ -142,6 +143,9 @@ void error_handler(int sig) {
142 void *array[max_lines]; 143 void *array[max_lines];
143 char **bt; 144 char **bt;
144 size_t bt_len; 145 size_t bt_len;
146 char maps_file[256];
147 char maps_buffer[1024];
148 FILE *maps;
145 149
146 sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig); 150 sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig);
147 bt_len = backtrace(array, max_lines); 151 bt_len = backtrace(array, max_lines);
@@ -155,6 +159,22 @@ void error_handler(int sig) {
155 for (i = 0; (size_t)i < bt_len; i++) { 159 for (i = 0; (size_t)i < bt_len; i++) {
156 sway_log(L_ERROR, "Backtrace: %s", bt[i]); 160 sway_log(L_ERROR, "Backtrace: %s", bt[i]);
157 } 161 }
162
163 sway_log(L_ERROR, "Maps:");
164 pid_t pid = getpid();
165 if (snprintf(maps_file, 255, "/proc/%zd/maps", (size_t)pid) < 255) {
166 maps = fopen(maps_file, "r");
167 while (!feof(maps)) {
168 char *m = read_line_buffer(maps, maps_buffer, 1024);
169 if (!m) {
170 fclose(maps);
171 sway_log(L_ERROR, "Unable to allocate memory to show maps");
172 break;
173 }
174 sway_log(L_ERROR, m);
175 }
176 fclose(maps);
177 }
158#else 178#else
159 sway_log(L_ERROR, "Error: Signal %d.", sig); 179 sway_log(L_ERROR, "Error: Signal %d.", sig);
160#endif 180#endif
diff --git a/common/readline.c b/common/readline.c
index e75b183f..76ed6926 100644
--- a/common/readline.c
+++ b/common/readline.c
@@ -3,7 +3,7 @@
3#include <stdio.h> 3#include <stdio.h>
4 4
5char *read_line(FILE *file) { 5char *read_line(FILE *file) {
6 int length = 0, size = 128; 6 size_t length = 0, size = 128;
7 char *string = malloc(size); 7 char *string = malloc(size);
8 if (!string) { 8 if (!string) {
9 return NULL; 9 return NULL;
@@ -37,3 +37,28 @@ char *read_line(FILE *file) {
37 string[length] = '\0'; 37 string[length] = '\0';
38 return string; 38 return string;
39} 39}
40
41char *read_line_buffer(FILE *file, char *string, size_t string_len) {
42 size_t length = 0;
43 if (!string) {
44 return NULL;
45 }
46 while (1) {
47 int c = getc(file);
48 if (c == EOF || c == '\n' || c == '\0') {
49 break;
50 }
51 if (c == '\r') {
52 continue;
53 }
54 string[length++] = c;
55 if (string_len <= length) {
56 return NULL;
57 }
58 }
59 if (length + 1 == string_len) {
60 return NULL;
61 }
62 string[length] = '\0';
63 return string;
64}
diff --git a/include/readline.h b/include/readline.h
index dbe937c1..b3e06d4b 100644
--- a/include/readline.h
+++ b/include/readline.h
@@ -4,5 +4,6 @@
4#include <stdio.h> 4#include <stdio.h>
5 5
6char *read_line(FILE *file); 6char *read_line(FILE *file);
7char *read_line_buffer(FILE *file, char *string, size_t string_len);
7 8
8#endif 9#endif
diff --git a/swaylock/main.c b/swaylock/main.c
index 020ff036..9b14086d 100644
--- a/swaylock/main.c
+++ b/swaylock/main.c
@@ -211,12 +211,12 @@ int main(int argc, char **argv) {
211 const char *usage = 211 const char *usage =
212 "Usage: swaylock [options...]\n" 212 "Usage: swaylock [options...]\n"
213 "\n" 213 "\n"
214 " -h, --help Show help message and quit.\n" 214 " -h, --help Show help message and quit.\n"
215 " -c, --color <rrggbb> Turn the screen into the given color instead of white.\n" 215 " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n"
216 " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n" 216 " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
217 " -t, --tiling Same as --scaling=tile.\n" 217 " -t, --tiling Same as --scaling=tile.\n"
218 " -v, --version Show the version number and quit.\n" 218 " -v, --version Show the version number and quit.\n"
219 " -i, --image <path> Display the given image.\n"; 219 " -i, --image <path> Display the given image.\n";
220 220
221 int c; 221 int c;
222 while (1) { 222 while (1) {
@@ -226,16 +226,22 @@ int main(int argc, char **argv) {
226 break; 226 break;
227 } 227 }
228 switch (c) { 228 switch (c) {
229 case 'c': 229 case 'c':
230 if (strlen(optarg) < 6) { 230 {
231 fprintf(stderr, "color must be specified in 3 byte format, e.g. ff0000\n"); 231 int colorlen = strlen(optarg);
232 if (colorlen < 6 || colorlen == 7 || colorlen > 8) {
233 fprintf(stderr, "color must be specified in 3 or 4 byte format, e.g. ff0000 or ff0000ff\n");
232 exit(EXIT_FAILURE); 234 exit(EXIT_FAILURE);
233 } 235 }
234 color = strtol(optarg, NULL, 16); 236 color = strtol(optarg, NULL, 16);
235 color <<= 8; 237
236 color |= 0xFF; 238 if (colorlen == 6) {
239 color <<= 8;
240 color |= 0xFF;
241 }
237 sway_log(L_DEBUG, "color: 0x%x", color); 242 sway_log(L_DEBUG, "color: 0x%x", color);
238 break; 243 break;
244 }
239 case 'i': 245 case 'i':
240 image_path = optarg; 246 image_path = optarg;
241 break; 247 break;