[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[vidalia-svn] r2571: Merge r2570 to trunk. (in vidalia: . trunk/src/common trunk/src/vidalia)
Author: edmanm
Date: 2008-05-10 00:23:18 -0400 (Sat, 10 May 2008)
New Revision: 2571
Added:
vidalia/trunk/src/common/procutil.cpp
vidalia/trunk/src/common/procutil.h
Removed:
vidalia/trunk/src/common/process.cpp
vidalia/trunk/src/common/process.h
Modified:
vidalia/
vidalia/trunk/src/common/CMakeLists.txt
vidalia/trunk/src/vidalia/main.cpp
Log:
r302@thebe: edmanm | 2008-05-10 00:23:55 -0400
Merge r2570 to trunk.
Property changes on: vidalia
___________________________________________________________________
svk:merge ticket from /local/vidalia [r302] on 45a62a8a-8088-484c-baad-c7b3e776dd32
Modified: vidalia/trunk/src/common/CMakeLists.txt
===================================================================
--- vidalia/trunk/src/common/CMakeLists.txt 2008-05-10 03:58:30 UTC (rev 2570)
+++ vidalia/trunk/src/common/CMakeLists.txt 2008-05-10 04:23:18 UTC (rev 2571)
@@ -17,7 +17,7 @@
html.cpp
log.cpp
net.cpp
- process.cpp
+ procutil.cpp
stringutil.cpp
torsocket.cpp
zlibbytearray.cpp
Deleted: vidalia/trunk/src/common/process.cpp
Deleted: vidalia/trunk/src/common/process.h
Added: vidalia/trunk/src/common/procutil.cpp
===================================================================
--- vidalia/trunk/src/common/procutil.cpp (rev 0)
+++ vidalia/trunk/src/common/procutil.cpp 2008-05-10 04:23:18 UTC (rev 2571)
@@ -0,0 +1,106 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.vidalia-project.net/. No part of Vidalia, including this file,
+** may be copied, modified, propagated, or distributed except according to the
+** terms described in the LICENSE file.
+*/
+
+/*
+** \file procutil.cpp
+** \version $Id$
+** \brief Process information and pidfile functions
+*/
+
+#include <QDir>
+#include <QFile>
+#include <QFileInfo>
+#include <QTextStream>
+#include <QApplication>
+
+#include "stringutil.h"
+#include "procutil.h"
+
+
+/** Returns the PID of the current process. */
+qint64
+get_pid()
+{
+#if defined(Q_OS_WIN)
+ return (qint64)GetCurrentProcessId();
+#else
+ return (qint64)getpid();
+#endif
+}
+
+/** Returns true if a process with the given PID is running. */
+bool
+is_process_running(qint64 pid)
+{
+#if defined(Q_OS_WIN)
+ QHash<qint64, QString> procList = win32_process_list();
+ if (procList.contains(pid)) {
+ /* A process with this ID exists. Check if it's the same as this process. */
+ QString exeFile = procList.value(pid);
+ QString thisExe = QFileInfo(QApplication::applicationFilePath()).fileName();
+ return (exeFile.toLower() == thisExe.toLower());
+ }
+ return false;
+#else
+ /* Send the "null" signal to check if a process exists */
+ if (kill((pid_t)pid, 0) < 0) {
+ return (errno != ESRCH);
+ }
+ return true;
+#endif
+}
+
+/** Writes the given file to disk containing the current process's PID. */
+bool
+write_pidfile(QString pidFileName, QString *errmsg)
+{
+ /* Make sure the directory exists */
+ QDir pidFileDir = QFileInfo(pidFileName).absoluteDir();
+ if (!pidFileDir.exists()) {
+ pidFileDir.mkpath(QDir::convertSeparators(pidFileDir.absolutePath()));
+ }
+
+ /* Try to open (and create if it doesn't exist) the pidfile */
+ QFile pidfile(pidFileName);
+ if (!pidfile.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ return err(errmsg, pidfile.errorString());
+ }
+
+ /* Write our current PID to it */
+ QTextStream pidstream(&pidfile);
+ pidstream << get_pid();
+ return true;
+}
+
+/** Reads the given pidfile and returns the value contained in it. If the file
+ * does not exist 0 is returned. Returns -1 if an error occurs. */
+qint64
+read_pidfile(QString pidFileName, QString *errmsg)
+{
+ qint64 pid;
+
+ /* Open the pidfile, if it exists */
+ QFile pidfile(pidFileName);
+ if (!pidfile.exists()) {
+ return 0;
+ }
+ if (!pidfile.open(QIODevice::ReadOnly | QIODevice::Text)) {
+ if (errmsg) {
+ *errmsg = pidfile.errorString();
+ }
+ return -1;
+ }
+
+ /* Read the PID in from the file */
+ QTextStream pidstream(&pidfile);
+ pidstream >> pid;
+ return pid;
+}
+
Property changes on: vidalia/trunk/src/common/procutil.cpp
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: vidalia/trunk/src/common/procutil.h
===================================================================
--- vidalia/trunk/src/common/procutil.h (rev 0)
+++ vidalia/trunk/src/common/procutil.h 2008-05-10 04:23:18 UTC (rev 2571)
@@ -0,0 +1,46 @@
+/*
+** This file is part of Vidalia, and is subject to the license terms in the
+** LICENSE file, found in the top level directory of this distribution. If you
+** did not receive the LICENSE file with this file, you may obtain it from the
+** Vidalia source package distributed by the Vidalia Project at
+** http://www.vidalia-project.net/. No part of Vidalia, including this file,
+** may be copied, modified, propagated, or distributed except according to the
+** terms described in the LICENSE file.
+*/
+
+/*
+** \file procutil.h
+** \version $Id$
+** \brief Process information and pidfile functions
+*/
+
+#ifndef _PROCUTIL_H
+#define _PROCUTIL_H
+
+#include <QString>
+
+#if defined(Q_OS_WIN)
+#include "win32.h"
+#else
+#include <sys/types.h>
+#include <unistd.h>
+#include <signal.h>
+#include <errno.h>
+#endif
+
+
+/** Returns the PID of the current process. */
+qint64 get_pid();
+
+/** Returns true if a process with the given PID is running. */
+bool is_process_running(qint64 pid);
+
+/** Writes the given file to disk containing the current process's PID. */
+bool write_pidfile(QString pidfile, QString *errmsg = 0);
+
+/** Reads the giiven pidfile and returns the value in it. If the file does not
+ * exist, -1 is returned. */
+qint64 read_pidfile(QString pidfile, QString *errmsg = 0);
+
+#endif
+
Property changes on: vidalia/trunk/src/common/procutil.h
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Modified: vidalia/trunk/src/vidalia/main.cpp
===================================================================
--- vidalia/trunk/src/vidalia/main.cpp 2008-05-10 03:58:30 UTC (rev 2570)
+++ vidalia/trunk/src/vidalia/main.cpp 2008-05-10 04:23:18 UTC (rev 2571)
@@ -18,7 +18,7 @@
#include <vidalia.h>
#include <mainwindow.h>
#include <vmessagebox.h>
-#include <process.h>
+#include <procutil.h>
#include <stringutil.h>
#if defined(Q_OS_WIN32)