ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/connection.C
(Generate patch)

Comparing gvpe/src/connection.C (file contents):
Revision 1.69 by pcg, Thu Aug 7 17:54:26 2008 UTC vs.
Revision 1.70 by pcg, Thu Aug 7 19:07:02 2008 UTC

30*/ 30*/
31 31
32#include "config.h" 32#include "config.h"
33 33
34#include <list> 34#include <list>
35#include <queue>
36#include <utility>
35 37
36#include <openssl/rand.h> 38#include <openssl/rand.h>
37#include <openssl/evp.h> 39#include <openssl/evp.h>
38#include <openssl/rsa.h> 40#include <openssl/rsa.h>
39#include <openssl/err.h> 41#include <openssl/err.h>
55#define ULTRA_FAST 1 57#define ULTRA_FAST 1
56#define HLOG 15 58#define HLOG 15
57#include "lzf/lzf.h" 59#include "lzf/lzf.h"
58#include "lzf/lzf_c.c" 60#include "lzf/lzf_c.c"
59#include "lzf/lzf_d.c" 61#include "lzf/lzf_d.c"
62
63//////////////////////////////////////////////////////////////////////////////
64
65static std::queue< std::pair<run_script_cb *, const char *> > rs_queue;
66static ev::child rs_child_ev;
67
68void // c++ requires external linkage here, apparently :(
69rs_child_cb (ev::child &w, int revents)
70{
71 w.stop ();
72
73 if (rs_queue.empty ())
74 return;
75
76 pid_t pid = run_script (*rs_queue.front ().first, false);
77 if (pid)
78 {
79 w.set (pid);
80 w.start ();
81 }
82 else
83 slog (L_WARN, rs_queue.front ().second);
84
85 delete rs_queue.front ().first;
86 rs_queue.pop ();
87}
88
89// despite the fancy name, this is quite a hack
90static void
91run_script_queued (run_script_cb *cb, const char *warnmsg)
92{
93 rs_queue.push (std::make_pair (cb, warnmsg));
94
95 if (!rs_child_ev.is_active ())
96 {
97 rs_child_ev.set<rs_child_cb> ();
98 rs_child_ev ();
99 }
100}
101
102//////////////////////////////////////////////////////////////////////////////
60 103
61struct crypto_ctx 104struct crypto_ctx
62{ 105{
63 EVP_CIPHER_CTX cctx; 106 EVP_CIPHER_CTX cctx;
64 HMAC_CTX hctx; 107 HMAC_CTX hctx;
858 slog (L_INFO, _("%s(%s): connection lost"), 901 slog (L_INFO, _("%s(%s): connection lost"),
859 conf->nodename, (const char *)si); 902 conf->nodename, (const char *)si);
860 903
861 if (::conf.script_node_down) 904 if (::conf.script_node_down)
862 { 905 {
863 run_script_cb cb; 906 run_script_cb *cb = new run_script_cb;
864 cb.set<connection, &connection::script_node_down> (this); 907 cb->set<connection, &connection::script_node_down> (this);
865 if (!run_script (cb, false))
866 slog (L_WARN, _("node-down command execution failed, continuing.")); 908 run_script_queued (cb, _("node-down command execution failed, continuing."));
867 } 909 }
868 } 910 }
869 911
870 delete ictx; ictx = 0; 912 delete ictx; ictx = 0;
871 delete octx; octx = 0; 913 delete octx; octx = 0;
1104 conf->nodename, (const char *)rsi, 1146 conf->nodename, (const char *)rsi,
1105 p->prot_major, p->prot_minor); 1147 p->prot_major, p->prot_minor);
1106 1148
1107 if (::conf.script_node_up) 1149 if (::conf.script_node_up)
1108 { 1150 {
1109 run_script_cb cb; 1151 run_script_cb *cb = new run_script_cb;
1110 cb.set<connection, &connection::script_node_up> (this); 1152 cb->set<connection, &connection::script_node_up> (this);
1111 if (!run_script (cb, false))
1112 slog (L_WARN, _("node-up command execution failed, continuing.")); 1153 run_script_queued (cb, _("node-up command execution failed, continuing."));
1113 } 1154 }
1114 1155
1115 break; 1156 break;
1116 } 1157 }
1117 else 1158 else

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines