blob: b38391e67123d31f5a170832ed885b6fe1d7721b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
--- kdeprint/cups/cupsdconf2/cupsddialog.cpp Tue Sep 11 09:26:39 2007
+++ kdeprint/cups/cupsdconf2/cupsddialog.cpp Tue Sep 11 14:38:28 2007
@@ -44,6 +44,7 @@
#include <kio/passdlg.h>
#include <kguiitem.h>
#include <kprocess.h>
+#include <qprocess.h>
#include <signal.h>
#include <cups/cups.h>
@@ -69,24 +70,38 @@
int getServerPid()
{
- QDir dir("/proc",QString::null,QDir::Name,QDir::Dirs);
- for (uint i=0;i<dir.count();i++)
- {
- if (dir[i] == "." || dir[i] == ".." || dir[i] == "self") continue;
- QFile f("/proc/" + dir[i] + "/cmdline");
- if (f.exists() && f.open(IO_ReadOnly))
+ // /proc doesn't work the same in FreeBSD. The simplest way to get cupsd's pid is via pgrep.
+ #if defined(__FreeBSD__)
+ QProcess *proc = new QProcess();
+ proc->addArgument("pgrep");
+ proc->addArgument("cupsd");
+ proc->start();
+ while (proc->isRunning()); //Wait for process to exit
+ QString pidString = proc->readLineStdout();
+ bool ok;
+ int pid = pidString.toInt(&ok);
+ if (ok) return pid;
+ return (-1);
+ #else
+ QDir dir("/proc",QString::null,QDir::Name,QDir::Dirs);
+ for (uint i=0;i<dir.count();i++)
{
- QTextStream t(&f);
- QString line;
- t >> line;
- f.close();
- if (line.right(5) == "cupsd" ||
- line.right(6).left(5) == "cupsd") // second condition for 2.4.x kernels
- // which add a null byte at the end
- return dir[i].toInt();
+ if (dir[i] == "." || dir[i] == ".." || dir[i] == "self") continue;
+ QFile f("/proc/" + dir[i] + "/cmdline");
+ if (f.exists() && f.open(IO_ReadOnly))
+ {
+ QTextStream t(&f);
+ QString line;
+ t >> line;
+ f.close();
+ if (line.right(5) == "cupsd" ||
+ line.right(6).left(5) == "cupsd") // second condition for 2.4.x kernels
+ // which add a null byte at the end
+ return dir[i].toInt();
+ }
}
- }
- return (-1);
+ return (-1);
+ #endif
}
const char* getPassword(const char*)
|