|
a/src/main.cxx |
|
b/src/main.cxx |
|
... |
|
... |
142 |
"" // imageUri
|
142 |
"" // imageUri
|
143 |
},
|
143 |
},
|
144 |
// Product
|
144 |
// Product
|
145 |
{
|
145 |
{
|
146 |
"Upmpdcli", // name
|
146 |
"Upmpdcli", // name
|
147 |
UPMPDCLI_PACKAGE_VERSION, // info
|
147 |
UPMPDCLI_PACKAGE_VERSION, // info
|
148 |
"", // url
|
148 |
"", // url
|
149 |
"" // imageUri
|
149 |
"" // imageUri
|
150 |
}
|
150 |
}
|
151 |
};
|
151 |
};
|
152 |
|
152 |
|
|
... |
|
... |
179 |
perror("Sigaction failed");
|
179 |
perror("Sigaction failed");
|
180 |
}
|
180 |
}
|
181 |
}
|
181 |
}
|
182 |
}
|
182 |
}
|
183 |
|
183 |
|
|
|
184 |
static vector<string> savedargs;
|
|
|
185 |
|
|
|
186 |
// See comment in main.hxx
|
|
|
187 |
bool startMsOnlyProcess()
|
|
|
188 |
{
|
|
|
189 |
static ExecCmd cmd;
|
|
|
190 |
if (cmd.getChildPid() > 0) {
|
|
|
191 |
return true;
|
|
|
192 |
}
|
|
|
193 |
// Fork process for media server, replacing whatever -m option
|
|
|
194 |
// was given with -m 2 (ms only)
|
|
|
195 |
vector<string> args{"-m", "2"};
|
|
|
196 |
string cmdpath(savedargs[0]);
|
|
|
197 |
for (unsigned int i = 1; i < savedargs.size(); i++) {
|
|
|
198 |
string sa(savedargs[i]);
|
|
|
199 |
if (sa[sa.length() - 1] == 'm') {
|
|
|
200 |
sa = sa.substr(0, sa.length()-1);
|
|
|
201 |
if (i == savedargs.size() - 1)
|
|
|
202 |
Usage();
|
|
|
203 |
i++;
|
|
|
204 |
}
|
|
|
205 |
if (!sa.empty() && sa.compare("-")) {
|
|
|
206 |
args.push_back(sa);
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
return cmd.startExec(cmdpath, args, false, false) >= 0;
|
|
|
210 |
}
|
|
|
211 |
|
184 |
int main(int argc, char *argv[])
|
212 |
int main(int argc, char *argv[])
|
185 |
{
|
213 |
{
|
186 |
vector<string> savedargs;
|
|
|
187 |
for (int i = 0; i < argc; i++) {
|
214 |
for (int i = 0; i < argc; i++) {
|
188 |
savedargs.push_back(argv[i]);
|
215 |
savedargs.push_back(argv[i]);
|
189 |
}
|
216 |
}
|
190 |
|
217 |
|
191 |
// Path for the sc2mpd command, or empty
|
218 |
// Path for the sc2mpd command, or empty
|
|
... |
|
... |
389 |
// If a streaming service is enabled, we need a Media
|
416 |
// If a streaming service is enabled, we need a Media
|
390 |
// Server. We let a static ContentDirectory method decide this
|
417 |
// Server. We let a static ContentDirectory method decide this
|
391 |
// for us. The way we then implement it depends on the command
|
418 |
// for us. The way we then implement it depends on the command
|
392 |
// line option (see the enum comments near the top of the file):
|
419 |
// line option (see the enum comments near the top of the file):
|
393 |
enableMediaServer = ContentDirectory::mediaServerNeeded();
|
420 |
enableMediaServer = ContentDirectory::mediaServerNeeded();
|
394 |
if (enableMediaServer) {
|
|
|
395 |
switch (arg_msmode) {
|
421 |
switch (arg_msmode) {
|
396 |
case MSOnly:
|
422 |
case MSOnly:
|
397 |
inprocessms = true;
|
423 |
inprocessms = true;
|
398 |
msonly = true;
|
424 |
msonly = true;
|
399 |
break;
|
425 |
break;
|
400 |
case Combined:
|
426 |
case Combined:
|
401 |
inprocessms = true;
|
427 |
inprocessms = true;
|
402 |
msonly = false;
|
428 |
msonly = false;
|
403 |
break;
|
429 |
break;
|
404 |
case RdrOnly:
|
430 |
case RdrOnly:
|
405 |
case Forked:
|
431 |
case Forked:
|
406 |
default:
|
432 |
default:
|
407 |
inprocessms = false;
|
433 |
inprocessms = false;
|
408 |
msonly = false;
|
434 |
msonly = false;
|
409 |
break;
|
435 |
break;
|
410 |
}
|
|
|
411 |
}
|
436 |
}
|
412 |
} else {
|
437 |
} else {
|
413 |
// g_configfilename is empty. Create an empty config anyway
|
438 |
// g_configfilename is empty. Create an empty config anyway
|
414 |
g_config = new ConfSimple(string(), 1, true);
|
439 |
g_config = new ConfSimple(string(), 1, true);
|
415 |
if (!g_config || !g_config->ok()) {
|
440 |
if (!g_config || !g_config->ok()) {
|
|
... |
|
... |
425 |
// Set inprocessms in this case ! No need to fork
|
450 |
// Set inprocessms in this case ! No need to fork
|
426 |
inprocessms = true;
|
451 |
inprocessms = true;
|
427 |
}
|
452 |
}
|
428 |
|
453 |
|
429 |
if (msonly && !enableMediaServer) {
|
454 |
if (msonly && !enableMediaServer) {
|
430 |
cerr << "Pure Media Server mode requested, but this is "
|
455 |
// We used to forbid this, but it's actually ok if we're just using
|
431 |
"disabled by the configuration or by absent Media Server "
|
456 |
// the "mediaserver" to redirect URLs for ohcredentials/Kazoo
|
432 |
"modules.\n";
|
457 |
;
|
433 |
return 1;
|
|
|
434 |
}
|
458 |
}
|
435 |
|
459 |
|
436 |
if (Logger::getTheLog(logfilename) == 0) {
|
460 |
if (Logger::getTheLog(logfilename) == 0) {
|
437 |
cerr << "Can't initialize log" << endl;
|
461 |
cerr << "Can't initialize log" << endl;
|
438 |
return 1;
|
462 |
return 1;
|
|
... |
|
... |
482 |
int fd;
|
506 |
int fd;
|
483 |
if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
|
507 |
if ((fd = open(mcfn.c_str(), O_CREAT|O_RDWR, 0644)) < 0) {
|
484 |
LOGERR("creat("<< mcfn << ") : errno : " << errno << endl);
|
508 |
LOGERR("creat("<< mcfn << ") : errno : " << errno << endl);
|
485 |
} else {
|
509 |
} else {
|
486 |
close(fd);
|
510 |
close(fd);
|
487 |
if (geteuid() == 0 && chown(mcfn.c_str(), runas, -1) != 0) {
|
|
|
488 |
LOGERR("chown("<< mcfn << ") : errno : " << errno << endl);
|
|
|
489 |
}
|
|
|
490 |
if (geteuid() == 0 &&
|
511 |
if (geteuid() == 0) {
|
|
|
512 |
if (chown(mcfn.c_str(), runas, -1) != 0) {
|
|
|
513 |
LOGERR("chown("<< mcfn << ") : errno : " <<
|
|
|
514 |
errno << endl);
|
|
|
515 |
}
|
491 |
chown(opts.cachedir.c_str(), runas, -1) != 0) {
|
516 |
if (chown(opts.cachedir.c_str(), runas, -1) != 0) {
|
492 |
LOGERR("chown("<< opts.cachedir << ") : errno : " <<
|
517 |
LOGERR("chown("<< opts.cachedir << ") : errno : " <<
|
493 |
errno << endl);
|
518 |
errno << endl);
|
|
|
519 |
}
|
494 |
}
|
520 |
}
|
495 |
}
|
521 |
}
|
496 |
}
|
522 |
}
|
497 |
}
|
523 |
}
|
498 |
|
524 |
|
|
... |
|
... |
704 |
|
730 |
|
705 |
MediaServer *mediaserver = nullptr;
|
731 |
MediaServer *mediaserver = nullptr;
|
706 |
unordered_map<string, VDirContent> emptyfiles =
|
732 |
unordered_map<string, VDirContent> emptyfiles =
|
707 |
unordered_map<string, VDirContent>();
|
733 |
unordered_map<string, VDirContent>();
|
708 |
unordered_map<string, VDirContent> *msfiles = &emptyfiles;
|
734 |
unordered_map<string, VDirContent> *msfiles = &emptyfiles;
|
709 |
vector<string> args{"-m", "2"};
|
|
|
710 |
// Having this as a stack object means that it will be
|
|
|
711 |
// deleted when we return from main (on a signal), ensuring that
|
|
|
712 |
// the child process gets killed.
|
|
|
713 |
ExecCmd cmd;
|
|
|
714 |
|
735 |
|
715 |
if (inprocessms) {
|
736 |
if (inprocessms) {
|
716 |
if (msonly) {
|
737 |
if (msonly) {
|
717 |
msfiles = &files;
|
738 |
msfiles = &files;
|
718 |
}
|
739 |
}
|
719 |
// Create the Media Server embedded device object. There needs
|
740 |
// Create the Media Server embedded device object. There needs
|
720 |
// be no reference to the root object because there can be
|
741 |
// be no reference to the root object because there can be
|
721 |
// only one (libupnp restriction)
|
742 |
// only one (libupnp restriction)
|
722 |
mediaserver = new MediaServer(string("uuid:") + ids.uuidMS, ids.fnameMS,
|
743 |
mediaserver = new MediaServer(string("uuid:") + ids.uuidMS, ids.fnameMS,
|
723 |
*msfiles);
|
744 |
enableMediaServer, *msfiles);
|
724 |
} else if (enableMediaServer) {
|
745 |
} else if (enableMediaServer) {
|
725 |
// Fork process for media server, replacing whatever -m option
|
746 |
startMsOnlyProcess();
|
726 |
// was given with -m 2 (ms only)
|
|
|
727 |
string cmdpath(savedargs[0]);
|
|
|
728 |
for (unsigned int i = 1; i < savedargs.size(); i++) {
|
|
|
729 |
string sa(savedargs[i]);
|
|
|
730 |
if (sa[sa.length()-1] == 'm') {
|
|
|
731 |
sa = sa.substr(0, sa.length()-1);
|
|
|
732 |
if (int(i) == argc -1)
|
|
|
733 |
Usage();
|
|
|
734 |
i++;
|
|
|
735 |
}
|
|
|
736 |
if (!sa.empty() && sa.compare("-")) {
|
|
|
737 |
args.push_back(sa);
|
|
|
738 |
}
|
|
|
739 |
}
|
|
|
740 |
cmd.startExec(cmdpath, args, false, false);
|
|
|
741 |
}
|
747 |
}
|
742 |
|
748 |
|
743 |
// And forever generate state change events.
|
749 |
// And forever generate state change events.
|
744 |
LOGDEB("Entering event loop" << endl);
|
750 |
LOGDEB("Entering event loop" << endl);
|
745 |
setupsigs();
|
751 |
setupsigs();
|
746 |
if (msonly) {
|
752 |
if (msonly) {
|
747 |
assert(nullptr != mediaserver);
|
753 |
assert(nullptr != mediaserver);
|
748 |
dev = mediaserver;
|
754 |
dev = mediaserver;
|
749 |
LOGDEB("Media server event loop" << endl);
|
755 |
LOGDEB("Media server event loop" << endl);
|
|
|
756 |
if (enableMediaServer) {
|
750 |
mediaserver->eventloop();
|
757 |
mediaserver->eventloop();
|
|
|
758 |
} else {
|
|
|
759 |
pause();
|
|
|
760 |
}
|
751 |
} else {
|
761 |
} else {
|
752 |
LOGDEB("Renderer event loop" << endl);
|
762 |
LOGDEB("Renderer event loop" << endl);
|
753 |
assert(nullptr != mediarenderer);
|
763 |
assert(nullptr != mediarenderer);
|
754 |
dev = mediarenderer;
|
764 |
dev = mediarenderer;
|
755 |
mediarenderer->eventloop();
|
765 |
mediarenderer->eventloop();
|