diff --git a/Makefile b/Makefile
index 752336f..2606d9c 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,26 @@
+OS := $(shell uname -o)
+ifeq ($(OS),illumos)
# for debug add -g -O0 to line below
-CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0
-prefix=/usr/local/bin
+ CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -lsocket -lnsl
+ prefix=/opt/local/bin
+
+all:
+ ${CC} main.c fiche.c $(CFLAGS) -o fiche
+
+install: fiche
+ install -m 0755 fiche $(prefix)
+ svccfg import fiche.xml
+else
+# for debug add -g -O0 to line below
+ CFLAGS+=-pthread -O2 -Wall -Wextra -Wpedantic -Wstrict-overflow -fno-strict-aliasing -std=gnu11 -g -O0
+ prefix=/usr/local/bin
all:
${CC} main.c fiche.c $(CFLAGS) -o fiche
install: fiche
install -m 0755 fiche $(prefix)
+endif
clean:
rm -f fiche
diff --git a/README.md b/README.md
index e3922d5..a0e1c5b 100644
--- a/README.md
+++ b/README.md
@@ -111,8 +111,10 @@ To use fiche you have to have netcat installed. You probably already have it - t
# Server-side usage
-## Installation
-
+## Installation
+
+__Linux__
+
1. Clone:
```
@@ -130,7 +132,30 @@ To use fiche you have to have netcat installed. You probably already have it - t
```
sudo make install
```
+
+__illumos__
+
+The install target also imports the smf manifest, so it must be configured before running the install target.
+
+1. Clone:
+
+ ```
+ git clone https://github.com/solusipse/fiche.git
+ ```
+
+2. Build:
+
+ ```
+ make
+ ```
+
+3. Install:
+
+ ```
+ pfexec make install
+ ```
+__FreeBSD__
### Using Ports on FreeBSD
To install the port: `cd /usr/ports/net/fiche/ && make install clean`. To add the package: `pkg install fiche`.
@@ -296,6 +321,8 @@ __WARNING:__ not implemented yet
### Running as a service
+__Linux__
+
There's a simple systemd example:
```
[Unit]
@@ -310,6 +337,74 @@ WantedBy=multi-user.target
__WARNING:__ In service mode you have to set output directory with `-o` parameter.
+__illumos__
+
+To run fiche as a service an example [smf](https://wiki.smartos.org/basic-smf-commands/) manifest is provided (fiche.xml).
+This manifest assumes that the user fiche exists and has a home directory to use
+as a output directory (`-o` parameter).
+Also exec_method must be changed to match the required flags for your use case.
+
+```xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ fiche
+
+
+
+
+
+
+
+```
+
+Relevant information for smf is available on the following links:
+- https://www.joyent.com/blog/documentation-for-smf
+- https://docs.joyent.com/public-cloud/instances/infrastructure/images/smartos/managing-smartos/using-smf
+
-------------------------------------------------------------------------------
### Example nginx config
diff --git a/fiche.c b/fiche.c
index 99d140d..ce3f5fd 100644
--- a/fiche.c
+++ b/fiche.c
@@ -175,8 +175,11 @@ static void log_entry(const Fiche_Settings *s, const char *ip,
* @brief Returns string containing current date
* @warning Output has to be freed!
*/
+#ifdef __sun
+static void get_date(char *buf, size_t len);
+#else
static void get_date(char *buf);
-
+#endif
/**
* @brief Time seed
@@ -228,7 +231,11 @@ int fiche_run(Fiche_Settings settings) {
// Display welcome message
{
char date[64];
+#ifdef __sun
+ get_date(date, sizeof(date));
+#else
get_date(date);
+#endif
print_status("Starting fiche on %s...", date);
}
@@ -334,14 +341,37 @@ static void log_entry(const Fiche_Settings *s, const char *ip,
}
char date[64];
+#ifdef __sun
+ get_date(date, sizeof(date));
+#else
get_date(date);
+#endif
// Write entry to file
fprintf(f, "%s -- %s -- %s (%s)\n", slug, date, ip, hostname);
fclose(f);
}
+#ifdef __sun
+static void get_date(char *buf, size_t len) {
+ struct tm curtime;
+ time_t ltime;
+
+ ltime=time(<ime);
+ localtime_r(<ime, &curtime);
+
+ // Save data to provided buffer
+ if (asctime_r(&curtime, buf,strnlen(buf,len) == 0)) {
+ // Couldn't get date, setting first byte of the
+ // buffer to zero so it won't be displayed
+ buf[0] = 0;
+ return;
+ }
+ // Remove newline char
+ buf[strlen(buf)-1] = 0;
+}
+#else
static void get_date(char *buf) {
struct tm curtime;
time_t ltime;
@@ -360,8 +390,7 @@ static void get_date(char *buf) {
// Remove newline char
buf[strlen(buf)-1] = 0;
}
-
-
+#endif
static int set_domain_name(Fiche_Settings *settings) {
char *prefix = "";
@@ -554,7 +583,11 @@ static void *handle_connection(void *args) {
// Print status on this connection
{
char date[64];
+#ifdef __sun
+ get_date(date, sizeof(date));
+#else
get_date(date);
+#endif
print_status("%s", date);
print_status("Incoming connection from: %s (%s).", ip, hostname);
diff --git a/fiche.xml b/fiche.xml
new file mode 100644
index 0000000..8221b21
--- /dev/null
+++ b/fiche.xml
@@ -0,0 +1,54 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ fiche
+
+
+
+
+
+
+