aboutsummaryrefslogtreecommitdiff
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 @@
#include "log.h"
#include "sway.h"
+#include "readline.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
@@ -142,6 +143,9 @@ void error_handler(int sig) {
void *array[max_lines];
char **bt;
size_t bt_len;
+ char maps_file[256];
+ char maps_buffer[1024];
+ FILE *maps;
sway_log(L_ERROR, "Error: Signal %d. Printing backtrace", sig);
bt_len = backtrace(array, max_lines);
@@ -155,6 +159,22 @@ void error_handler(int sig) {
for (i = 0; (size_t)i < bt_len; i++) {
sway_log(L_ERROR, "Backtrace: %s", bt[i]);
}
+
+ sway_log(L_ERROR, "Maps:");
+ pid_t pid = getpid();
+ if (snprintf(maps_file, 255, "/proc/%zd/maps", (size_t)pid) < 255) {
+ maps = fopen(maps_file, "r");
+ while (!feof(maps)) {
+ char *m = read_line_buffer(maps, maps_buffer, 1024);
+ if (!m) {
+ fclose(maps);
+ sway_log(L_ERROR, "Unable to allocate memory to show maps");
+ break;
+ }
+ sway_log(L_ERROR, m);
+ }
+ fclose(maps);
+ }
#else
sway_log(L_ERROR, "Error: Signal %d.", sig);
#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 @@
#include <stdio.h>
char *read_line(FILE *file) {
- int length = 0, size = 128;
+ size_t length = 0, size = 128;
char *string = malloc(size);
if (!string) {
return NULL;
@@ -37,3 +37,28 @@ char *read_line(FILE *file) {
string[length] = '\0';
return string;
}
+
+char *read_line_buffer(FILE *file, char *string, size_t string_len) {
+ size_t length = 0;
+ if (!string) {
+ return NULL;
+ }
+ while (1) {
+ int c = getc(file);
+ if (c == EOF || c == '\n' || c == '\0') {
+ break;
+ }
+ if (c == '\r') {
+ continue;
+ }
+ string[length++] = c;
+ if (string_len <= length) {
+ return NULL;
+ }
+ }
+ if (length + 1 == string_len) {
+ return NULL;
+ }
+ string[length] = '\0';
+ return string;
+}
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 @@
#include <stdio.h>
char *read_line(FILE *file);
+char *read_line_buffer(FILE *file, char *string, size_t string_len);
#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) {
const char *usage =
"Usage: swaylock [options...]\n"
"\n"
- " -h, --help Show help message and quit.\n"
- " -c, --color <rrggbb> Turn the screen into the given color instead of white.\n"
- " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
- " -t, --tiling Same as --scaling=tile.\n"
- " -v, --version Show the version number and quit.\n"
- " -i, --image <path> Display the given image.\n";
+ " -h, --help Show help message and quit.\n"
+ " -c, --color <rrggbb[aa]> Turn the screen into the given color instead of white.\n"
+ " -s, --scaling Scaling mode: stretch, fill, fit, center, tile.\n"
+ " -t, --tiling Same as --scaling=tile.\n"
+ " -v, --version Show the version number and quit.\n"
+ " -i, --image <path> Display the given image.\n";
int c;
while (1) {
@@ -226,16 +226,22 @@ int main(int argc, char **argv) {
break;
}
switch (c) {
- case 'c':
- if (strlen(optarg) < 6) {
- fprintf(stderr, "color must be specified in 3 byte format, e.g. ff0000\n");
+ case 'c':
+ {
+ int colorlen = strlen(optarg);
+ if (colorlen < 6 || colorlen == 7 || colorlen > 8) {
+ fprintf(stderr, "color must be specified in 3 or 4 byte format, e.g. ff0000 or ff0000ff\n");
exit(EXIT_FAILURE);
}
color = strtol(optarg, NULL, 16);
- color <<= 8;
- color |= 0xFF;
+
+ if (colorlen == 6) {
+ color <<= 8;
+ color |= 0xFF;
+ }
sway_log(L_DEBUG, "color: 0x%x", color);
break;
+ }
case 'i':
image_path = optarg;
break;