#include <linux/limits.h>
#include <ttrace.h>
#include <vconf.h>
+#include <libgen.h>
#include "perf.h"
#include "launchpad_common.h"
_signal_fini();
_close_all_fds();
+ _setup_stdio(basename(argv[LOADER_ARG_PATH]));
if (execv(argv[LOADER_ARG_PATH], argv) < 0)
_E("Failed to prepare candidate_process");
}
_close_all_fds();
+ _setup_stdio(basename(argv[LOADER_ARG_PATH]));
if (execv(argv[LOADER_ARG_PATH], argv) < 0) { /* Flawfinder: ignore */
if (errno == EACCES) {
_E("such a file is no executable - %s",
#include <unistd.h>
#include <tzplatform_config.h>
#include <stdio.h>
+#include <stdbool.h>
+#include <systemd/sd-journal.h>
#include "launchpad_common.h"
#include "key.h"
#define CONNECT_RETRY_COUNT 3
#define AUL_PKT_HEADER_SIZE (sizeof(int) + sizeof(int) + sizeof(int))
#define PATH_AMD_SOCK "/run/aul/daemons/.amd-sock"
+#define PATH_DEV_NULL "/dev/null"
static int __read_proc(const char *path, char *buf, int size)
{
return 0;
}
+int _setup_stdio(const char *ident)
+{
+ int fd;
+
+ /* stdin */
+ fd = open(PATH_DEV_NULL, O_RDONLY | O_NOCTTY);
+ if (fd < 0) {
+ _W("Failed to open /dev/null - err(%d)", errno);
+ return -1;
+ }
+ if (dup2(fd, STDIN_FILENO) < 0) {
+ _W("Failed to duplicate fd - oldfd(%d), newfd(%d)",
+ fd, STDIN_FILENO);
+ }
+ close(fd);
+
+ /* stdout */
+ fd = sd_journal_stream_fd(ident, LOG_INFO, false);
+ if (fd < 0) {
+ _W("Failed to connect journal socket - err(%d)", errno);
+ fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
+ if (fd < 0) {
+ _W("Failed to open /dev/null - err(%d)", errno);
+ return -1;
+ }
+ }
+ if (dup2(fd, STDOUT_FILENO) < 0) {
+ _W("Failed to duplicate fd - oldfd(%d), newfd(%d)",
+ fd, STDOUT_FILENO);
+ }
+ close(fd);
+
+ /* stderr */
+ fd = sd_journal_stream_fd(ident, LOG_INFO, false);
+ if (fd < 0) {
+ _W("Failed to connect journal socket - err(%d)", errno);
+ fd = open(PATH_DEV_NULL, O_WRONLY | O_NOCTTY);
+ if (fd < 0) {
+ _W("Failed to open /dev/null - err(%d)", errno);
+ return -1;
+ }
+ }
+ if (dup2(fd, STDERR_FILENO) < 0) {
+ _W("Failed to duplicate fd - oldfd(%d), newfd(%d)",
+ fd, STDERR_FILENO);
+ }
+ close(fd);
+
+ return 0;
+}