aboutsummaryrefslogtreecommitdiff
path: root/client.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-02-05 18:54:16 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-02-05 18:54:16 +0000
commit82b8853f17b943901776eddcb857089384a61dda (patch)
treed9eb3ac6ef72ee3a7b69c7fa0f3d16e6f6f4d921 /client.c
parentmain: add --print-pid=FILE|FD (diff)
main: add --print-pid=FILE|FD
When specified, our PID is written to the specified file (or FD), after we've successfully started up.
Diffstat (limited to 'client.c')
-rw-r--r--client.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/client.c b/client.c
index bbb8ea8c..33af8e87 100644
--- a/client.c
+++ b/client.c
@@ -32,15 +32,15 @@ print_usage(const char *prog_name)
printf("Usage: %s [OPTIONS]... -- command\n", prog_name);
printf("\n");
printf("Options:\n");
- printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
- " -s,--server-socket=PATH path to the server UNIX domain socket (default=XDG_RUNTIME_DIR/foot.sock)\n"
- " -v,--version show the version number and quit\n");
+ printf(" -t,--term=TERM value to set the environment variable TERM to (foot)\n"
+ " -s,--server-socket=PATH path to the server UNIX domain socket (default=XDG_RUNTIME_DIR/foot.sock)\n"
+ " -l,--log-colorize=[never|always|auto] enable/disable colorization of log output on stderr\n"
+ " -v,--version show the version number and quit\n");
}
int
main(int argc, char *const *argv)
{
- log_init(LOG_FACILITY_USER, LOG_CLASS_WARNING);
int ret = EXIT_FAILURE;
const char *const prog_name = argv[0];
@@ -48,6 +48,7 @@ main(int argc, char *const *argv)
static const struct option longopts[] = {
{"term", required_argument, 0, 't'},
{"server-socket", required_argument, 0, 's'},
+ {"log-colorize", optional_argument, NULL, 'l'},
{"version", no_argument, 0, 'v'},
{"help", no_argument, 0, 'h'},
{NULL, no_argument, 0, 0},
@@ -55,9 +56,10 @@ main(int argc, char *const *argv)
const char *term = "";
const char *server_socket_path = NULL;
+ enum log_colorize log_colorize = LOG_COLORIZE_AUTO;
while (true) {
- int c = getopt_long(argc, argv, ":t:s:hv", longopts, NULL);
+ int c = getopt_long(argc, argv, ":t:s:l::hv", longopts, NULL);
if (c == -1)
break;
@@ -70,6 +72,19 @@ main(int argc, char *const *argv)
server_socket_path = optarg;
break;
+ case 'l':
+ if (optarg == NULL || strcmp(optarg, "auto") == 0)
+ log_colorize = LOG_COLORIZE_AUTO;
+ else if (strcmp(optarg, "never") == 0)
+ log_colorize = LOG_COLORIZE_NEVER;
+ else if (strcmp(optarg, "always") == 0)
+ log_colorize = LOG_COLORIZE_ALWAYS;
+ else {
+ fprintf(stderr, "%s: argument must be one of 'never', 'always' or 'auto'\n", optarg);
+ return EXIT_FAILURE;
+ }
+ break;
+
case 'v':
printf("footclient version %s\n", FOOT_VERSION);
return EXIT_SUCCESS;
@@ -91,6 +106,8 @@ main(int argc, char *const *argv)
argc -= optind;
argv += optind;
+ log_init(log_colorize, false, LOG_FACILITY_USER, LOG_CLASS_WARNING);
+
int fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
LOG_ERRNO("failed to create socket");