-/* SPDX-License-Identifier: LGPL-2.1+ */
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
#include <errno.h>
#include <fcntl.h>
#include "sd-journal.h"
#include "alloc-util.h"
+#include "build.h"
#include "fd-util.h"
#include "main-func.h"
+#include "parse-argument.h"
#include "parse-util.h"
#include "pretty-print.h"
#include "string-util.h"
#include "syslog-util.h"
-#include "util.h"
+#include "terminal-util.h"
static const char *arg_identifier = NULL;
static int arg_priority = LOG_INFO;
if (r < 0)
return log_oom();
- printf("%s [OPTIONS...] {COMMAND} ...\n\n"
- "Execute process with stdout/stderr connected to the journal.\n\n"
+ printf("%s [OPTIONS...] COMMAND ...\n"
+ "\n%sExecute process with stdout/stderr connected to the journal.%s\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -t --identifier=STRING Set syslog identifier\n"
" -p --priority=PRIORITY Set priority value (0..7)\n"
" --stderr-priority=PRIORITY Set priority value (0..7) used for stderr\n"
" --level-prefix=BOOL Control whether level prefix shall be parsed\n"
- "\nSee the %s for details.\n"
- , program_invocation_short_name
- , link
- );
+ "\nSee the %s for details.\n",
+ program_invocation_short_name,
+ ansi_highlight(),
+ ansi_normal(),
+ link);
return 0;
}
{}
};
- int c;
+ int c, r;
assert(argc >= 0);
assert(argv);
"Failed to parse stderr priority value.");
break;
- case ARG_LEVEL_PREFIX: {
- int k;
-
- k = parse_boolean(optarg);
- if (k < 0)
- return log_error_errno(k, "Failed to parse level prefix value.");
-
- arg_level_prefix = k;
+ case ARG_LEVEL_PREFIX:
+ r = parse_boolean_argument("--level-prefix=", optarg, &arg_level_prefix);
+ if (r < 0)
+ return r;
break;
- }
case '?':
return -EINVAL;
default:
- assert_not_reached("Unhandled option");
+ assert_not_reached();
}
return 1;
}
static int run(int argc, char *argv[]) {
- _cleanup_close_ int outfd = -1, errfd = -1, saved_stderr = -1;
+ _cleanup_close_ int outfd = -EBADF, errfd = -EBADF, saved_stderr = -EBADF;
int r;
- log_parse_environment();
- log_open();
+ log_setup();
r = parse_argv(argc, argv);
if (r <= 0)
saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3);
- r = rearrange_stdio(STDIN_FILENO, outfd, errfd < 0 ? outfd : errfd); /* Invalidates fd on succcess + error! */
+ r = rearrange_stdio(STDIN_FILENO, outfd, errfd < 0 ? outfd : errfd); /* Invalidates fd on success + error! */
TAKE_FD(outfd);
TAKE_FD(errfd);
if (r < 0)