Merge lp:~develop7/synapse-project/ssh-plugin-tweaks into lp:synapse-project

Proposed by Andrei Dziahel
Status: Merged
Merged at revision: 481
Proposed branch: lp:~develop7/synapse-project/ssh-plugin-tweaks
Merge into: lp:synapse-project
Diff against target: 67 lines (+28/-4)
1 file modified
src/plugins/ssh-plugin.vala (+28/-4)
To merge this branch: bzr merge lp:~develop7/synapse-project/ssh-plugin-tweaks
Reviewer Review Type Date Requested Status
Alberto Aldegheri Approve
Review via email: mp+76444@code.launchpad.net

Description of the change

In synapse 0.2.8 after updating ssh_config (like adding new hosts) you have to restart synapse. After applying this patch, ssh_config becomes monitored by glib and is reparsed automatically on updating.

Code is definitely not production-ready, and there could be some caveats, so I'd appreciate to be reviewed by someone experienced.

To post a comment you must log in.
Revision history for this message
Andrei Dziahel (develop7) wrote :

well, it works for me, but there's some things I'm worried about

Like following:

At L51 diagnostic message is printed on detecting changes in file. And here's what is really printed on saving .ssh/config:

% ./src/ui/synapse
[16:08:48.986272 Info] Starting up...
...skip...
[16:09:10.456628 Info] [SshPlugin] ssh_config is changed, reparsing
[16:09:10.456982 Info] [SshPlugin] ssh_config is changed, reparsing
[16:09:10.457302 Info] [SshPlugin] ssh_config is changed, reparsing
[16:09:10.457462 Info] [SshPlugin] ssh_config is changed, reparsing

Reparsing is done 4 times every single save. And I don't know, why. Any ideas?

Revision history for this message
Alberto Aldegheri (albyrock87) wrote :

This is strange, I'm not an expert on monitors, but I suggest another way to do this.
In example you could simply reparse the file every 5 minutes (if it exists).

Also, are you checking that ssh_config exists before creating the monitor?

Revision history for this message
Andrei Dziahel (develop7) wrote :

> This is strange, I'm not an expert on monitors, but I suggest another way to do this.
> In example you could simply reparse the file every 5 minutes (if it exists).
And then I have to wait 5 minutes (worst scenario) while synapse will hook up new ssh hosts/ditch old ones? Looks no good to me, sorry.
Anyway then, I'll delay actual reparsing to, say, 500ms.
> Also, are you checking that ssh_config exists before creating the monitor?
No. I'll fix that, thanks.

Revision history for this message
Michal Hruby (mhr3) wrote :

There are some hints when a monitor fires, I think you should be looking for CHANGES_DONE, but you better check that.

478. By Andrei Dziahel

tuned monitoring subscription

Revision history for this message
Andrei Dziahel (develop7) wrote :

@mhr3, thanks for pointing out. I've reduced reparsing count to 2 instead of 4 (see r478)
Still considering delay reparsing to, say, 200 ms.

479. By Andrei Dziahel

fixed double reparsing of ssh config file; implemented handling of config monitoring error

Revision history for this message
Andrei Dziahel (develop7) wrote :

Ok, so I've just added monitoring error handling (like Alberto suggested) and learned that FileMonitorEvent.CHANGES_DONE_HINT should be used alone (in my case).

480. By Andrei Dziahel

merged with upstream

Revision history for this message
Andrei Dziahel (develop7) wrote :

So, um, I suppose this branch is ready for merging into upstream/trunk/whatever you'd like to merge it.

Revision history for this message
Alberto Aldegheri (albyrock87) wrote :

Yes, I will merge it soon!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugins/ssh-plugin.vala'
2--- src/plugins/ssh-plugin.vala 2011-08-04 16:37:34 +0000
3+++ src/plugins/ssh-plugin.vala 2011-09-26 09:46:23 +0000
4@@ -27,6 +27,9 @@
5 {
6 public bool enabled { get; set; default = true; }
7 private ArrayList<SshHost> hosts;
8+
9+ protected File config_file;
10+ protected FileMonitor monitor;
11
12 static construct
13 {
14@@ -40,7 +43,21 @@
15
16 public void activate ()
17 {
18+ this.config_file = File.new_for_path (Environment.get_home_dir () + "/.ssh/config");
19+
20 parse_ssh_config.begin ();
21+
22+ try
23+ {
24+ this.monitor = config_file.monitor_file(FileMonitorFlags.NONE);
25+ this.monitor.changed.connect((m, f, of, type) => {
26+ handle_ssh_config_update(m, f, of, type);
27+ });
28+ }
29+ catch (IOError e)
30+ {
31+ Utils.Logger.warning(this, "Failed to start monitoring changes of ssh client config file");
32+ }
33 }
34
35 public void deactivate () {}
36@@ -61,13 +78,11 @@
37
38 private async void parse_ssh_config ()
39 {
40- var file = File.new_for_path (Environment.get_home_dir () + "/.ssh/config");
41-
42 hosts.clear ();
43
44 try
45 {
46- var dis = new DataInputStream (file.read ());
47+ var dis = new DataInputStream (config_file.read ());
48
49 // TODO: match key boundary
50 Regex host_key_re = new Regex ("(host\\s)", RegexCompileFlags.OPTIMIZE | RegexCompileFlags.CASELESS);
51@@ -102,7 +117,16 @@
52 }
53 catch (Error e)
54 {
55- Utils.Logger.warning (this, "%s: %s", file.get_path (), e.message);
56+ Utils.Logger.warning (this, "%s: %s", config_file.get_path (), e.message);
57+ }
58+ }
59+
60+ public void handle_ssh_config_update(FileMonitor monitor, File file, File? other_file, FileMonitorEvent event_type)
61+ {
62+ if (event_type == FileMonitorEvent.CHANGES_DONE_HINT)
63+ {
64+ Utils.Logger.log(this, "ssh_config is changed, reparsing");
65+ parse_ssh_config.begin ();
66 }
67 }
68