summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@osg.samsung.com>2015-09-06 22:13:41 -0400
committerMike Blumenkrantz <zmike@osg.samsung.com>2015-09-06 22:21:20 -0400
commit5cd08a5df93d130d674cd6a6f4dbc52ddf6e2a7c (patch)
tree97bc23fad2e621f0a2cdad2bed5832f499cdfe01 /src
parent627050e55fcf03efc8232dab726aed4a57dad8af (diff)
allow empdd to start up without connection info
in the case of being started by dbus, no environment variables are available, so making a connection based on the usual MPD_* variables will be impossible; instead, ensure that the daemon can idle peacefully while doing nothing until someone attempts to connect it
Diffstat (limited to 'src')
-rw-r--r--src/bin/empdd.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/src/bin/empdd.c b/src/bin/empdd.c
index c80d381..63442a3 100644
--- a/src/bin/empdd.c
+++ b/src/bin/empdd.c
@@ -283,20 +283,21 @@ static void
283reconnect(const char *host, int port, const char *pass) 283reconnect(const char *host, int port, const char *pass)
284{ 284{
285 struct mpd_settings *s = empd->settings; 285 struct mpd_settings *s = empd->settings;
286 const char *h; 286 const char *h = host;
287 int p; 287 int p = port;
288 288
289 if (pass && (!pass[0])) 289 if (pass && (!pass[0]))
290 pass = NULL; 290 pass = NULL;
291 291
292 h = host && host[0] ? host : mpd_settings_get_host(empd->settings); 292 if (s)
293 if (h[0] == '/') 293 h = host && host[0] ? host : mpd_settings_get_host(s);
294 if (h && (h[0] == '/'))
294 p = -1; 295 p = -1;
295 else 296 else if (s)
296 p = port == -1 ? (int)mpd_settings_get_port(empd->settings) : port; 297 p = port == -1 ? (int)mpd_settings_get_port(s) : port;
297 if (host || s) 298 if (host || s)
298 s = mpd_settings_new(h, p, 3000, NULL, pass); 299 s = mpd_settings_new(h, p, 3000, NULL, pass);
299 if ((empd->async || empd->svr) && 300 if ((empd->async || empd->svr) && empd->settings &&
300 ((!host) || (!host[0]) || (!strcmp(host, mpd_settings_get_host(empd->settings)))) && 301 ((!host) || (!host[0]) || (!strcmp(host, mpd_settings_get_host(empd->settings)))) &&
301 ((port == -1) || ((unsigned int)port == mpd_settings_get_port(empd->settings)))) 302 ((port == -1) || ((unsigned int)port == mpd_settings_get_port(empd->settings))))
302 { 303 {
@@ -1263,22 +1264,35 @@ static Eldbus_Message *
1263_dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) 1264_dbus_isconnected_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
1264{ 1265{
1265 Eldbus_Message *ret; 1266 Eldbus_Message *ret;
1267 const char *host = "";
1268 unsigned int port = DEFAULT_PORT;
1266 1269
1267 ret = eldbus_message_method_return_new(msg); 1270 ret = eldbus_message_method_return_new(msg);
1268 eldbus_message_arguments_append(ret, "bsu", empd->connected, mpd_settings_get_host(empd->settings), mpd_settings_get_port(empd->settings)); 1271 if (empd->settings)
1272 {
1273 host = mpd_settings_get_host(empd->settings);
1274 port = mpd_settings_get_port(empd->settings);
1275 }
1276 eldbus_message_arguments_append(ret, "bsu", empd->connected, host, port);
1269 return ret; 1277 return ret;
1270} 1278}
1271 1279
1272static Eldbus_Message * 1280static Eldbus_Message *
1273_dbus_connect_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg) 1281_dbus_connect_cb(const Eldbus_Service_Interface *iface EINA_UNUSED, const Eldbus_Message *msg)
1274{ 1282{
1275 const char *host, *pass; 1283 const char *host = NULL, *pass = NULL;
1276 int port; 1284 int port = DEFAULT_PORT;
1277 1285
1278 if (!eldbus_message_arguments_get(msg, "sis", &host, &port, &pass)) 1286 if (!eldbus_message_arguments_get(msg, "sis", &host, &port, &pass))
1279 return eldbus_message_method_return_new(msg); 1287 return eldbus_message_method_return_new(msg);
1280 1288
1281 reconnect(host, port, pass); 1289 if (empd->settings)
1290 reconnect(host, port, pass);
1291 else
1292 {
1293 empd->settings = mpd_settings_new(host, port, 3000, NULL, pass);
1294 reconnect(NULL, -1, NULL);
1295 }
1282 return eldbus_message_method_return_new(msg); 1296 return eldbus_message_method_return_new(msg);
1283} 1297}
1284 1298
@@ -1414,7 +1428,6 @@ main(int argc, char *argv[])
1414 else 1428 else
1415 settings = mpd_settings_new(argv[1], atoi(argv[2]), 3000, NULL, pass); 1429 settings = mpd_settings_new(argv[1], atoi(argv[2]), 3000, NULL, pass);
1416 1430
1417 if (!settings) return 1;
1418 empd = calloc(1, sizeof(EMPD)); 1431 empd = calloc(1, sizeof(EMPD));
1419 empd->settings = settings; 1432 empd->settings = settings;
1420 ecore_app_no_system_modules(); 1433 ecore_app_no_system_modules();
@@ -1439,7 +1452,8 @@ main(int argc, char *argv[])
1439 E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DEL, del, NULL); 1452 E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DEL, del, NULL);
1440 E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DATA, data_cb, NULL); 1453 E_LIST_HANDLER_APPEND(handlers, ECORE_CON_EVENT_SERVER_DATA, data_cb, NULL);
1441 1454
1442 reconnect(NULL, -1, NULL); 1455 if (settings)
1456 reconnect(NULL, -1, NULL);
1443 ecore_main_loop_begin(); 1457 ecore_main_loop_begin();
1444 1458
1445 return 0; 1459 return 0;