From: Wichert Akkerman Date: Fri, 23 Feb 2001 15:07:35 +0000 (+0000) Subject: utils/start-stop-daemon.c: Add OpenBSD support X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7f0e716370eaee40e7804ba3f257500a69c314b3;p=dpkg utils/start-stop-daemon.c: Add OpenBSD support utils/md5sum.c: include unistd.h to things compile on OpenBSD configure.in: test to see if we need to link to kvm --- diff --git a/ChangeLog b/ChangeLog index 36454462..2fb0a23b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Fri Feb 23 15:54:00 CET 2001 Wichert Akkerman + + * utils/start-stop-daemon.c: Add OpenBSD support + * utils/md5sum.c: include unistd.h to things compile on OpenBSD + * configure.in: test to see if we need to link to kvm + Fri Feb 23 10:22:02 CET 2001 Wichert Akkerman * scripts/dpkg-divert.pl: fix typo in usage message @@ -7,7 +13,7 @@ Fri Feb 23 10:22:02 CET 2001 Wichert Akkerman Thu Feb 15 11:24:46 EST 2001 Ben Collins - * utils/Makefile.in: Do not use libopt.a, since libdpkg.a not includes those + * utils/Makefile.in: Do not use libopt.a, since libdpkg.a now includes those objects * optlib/Makefile.in: do not generate libopt.a * lib/Makefile.in: build libdpkg.a to include the objects from optlib @@ -1156,105 +1162,7 @@ Tue Jan 11 03:34:22 CET 2000 Wichert Akkerman * scripts/dpkg-genchanges.pl: also upload full source if version is *-0.1 * doc/ja/dpkg.8: updated with patch from Hiroshi KISE -Tue Jan 11 18:32:52 CET 2000 Wichert Akkerman - - * configure.in: Fix include in test for alphasort - * Makefile.in: add intl to subdirectory-list - * dpkg-deb/Makefile.in: set top_builddir - * dselect/Makefile.in: set top_builddir - * main/Makefile.in: set top_builddir - * lib/compat.c: add really simple snprintf (doesn't do range-checking) - * lib/compat.c: add sys_siglist - * configure.in: add tests for snprintf and sys_siglist - * include/dpkg.h.in: don't include sys/sysinfo.h, filesdb.c is the only - thing that needs it and it has its own include. - -Tue Jan 11 02:02:00 CET 2000 Wichert Akkerman - - * dselect/baselist.cc: don't specify SA_INTERRUPT, since it's - not portable and the default behaviour - * main/enquiry.c: include sys/termios.h (needed on Solaris) - * lib/lock.c: use EACCESS instead of EWOULDBLOCK - * dselect/main.cc: fix help for -D - * dselect/main.cc: try to lock admindir instead of using readwrite - * dselect/method.cc: switch to using fcntl for lock since that is more - portable, and revamp lockingcode to reduce code duplication - -Mon Jan 10 20:55:45 CET 2000 Wichert Akkerman - - * Update Swedish and Russian translation - -Sun Jan 9 16:11:39 CET 2000 Wichert Akkerman - - * Merge patches from Josip Rodin: - + various text and manpage updates - + dselect/method.cc: don't abort if locking fails but give a - warning - + THANKS: fix various small errors - -Sun Jan 9 01:40:23 CET 2000 Wichert Akkerman - - * scripts/cl-debian.pl: Allow space between `#' and the bugnumber in the - changelog scripts - * scripts/start-stop-daemon.c: test for __sparc__ instead - * scripts/Makefile.in: add optlib to CFLAGS - * utils/start-stop-daemon.c: add option to chroot first, patch from Marco d'Itri - * utils/start-stop-daemon.8: document chroot option - * dselect/pkgtop.cc: use waddnstr to print package description instead of waddch - -Fri Jan 7 18:24:45 CET 2000 Wichert Akkerman - - * dselect/method.cc: pass admindir to dpkg - * dselect/Makefile.in: fix rule to build helpmessages - * dselect/curkeys.h: use curses.h instead of ncurses.h, since someone - decided to play nasty and just remove that - * scripts/: remove dpkg-safelist - * dpkg-deb/build.c: remove dpkg-safelist calls - * main/enquiry.c: redo formula to get fieldwidths for packages - -Wed Jan 5 17:09:45 CET 2000 Wichert Akkerman - - * Merge patch from Tom Lees : - + scripts/dpkg-buildpackage.sh: support debsign - * scripts/update-alternatives.8: fix wrong order of parameters - in ACTION section - * Updated Polish translation - -Sun Dec 26 01:31:08 CET 1999 Wichert Akkerman - - * Update copyright for Swedish translation to SPI instead of Debian - -Sat Dec 25 04:04:48 CET 1999 Wichert Akkerman - - * dselect/pkgtop.cc: use waddnstr instead of waddch so we don't strip - the 8th bit of characters - * Replace `Debian Linux' with `Debian GNU/Linux' in some more places - * Update Spanish translation - * main/enquire.c: always use a minimum width of 80 in list1package - * debian/rules: install dpkg-safefilelist - -Sat Dec 25 02:50:31 CET 1999 Wichert Akkerman - - * Oops, forgot to add scripts/dpkg-safefilelist.{1,pl} - * debian/control: remove double empty line - * dpkg-deb/main.c: Fix help-message - -Fri Dec 24 17:34:30 CET 1999 Wichert Akkerman - - * version-nr: update to 1.6.5 - * doc/Makefile.in: install THANKS - * TODO: remove items that have been done - * lib/showcright.c: exit(0) after showing the copyright since - we don't exec cat anymore - * Patch from David Huggins-Daines : - + main/configure.c: add NULL to execlp() parameters; this fixes the random - segfaults when showing the conffile-diff - -Fri Dec 24 15:35:29 CET 1999 Wichert Akkerman - - * debian/control: add Build-Depends - * THANKS: new file which lists everyone who contributed to the code - * Change `Debian Linux' to `Debian GNU/Linux' in a couple of manpages +Tue Jan 11 18:32:52 CET 2000 Wichert Akkerman #include #include +#include #include "config.h" diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index 7906620f..73a58a16 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -13,23 +13,41 @@ * * Changes by Ben Collins , added --chuid, --background * and --make-pidfile options, placed in public domain aswell. + * + * Port to OpenBSD by Sontri Tomo Huynh + * and Andreas Schuldei */ #include "config.h" #if defined(linux) -#define OSLinux +# define OSLinux #elif defined(__GNU__) -#define OSHURD +# define OSHURD #elif defined(__sparc__) -#define OSsunos +# define OSsunos +#elif defined(OPENBSD) +# define OSOpenBSD #else -#error Unknown architecture - cannot build start-stop-daemon +# error Unknown architecture - cannot build start-stop-daemon #endif -#ifdef OSHURD -#include -#include +#if defined(OSHURD) +# include +# include +#endif + +#if defined(OSOpenBSD) +#include +#include +#include +#include +#include +#include + +#include +#include +#include #endif #include @@ -50,10 +68,10 @@ #include #ifdef HAVE_ERROR_H -#include +# include #endif #ifdef HURD_IHASH_H -#include + #include #endif static int testmode = 0; @@ -205,25 +223,25 @@ struct sigpair { }; const struct sigpair siglist[] = { - { "ABRT", SIGABRT }, - { "ALRM", SIGALRM }, - { "FPE", SIGFPE }, - { "HUP", SIGHUP }, - { "ILL", SIGILL }, - { "INT", SIGINT }, - { "KILL", SIGKILL }, - { "PIPE", SIGPIPE }, - { "QUIT", SIGQUIT }, - { "SEGV", SIGSEGV }, - { "TERM", SIGTERM }, - { "USR1", SIGUSR1 }, - { "USR2", SIGUSR2 }, - { "CHLD", SIGCHLD }, - { "CONT", SIGCONT }, - { "STOP", SIGSTOP }, - { "TSTP", SIGTSTP }, - { "TTIN", SIGTTIN }, - { "TTOU", SIGTTOU } + { "ABRT", SIGABRT }, + { "ALRM", SIGALRM }, + { "FPE", SIGFPE }, + { "HUP", SIGHUP }, + { "ILL", SIGILL }, + { "INT", SIGINT }, + { "KILL", SIGKILL }, + { "PIPE", SIGPIPE }, + { "QUIT", SIGQUIT }, + { "SEGV", SIGSEGV }, + { "TERM", SIGTERM }, + { "USR1", SIGUSR1 }, + { "USR2", SIGUSR2 }, + { "CHLD", SIGCHLD }, + { "CONT", SIGCONT }, + { "STOP", SIGSTOP }, + { "TSTP", SIGTSTP }, + { "TTIN", SIGTTIN }, + { "TTOU", SIGTTOU } }; static int parse_signal (const char *signal_str, int *signal_nr) @@ -417,34 +435,35 @@ pid_is_cmd(int pid, const char *name) } #endif /* OSLinux */ + #if defined(OSHURD) static int pid_is_user(int pid, int uid) { - struct stat sb; - char buf[32]; - struct proc_stat *pstat; - - sprintf(buf, "/proc/%d", pid); - if (stat(buf, &sb) != 0) - return 0; - return (sb.st_uid == uid); - pstat = proc_stat_list_pid_proc_stat (procset, pid); - if (pstat == NULL) - fatal ("Error getting process information: NULL proc_stat struct"); - proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID); - return (pstat->owner_uid == uid); + struct stat sb; + char buf[32]; + struct proc_stat *pstat; + + sprintf(buf, "/proc/%d", pid); + if (stat(buf, &sb) != 0) + return 0; + return (sb.st_uid == uid); + pstat = proc_stat_list_pid_proc_stat (procset, pid); + if (pstat == NULL) + fatal ("Error getting process information: NULL proc_stat struct"); + proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_OWNER_UID); + return (pstat->owner_uid == uid); } static int pid_is_cmd(int pid, const char *name) { - struct proc_stat *pstat; - pstat = proc_stat_list_pid_proc_stat (procset, pid); - if (pstat == NULL) - fatal ("Error getting process information: NULL proc_stat struct"); - proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS); - return (!strcmp (name, pstat->args)); + struct proc_stat *pstat; + pstat = proc_stat_list_pid_proc_stat (procset, pid); + if (pstat == NULL) + fatal ("Error getting process information: NULL proc_stat struct"); + proc_stat_set_flags (pstat, PSTAT_PID | PSTAT_ARGS); + return (!strcmp (name, pstat->args)); } #endif /* OSHURD */ @@ -516,35 +535,130 @@ do_procinit(void) error_t check_all (void *ptr) { - struct proc_stat *pstat = ptr; + struct proc_stat *pstat = ptr; - check (pstat->pid); - return (0); + check (pstat->pid); + return (0); } static void do_procinit(void) { - struct ps_context *context; - error_t err; + struct ps_context *context; + error_t err; - err = ps_context_create (getproc (), &context); - if (err) - error (1, err, "ps_context_create"); + err = ps_context_create (getproc (), &context); + if (err) + error (1, err, "ps_context_create"); - err = proc_stat_list_create (context, &procset); - if (err) - error (1, err, "proc_stat_list_create"); + err = proc_stat_list_create (context, &procset); + if (err) + error (1, err, "proc_stat_list_create"); - err = proc_stat_list_add_all (procset, 0, 0); - if (err) - error (1, err, "proc_stat_list_add_all"); + err = proc_stat_list_add_all (procset, 0, 0); + if (err) + error (1, err, "proc_stat_list_add_all"); - /* Check all pids */ - ihash_iterate (context->procs, check_all); + /* Check all pids */ + ihash_iterate (context->procs, check_all); } #endif /* OSHURD */ + +#if defined(OSOpenBSD) +int +pid_is_cmd(int pid, const char *name) +{ + kvm_t *kd; + int nentries, argv_len=0; + struct kinfo_proc *kp; + char errbuf[_POSIX2_LINE_MAX], buf[_POSIX2_LINE_MAX]; + char **pid_argv_p; + char *start_argv_0_p, *end_argv_0_p; + + + kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (kd == 0) + errx(1, "%s", errbuf); + if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0) + errx(1, "%s", kvm_geterr(kd)); + if ( ( pid_argv_p = kvm_getargv(kd, kp, argv_len)) == 0) + errx(1, "%s", kvm_geterr(kd)); + + start_argv_0_p = *pid_argv_p; + /* find and compare string */ + + /* find end of argv[0] then copy and cut of str there. */ + if ( (end_argv_0_p = strchr(*pid_argv_p, ' ')) == 0 ) + /* There seems to be no space, so we have the command + * allready in its desired form. */ + start_argv_0_p = *pid_argv_p; + else { + /* Tests indicate that this never happens, since + * kvm_getargv itselfe cuts of tailing stuff. This is + * not what the manpage says, however. */ + strncpy(buf, *pid_argv_p, (end_argv_0_p - start_argv_0_p)); + buf[(end_argv_0_p - start_argv_0_p) + 1] = '\0'; + start_argv_0_p = buf; + } + + if (strlen(name) != strlen(start_argv_0_p)) + return 0; + return (strcmp(name, start_argv_0_p) == 0) ? 1 : 0; +} + +int +pid_is_user(int pid, int uid) +{ + kvm_t *kd; + int nentries; /* Value not used */ + uid_t proc_uid; + struct kinfo_proc *kp; + char errbuf[_POSIX2_LINE_MAX]; + + + kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (kd == 0) + errx(1, "%s", errbuf); + if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0) + errx(1, "%s", kvm_geterr(kd)); + if ( kp->kp_proc.p_cred ) + kvm_read(kd, (u_long)&(kp->kp_proc.p_cred->p_ruid), + &proc_uid, sizeof(uid_t)); + else + return 0; + return (proc_uid == (uid_t)uid); +} + +int +pid_is_exec(int pid, const char *name) +{ + kvm_t *kd; + int nentries; + struct kinfo_proc *kp; + char errbuf[_POSIX2_LINE_MAX], *pidexec; + + kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errbuf); + if (kd == 0) + errx(1, "%s", errbuf); + if ((kp = kvm_getprocs(kd, KERN_PROC_PID, pid, &nentries)) == 0) + errx(1, "%s", kvm_geterr(kd)); + pidexec = (&kp->kp_proc)->p_comm; + if (strlen(name) != strlen(pidexec)) + return 0; + return (strcmp(name, pidexec) == 0) ? 1 : 0; +} + + +static void +do_procinit(void) +{ + /* Nothing to do */ +} + +#endif /* OSOpenBSD */ + + /* return 1 on failure */ static int do_stop(void) @@ -708,7 +822,7 @@ main(int argc, char **argv) close(fd); chdir("/"); umask(022); /* set a default for dumb programs */ - setpgrp(); /* set the process group */ + setpgid(0,0); /* set the process group */ fd=open("/dev/null", O_RDWR); /* stdin */ dup(fd); /* stdout */ dup(fd); /* stderr */