wip
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*-------------------------------- INCLUDES ---------------------------------*/
|
||||
|
||||
#include <cstdio>
|
||||
@@ -34,6 +35,10 @@ extern "C" {
|
||||
#include <libubus.h>
|
||||
}
|
||||
|
||||
/*-------------------------------- DEFINES ---------------------------------*/
|
||||
|
||||
#define k_path_max 1024
|
||||
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn setup_ubus
|
||||
@@ -67,6 +72,38 @@ static struct ubus_context *setup_ubus (void)
|
||||
}
|
||||
}
|
||||
|
||||
/*! ----------------------------------------------------------------------------
|
||||
* @fn is_path_absolute
|
||||
*
|
||||
* @brief return true if the patch is absolute.
|
||||
*/
|
||||
static bool is_path_absolute (const char *a_path)
|
||||
{
|
||||
return a_path != NULL && a_path[0] == '/';
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
@@ -76,8 +113,12 @@ static struct ubus_context *setup_ubus (void)
|
||||
int main (void)
|
||||
{
|
||||
int the_ret = 0;
|
||||
char path[k_path_max] = "";
|
||||
struct ubus_context *the_ctx = NULL;
|
||||
|
||||
/* Get the Path of the binary to load configs. */
|
||||
|
||||
|
||||
/* Setup the Ubus context. */
|
||||
the_ctx = setup_ubus();
|
||||
if (the_ctx == NULL) {
|
||||
@@ -92,7 +133,45 @@ 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"
|
||||
|
||||
Reference in New Issue
Block a user