diff --git a/meson.build b/meson.build index 9b24bdf..84b20c3 100644 --- a/meson.build +++ b/meson.build @@ -44,6 +44,8 @@ add_project_arguments('-DIP_BINARY='+get_option('ip-binary'), language: 'c') glib2 = dependency('glib-2.0') udev = dependency('libudev') +m = c_compiler.find_library('m', required: false) + subdir('src') subdir('res') diff --git a/res/miracle-utils.sh b/res/miracle-utils.sh index 57f5121..05ce20e 100755 --- a/res/miracle-utils.sh +++ b/res/miracle-utils.sh @@ -168,9 +168,11 @@ function kill_network_manager { # ubuntu manager restarts automatically wpa_supplicant sudo service NetworkManager stop elif check_archlinux_distro + then sudo systemctl stop Network.service else - sudo systemctl stop Network.service + sudo systemctl stop NetworkManager + sudo systemctl stop wpa_supplicant fi } @@ -183,6 +185,9 @@ function start_network_manager { then sudo service NetworkManager start elif check_archlinux_distro + then sudo systemctl start Network.service + else + sudo service NetworkManager start fi } diff --git a/src/ctl/ctl-cli.c b/src/ctl/ctl-cli.c index 0897aa7..654b434 100644 --- a/src/ctl/ctl-cli.c +++ b/src/ctl/ctl-cli.c @@ -32,6 +32,9 @@ #include "ctl.h" #include "shl_macro.h" #include "shl_util.h" +#include "shl_log.h" +#include +#include /* *sigh* readline doesn't include all their deps, so put them last */ #include @@ -73,6 +76,37 @@ void cli_printv(const char *fmt, va_list args) rl_redisplay(); } + long long sec, usec; + time_t now; + struct tm *timeinfo; + struct timeval tv; + char buffertmp[80]; + char buffer[80]; + int millisec; + + + log__time(&sec, &usec); + + if (log_date_time) { + gettimeofday(&tv, NULL); + millisec = lrint(tv.tv_usec/1000.0); + if (millisec>=1000) { + millisec -=1000; + tv.tv_sec++; + } + + time(&now); + timeinfo = localtime(&now); + + strftime(buffertmp, 80, "%x - %X.%03d", timeinfo); + sprintf(buffer, "%s.%03d", buffertmp, millisec); + } + + if (log_date_time) + printf("[%s] ", buffer); + else if (log__have_time()) + printf("[%.4lld.%.6lld] ", sec, usec); + vprintf(fmt, args); if (async) { diff --git a/src/ctl/meson.build b/src/ctl/meson.build index d2ba182..cd9b77a 100644 --- a/src/ctl/meson.build +++ b/src/ctl/meson.build @@ -1,5 +1,5 @@ inc = include_directories('../..') -deps = [libsystemd, libmiracle_shared_dep, glib2] +deps = [libsystemd, libmiracle_shared_dep, glib2, m] if readline.found() deps += readline endif diff --git a/src/ctl/sinkctl.c b/src/ctl/sinkctl.c index e24e2b3..9781bc6 100644 --- a/src/ctl/sinkctl.c +++ b/src/ctl/sinkctl.c @@ -726,6 +726,9 @@ void cli_fn_help() " --help-commands Show available commands\n" " --version Show package version\n" " --log-level Maximum level for log messages\n" + " --log-time Prefix log-messages with timestamp\n" + " --log-date-time Prefix log-messages with date time\n" + "\n" " --log-journal-level Maximum level for journal log messages\n" " --gst-debug [cat:]lvl[,...] List of categories an level of debug\n" " --audio <0/1> Enable audio support (default %d)\n" @@ -813,6 +816,8 @@ static int parse_argv(int argc, char *argv[]) enum { ARG_VERSION = 0x100, ARG_LOG_LEVEL, + ARG_LOG_TIME, + ARG_LOG_DATE_TIME, ARG_JOURNAL_LEVEL, ARG_GST_DEBUG, ARG_AUDIO, @@ -823,10 +828,12 @@ static int parse_argv(int argc, char *argv[]) ARG_HELP_COMMANDS, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, + { "help", no_argument, NULL, 'h' }, { "help-commands", no_argument, NULL, ARG_HELP_COMMANDS }, - { "version", no_argument, NULL, ARG_VERSION }, - { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "version" , no_argument, NULL, ARG_VERSION }, + { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "log-date-time", no_argument, NULL, ARG_LOG_DATE_TIME }, { "log-journal-level", required_argument, NULL, ARG_JOURNAL_LEVEL }, { "gst-debug", required_argument, NULL, ARG_GST_DEBUG }, { "audio", required_argument, NULL, ARG_AUDIO }, @@ -861,6 +868,12 @@ static int parse_argv(int argc, char *argv[]) case ARG_LOG_LEVEL: cli_max_sev = log_parse_arg(optarg); break; + case ARG_LOG_TIME: + log_init_time(); + break; + case ARG_LOG_DATE_TIME: + log_date_time = true; + break; case ARG_GST_DEBUG: gst_debug = optarg; break; diff --git a/src/dhcp/dhcp.c b/src/dhcp/dhcp.c index 83e7295..3a43af5 100644 --- a/src/dhcp/dhcp.c +++ b/src/dhcp/dhcp.c @@ -750,6 +750,7 @@ static int help(void) " --version Show package version\n" " --log-level Maximum level for log messages\n" " --log-time Prefix log-messages with timestamp\n" + " --log-date-time Prefix log-messages with date time\n" "\n" " --netdev Network device to run on\n" " --ip-binary Path to 'ip' binary [default: "XSTR(IP_BINARY)"]\n" @@ -775,6 +776,7 @@ static int parse_argv(int argc, char *argv[]) ARG_VERSION = 0x100, ARG_LOG_LEVEL, ARG_LOG_TIME, + ARG_LOG_DATE_TIME, ARG_NETDEV, ARG_IP_BINARY, @@ -790,10 +792,11 @@ static int parse_argv(int argc, char *argv[]) ARG_TO, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, - { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "log-date-time", no_argument, NULL, ARG_LOG_DATE_TIME }, { "netdev", required_argument, NULL, ARG_NETDEV }, { "ip-binary", required_argument, NULL, ARG_IP_BINARY }, @@ -826,6 +829,9 @@ static int parse_argv(int argc, char *argv[]) case ARG_LOG_TIME: log_init_time(); break; + case ARG_LOG_DATE_TIME: + log_date_time = true; + break; case ARG_NETDEV: arg_netdev = optarg; break; diff --git a/src/dhcp/meson.build b/src/dhcp/meson.build index 1dce905..9a52302 100644 --- a/src/dhcp/meson.build +++ b/src/dhcp/meson.build @@ -7,5 +7,5 @@ miracle_dhcp_srcs = ['dhcp.c', executable('miracle-dhcp', miracle_dhcp_srcs, install: true, include_directories: include_directories('../..'), - dependencies: [glib2, udev, libmiracle_shared_dep] + dependencies: [glib2, udev, libmiracle_shared_dep, m] ) diff --git a/src/meson.build b/src/meson.build index 1179ab3..bf7311b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -5,7 +5,7 @@ subdir('ctl') subdir('uibc') executable('miracled', 'miracled.c', - dependencies: libmiracle_shared_dep, + dependencies: [libmiracle_shared_dep, m], include_directories: include_directories('..'), install: true ) diff --git a/src/miracled.c b/src/miracled.c index 2fd435f..c193e95 100644 --- a/src/miracled.c +++ b/src/miracled.c @@ -66,6 +66,7 @@ static int help(void) " --version Show package version\n" " --log-level Maximum level for log messages\n" " --log-time Prefix log-messages with timestamp\n" + " --log-date-time Prefix log-messages with date time\n" , program_invocation_short_name); /* * 80-char barrier: @@ -81,12 +82,14 @@ static int parse_argv(int argc, char *argv[]) ARG_VERSION = 0x100, ARG_LOG_LEVEL, ARG_LOG_TIME, + ARG_LOG_DATE_TIME, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, - { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "log-date-time", no_argument, NULL, ARG_LOG_DATE_TIME }, {} }; int c; @@ -104,6 +107,9 @@ static int parse_argv(int argc, char *argv[]) case ARG_LOG_TIME: log_init_time(); break; + case ARG_LOG_DATE_TIME: + log_date_time = true; + break; case '?': return -EINVAL; } diff --git a/src/shared/shl_log.c b/src/shared/shl_log.c index 9b311be..eb55501 100644 --- a/src/shared/shl_log.c +++ b/src/shared/shl_log.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include #include "shl_log.h" @@ -37,7 +39,7 @@ static inline void log_unlock() static struct timeval log__ftime; -static bool log__have_time(void) +bool log__have_time(void) { return !(log__ftime.tv_sec == 0 && log__ftime.tv_usec == 0); } @@ -48,7 +50,7 @@ void log_init_time(void) gettimeofday(&log__ftime, NULL); } -static void log__time(long long *sec, long long *usec) +void log__time(long long *sec, long long *usec) { struct timeval t; @@ -84,6 +86,7 @@ const char *LOG_SUBSYSTEM = NULL; */ unsigned int log_max_sev = LOG_NOTICE; +bool log_date_time = false; char *gst_debug = NULL; @@ -138,25 +141,51 @@ static void log__submit(const char *file, const char *prefix = NULL; FILE *out; long long sec, usec; + time_t now; + struct tm *timeinfo; + struct timeval tv; + char buffertmp[80]; + char buffer[80]; + int millisec; out = stderr; - log__time(&sec, &usec); if (sev < LOG_SEV_NUM && sev > log_max_sev) return; + log__time(&sec, &usec); + + if (log_date_time) { + gettimeofday(&tv, NULL); + millisec = lrint(tv.tv_usec/1000.0); + if (millisec>=1000) { + millisec -=1000; + tv.tv_sec++; + } + + time(&now); + timeinfo = localtime(&now); + + strftime(buffertmp, 80, "%x - %X.%03d", timeinfo); + sprintf(buffer, "%s.%03d", buffertmp, millisec); + } + if (sev < LOG_SEV_NUM) prefix = log__sev2str[sev]; if (prefix) { if (subs) { - if (log__have_time()) + if (log_date_time) + fprintf(out, "[%s] %s: %s: ", buffer, prefix, subs); + else if (log__have_time()) fprintf(out, "[%.4lld.%.6lld] %s: %s: ", sec, usec, prefix, subs); else fprintf(out, "%s: %s: ", prefix, subs); } else { - if (log__have_time()) + if (log_date_time) + fprintf(out, "[%s] %s: ", buffer, prefix); + else if (log__have_time()) fprintf(out, "[%.4lld.%.6lld] %s: ", sec, usec, prefix); else @@ -164,13 +193,18 @@ static void log__submit(const char *file, } } else { if (subs) { - if (log__have_time()) + if (log_date_time) + fprintf(out, "[%s] %s: ", + buffer, subs); + else if (log__have_time()) fprintf(out, "[%.4lld.%.6lld] %s: ", sec, usec, subs); else fprintf(out, "%s: ", subs); } else { - if (log__have_time()) + if (log_date_time) + fprintf(out, "[%s] ", buffer); + else if (log__have_time()) fprintf(out, "[%.4lld.%.6lld] ", sec, usec); } } diff --git a/src/shared/shl_log.h b/src/shared/shl_log.h index 43e972b..61225f2 100644 --- a/src/shared/shl_log.h +++ b/src/shared/shl_log.h @@ -61,6 +61,12 @@ enum log_severity { extern unsigned int log_max_sev; +/* + * Defines if log time should use local time + * Default: false + */ +extern bool log_date_time; + /* * Defines the debug configuration for gstreamer */ @@ -74,6 +80,10 @@ extern char* gst_debug; void log_init_time(void); +void log__time(long long *sec, long long *usec); + +bool log__have_time(void); + /* * Log-Functions * These functions pass a log-message to the log-subsystem. Handy helpers are diff --git a/src/uibc/meson.build b/src/uibc/meson.build index 17a06db..8620ba0 100644 --- a/src/uibc/meson.build +++ b/src/uibc/meson.build @@ -1,4 +1,3 @@ -m = c_compiler.find_library('m', required: false) executable('miracle-uibcctl', 'miracle-uibcctl.h', 'miracle-uibcctl.c', install: true, dependencies: [m, libmiracle_shared_dep] diff --git a/src/wifi/meson.build b/src/wifi/meson.build index e0176f4..c8eac31 100644 --- a/src/wifi/meson.build +++ b/src/wifi/meson.build @@ -9,6 +9,6 @@ miracle_wifid_src = ['wifid.h', executable('miracle-wifid', miracle_wifid_src, include_directories: inc, install: true, - dependencies: [udev, glib2, libsystemd, libmiracle_shared_dep] + dependencies: [udev, glib2, libsystemd, libmiracle_shared_dep, m] ) diff --git a/src/wifi/wifid.c b/src/wifi/wifid.c index 7a45b94..86fb3ff 100644 --- a/src/wifi/wifid.c +++ b/src/wifi/wifid.c @@ -482,6 +482,7 @@ static int help(void) " --version Show package version\n" " --log-level Maximum level for log messages\n" " --log-time Prefix log-messages with timestamp\n" + " --log-date-time Prefix log-messages with date time\n" "\n" " -i --interface Choose the interface to use\n" " --config-methods Define config methods for pairing, default 'pbc'\n" @@ -506,6 +507,7 @@ static int parse_argv(int argc, char *argv[]) ARG_VERSION = 0x100, ARG_LOG_LEVEL, ARG_LOG_TIME, + ARG_LOG_DATE_TIME, ARG_WPA_LOGLEVEL, ARG_WPA_SYSLOG, ARG_USE_DEV, @@ -514,10 +516,11 @@ static int parse_argv(int argc, char *argv[]) ARG_IP_BINARY, }; static const struct option options[] = { - { "help", no_argument, NULL, 'h' }, - { "version", no_argument, NULL, ARG_VERSION }, - { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, - { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, ARG_VERSION }, + { "log-level", required_argument, NULL, ARG_LOG_LEVEL }, + { "log-time", no_argument, NULL, ARG_LOG_TIME }, + { "log-date-time", no_argument, NULL, ARG_LOG_DATE_TIME }, { "wpa-loglevel", required_argument, NULL, ARG_WPA_LOGLEVEL }, { "wpa-syslog", no_argument, NULL, ARG_WPA_SYSLOG }, @@ -546,6 +549,9 @@ static int parse_argv(int argc, char *argv[]) case ARG_LOG_TIME: log_init_time(); break; + case ARG_LOG_DATE_TIME: + log_date_time = true; + break; case ARG_USE_DEV: use_dev = true; break; diff --git a/test/meson.build b/test/meson.build index 1514773..46400cf 100644 --- a/test/meson.build +++ b/test/meson.build @@ -1,5 +1,5 @@ check = dependency('check', required: false) -deps = [udev, glib2, check, libsystemd, libmiracle_shared_dep] +deps = [udev, glib2, check, libsystemd, libmiracle_shared_dep, m] if check.found() test_rtsp = executable('test_rtsp', 'test_rtsp.c', dependencies: deps)