#include <linux/limits.h>
#include <string.h>
#include <signal.h>
+#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "builtin.h"
#include "perf.h"
#include "debug.h"
+#include "config.h"
#include "util.h"
struct daemon {
+ const char *config;
+ char *config_real;
char *base;
FILE *out;
char perf[PATH_MAX];
done = true;
}
+static void daemon__exit(struct daemon *daemon)
+{
+ free(daemon->config_real);
+}
+
+static int setup_config(struct daemon *daemon)
+{
+ if (daemon->config) {
+ char *real = realpath(daemon->config, NULL);
+
+ if (!real) {
+ perror("failed: realpath");
+ return -1;
+ }
+ daemon->config_real = real;
+ return 0;
+ }
+
+ if (perf_config_system() && !access(perf_etc_perfconfig(), R_OK))
+ daemon->config_real = strdup(perf_etc_perfconfig());
+ else if (perf_config_global() && perf_home_perfconfig())
+ daemon->config_real = strdup(perf_home_perfconfig());
+
+ return daemon->config_real ? 0 : -1;
+}
+
static int __cmd_start(struct daemon *daemon, struct option parent_options[],
int argc, const char **argv)
{
if (argc)
usage_with_options(daemon_usage, start_options);
+ if (setup_config(daemon)) {
+ pr_err("failed: config not found\n");
+ return -1;
+ }
+
debug_set_file(daemon->out);
debug_set_display_time(true);
sleep(1);
}
+ daemon__exit(daemon);
+
pr_info("daemon exited\n");
fclose(daemon->out);
return err;
{
struct option daemon_options[] = {
OPT_INCR('v', "verbose", &verbose, "be more verbose"),
+ OPT_STRING(0, "config", &__daemon.config,
+ "config file", "config file path"),
OPT_END()
};
return -1;
}
+ if (setup_config(&__daemon)) {
+ pr_err("failed: config not found\n");
+ return -1;
+ }
+
return -1;
}