aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-03 13:33:09 +0100
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2019-02-03 13:33:09 +0100
commitf0725f2db0e34488f5f269cdb442c50458263cf6 (patch)
tree9de89805faf542c80ddfc25512070cc367e1e1a0
parent0b5ff9516f6ffda69b779a560d01c1a2dfb5e825 (diff)
downloadblogc-f0725f2db0e34488f5f269cdb442c50458263cf6.tar.gz
blogc-f0725f2db0e34488f5f269cdb442c50458263cf6.tar.bz2
blogc-f0725f2db0e34488f5f269cdb442c50458263cf6.zip
blogc: added hostmane template variable
-rw-r--r--Makefile.am2
-rw-r--r--configure.ac2
-rw-r--r--src/blogc/funcvars.c5
-rw-r--r--src/blogc/sysinfo.c47
-rw-r--r--src/blogc/sysinfo.h25
5 files changed, 80 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am
index e2985cd..11d9605 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,6 +44,7 @@ noinst_HEADERS = \
src/blogc/loader.h \
src/blogc/renderer.h \
src/blogc/rusage.h \
+ src/blogc/sysinfo.h \
src/blogc/source-parser.h \
src/blogc/template-parser.h \
src/blogc-git-receiver/post-receive.h \
@@ -130,6 +131,7 @@ libblogc_la_SOURCES = \
src/blogc/loader.c \
src/blogc/renderer.c \
src/blogc/rusage.c \
+ src/blogc/sysinfo.c \
src/blogc/source-parser.c \
src/blogc/template-parser.c \
$(NULL)
diff --git a/configure.ac b/configure.ac
index cb68940..761e37a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -220,7 +220,7 @@ AM_CONDITIONAL([USE_BGR_DEPS], [test "x$have_bgr_deps" = "xyes"])
BASH="$ac_cv_path_bash"
AC_SUBST(BASH)
-AC_CHECK_HEADERS([sys/resource.h sys/stat.h sys/time.h sys/wait.h time.h])
+AC_CHECK_HEADERS([sys/resource.h sys/stat.h sys/time.h sys/wait.h time.h unistd.h])
LT_LIB_M
diff --git a/src/blogc/funcvars.c b/src/blogc/funcvars.c
index 4fc12cf..50abbb8 100644
--- a/src/blogc/funcvars.c
+++ b/src/blogc/funcvars.c
@@ -12,6 +12,7 @@
#include "funcvars.h"
#include "rusage.h"
+#include "sysinfo.h"
#include "../common/utils.h"
@@ -25,6 +26,10 @@ static const struct func_map {
{"BLOGC_RUSAGE_MEMORY", blogc_rusage_inject},
#endif
+#ifdef HAVE_SYSINFO_HOSTNAME
+ {"BLOGC_SYSINFO_HOSTNAME", blogc_sysinfo_inject_hostname},
+#endif
+
{NULL, NULL},
};
diff --git a/src/blogc/sysinfo.c b/src/blogc/sysinfo.c
new file mode 100644
index 0000000..191f60e
--- /dev/null
+++ b/src/blogc/sysinfo.c
@@ -0,0 +1,47 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif /* HAVE_UNISTD_H */
+
+#include <stdlib.h>
+#include "../common/utils.h"
+#include "sysinfo.h"
+
+
+char*
+blogc_sysinfo_get_hostname(void)
+{
+#ifndef HAVE_SYSINFO_HOSTNAME
+ return NULL;
+#else
+ char buf[1024]; // could be 256 according to gethostname(2), but *shrug*.
+ buf[1023] = '\0';
+ if (-1 == gethostname(buf, 1024))
+ return NULL;
+
+ // FIXME: return FQDN instead of local host name
+ return bc_strdup(buf);
+#endif
+}
+
+
+void
+blogc_sysinfo_inject_hostname(bc_trie_t *global)
+{
+ char *hostname = blogc_sysinfo_get_hostname();
+ if (hostname == NULL)
+ return;
+
+ bc_trie_insert(global, "BLOGC_SYSINFO_HOSTNAME", hostname);
+}
diff --git a/src/blogc/sysinfo.h b/src/blogc/sysinfo.h
new file mode 100644
index 0000000..51640e0
--- /dev/null
+++ b/src/blogc/sysinfo.h
@@ -0,0 +1,25 @@
+/*
+ * blogc: A blog compiler.
+ * Copyright (C) 2014-2019 Rafael G. Martins <rafael@rafaelmartins.eng.br>
+ *
+ * This program can be distributed under the terms of the BSD License.
+ * See the file LICENSE.
+ */
+
+#ifndef ___SYSINFO_H
+#define ___SYSINFO_H
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif /* HAVE_CONFIG_H */
+
+#ifdef HAVE_UNISTD_H
+#define HAVE_SYSINFO_HOSTNAME 1
+#endif /* HAVE_UNISTD_H */
+
+#include "../common/utils.h"
+
+char* blogc_sysinfo_get_hostname(void);
+void blogc_sysinfo_inject_hostname(bc_trie_t *global);
+
+#endif /* ___SYSINFO_H */