summaryrefslogtreecommitdiff
path: root/apt-pkg/deb
diff options
context:
space:
mode:
Diffstat (limited to 'apt-pkg/deb')
-rw-r--r--apt-pkg/deb/dpkginit.cc105
-rw-r--r--apt-pkg/deb/dpkginit.h33
-rw-r--r--apt-pkg/deb/dpkgpm.cc3
-rw-r--r--apt-pkg/deb/dpkgpm.h3
4 files changed, 141 insertions, 3 deletions
diff --git a/apt-pkg/deb/dpkginit.cc b/apt-pkg/deb/dpkginit.cc
new file mode 100644
index 000000000..095156d0d
--- /dev/null
+++ b/apt-pkg/deb/dpkginit.cc
@@ -0,0 +1,105 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: dpkginit.cc,v 1.1 1998/11/23 07:03:10 jgg Exp $
+/* ######################################################################
+
+ DPKG init - Initialize the dpkg stuff
+
+ ##################################################################### */
+ /*}}}*/
+// Includes /*{{{*/
+#ifdef __GNUG__
+#pragma implementation "apt-pkg/dpkginit.h"
+#endif
+#include <apt-pkg/dpkginit.h>
+#include <apt-pkg/error.h>
+#include <apt-pkg/configuration.h>
+#include <apt-pkg/fileutl.h>
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <dirent.h>
+ /*}}}*/
+
+// DpkgLock::pkgDpkgLock - Constructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgDpkgLock::pkgDpkgLock()
+{
+ LockFD = -1;
+ GetLock();
+}
+ /*}}}*/
+// DpkgLock::~pkgDpkgLock - Destructor /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+pkgDpkgLock::~pkgDpkgLock()
+{
+ Close();
+}
+ /*}}}*/
+// DpkgLock::GetLock - Get the lock /*{{{*/
+// ---------------------------------------------------------------------
+/* This mirrors the operations dpkg does when it starts up. Note the
+ checking of the updates directory. */
+bool pkgDpkgLock::GetLock()
+{
+ // Disable file locking
+ if (_config->FindB("Debug::NoLocking",false) == true)
+ return true;
+
+ Close();
+
+ // Create the lockfile
+ string AdminDir = flNotFile(_config->Find("Dir::State::status"));
+ LockFD = ::GetLock(AdminDir + "lock");
+ if (LockFD == -1)
+ return _error->Errno("Open","Unable to lock the administration directory "
+ "%s, are you root?",AdminDir.c_str());
+
+ // Check for updates.. (dirty)
+ string File = AdminDir + "updates/";
+ DIR *DirP = opendir(File.c_str());
+ if (DirP != 0)
+ {
+ /* We ignore any files that are not all digits, this skips .,.. and
+ some tmp files dpkg will leave behind.. */
+ bool Damaged = false;
+ for (struct dirent *Ent = readdir(DirP); Ent != 0; Ent = readdir(DirP))
+ {
+ Damaged = true;
+ for (unsigned int I = 0; Ent->d_name[I] != 0; I++)
+ {
+ // Check if its not a digit..
+ if (isdigit(Ent->d_name[I]) == 0)
+ {
+ Damaged = false;
+ break;
+ }
+ }
+ if (Damaged == true)
+ break;
+ }
+ closedir(DirP);
+
+ // Woops, we have to run dpkg to rewrite the status file
+ if (Damaged == true)
+ {
+ Close();
+ return _error->Error("dpkg was interrupted, you must manually "
+ "run 'dpkg --configure -a' to correct the problem. ");
+ }
+ }
+
+ return true;
+}
+ /*}}}*/
+// DpkgLock::Close - Close the lock /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+void pkgDpkgLock::Close()
+{
+ close(LockFD);
+ LockFD = -1;
+}
+ /*}}}*/
diff --git a/apt-pkg/deb/dpkginit.h b/apt-pkg/deb/dpkginit.h
new file mode 100644
index 000000000..288f50d04
--- /dev/null
+++ b/apt-pkg/deb/dpkginit.h
@@ -0,0 +1,33 @@
+// -*- mode: cpp; mode: fold -*-
+// Description /*{{{*/
+// $Id: dpkginit.h,v 1.1 1998/11/23 07:03:11 jgg Exp $
+/* ######################################################################
+
+ DPKG init - Initialize the dpkg stuff
+
+ This basically gets a lock in /var/lib/dpkg and checks the updates
+ directory
+
+ ##################################################################### */
+ /*}}}*/
+#ifndef PKGLIB_DPKGINIT_H
+#define PKGLIB_DPKGINIT_H
+
+#ifdef __GNUG__
+#pragma interface "apt-pkg/dpkginit.h"
+#endif
+
+class pkgDpkgLock
+{
+ int LockFD;
+
+ public:
+
+ bool GetLock();
+ void Close();
+
+ pkgDpkgLock();
+ ~pkgDpkgLock();
+};
+
+#endif
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index dfdc0c4b5..e437ad7a3 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/apt-pkg/deb/dpkgpm.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: dpkgpm.cc,v 1.2 1998/11/22 03:20:35 jgg Exp $
+// $Id: dpkgpm.cc,v 1.3 1998/11/23 07:03:11 jgg Exp $
/* ######################################################################
DPKG Package Manager - Provide an interface to dpkg
@@ -163,6 +163,7 @@ bool pkgDPkgPM::Go()
// This is the child
if (Child == 0)
{
+ signal(SIGPIPE,SIG_DFL);
signal(SIGQUIT,SIG_DFL);
signal(SIGINT,SIG_DFL);
signal(SIGWINCH,SIG_DFL);
diff --git a/apt-pkg/deb/dpkgpm.h b/apt-pkg/deb/dpkgpm.h
index b5f08ea32..dcb6e9db0 100644
--- a/apt-pkg/deb/dpkgpm.h
+++ b/apt-pkg/deb/dpkgpm.h
@@ -1,13 +1,12 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: dpkgpm.h,v 1.1 1998/11/13 04:23:39 jgg Exp $
+// $Id: dpkgpm.h,v 1.2 1998/11/23 07:03:12 jgg Exp $
/* ######################################################################
DPKG Package Manager - Provide an interface to dpkg
##################################################################### */
/*}}}*/
-// Header section: pkglib
#ifndef PKGLIB_DPKGPM_H
#define PKGLIB_DPKGPM_H