summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/ppp/modem.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/networksettings/ppp/modem.cpp b/noncore/settings/networksettings/ppp/modem.cpp
index 2da9b14..d23fee4 100644
--- a/noncore/settings/networksettings/ppp/modem.cpp
+++ b/noncore/settings/networksettings/ppp/modem.cpp
@@ -863,161 +863,161 @@ int checkForInterface()
struct stat buf;
memset(&buf, 0, sizeof(buf));
return stat("/dev/ppp", &buf);
#endif
}
bool Modem::execpppd(const char *arguments) {
char buf[MAX_CMDLEN];
char *args[MaxArgs];
pid_t pgrpid;
if(modemfd<0)
return false;
_pppdExitStatus = -1;
switch(pppdPid = fork())
{
case -1:
fprintf(stderr,"In parent: fork() failed\n");
return false;
break;
case 0:
// let's parse the arguments the user supplied into UNIX suitable form
// that is a list of pointers each pointing to exactly one word
strlcpy(buf, arguments);
parseargs(buf, args);
// become a session leader and let /dev/ttySx
// be the controlling terminal.
pgrpid = setsid();
#ifdef TIOCSCTTY
if(ioctl(modemfd, TIOCSCTTY, 0)<0)
fprintf(stderr, "ioctl() failed.\n");
#elif defined (TIOCSPGRP)
if(ioctl(modemfd, TIOCSPGRP, &pgrpid)<0)
fprintf(stderr, "ioctl() failed.\n");
#endif
if(tcsetpgrp(modemfd, pgrpid)<0)
fprintf(stderr, "tcsetpgrp() failed.\n");
dup2(modemfd, 0);
dup2(modemfd, 1);
switch (checkForInterface()) {
case 1:
fprintf(stderr, "Cannot determine if kernel supports ppp.\n");
break;
case -1:
fprintf(stderr, "Kernel does not support ppp, oops.\n");
break;
case 0:
fprintf(stderr, "Kernel supports ppp alright.\n");
break;
}
execve(pppdPath(), args, 0L);
_exit(0);
break;
default:
qDebug("In parent: pppd pid %d\n",pppdPid);
close(modemfd);
modemfd = -1;
return true;
break;
}
}
bool Modem::killpppd() {
if(pppdPid > 0) {
qDebug("In killpppd(): Sending SIGTERM to %d\n", pppdPid);
if(kill(pppdPid, SIGTERM) < 0) {
qDebug("Error terminating %d. Sending SIGKILL\n", pppdPid);
if(kill(pppdPid, SIGKILL) < 0) {
qDebug("Error killing %d\n", pppdPid);
return false;
}
}
}
return true;
}
void Modem::parseargs(char* buf, char** args) {
int nargs = 0;
int quotes;
while(nargs < MaxArgs-1 && *buf != '\0') {
quotes = 0;
// Strip whitespace. Use nulls, so that the previous argument is
// terminated automatically.
while ((*buf == ' ' ) || (*buf == '\t' ) || (*buf == '\n' ) )
*buf++ = '\0';
// detect begin of quoted argument
if (*buf == '"' || *buf == '\'') {
quotes = *buf;
*buf++ = '\0';
}
// save the argument
if(*buf != '\0') {
*args++ = buf;
nargs++;
}
if (!quotes)
while ((*buf != '\0') && (*buf != '\n') &&
(*buf != '\t') && (*buf != ' '))
buf++;
else {
while ((*buf != '\0') && (*buf != quotes))
buf++;
*buf++ = '\0';
}
}
*args = 0L;
}
bool Modem::execPPPDaemon(const QString & arguments)
{
- if(execpppd(arguments)==0) {
+ if(execpppd(arguments)) {
_pppdata->setpppdRunning(true);
return true;
} else
return false;
}
void Modem::killPPPDaemon()
{
_pppdata->setpppdRunning(false);
killpppd();
}
int Modem::pppdExitStatus()
{
return _pppdExitStatus;
}
int Modem::openResolv(int flags)
{
int fd;
if ((fd = open(_PATH_RESCONF, flags)) == -1) {
qDebug("error opening resolv.conf!");
fd = open(DEVNULL, O_RDONLY);
}
return fd;
}
bool Modem::setHostname(const QString & name)
{
return sethostname(name, name.length()) == 0;
}