|
Lines 573-643
Link Here
|
| 573 |
return dirname; |
573 |
return dirname; |
| 574 |
} |
574 |
} |
| 575 |
|
575 |
|
|
|
576 |
void KStandardDirs::createSpecialResource(const char *type) |
| 577 |
{ |
| 578 |
char hostname[256]; |
| 579 |
hostname[0] = 0; |
| 580 |
gethostname(hostname, 255); |
| 581 |
QString dir = QString("%1%2-%3").arg(localkdedir()).arg(type).arg(hostname); |
| 582 |
char link[1024]; |
| 583 |
link[1023] = 0; |
| 584 |
int result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 585 |
bool relink = (result == -1) && (errno == ENOENT); |
| 586 |
if ((result > 0) && (link[0] == '/')) |
| 587 |
{ |
| 588 |
link[result] = 0; |
| 589 |
struct stat stat_buf; |
| 590 |
int res = lstat(link, &stat_buf); |
| 591 |
if ((res == -1) && (errno == ENOENT)) |
| 592 |
{ |
| 593 |
relink = true; |
| 594 |
} |
| 595 |
else if ((res == -1) || (!S_ISDIR(stat_buf.st_mode))) |
| 596 |
{ |
| 597 |
fprintf(stderr, "Error: \"%s\" is not a directory.\n", link); |
| 598 |
relink = true; |
| 599 |
} |
| 600 |
else if (stat_buf.st_uid != getuid()) |
| 601 |
{ |
| 602 |
fprintf(stderr, "Error: \"%s\" is owned by uid %d instead of uid %d.\n", link, stat_buf.st_uid, getuid()); |
| 603 |
relink = true; |
| 604 |
} |
| 605 |
} |
| 606 |
if (relink) |
| 607 |
{ |
| 608 |
QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); |
| 609 |
if (srv.isEmpty()) |
| 610 |
srv = findExe(QString::fromLatin1("lnusertemp")); |
| 611 |
if (!srv.isEmpty()) |
| 612 |
{ |
| 613 |
system(QFile::encodeName(srv)+" "+type); |
| 614 |
result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 615 |
} |
| 616 |
} |
| 617 |
if (result > 0) |
| 618 |
{ |
| 619 |
link[result] = 0; |
| 620 |
if (link[0] == '/') |
| 621 |
dir = QFile::decodeName(link); |
| 622 |
else |
| 623 |
dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); |
| 624 |
} |
| 625 |
addResourceDir(type, dir+'/'); |
| 626 |
} |
| 627 |
|
| 576 |
QStringList KStandardDirs::resourceDirs(const char *type) const |
628 |
QStringList KStandardDirs::resourceDirs(const char *type) const |
| 577 |
{ |
629 |
{ |
| 578 |
QStringList *candidates = dircache.find(type); |
630 |
QStringList *candidates = dircache.find(type); |
| 579 |
|
631 |
|
| 580 |
if (!candidates) { // filling cache |
632 |
if (!candidates) { // filling cache |
| 581 |
if (strcmp(type, "socket") == 0) |
633 |
if (strcmp(type, "socket") == 0) |
| 582 |
{ |
634 |
const_cast<KStandardDirs *>(this)->createSpecialResource(type); |
| 583 |
char hostname[256]; |
635 |
else if (strcmp(type, "tmp") == 0) |
| 584 |
hostname[0] = 0; |
636 |
const_cast<KStandardDirs *>(this)->createSpecialResource(type); |
| 585 |
gethostname(hostname, 255); |
637 |
|
| 586 |
QString dir = QString("%1socket-%2").arg(localkdedir()).arg(hostname); |
|
|
| 587 |
char link[1024]; |
| 588 |
link[1023] = 0; |
| 589 |
int result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 590 |
if ((result == -1) && (errno == ENOENT)) |
| 591 |
{ |
| 592 |
QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); |
| 593 |
if (srv.isEmpty()) |
| 594 |
srv = findExe(QString::fromLatin1("lnusertemp")); |
| 595 |
if (!srv.isEmpty()) |
| 596 |
{ |
| 597 |
system(QFile::encodeName(srv)+" socket"); |
| 598 |
result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 599 |
} |
| 600 |
} |
| 601 |
if (result > 0) |
| 602 |
{ |
| 603 |
link[result] = 0; |
| 604 |
if (link[0] == '/') |
| 605 |
dir = QFile::decodeName(link); |
| 606 |
else |
| 607 |
dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); |
| 608 |
} |
| 609 |
const_cast<KStandardDirs *>(this)->addResourceDir("socket", dir+'/'); |
| 610 |
} |
| 611 |
if (strcmp(type, "tmp") == 0) |
| 612 |
{ |
| 613 |
char hostname[256]; |
| 614 |
hostname[0] = 0; |
| 615 |
gethostname(hostname, 255); |
| 616 |
QString dir = QString("%1tmp-%2").arg(localkdedir()).arg(hostname); |
| 617 |
char link[1024]; |
| 618 |
link[1023] = 0; |
| 619 |
int result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 620 |
if ((result == -1) && (errno == ENOENT)) |
| 621 |
{ |
| 622 |
QString srv = findExe(QString::fromLatin1("lnusertemp"), KDEDIR+QString::fromLatin1("/bin")); |
| 623 |
if (srv.isEmpty()) |
| 624 |
srv = findExe(QString::fromLatin1("lnusertemp")); |
| 625 |
if (!srv.isEmpty()) |
| 626 |
{ |
| 627 |
system(QFile::encodeName(srv)+" tmp"); |
| 628 |
result = readlink(QFile::encodeName(dir).data(), link, 1023); |
| 629 |
} |
| 630 |
} |
| 631 |
if (result > 0) |
| 632 |
{ |
| 633 |
link[result] = 0; |
| 634 |
if (link[0] == '/') |
| 635 |
dir = QFile::decodeName(link); |
| 636 |
else |
| 637 |
dir = QDir::cleanDirPath(dir+QFile::decodeName(link)); |
| 638 |
} |
| 639 |
const_cast<KStandardDirs *>(this)->addResourceDir("tmp", dir+'/'); |
| 640 |
} |
| 641 |
QDir testdir; |
638 |
QDir testdir; |
| 642 |
|
639 |
|
| 643 |
candidates = new QStringList(); |
640 |
candidates = new QStringList(); |