From 82b8853f17b943901776eddcb857089384a61dda Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 5 Feb 2020 19:54:16 +0100 Subject: main: add --print-pid=FILE|FD When specified, our PID is written to the specified file (or FD), after we've successfully started up. --- client.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) (limited to 'client.c') 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"); -- cgit v1.3