Skip to content

Commit

Permalink
Log the asmdll initialisation results in the ArmA server log output
Browse files Browse the repository at this point in the history
  • Loading branch information
Killswitch00 committed May 9, 2015
1 parent 19cce3f commit a5c81b7
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 42 deletions.
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for Arma Server Monitor 0.2.
# Generated by GNU Autoconf 2.69 for Arma Server Monitor 0.3.
#
# Report bugs to <[email protected]>.
#
Expand Down Expand Up @@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='Arma Server Monitor'
PACKAGE_TARNAME='armaservermonitor'
PACKAGE_VERSION='0.2'
PACKAGE_STRING='Arma Server Monitor 0.2'
PACKAGE_VERSION='0.3'
PACKAGE_STRING='Arma Server Monitor 0.3'
PACKAGE_BUGREPORT='[email protected]'
PACKAGE_URL='https://dev.withsix.com/projects/asm-linux/'

Expand Down Expand Up @@ -1320,7 +1320,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures Arma Server Monitor 0.2 to adapt to many kinds of systems.
\`configure' configures Arma Server Monitor 0.3 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1391,7 +1391,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of Arma Server Monitor 0.2:";;
short | recursive ) echo "Configuration of Arma Server Monitor 0.3:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1504,7 +1504,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
Arma Server Monitor configure 0.2
Arma Server Monitor configure 0.3
generated by GNU Autoconf 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1782,7 +1782,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by Arma Server Monitor $as_me 0.2, which was
It was created by Arma Server Monitor $as_me 0.3, which was
generated by GNU Autoconf 2.69. Invocation command line was
$ $0 $@
Expand Down Expand Up @@ -2652,7 +2652,7 @@ fi

# Define the identity of the package.
PACKAGE='armaservermonitor'
VERSION='0.2'
VERSION='0.3'


cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -12975,7 +12975,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by Arma Server Monitor $as_me 0.2, which was
This file was extended by Arma Server Monitor $as_me 0.3, which was
generated by GNU Autoconf 2.69. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -13042,7 +13042,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
Arma Server Monitor config.status 0.2
Arma Server Monitor config.status 0.3
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AC_INIT([Arma Server Monitor], [0.2],[[email protected]],
AC_INIT([Arma Server Monitor], [0.3],[[email protected]],
[armaservermonitor], [https://dev.withsix.com/projects/asm-linux/])
AC_PREREQ([2.59])

Expand Down
4 changes: 2 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ pkglib_LTLIBRARIES = asmdll.la

# TODO: run the test program during "make check"
#TESTS = ...

asm_SOURCES = asm.h asm.c client.h client.c gettickcount.h gettickcount.c \
server.h server.c settings.h settings.c util.h util.c
asm_CFLAGS = $(AM_CFLAGS)
asm_LDFLAGS = -lrt -lm $(GLIB_LIBS)

asmdll_la_SOURCES = asmdll.h asmdll.c gettickcount.h gettickcount.c \
settings.h settings.c
settings.h settings.c util.h util.c
asmdll_la_LDFLAGS = -avoid-version -module -lrt -lm $(GLIB_LIBS)

test_SOURCES = test.c
Expand Down
5 changes: 3 additions & 2 deletions src/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ am__uninstall_files_from_dir = { \
am__installdirs = "$(DESTDIR)$(pkglibdir)" "$(DESTDIR)$(bindir)"
LTLIBRARIES = $(pkglib_LTLIBRARIES)
asmdll_la_LIBADD =
am_asmdll_la_OBJECTS = asmdll.lo gettickcount.lo settings.lo
am_asmdll_la_OBJECTS = asmdll.lo gettickcount.lo settings.lo util.lo
asmdll_la_OBJECTS = $(am_asmdll_la_OBJECTS)
AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
Expand Down Expand Up @@ -342,7 +342,7 @@ asm_SOURCES = asm.h asm.c client.h client.c gettickcount.h gettickcount.c \
asm_CFLAGS = $(AM_CFLAGS)
asm_LDFLAGS = -lrt -lm $(GLIB_LIBS)
asmdll_la_SOURCES = asmdll.h asmdll.c gettickcount.h gettickcount.c \
settings.h settings.c
settings.h settings.c util.h util.c

asmdll_la_LDFLAGS = -avoid-version -module -lrt -lm $(GLIB_LIBS)
test_SOURCES = test.c
Expand Down Expand Up @@ -518,6 +518,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gettickcount.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/settings.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/test.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/util.Plo@am__quote@

.c.o:
@am__fastdepCC_TRUE@ $(AM_V_CC)$(COMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $<
Expand Down
49 changes: 25 additions & 24 deletions src/asmdll.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "settings.h"
#include "asmdll.h"
#include "gettickcount.h"
#include "util.h"

#include <ctype.h>
#include <errno.h>
Expand Down Expand Up @@ -53,26 +54,26 @@ void __attribute ((constructor)) libasm_open(void)
{
int firstload = 0;

openlog("asmdll", LOG_CONS|LOG_ODELAY|LOG_PID, LOG_USER);
asmlog_open("asmdll", LOG_CONS|LOG_ODELAY|LOG_PID, LOG_USER);

pagesize = sysconf(_SC_PAGESIZE);
FileMapHandle = shm_open("/ASM_MapFile", O_CREAT|O_RDWR, S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);

if (FileMapHandle < 0) {
syslog(LOG_ERR, "Could not create shared memory object: %s", strerror(errno));
asmlog(LOG_ERR, "Could not create shared memory object: %s", strerror(errno));
return;
}
memset(&filestat, 0, sizeof(filestat));
if (fstat(FileMapHandle, &filestat) != 0) {
syslog(LOG_ERR, "Could not fstat() the shared memory object: %s", strerror(errno));
asmlog(LOG_ERR, "Could not fstat() the shared memory object: %s", strerror(errno));
shm_unlink("/ASM_MapFile");
close(FileMapHandle);
return;
}
if (filestat.st_size == 0) {
// First load of the extension - resize the shared memory for our needs
if (ftruncate(FileMapHandle, FILEMAPSIZE) != 0) {
syslog(LOG_ERR, "Could not set shared memory object size: %s", strerror(errno));
asmlog(LOG_ERR, "Could not set shared memory object size: %s", strerror(errno));
shm_unlink("/ASM_MapFile");
close(FileMapHandle);
return;
Expand All @@ -85,15 +86,15 @@ void __attribute ((constructor)) libasm_open(void)
FileMap = NULL;
shm_unlink("/ASM_MapFile");
close(FileMapHandle);
syslog(LOG_ERR, "Could not memory map the object: %s", strerror(errno));
asmlog(LOG_ERR, "Could not memory map the object: %s", strerror(errno));
return;
}

if (firstload) {
syslog(LOG_INFO, "first load - clearing shared memory area.");
asmlog(LOG_DEBUG, "first load - clearing shared memory area.");
memset(FileMap, 0, FILEMAPSIZE);
} else {
syslog(LOG_INFO, "existing shared memory area opened");
asmlog(LOG_DEBUG, "using existing shared memory area");
}

memset(&PCF, 0, sizeof(PCF));
Expand All @@ -103,7 +104,7 @@ void __attribute ((constructor)) libasm_open(void)

read_settings(); // ASM.ini

syslog(LOG_INFO, "asmdll loaded");
asmlog(LOG_INFO, "extension loaded");
}


Expand All @@ -120,8 +121,8 @@ void __attribute ((destructor)) libasm_close(void)
shm_unlink("/ASM_MapFile");
close(FileMapHandle);
}
syslog(LOG_INFO, "asmdll unloaded");
closelog();
asmlog(LOG_INFO, "extension unloaded");
asmlog_close();
}


Expand All @@ -137,7 +138,7 @@ void RVExtension(char *output, int outputSize, const char *function)

*output = '\0';

//syslog(LOG_INFO, "RVExtension(%p, %d, \"%s\")", output, outputSize, function);
//asmlog(LOG_INFO, "RVExtension(%p, %d, \"%s\")", output, outputSize, function);
if (!isdigit(*function)) {
do {
// Get version
Expand All @@ -161,7 +162,7 @@ void RVExtension(char *output, int outputSize, const char *function)
}

if (!FileMap) {
syslog(LOG_ERR, "asmdll: no FileMap");
asmlog(LOG_ERR, "no FileMap");
return;
}

Expand All @@ -176,7 +177,7 @@ void RVExtension(char *output, int outputSize, const char *function)
ArmaServerInfo->SERVER_FPSMIN = FPSMIN;
ArmaServerInfo->TICK_COUNT = gettickcount();

syslog(LOG_DEBUG, "0: FPS update");
asmlog(LOG_DEBUG, "0: FPS update");
}
break;

Expand All @@ -192,7 +193,7 @@ void RVExtension(char *output, int outputSize, const char *function)
ArmaServerInfo->FSM_CE_FREQ = floor(conditionNo * 1000 / tnsec + 0.5);

PCS = PCE;
syslog(LOG_DEBUG, "1: CPS update");
asmlog(LOG_DEBUG, "1: CPS update");
}
break;

Expand Down Expand Up @@ -221,7 +222,7 @@ void RVExtension(char *output, int outputSize, const char *function)
fclose(f);
}
ArmaServerInfo->MEM = rss * pagesize;
syslog(LOG_DEBUG, "2: GEN update");
asmlog(LOG_DEBUG, "2: GEN update");
}
break;

Expand All @@ -230,7 +231,7 @@ void RVExtension(char *output, int outputSize, const char *function)
memset(ArmaServerInfo->MISSION, 0, SMALSTRINGSIZE);
strncpy(ArmaServerInfo->MISSION, &function[2], SMALSTRINGSIZE);
ArmaServerInfo->MISSION[SMALSTRINGSIZE-1] = 0;
syslog(LOG_DEBUG, "3: MISSION update");
asmlog(LOG_DEBUG, "3: MISSION update");
}
break;

Expand All @@ -239,7 +240,7 @@ void RVExtension(char *output, int outputSize, const char *function)
unsigned obj;
obj = strtol(&function[2], &stopstring, 10);
ArmaServerInfo->OBJ_COUNT_0 = obj;
syslog(LOG_DEBUG, "4: OBJ_COUNT_0 update");
asmlog(LOG_DEBUG, "4: OBJ_COUNT_0 update");
}
break;

Expand All @@ -248,7 +249,7 @@ void RVExtension(char *output, int outputSize, const char *function)
unsigned obj;
obj = strtol(&function[2], &stopstring, 10);
ArmaServerInfo->OBJ_COUNT_1 = obj;
syslog(LOG_DEBUG, "5: OBJ_COUNT_1 update");
asmlog(LOG_DEBUG, "5: OBJ_COUNT_1 update");
}
break;

Expand All @@ -257,22 +258,22 @@ void RVExtension(char *output, int outputSize, const char *function)
unsigned obj;
obj = strtol(&function[2], &stopstring, 10);
ArmaServerInfo->OBJ_COUNT_2 = obj;
syslog(LOG_DEBUG, "6: OBJ_COUNT_2 update");
asmlog(LOG_DEBUG, "6: OBJ_COUNT_2 update");
}
break;

case '9': // init
if (ArmaServerInfo == NULL) {
if (enableProfilePrefixSlotSelection > 0 && isdigit(function[2])) {
syslog(LOG_DEBUG, "selecting slot based on profileName...");
asmlog(LOG_DEBUG, "selecting slot based on profileName...");
// Select the instance based on the leading digit in the server's profile name
errno = 0;
InstanceID = strtol(&function[2], &stopstring, 10);
if (errno == 0 && InstanceID < MAX_ARMA_INSTANCES) {
ArmaServerInfo = (struct ARMA_SERVER_INFO*)((unsigned char *)FileMap + (InstanceID * pagesize));
}
} else {
syslog(LOG_DEBUG, "finding available slot");
asmlog(LOG_DEBUG, "finding available slot");
// Find a free server info slot or re-use one if it hasn't been updated in the last 10 seconds
uint32_t DeadTimeout = gettickcount() - 10000;
for (InstanceID = 0 ; InstanceID < MAX_ARMA_INSTANCES ; InstanceID++) {
Expand All @@ -287,11 +288,11 @@ void RVExtension(char *output, int outputSize, const char *function)
memset(ArmaServerInfo->PROFILE, 0, sizeof(ArmaServerInfo->PROFILE));
strncpy(ArmaServerInfo->PROFILE, &function[2], sizeof(ArmaServerInfo->PROFILE));
ArmaServerInfo->PROFILE[sizeof(ArmaServerInfo->PROFILE) - 1] = '\0';
syslog(LOG_DEBUG, "9:init successful, pid %zd, initialized instance %d", ArmaServerInfo->PID, InstanceID);
asmlog(LOG_INFO, "init successful, pid %zd, using slot %d", ArmaServerInfo->PID, InstanceID);
snprintf(output, outputSize, "_ASM_OPT=[%s,%s,%s,\"%s\",\"%s\",\"%s\"];", OCI0, OCI1, OCI2, OCC0, OCC1, OCC2);
} else {
ArmaServerInfo = NULL;
syslog(LOG_ERR, "9:init failed - no available slots.");
asmlog(LOG_ERR, "init failed - no available slots.");
snprintf(output, outputSize, "_ASM_OPT=[0,0,0,\"\",\"\",\"\"];");
}
output[outputSize - 1] = '\0';
Expand All @@ -305,7 +306,7 @@ void RVExtension(char *output, int outputSize, const char *function)
}
if (ArmaServerInfo != NULL) {
if (msync(ArmaServerInfo, pagesize, MS_ASYNC|MS_INVALIDATE) != 0) {
syslog(LOG_ERR, "msync(): %s", strerror(errno));
asmlog(LOG_ERR, "msync(): %s", strerror(errno));
}
}
return;
Expand Down
7 changes: 4 additions & 3 deletions src/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>

#include "asm.h"
#include "util.h"

// Settings and their default values
int enableAPImonitoring = 0; // Because not implemented
Expand Down Expand Up @@ -129,7 +131,7 @@ int read_settings(void)
int ival;
gchar *value;

printf("Reading settings from %s\n", inipath);
asmlog(LOG_INFO, "reading settings from %s", inipath);

value = g_key_file_get_string(settings, "ASM", "enableAPImonitoring", NULL);
if (value != NULL)
Expand Down Expand Up @@ -197,8 +199,7 @@ int read_settings(void)
}
else
{
// TODO: syslog it?
fprintf(stderr, "No ASM.ini file could be loaded - using default values.\n");
asmlog(LOG_ERR, "no ASM.ini file could be loaded - using default values.");
}
g_key_file_free(settings);
}
Expand Down
Loading

0 comments on commit a5c81b7

Please sign in to comment.