Ticket #39018: dpkg_1.18.3.patch
File dpkg_1.18.3.patch, 21.2 KB (added by xeron (Ivan Larionov), 9 years ago) |
---|
-
sysutils/dpkg/Portfile
diff --git a/sysutils/dpkg/Portfile b/sysutils/dpkg/Portfile index c6f72ca..dd47dc7 100644
a b 1 # $Id: Portfile 105815 2013-05-06 14:52:20Z landonf@macports.org $ 2 3 PortSystem 1.0 4 5 name dpkg 6 version 1.14.29 7 revision 4 8 platforms darwin freebsd 9 categories sysutils archivers 10 license GPL-2+ 11 maintainers nomaintainer 12 description Debian package maintenance system 13 long_description ${description} 14 homepage http://wiki.debian.org/Teams/Dpkg 15 16 master_sites debian:d/dpkg/ 17 checksums md5 4326172a959b5b6484b4bc126e9f628d \ 18 sha1 15a35dd96dac6a99f24844b2eff85f8fad37ab06 1 # -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4 2 # $Id$ 3 4 PortSystem 1.0 5 PortGroup perl5 1.0 6 7 name dpkg 8 version 1.18.3 9 platforms darwin 10 categories sysutils archivers 11 license GPL-2+ 12 maintainers gwmail.gwu.edu:egall openmaintainer 13 description Debian package maintenance system 14 long_description ${name} is the basis of the ${description}. 15 16 homepage http://wiki.debian.org/Teams/Dpkg 17 master_sites debian:d/${name}/ 18 distname ${name}_${version} 19 worksrcdir ${name}-${version} 20 21 use_xz yes 22 extract.asroot yes 23 24 checksums rmd160 baffcdf3bb72ad535d6aacbcee88202488e4612a \ 25 sha256 a40ffe38d7f36d858a752189a306433cfc52c7d15d7b98f61d9f9dd49e0e4807 26 27 depends_build-append \ 28 port:pkgconfig \ 29 port:flex \ 30 port:gnutar \ 31 port:perl${perl5.major} \ 32 bin:lzma:xz 19 33 20 34 # Use MacPorts versions explicitly 21 depends_lib port:gettext \ 22 port:libiconv \ 23 port:perl5 \ 24 port:coreutils \ 25 port:bzip2 \ 26 port:zlib 27 28 depends_run bin:gnutar:gnutar \ 29 bin:lzma:xz 30 31 32 distname ${name}_${version} 33 worksrcdir ${name}-${version} 34 35 patchfiles patch-lib_tarfn.c \ 36 patch-main_remove.c \ 37 patch-main_archives.c \ 38 patch-scripts-Makefile \ 39 patch-lib_dpkg.h \ 40 ncurses.diff 41 42 configure.env PERL=${prefix}/bin/perl5 43 configure.args --without-sgml-doc --with-libintl-prefix=${prefix} \ 44 --with-libiconv-prefix=${prefix} --with-admindir=${prefix}/var/db/dpkg \ 45 --mandir=${prefix}/share/man \ 46 --with-zlib --with-bz2 \ 47 --disable-linker-optimisations 48 49 build.type gnu 50 51 set vardpkg ${destroot}${prefix}/var/db/dpkg 52 destroot.keepdirs ${vardpkg} ${vardpkg}/updates ${vardpkg}/info 53 54 post-patch { 55 set scripts ${worksrcpath}/scripts 56 reinplace s|/etc/dpkg/|${prefix}/etc/dpkg/| \ 57 ${scripts}/dpkg-shlibdeps.pl \ 58 ${scripts}/dpkg-source.pl 59 60 reinplace s|/etc/alternatives|${prefix}/etc/alternatives|g \ 61 ${scripts}/update-alternatives.pl 62 } 35 depends_lib-append port:gettext \ 36 port:libiconv \ 37 port:perl${perl5.major} \ 38 port:coreutils \ 39 port:bzip2 \ 40 port:gzip \ 41 port:zlib \ 42 port:ncurses \ 43 port:gnutar \ 44 path:lib/pkgconfig/liblzma.pc:xz 45 46 depends_run-append port:gnutar \ 47 port:gzip \ 48 port:debianutils \ 49 bin:perl5:perl${perl5.major} \ 50 bin:lzma:xz 51 52 configure.perl ${prefix}/bin/perl5 53 configure.pkg_config ${prefix}/bin/pkg-config 54 configure.env-append TAR=${prefix}/bin/gnutar 55 configure.args-append \ 56 --with-libintl-prefix=${prefix} \ 57 --with-libiconv-prefix=${prefix} \ 58 --with-admindir=${prefix}/var/db/${name} \ 59 --with-logdir=${prefix}/var/log \ 60 --mandir=${prefix}/share/man \ 61 --with-zlib \ 62 --with-bz2 \ 63 --with-liblzma \ 64 --disable-linker-optimisations \ 65 --disable-silent-rules \ 66 --disable-start-stop-daemon 67 68 compiler.blacklist-append cc gcc-3.3 gcc-4.0 apple-gcc-4.0 69 70 build.type gnu 71 72 set vardpkg ${destroot}${prefix}/var/db/${name} 73 destroot.keepdirs-append \ 74 ${vardpkg} \ 75 ${vardpkg}/updates \ 76 ${vardpkg}/info \ 77 ${destroot}${prefix}/var/log \ 78 ${destroot}${prefix}/etc/${name} 79 80 patchfiles-append patch-scripts_Dpkg_Source_Archive.pm.diff 81 82 use_autoreconf yes 83 autoreconf.args -fvi --warnings=all 63 84 64 85 pre-destroot { 65 file mkdir ${destroot}${prefix}/share/doc/dpkg 86 file mkdir ${destroot}${prefix}/share/doc/${name} 66 87 } 67 88 68 89 post-destroot { 69 70 71 72 90 file mkdir ${vardpkg} 91 file mkdir ${vardpkg}/updates 92 file mkdir ${vardpkg}/info 93 system "touch ${vardpkg}/available ${vardpkg}/status" 73 94 } 74 95 75 platform darwin { 76 depends_build-append bin:gnumake:gmake 77 patchfiles-append patch-utils_start-stop-daemon.c bsd/patch-main_help.c 96 # This variant sometimes hangs while building... 97 variant docs description "Build documentation (warning: building documentation takes a long time)" { 98 depends_build-append port:doxygen \ 99 path:bin/dot:graphviz \ 100 port:fontconfig \ 101 port:freefont-ttf 102 set docdir ${prefix}/share/doc/${name} 103 configure.args-append --docdir=${docdir} \ 104 --htmldir=${docdir}/html \ 105 --dvidir=${docdir}/dvi \ 106 --pdfdir=${docdir}/pdf \ 107 --psdir=${docdir}/ps 108 build.target-append doc 109 pre-build { 110 elevateToRoot "doxygen" 111 system -W ${worksrcpath}/doc "${prefix}/bin/doxygen -u" 112 } 113 post-build { 114 system -W ${worksrcpath}/doc "${prefix}/bin/doxygen" 115 dropPrivileges 116 set destroot_docdir ${destroot}${prefix}/share/doc/${name} 117 xinstall -d ${destroot_docdir} 118 copy ${worksrcpath}/doc/doc ${destroot_docdir} 119 copy ${worksrcpath}/doc/html ${destroot_docdir} 120 foreach docfile {coding-style.txt triggers.txt README.feature-removal-schedule frontend.txt README.api} { 121 xinstall -m 644 ${worksrcpath}/doc/${docfile} ${destroot_docdir} 122 } 123 } 78 124 } 79 125 80 platform freebsd { 81 depends_build-append bin:gmake:gmake 82 patchfiles-append patch-utils_start-stop-daemon.c bsd/patch-main_help.c 126 # Tests currently fail, this needs to be fixed eventually: 127 test.run yes 128 test.target check 129 130 pre-test { 131 elevateToRoot "test" 132 } 133 post-test { 134 dropPrivileges 83 135 } 84 136 85 livecheck.type 86 livecheck.url http://ftp.debian.org/debian/pool/main/d/dpkg/87 livecheck.regex 137 livecheck.type regex 138 livecheck.url http://ftp.debian.org/debian/pool/main/d/${name}/ 139 livecheck.regex "${name}_(\\d+\\.\\d+(\\.\\d+)*)" -
deleted file sysutils/dpkg/files/bsd/patch-main_help.c
diff --git a/sysutils/dpkg/files/bsd/patch-main_help.c b/sysutils/dpkg/files/bsd/patch-main_help.c deleted file mode 100644 index e4f4b89..0000000
+ - 1 --- src/help.c.old Thu Dec 9 16:35:16 20042 +++ src/help.c Thu Dec 9 16:35:38 20043 @@ -77,12 +77,11 @@4 5 void checkpath(void) {6 /* Verify that some programs can be found in the PATH. */7 - static const char *const checklist[]= { "ldconfig",8 + static const char *const checklist[]= {9 #if WITH_START_STOP_DAEMON10 "start-stop-daemon",11 #endif12 "install-info",13 - "update-rc.d",14 NULL15 };16 -
deleted file sysutils/dpkg/files/ncurses.diff
diff --git a/sysutils/dpkg/files/ncurses.diff b/sysutils/dpkg/files/ncurses.diff deleted file mode 100644 index 4e49161..0000000
+ - 1 --- dselect/Makefile.in.orig 2010-03-09 07:32:20.000000000 +11002 +++ dselect/Makefile.in 2011-03-11 12:01:25.000000000 +11003 @@ -640,7 +640,7 @@4 5 curkeys.$(OBJEXT): curkeys.h6 curkeys.h: $(srcdir)/keyoverride $(srcdir)/mkcurkeys.pl7 - cursesfile=`echo '#include <ncursesw/curses.h>' | \8 + cursesfile=`echo '#include <curses.h>' | \9 $(CC) -E - | grep 'curses.h' | head -n 1 | \10 sed -e 's/^[^"]*"//; s/".*$$//'`; \11 if [ "$$cursesfile" = "" ]; then \12 --- dselect/dselect.h.orig 2010-03-09 07:27:35.000000000 +110013 +++ dselect/dselect.h 2011-03-11 12:01:43.000000000 +110014 @@ -28,7 +28,7 @@15 16 #include <signal.h>17 #undef ERR18 -#include <ncursesw/curses.h>19 +#include <curses.h>20 21 struct helpmenuentry {22 char key;23 --- dselect/main.cc.orig 2010-03-09 07:27:35.000000000 +110024 +++ dselect/main.cc 2011-03-11 12:01:36.000000000 +110025 @@ -37,7 +37,7 @@ extern "C" {26 #include <ctype.h>27 #include <assert.h>28 29 -#include <ncursesw/term.h>30 +#include <term.h>31 32 extern "C" {33 #include <dpkg.h> -
deleted file sysutils/dpkg/files/patch-lib_dpkg.h
diff --git a/sysutils/dpkg/files/patch-lib_dpkg.h b/sysutils/dpkg/files/patch-lib_dpkg.h deleted file mode 100644 index f683a0c..0000000
+ - 1 --- ./lib/dpkg.h.orig 2010-03-08 21:27:35.000000000 +01002 +++ ./lib/dpkg.h 2011-04-07 09:51:21.000000000 +02003 @@ -147,7 +147,7 @@4 #define DPKG "dpkg"5 #define DEBSIGVERIFY "/usr/bin/debsig-verify"6 7 -#define TAR "tar"8 +#define TAR "gnutar"9 #define GZIP "gzip"10 #define BZIP2 "bzip2"11 #define LZMA "lzma" -
deleted file sysutils/dpkg/files/patch-lib_tarfn.c
diff --git a/sysutils/dpkg/files/patch-lib_tarfn.c b/sysutils/dpkg/files/patch-lib_tarfn.c deleted file mode 100644 index 1365bb8..0000000
+ - 1 --- lib/tarfn.c.orig Wed Jan 26 18:31:15 20052 +++ lib/tarfn.c Wed Jan 26 19:26:19 20053 @@ -18,6 +18,9 @@4 5 #include "strnlen.h"6 7 +static const char ustarMagic[] = { 'u', 's', 't', 'a', 'r', '\0', '0', '0', '\0' };8 +static const char gnutarMagic[] = { 'u', 's', 't', 'a', 'r', ' ', ' ', '\0' };9 +10 struct TarHeader {11 char Name[100];12 char Mode[8];13 @@ -28,11 +31,12 @@14 char Checksum[8];15 char LinkFlag;16 char LinkName[100];17 - char MagicNumber[8];18 + char MagicNumber[8]; /* POSIX: "ustar\000", GNU: "ustar \0" (blank blank null) */19 char UserName[32];20 char GroupName[32];21 char MajorDevice[8];22 char MinorDevice[8];23 + char Prefix[155]; /* POSIX ustar header */24 };25 typedef struct TarHeader TarHeader;26 27 @@ -78,6 +82,10 @@28 struct passwd * passwd = NULL;29 struct group * group = NULL;30 unsigned int i;31 + char *prefix, *name, *file;32 + size_t prefixLen;33 + size_t nameLen;34 + size_t fileLen;35 long sum;36 long checksum;37 38 @@ -86,7 +94,35 @@39 if ( *h->GroupName )40 group = getgrnam(h->GroupName);41 42 - d->Name = StoC(h->Name, sizeof(h->Name));43 + /*44 + * Is this a ustar archive entry?45 + * Is Prefix in use?46 + */47 + if ((memcmp(h->MagicNumber, ustarMagic, sizeof(h->MagicNumber)) == 0) && h->Prefix[0]) {48 + prefixLen = strnlen(h->Prefix, sizeof(h->Prefix));49 +50 + prefix = StoC(h->Prefix, prefixLen);51 + if (h->Prefix[prefixLen - 1] != '/') {52 + prefixLen++; /* Space for '/' */53 + /* The rest of the code doesn't care if malloc fails, so we won't either */54 + prefix = realloc(prefix, prefixLen + 1); /* prefix + \0 */55 + prefix[prefixLen - 1] = '/';56 + prefix[prefixLen] = '\0';57 + }58 +59 + nameLen = strnlen(h->Name, sizeof(h->Name));60 + name = StoC(h->Name, nameLen);61 +62 + file = realloc(prefix, prefixLen + nameLen + 1); /* prefix + name + \0 */63 + strcat(file, name);64 +65 + free(name);66 +67 + d->Name = file;68 + } else {69 + d->Name = StoC(h->Name, sizeof(h->Name));70 + }71 +72 d->LinkName = StoC(h->LinkName, sizeof(h->LinkName));73 d->Mode = (mode_t)OtoL(h->Mode, sizeof(h->Mode));74 d->Size = (size_t)OtoL(h->Size, sizeof(h->Size)); -
deleted file sysutils/dpkg/files/patch-main_archives.c
diff --git a/sysutils/dpkg/files/patch-main_archives.c b/sysutils/dpkg/files/patch-main_archives.c deleted file mode 100644 index 35dbe56..0000000
+ - 1 --- src/archives.c.orig Thu Nov 11 20:10:03 20042 +++ src/archives.c Fri Dec 17 17:34:55 20043 @@ -373,6 +373,7 @@4 static struct varbuf conffderefn, hardlinkfn, symlinkfn;5 static int fd;6 const char *usename;7 + char *s = NULL;8 9 struct conffile *conff;10 struct tarcontext *tc= (struct tarcontext*)ti->UserData;11 @@ -423,7 +424,15 @@12 }13 }14 15 - usename= namenodetouse(nifd->namenode,tc->pkg)->name + 1; /* Skip the leading `/' */16 + usename= namenodetouse(nifd->namenode,tc->pkg)->name; /* Skip the leading `/' */17 + if (*usename == '.' && *usename + 1 == '/') {18 + usename += 1; /* Skip the leading `.' */19 + } else if (*usename != '/') {20 + s = malloc(strlen(usename) + 2); /* 1 for NULL, one for `/' we're going to add */21 + strcpy(s + 1, usename);22 + *s = '/';23 + usename = s;24 + }25 26 if (nifd->namenode->flags & fnnf_new_conff) {27 /* If it's a conffile we have to extract it next to the installed28 @@ -435,6 +444,10 @@29 }30 31 setupfnamevbs(usename);32 +33 + if (s != NULL) {34 + free(s);35 + }36 37 statr= lstat(fnamevb.buf,&stab);38 if (statr) { -
deleted file sysutils/dpkg/files/patch-main_remove.c
diff --git a/sysutils/dpkg/files/patch-main_remove.c b/sysutils/dpkg/files/patch-main_remove.c deleted file mode 100644 index d9fe787..0000000
+ - 1 --- src/remove.c.orig Fri Dec 10 15:48:16 20042 +++ src/remove.c Fri Dec 10 15:51:29 20043 @@ -266,7 +266,18 @@4 push_leftover(&leftover,namenode);5 continue;6 }7 - if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);8 + if (errno != ENOTDIR) {9 + /* XXX Hack:10 + * dpkg includes /. in the packing list.11 + * rmdir("/.") will return EINVAL. dpkg will12 + * only attempt to remove /. when uninstalling13 + * the last package on the system, which is why14 + * Debian has never run into this issue. */15 + if (errno == EINVAL && strcmp(fnvb.buf, "/.") == 0)16 + continue;17 + else18 + ohshite(_("cannot remove `%.250s'"),fnvb.buf);19 + }20 debug(dbg_eachfiledetail, "removal_bulk unlinking `%s'", fnvb.buf);21 {22 /*23 @@ -383,7 +394,18 @@24 push_leftover(&leftover,namenode);25 continue;26 }27 - if (errno != ENOTDIR) ohshite(_("cannot remove `%.250s'"),fnvb.buf);28 + if (errno != ENOTDIR) {29 + /* XXX Hack:30 + * dpkg includes /. in the packing list.31 + * rmdir("/.") will return EINVAL. dpkg will32 + * only attempt to remove /. when uninstalling33 + * the last package on the system, which is why34 + * Debian has never run into this issue. */35 + if (errno == EINVAL && strcmp(fnvb.buf, "/.") == 0)36 + continue;37 + else38 + ohshite(_("cannot remove `%.250s'"),fnvb.buf);39 + }40 41 push_leftover(&leftover,namenode);42 continue; -
deleted file sysutils/dpkg/files/patch-scripts-Makefile
diff --git a/sysutils/dpkg/files/patch-scripts-Makefile b/sysutils/dpkg/files/patch-scripts-Makefile deleted file mode 100644 index 823c12a..0000000
+ - 1 --- scripts/Makefile.am.orig 2010-03-08 21:27:35.000000000 +01002 +++ scripts/Makefile.am 2011-01-03 10:15:37.000000000 +01003 @@ -123,7 +123,7 @@ nobase_dist_perllib_DATA = \4 Dpkg/Source/Patch.pm \5 Dpkg.pm6 7 -do_perl_subst = sed -e "s:^\#![:space:]*/usr/bin/perl:\#!$(PERL):" \8 +do_perl_subst = sed -e "s:^\#![[:space:]]*/usr/bin/perl:\#!$(PERL):" \9 -e "s:\$$dpkglibdir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$dpkglibdir=\"$(pkglibdir)\":" \10 -e "s:\$$pkgdatadir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$pkgdatadir=\"$(pkgdatadir)\":" \11 -e "s:\$$admindir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$admindir=\"$(admindir)\":" \12 --- scripts/Makefile.in.orig 2010-03-08 21:32:20.000000000 +010013 +++ scripts/Makefile.in 2011-01-03 10:15:50.000000000 +010014 @@ -330,7 +330,7 @@ nobase_dist_perllib_DATA = \15 Dpkg/Source/Patch.pm \16 Dpkg.pm17 18 -do_perl_subst = sed -e "s:^\#![:space:]*/usr/bin/perl:\#!$(PERL):" \19 +do_perl_subst = sed -e "s:^\#![[:space:]]*/usr/bin/perl:\#!$(PERL):" \20 -e "s:\$$dpkglibdir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$dpkglibdir=\"$(pkglibdir)\":" \21 -e "s:\$$pkgdatadir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$pkgdatadir=\"$(pkgdatadir)\":" \22 -e "s:\$$admindir[[:space:]]*=[[:space:]]*['\"][^'\"]*['\"]:\$$admindir=\"$(admindir)\":" \ -
new file sysutils/dpkg/files/patch-scripts_Dpkg_Source_Archive.pm.diff
diff --git a/sysutils/dpkg/files/patch-scripts_Dpkg_Source_Archive.pm.diff b/sysutils/dpkg/files/patch-scripts_Dpkg_Source_Archive.pm.diff new file mode 100644 index 0000000..b6d391d
- + 1 --- scripts/Dpkg/Source/Archive.pm.orig 2015-11-19 21:10:57.000000000 -0800 2 +++ scripts/Dpkg/Source/Archive.pm 2015-11-19 21:18:41.000000000 -0800 3 @@ -48,7 +48,7 @@ 4 $spawn_opts{from_pipe} = \*$self->{tar_input}; 5 # Call tar creation process 6 $spawn_opts{delete_env} = [ 'TAR_OPTIONS' ]; 7 - $spawn_opts{exec} = [ 'tar', '-cf', '-', '--format=gnu', '--null', 8 + $spawn_opts{exec} = [ 'gnutar', '-cf', '-', '--format=gnu', '--null', 9 '--numeric-owner', '--owner=0', '--group=0', 10 @{$opts{options}}, '-T', '-' ]; 11 *$self->{pid} = spawn(%spawn_opts); 12 @@ -90,7 +90,7 @@ 13 my $self = shift; 14 15 close(*$self->{tar_input}) or syserr(g_('close on tar input')); 16 - wait_child(*$self->{pid}, cmdline => 'tar -cf -'); 17 + wait_child(*$self->{pid}, cmdline => 'gnutar -cf -'); 18 delete *$self->{pid}; 19 delete *$self->{tar_input}; 20 delete *$self->{cwd}; 21 @@ -126,7 +126,7 @@ 22 23 # Call tar extraction process 24 $spawn_opts{delete_env} = [ 'TAR_OPTIONS' ]; 25 - $spawn_opts{exec} = [ 'tar', '-xf', '-', '--no-same-permissions', 26 + $spawn_opts{exec} = [ 'gnutar', '-xf', '-', '--no-same-permissions', 27 '--no-same-owner', @{$opts{options}} ]; 28 spawn(%spawn_opts); 29 $self->close(); -
deleted file sysutils/dpkg/files/patch-utils_start-stop-daemon.c
diff --git a/sysutils/dpkg/files/patch-utils_start-stop-daemon.c b/sysutils/dpkg/files/patch-utils_start-stop-daemon.c deleted file mode 100644 index 608cb53..0000000
+ - 1 --- utils/start-stop-daemon.c.orig Thu Nov 11 12:10:04 20042 +++ utils/start-stop-daemon.c Mon Dec 13 16:02:18 20043 @@ -38,6 +38,8 @@4 # define OSFreeBSD5 #elif defined(__NetBSD__)6 # define OSNetBSD7 +#elif defined(__APPLE__)8 +# define OSDarwin9 #else10 # error Unknown architecture - cannot build start-stop-daemon11 #endif12 @@ -49,7 +51,8 @@13 #include <ps.h>14 #endif15 16 -#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD)17 +#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)18 +#include <sys/time.h>19 #include <sys/param.h>20 #include <sys/proc.h>21 #include <sys/stat.h>22 @@ -804,7 +807,7 @@23 #if defined(OSLinux) || defined(OShpux)24 if (execname && !pid_is_exec(pid, &exec_stat))25 return;26 -#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD)27 +#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)28 /* Let's try this to see if it works */29 if (execname && !pid_is_cmd(pid, execname))30 return;31 @@ -882,6 +882,7 @@32 }33 #endif /* OSHURD */34 35 +#if defined(OSOpenBSD) || defined(OSFreeBSD) || defined(OSNetBSD)36 #ifdef HAVE_KVM_H37 static int38 pid_is_cmd(pid_t pid, const char *name)39 @@ -974,6 +975,7 @@40 {41 /* Nothing to do */42 }43 +#endif44 #endif /* OSOpenBSD */45 46 #if defined(OShpux)47 @@ -975,6 +954,80 @@48 /* Nothing to do */49 }50 #endif /* OSOpenBSD */51 +52 +#if defined(OSDarwin)53 +#include <sys/sysctl.h>54 +int55 +pid_is_user(pid_t pid, uid_t uid)56 +{57 + int mib[4];58 + size_t size;59 + struct kinfo_proc ki;60 +61 + size = sizeof(ki);62 + mib[0] = CTL_KERN;63 + mib[1] = KERN_PROC;64 + mib[2] = KERN_PROC_PID;65 + mib[3] = pid;66 + if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)67 + errx(1, "%s", "Failure calling sysctl");68 + return (uid == ki.kp_eproc.e_pcred.p_ruid);69 +}70 +71 +static int72 +pid_is_cmd(pid_t pid, const char *name)73 +{74 + int mib[4];75 + size_t size;76 + struct kinfo_proc ki;77 +78 + size = sizeof(ki);79 + mib[0] = CTL_KERN;80 + mib[1] = KERN_PROC;81 + mib[2] = KERN_PROC_PID;82 + mib[3] = pid;83 + if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)84 + errx(1, "%s", "Failure calling sysctl");85 + return (!strncmp(name, ki.kp_proc.p_comm, MAXCOMLEN));86 +}87 +88 +static void89 +do_procinit(void)90 +{91 + int mib[3];92 + size_t size;93 + int nprocs, ret, i;94 + struct kinfo_proc *procs = NULL, *newprocs;95 +96 + mib[0] = CTL_KERN;97 + mib[1] = KERN_PROC;98 + mib[2] = KERN_PROC_ALL;99 + ret = sysctl(mib, 3, NULL, &size, NULL, 0);100 + /* Allocate enough memory for entire process table */101 + do {102 + size += size / 10;103 + newprocs = realloc(procs, size);104 + if (newprocs == NULL) {105 + if (procs)106 + free(procs);107 + errx(1, "%s", "Could not reallocate memory");108 + }109 + procs = newprocs;110 + ret = sysctl(mib, 3, procs, &size, NULL, 0);111 + } while (ret >= 0 && errno == ENOMEM);112 +113 + if (ret < 0)114 + errx(1, "%s", "Failure calling sysctl");115 +116 + /* Verify size of proc structure */117 + if (size % sizeof(struct kinfo_proc) != 0)118 + errx(1, "%s", "proc size mismatch, userland out of sync with kernel");119 + nprocs = size / sizeof(struct kinfo_proc);120 + for (i = 0; i < nprocs; i++) {121 + check(procs[i].kp_proc.p_pid);122 + }123 +}124 +#endif /* OSDarwin */125 126 #if defined(OShpux)127 static int