kdesu: remove irrelevant kdesud daemon path check

is was (most likely) for platforms that are no longer supported,
also a few identation corrections have been made
This commit is contained in:
Ivailo Monev 2015-10-14 20:46:12 +03:00
parent 587dfedf8e
commit efa6eb3caf

View file

@ -50,7 +50,7 @@ public:
#ifndef SUN_LEN
#define SUN_LEN(ptr) ((socklen_t) (((struct sockaddr_un *) 0)->sun_path) \
+ strlen ((ptr)->sun_path))
+ strlen ((ptr)->sun_path))
#endif
KDEsuClient::KDEsuClient()
@ -81,25 +81,25 @@ KDEsuClient::KDEsuClient()
KDEsuClient::~KDEsuClient()
{
if (d->sockfd >= 0)
close(d->sockfd);
close(d->sockfd);
delete d;
}
int KDEsuClient::connect()
{
if (d->sockfd >= 0)
close(d->sockfd);
close(d->sockfd);
if (access(d->sock, R_OK|W_OK))
{
d->sockfd = -1;
return -1;
d->sockfd = -1;
return -1;
}
d->sockfd = socket(PF_UNIX, SOCK_STREAM, 0);
if (d->sockfd < 0)
{
kWarning(kdesuDebugArea()) << "socket():" << perror;
return -1;
kWarning(kdesuDebugArea()) << "socket():" << perror;
return -1;
}
struct sockaddr_un addr;
addr.sun_family = AF_UNIX;
@ -108,8 +108,8 @@ int KDEsuClient::connect()
if (::connect(d->sockfd, (struct sockaddr *) &addr, SUN_LEN(&addr)) < 0)
{
kWarning(kdesuDebugArea()) << "connect():" << perror;
close(d->sockfd); d->sockfd = -1;
return -1;
close(d->sockfd); d->sockfd = -1;
return -1;
}
#if !defined(SO_PEERCRED) || !defined(HAVE_STRUCT_UCRED)
@ -197,26 +197,26 @@ QByteArray KDEsuClient::escape(const QByteArray &str)
int KDEsuClient::command(const QByteArray &cmd, QByteArray *result)
{
if (d->sockfd < 0)
return -1;
return -1;
if (send(d->sockfd, cmd, cmd.length(), 0) != (int) cmd.length())
return -1;
return -1;
char buf[1024];
int nbytes = recv(d->sockfd, buf, 1023, 0);
if (nbytes <= 0)
{
kWarning(kdesuDebugArea()) << "no reply from daemon.";
return -1;
kWarning(kdesuDebugArea()) << "no reply from daemon.";
return -1;
}
buf[nbytes] = '\000';
QByteArray reply = buf;
if (reply.left(2) != "OK")
return -1;
return -1;
if (result)
*result = reply.mid(3, reply.length()-4);
*result = reply.mid(3, reply.length()-4);
return 0;
}
@ -399,13 +399,11 @@ int KDEsuClient::stopServer()
static QString findDaemon()
{
QString daemon = KStandardDirs::locate("bin", "kdesud");
if (daemon.isEmpty()) // if not in KDEDIRS, rely on PATH
daemon = KStandardDirs::findExe("kdesud");
const QString daemon = KStandardDirs::locate("bin", "kdesud");
if (daemon.isEmpty())
{
kWarning(kdesuDebugArea()) << "daemon not found.";
kWarning(kdesuDebugArea()) << "daemon not found.";
}
return daemon;
}
@ -420,8 +418,8 @@ bool KDEsuClient::isServerSGID()
KDE_struct_stat sbuf;
if (KDE::stat(d->daemon, &sbuf) < 0)
{
kWarning(kdesuDebugArea()) << "stat():" << perror;
return false;
kWarning(kdesuDebugArea()) << "stat():" << perror;
return false;
}
return (sbuf.st_mode & S_ISGID);
}