aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/daemon/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/daemon/daemon.c')
-rw-r--r--src/plugins/daemon/daemon.c103
1 files changed, 90 insertions, 13 deletions
diff --git a/src/plugins/daemon/daemon.c b/src/plugins/daemon/daemon.c
index 27b95cfd..a3d0af10 100644
--- a/src/plugins/daemon/daemon.c
+++ b/src/plugins/daemon/daemon.c
@@ -26,7 +26,9 @@
26 26
27#include "platform.h" 27#include "platform.h"
28#include "gnunetgtk_common.h" 28#include "gnunetgtk_common.h"
29#include <GNUnet/gnunet_directories.h>
29#include <GNUnet/gnunet_getoption_lib.h> 30#include <GNUnet/gnunet_getoption_lib.h>
31#include <GNUnet/gnunet_util_config_impl.h>
30#include <GNUnet/gnunet_util_cron.h> 32#include <GNUnet/gnunet_util_cron.h>
31#include <GNUnet/gnunet_util_network_client.h> 33#include <GNUnet/gnunet_util_network_client.h>
32#include <gtk/gtk.h> 34#include <gtk/gtk.h>
@@ -114,9 +116,16 @@ static void * doUpdateMenus(void * arg) {
114 static GtkWidget * launchEntry = NULL; 116 static GtkWidget * launchEntry = NULL;
115 static GtkWidget * statsEntryYes = NULL; 117 static GtkWidget * statsEntryYes = NULL;
116 static GtkWidget * statsEntryNo = NULL; 118 static GtkWidget * statsEntryNo = NULL;
119 static GtkWidget * statsEntryError = NULL;
120 static GtkWidget * chooser = NULL;
117 static int once = 1; 121 static int once = 1;
118 static int isLocal; 122 static int isLocal;
119 char * host; 123 char * host;
124 int canStart;
125 struct GC_Configuration * dcfg;
126 char * fn;
127 char * user;
128 struct passwd * pws;
120 129
121 if (once) { 130 if (once) {
122 once = 0; 131 once = 0;
@@ -132,6 +141,12 @@ static void * doUpdateMenus(void * arg) {
132 statsEntryNo 141 statsEntryNo
133 = glade_xml_get_widget(getMainXML(), 142 = glade_xml_get_widget(getMainXML(),
134 "statusPixmapNo"); 143 "statusPixmapNo");
144 statsEntryError
145 = glade_xml_get_widget(getMainXML(),
146 "statusPixmapError");
147 chooser
148 = glade_xml_get_widget(getMainXML(),
149 "gnunetdconfigFileChooserButton");
135 GC_get_configuration_value_string(cfg, 150 GC_get_configuration_value_string(cfg,
136 "NETWORK", 151 "NETWORK",
137 "HOST", 152 "HOST",
@@ -141,16 +156,53 @@ static void * doUpdateMenus(void * arg) {
141 isLocal = TRUE; 156 isLocal = TRUE;
142 else 157 else
143 isLocal = FALSE; 158 isLocal = FALSE;
144 FREENONNULL(host); 159 FREE(host);
145 } 160 }
146 updateAppModelSafe(NULL); 161 updateAppModelSafe(NULL);
147 if (ret == SYSERR) { 162 if (ret == 0) {
163 canStart = 0;
164 if ( (isLocal) &&
165 (NULL != (fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser)))) ) {
166 if (disk_file_test(ectx, fn) == YES) {
167 dcfg = GC_create_C_impl();
168 canStart = 1;
169 if (0 != GC_parse_configuration(dcfg, fn))
170 canStart = 0;
171 user = NULL;
172 GC_get_configuration_value_string(dcfg,
173 "GNUNETD",
174 "USER",
175 "",
176 &user);
177 if (strlen(user) > 0) {
178 if (NULL == (pws = getpwnam(user))) {
179 canStart = 0;
180 } else {
181 if (pws->pw_uid != getuid())
182 canStart = (geteuid() == 0);
183 else
184 canStart = 1;
185 }
186 }
187 FREE(user);
188 GC_free(dcfg);
189 }
190 g_free(fn);
191 }
148 gtk_widget_hide(statsEntryYes); 192 gtk_widget_hide(statsEntryYes);
149 gtk_widget_show_all(statsEntryNo);
150 gtk_widget_set_sensitive(killEntry, FALSE); 193 gtk_widget_set_sensitive(killEntry, FALSE);
151 gtk_widget_set_sensitive(launchEntry, (TRUE & isLocal) ); 194 if (canStart && isLocal) {
195 gtk_widget_set_sensitive(launchEntry, TRUE);
196 gtk_widget_show_all(statsEntryNo);
197 gtk_widget_hide(statsEntryError);
198 } else {
199 gtk_widget_set_sensitive(launchEntry, FALSE);
200 gtk_widget_show_all(statsEntryError);
201 gtk_widget_hide(statsEntryNo);
202 }
152 } else { 203 } else {
153 gtk_widget_hide(statsEntryNo); 204 gtk_widget_hide(statsEntryNo);
205 gtk_widget_hide(statsEntryError);
154 gtk_widget_show_all(statsEntryYes); 206 gtk_widget_show_all(statsEntryYes);
155 gtk_widget_set_sensitive(killEntry, TRUE); 207 gtk_widget_set_sensitive(killEntry, TRUE);
156 gtk_widget_set_sensitive(launchEntry, FALSE); 208 gtk_widget_set_sensitive(launchEntry, FALSE);
@@ -159,15 +211,14 @@ static void * doUpdateMenus(void * arg) {
159} 211}
160 212
161static void cronCheckDaemon(void * dummy) { 213static void cronCheckDaemon(void * dummy) {
162 static int last = 42;
163 int ret; 214 int ret;
164 215
165 ret = connection_test_running(ectx, 216 if (OK == connection_test_running(ectx,
166 cfg); 217 cfg))
167 if (ret != last) { 218 ret = 1;
168 last = ret; 219 else
169 gtkSaveCall(&doUpdateMenus, &ret); 220 ret = 0;
170 } 221 gtkSaveCall(&doUpdateMenus, &ret);
171} 222}
172 223
173 224
@@ -177,7 +228,9 @@ static void cronCheckDaemon(void * dummy) {
177void on_startDaemon_clicked_daemon(GtkWidget * widget, 228void on_startDaemon_clicked_daemon(GtkWidget * widget,
178 gpointer data) { 229 gpointer data) {
179 GtkWidget * launchEntry; 230 GtkWidget * launchEntry;
180 231 GtkWidget * chooser;
232 char * fn;
233
181 launchEntry 234 launchEntry
182 = glade_xml_get_widget(getMainXML(), 235 = glade_xml_get_widget(getMainXML(),
183 "startDaemon"); 236 "startDaemon");
@@ -188,14 +241,21 @@ void on_startDaemon_clicked_daemon(GtkWidget * widget,
188 return; 241 return;
189 } else { 242 } else {
190 addLogEntry(_("Launching gnunetd...")); 243 addLogEntry(_("Launching gnunetd..."));
244 chooser
245 = glade_xml_get_widget(getMainXML(),
246 "gnunetdconfigFileChooserButton");
247 fn = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(chooser));
248 GE_BREAK(ectx, fn != NULL);
191 if (SYSERR != os_daemon_start(ectx, 249 if (SYSERR != os_daemon_start(ectx,
192 cfg, 250 cfg,
193 NULL, /* fixme: cfgFile */ 251 fn,
194 YES)) { 252 YES)) {
195 addLogEntry(_("Launched gnunetd")); 253 addLogEntry(_("Launched gnunetd"));
196 } else { 254 } else {
197 addLogEntry(_("Launching gnunetd failed")); 255 addLogEntry(_("Launching gnunetd failed"));
198 } 256 }
257 if (fn != NULL)
258 g_free(fn);
199 } 259 }
200} 260}
201 261
@@ -242,6 +302,7 @@ void init_daemon(struct GE_Context * e,
242 GtkListStore * model; 302 GtkListStore * model;
243 GtkCellRenderer * renderer; 303 GtkCellRenderer * renderer;
244 int col; 304 int col;
305 char * daemon_config;
245 306
246 ectx = e; 307 ectx = e;
247 cfg = c; 308 cfg = c;
@@ -277,6 +338,22 @@ void init_daemon(struct GE_Context * e,
277 = glade_xml_get_widget(getMainXML(), 338 = glade_xml_get_widget(getMainXML(),
278 "daemonScrolledWindow"); 339 "daemonScrolledWindow");
279 gtk_widget_show(tab); 340 gtk_widget_show(tab);
341 daemon_config = NULL;
342 GC_get_configuration_value_filename(cfg,
343 "DAEMON",
344 "CONFIGFILE",
345 DEFAULT_DAEMON_CONFIG_FILE,
346 &daemon_config);
347 if (YES == disk_file_test(NULL, daemon_config)) {
348 gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(glade_xml_get_widget(getMainXML(),
349 "gnunetdconfigFileChooserButton")),
350 daemon_config);
351 } else {
352 addLogEntry(_("Configuration file for GNUnet daemon `%s' does not exist! Run `gnunet-setup -d'."),
353 daemon_config);
354 }
355 FREE(daemon_config);
356
280 cron = cron_create(ectx); 357 cron = cron_create(ectx);
281 cron_add_job(cron, 358 cron_add_job(cron,
282 &cronCheckDaemon, 359 &cronCheckDaemon,