From 0d7b381b391bffd7d26d7122142793a1fac0e4b8 Mon Sep 17 00:00:00 2001 From: jbnadal Date: Tue, 3 Apr 2018 15:09:38 +0200 Subject: [PATCH] Fix post build --- bsp/board/domo/scripts/post-build.sh | 6 +- projects/x86_64_domo/post-build.sh | 22 +++++ src/prog/domod/src/main.cpp | 132 ++++++++++----------------- 3 files changed, 75 insertions(+), 85 deletions(-) create mode 100755 projects/x86_64_domo/post-build.sh diff --git a/bsp/board/domo/scripts/post-build.sh b/bsp/board/domo/scripts/post-build.sh index 66f3d575..0a886949 100755 --- a/bsp/board/domo/scripts/post-build.sh +++ b/bsp/board/domo/scripts/post-build.sh @@ -32,12 +32,12 @@ done fi # Copy the overlay of the target. -if [ -d ${PROJECT}/ovl ]; then +if [ -d ${BR_PROJECT}/ovl ]; then mkdir -p ${BR_STAGING}/buildroot/target/usr/local/ cp -a ${BR_PROJECT}/ovl/* ${BR_STAGING}/buildroot/target/ fi # Finaly apply post build script of the target if the script exist. -if [ -e ${PROJECT}/post-build.sh ]; then - ${PROJECT}/post-build.sh +if [ -e ${BR_PROJECT}/post-build.sh ]; then + ${BR_PROJECT}/post-build.sh fi diff --git a/projects/x86_64_domo/post-build.sh b/projects/x86_64_domo/post-build.sh new file mode 100755 index 00000000..87ddfb7b --- /dev/null +++ b/projects/x86_64_domo/post-build.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +# Catch Postbuild Error +function error { + + echo "Postbuild Failed." + exit 1; +} + +set -e +trap error ERR + +echo "==> POSTBUILD:" + +echo "BR_STAGING: ${BR_STAGING}" +echo "BR_PROJECT: ${BR_PROJECT}" + +# Copy the overlay of the target. +if [ -d ${PROJECT}/ovl ]; then + mkdir -p ${BR_STAGING}/buildroot/staging/usr/local/ + cp -a ${BR_BOARD}/ovl/* ${BR_STAGING}/buildroot/staging/ +fi diff --git a/src/prog/domod/src/main.cpp b/src/prog/domod/src/main.cpp index 4552ca99..5dc61fb1 100644 --- a/src/prog/domod/src/main.cpp +++ b/src/prog/domod/src/main.cpp @@ -23,22 +23,24 @@ * */ - /*-------------------------------- INCLUDES ---------------------------------*/ +#include +#include #include +#include #include extern "C" { -#include /* getenv */ +#include /* getenv */ #include } /*-------------------------------- DEFINES ---------------------------------*/ -#define k_path_max 1024 - +#define k_dir_sep '/' +#define k_config_dir "share/domo/" /*! ---------------------------------------------------------------------------- * @fn setup_ubus @@ -46,82 +48,86 @@ extern "C" { * @brief Setup the UBus Mechanism. */ extern "C" { -static struct ubus_context *setup_ubus (void) +static struct ubus_context *setup_ubus(void) { ubus_context *the_ctx; - - if (uloop_init() !=0) { - + + if (uloop_init() != 0) + { + fprintf(stderr, "Failed to init Uloop.\n"); return NULL; } - + signal(SIGPIPE, SIG_IGN); the_ctx = ubus_connect(NULL); - if (!the_ctx) { + if (!the_ctx) + { fprintf(stderr, "Failed to connect to ubus\n"); return NULL; } - + ubus_add_uloop(the_ctx); - + return the_ctx; } } + + /*! ---------------------------------------------------------------------------- - * @fn is_path_absolute + * @fn get_config_path * - * @brief return true if the patch is absolute. + * @brief This function return the config path from executable path. */ -static bool is_path_absolute (const char *a_path) +const std::string get_config_path(char *an_exec_path) { - return a_path != NULL && a_path[0] == '/'; + int the_pos; + std::string the_config_path; + std::string the_exec_path(an_exec_path); + + the_pos = the_exec_path.rfind(k_dir_sep); + + // get exec path. + the_config_path = the_exec_path.substr(0, the_pos + 1); + + // remove last / is necessary. + if (the_config_path[the_config_path.size()-1] == k_dir_sep) { + the_config_path = the_exec_path.substr(0, the_config_path.size() - 1); + } + + // Remove the binary directory. + the_pos = the_config_path.rfind(k_dir_sep); + the_config_path = the_config_path.substr(0, the_pos + 1); + + the_config_path += k_config_dir; + + return the_config_path; } - -char * app_path (char * path, const char * argv0) -{ - char buf[PATH_MAX]; - char * pos; - if (argv0[0] == '/') { // run with absolute path - strcpy(buf, argv0); - } else { // run with relative path - if(NULL == getcwd(buf, PATH_MAX)) { - perror("getcwd error"); - return NULL; - } - strcat(buf, "/"); - strcat(buf, argv0); - } - if (NULL == realpath(buf, path)) { - perror("realpath error"); - return NULL; - } - return path; -} - - /*! ---------------------------------------------------------------------------- * @fn main * * @brief Main function of Domo Daemon. */ -int main (void) +int main(int argc, char *argv[]) { int the_ret = 0; - char path[k_path_max] = ""; + std::string the_config_path; struct ubus_context *the_ctx = NULL; /* Get the Path of the binary to load configs. */ - - + the_config_path = get_config_path(argv[0]); + printf ("config path: %s\n", the_config_path.c_str()); + return 0; + /* Setup the Ubus context. */ the_ctx = setup_ubus(); - if (the_ctx == NULL) { + if (the_ctx == NULL) + { return -1; } @@ -133,45 +139,7 @@ int main (void) return the_ret; } -#if 0 -tatic void -set_absolute_path(char *options[], - const char *option_name, - const char *path_to_civetweb_exe) -{ - char path[PATH_MAX] = "", absolute[PATH_MAX] = ""; - const char *option_value; - const char *p; - /* Check whether option is already set */ - option_value = get_option(options, option_name); - - /* If option is already set and it is an absolute path, - leave it as it is -- it's already absolute. */ - if (option_value != NULL && !is_path_absolute(option_value)) { - /* Not absolute. Use the directory where civetweb executable lives - be the relative directory for everything. - Extract civetweb executable directory into path. */ - if ((p = strrchr(path_to_civetweb_exe, DIRSEP)) == NULL) { - IGNORE_UNUSED_RESULT(getcwd(path, sizeof(path))); - } else { - snprintf(path, - sizeof(path) - 1, - "%.*s", - (int)(p - path_to_civetweb_exe), - path_to_civetweb_exe); - path[sizeof(path) - 1] = 0; - } - - strncat(path, "/", sizeof(path) - strlen(path) - 1); - strncat(path, option_value, sizeof(path) - strlen(path) - 1); - - /* Absolutize the path, and set the option */ - IGNORE_UNUSED_RESULT(abs_path(path, absolute, sizeof(absolute))); - set_option(options, option_name, absolute); - } -} -#endif #if 0 #include "ubus/capabilities.h" #include "ubus/capabilities_lights.h"