Skip to contentSkip to conversation

alfred: Externalizing ALFRED_INTERVAL for setting synchronization interval

PATCH In review Jonathan Haws 2 participants 3 messages Jul 28, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alfred: Externalizing ALFRED_INTERVAL for setting synchronization interval

ALFRED_INTERVAL is now externalized via the -p option (synchronization period). If specified as option, user supplied interval is used, otherwise the default interval of ALFRED_INTERVAL is used.

---
 alfred.h     |  1 +
 main.c       | 14 +++++++++++++-
 man/alfred.8 |  5 +++++
 server.c     |  4 ++--
 4 files changed, 21 insertions(+), 3 deletions(-)
alfred.h +1 -0
index a9906c8..5b7e965 100644
@@ -131,6 +131,7 @@ struct globals {
 	uint16_t changed_data_type_count; /* maximum is 256 */
 
 	struct timespec if_check;
+	struct timespec sync_period;
 
 	struct hashtable_t *data_hash;
 	struct hashtable_t *transaction_hash;
main.c +0 -0
index 9cab705..3aa89fd 100644
@@ -59,6 +59,8 @@ static void alfred_usage(void)
 	printf("  -m, --master                        start up the daemon in

master mode, which\n");
printf(" accepts data from slaves
and syncs it with\n");
printf(" other masters\n");
+ printf(" -p, --sync-period [period] set synchronization
period, in seconds\n");
+ printf(" fractional seconds are
supported (i.e. 0.2 = 5 Hz)\n");
printf("\n");
printf(" -u, --unix-path [path] path to unix socket used
for client-server\n");
printf(" communication (default:
\""ALFRED_SOCK_PATH_DEFAULT"\")\n");
@@ -156,6 +158,7 @@ out:
static struct globals *alfred_init(int argc, char *argv[]) {
int opt, opt_ind, i, ret;
+ double sync_period = 0.0;
struct globals *globals;
struct option long_options[] = {
{"set-data", required_argument, NULL, 's'},
@@ -170,6 +173,7 @@ static struct globals *alfred_init(int argc, char *argv[])
{"update-command", required_argument, NULL, 'c'},
{"version", no_argument, NULL, 'v'},
{"verbose", no_argument, NULL, 'd'},
+ {"sync-period", required_argument, NULL, 'p'},
{NULL, 0, NULL, 0},
};

@@ -193,12 +197,14 @@ static struct globals *alfred_init(int argc, char *argv[])
globals->unix_path = ALFRED_SOCK_PATH_DEFAULT; globals->verbose = 0;
globals->update_command = NULL;
+ globals->sync_period.tv_sec = ALFRED_INTERVAL;
+ globals->sync_period.tv_nsec = 0;
INIT_LIST_HEAD(&globals->changed_data_types); globals->changed_data_type_count = 0;

time_random_seed();

- while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:dc:",
long_options,
+ while ((opt = getopt_long(argc, argv, "ms:r:hi:b:vV:M:I:u:dc:p:",
long_options,
&opt_ind)) != -1) {
switch (opt) {
case 'r':
@@ -265,6 +271,12 @@ static struct globals *alfred_init(int argc, char *argv[])
printf("%s %s\n", argv[0], SOURCE_VERSION); printf("A.L.F.R.E.D. - Almighty Lightweight Remote Fact Exchange
Daemon\n");
return NULL;
+ case 'p':
+ sync_period = strtod(optarg, NULL);
+ globals->sync_period.tv_sec = (int) sync_period;
+ globals->sync_period.tv_nsec = (double)(sync_period -
(int)sync_period) * 1e9;
+ printf(" ** Setting sync interval to: %.9f seconds (%ld.%09ld)\n",
sync_period, globals->sync_period.tv_sec, globals->sync_period.tv_nsec);
+ break;
case 'h':
default:
alfred_usage();

man/alfred.8 +0 -0
index 49d42bc..df37040 100644
@@ -118,6 +118,11 @@ overhead).
 \fB\-c\fP, \fB\-\-update-command\fP \fIcommand\fP
 Specify command to execute on data change. It will be called with

data-type list
as arguments.
+.TP
+\fB\-p\fP, \fB\-\-sync-period\fP \fIperiod\fP
+Specify alfred synchronization period, in seconds. If not specified, the default
+ALFRED_INTERVAL setting of 10 seconds will be used. Fractional seconds are
+supported.
.
.SH EXAMPLES
Start an alfred server listening on bridge br0 (assuming that this
bridge

server.c +2 -2
index 47aee4f..c5df945 100644
@@ -372,7 +372,7 @@ int alfred_server(struct globals *globals)
 
 	while (1) {
 		clock_gettime(CLOCK_MONOTONIC, &now);
-		now.tv_sec -= ALFRED_INTERVAL;
+		time_diff(&now, &globals->sync_period, &now);
 		if (!time_diff(&last_check, &now, &tv)) {
 			tv.tv_sec = 0;
 			tv.tv_nsec = 0;
@@ -409,7 +409,7 @@ int alfred_server(struct globals *globals)
 
 		if (globals->opmode == OPMODE_MASTER) {
 			/* we are a master */
-			printf("announce master ...\n");
+			printf("[%ld.%09ld] announce master ...\n", last_check.tv_sec,

last_check.tv_nsec);
announce_master(globals);
sync_data(globals);
} else {

Signature · 1 line
1.9.1
#1 lore raw
Quoted 3 lines · On Donnerstag, 28. Juli 2016 17:19:22 CEST Jonathan Haws wrote:

ALFRED_INTERVAL is now externalized via the -p option (synchronization period). If specified as option, user supplied interval is used, otherwise the default interval of ALFRED_INTERVAL is used.

Fails to apply because your mail client corrupted the patch:

Description: alfred: Externalizing ALFRED_INTERVAL for setting synchronization interval
Applying: alfred: Externalizing ALFRED_INTERVAL for setting synchronization interval
fatal: corrupt patch at line 30
Patch failed at 0001 alfred: Externalizing ALFRED_INTERVAL for setting synchronization interval The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".
'git am' failed with exit status 128

Looks like you are using "Evolution 3.10.4-0ubuntu2". Please check
https://www.kernel.org/doc/Documentation/email-clients.txt for instructions
how to force this client not to corrupt patches. Or just use "git send-email" (like most developers)

Kind regards,
Sven

A message that is not in the archive (sent off-list or not yet received): 1469729158.5505.10.camel@c00941

#3 lore raw
Quoted 2 lines · On Donnerstag, 28. Juli 2016 18:05:59 CEST Jonathan Haws wrote:

I've never used send-email. I'll do some digging, learn it, and resubmit.

I would recommend to use msmtp to communicate with your remote SMTP server. More informations can be found [1] when searching for

"git send-email" "sendemail.smtpserver" "msmtp"

Btw. you can remove your password from the smtp config (but keep the "password" line without the "my-secret" part) and msmtp will then ask for each mail for your password.

The interface of "git send-email" is quite easy. Just specify the name of the patch files as argument of "git send-email" and then it will handle the sending + threading for you.

Kind regards,
Sven

[1] https://git.wiki.kernel.org/index.php/GitTips#Using_msmtp_to_send_your_patches