From: Wichert Akkerman Date: Mon, 11 Oct 1999 15:42:59 +0000 (+0000) Subject: Add support for HURD to start-stop-daemon X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ddaff1f222609a64e47c0e9a74b952684aefdb05;p=dpkg Add support for HURD to start-stop-daemon Move start-stop-daemon to a new utils/ subdirectory --- diff --git a/ChangeLog b/ChangeLog index e70d30f1..a92607cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 11 17:37:47 CEST 1999 Wichert Akkerman + + * Added support for HURD to start-stop-daemon + * Create new directory utils/ for extra C-programs, and move + start-stop-daemon there. + Mon Oct 11 15:47:18 CEST 1999 Wichert Akkerman * Preparation to move start-stop-daemon from scripts to utils diff --git a/autogen.sh b/autogen.sh new file mode 100755 index 00000000..5f5b83d8 --- /dev/null +++ b/autogen.sh @@ -0,0 +1,20 @@ +#! /bin/sh + +# Start by setting up everything for main tree +aclocal -I ./automake +autohedaer +gettextize +libtoolize +automake --add-missing --foreign +autoconf + +# Utils has it's own configure, so we need to repeat this there +cd utils +aclocal -I ../automake +autoheader +automake --foreign +autoconf + +# Return to the previous directory +cd .. + diff --git a/configure.in b/configure.in index d17b03ae..01c9d891 100644 --- a/configure.in +++ b/configure.in @@ -205,7 +205,8 @@ fi echo "#define DPKG_VERSION \"$VERSION\" /* This line modified by configure */" > version.h.new cmp -s version.h.new version.h || mv version.h.new version.h +AC_CONFIG_SUBDIRS(utils) AC_OUTPUT([Makefile intl/Makefile dpkg-deb/Makefile lib/Makefile include/Makefile dselect/Makefile split/Makefile methods/Makefile md5sum/Makefile main/Makefile doc/Makefile doc/ja/Makefile scripts/Makefile - po/Makefile.in]) + utils/Makefile po/Makefile.in]) diff --git a/debian/rules b/debian/rules index ea301855..dc2ee194 100755 --- a/debian/rules +++ b/debian/rules @@ -21,6 +21,11 @@ maintainer-configure: Makefile.am configure.in patch -p0 < debian/ltconfig-1.3.2.diff automake --copy --add-missing --foreign autoconf + cd utils ; \ + aclocal -I ../automake ; \ + autoheader ; \ + automake --foreign ; \ + autoconf $(BUILD)/config.status: $(checkdir) diff --git a/utils/.cvsignore b/utils/.cvsignore index 70845e08..27b7fef1 100644 --- a/utils/.cvsignore +++ b/utils/.cvsignore @@ -1 +1,5 @@ Makefile.in +configure +aclocal.m4 +Makefile.in +stamp-h.in diff --git a/utils/Makefile.am b/utils/Makefile.am index 3b890ea4..953310a5 100644 --- a/utils/Makefile.am +++ b/utils/Makefile.am @@ -9,12 +9,12 @@ localedir = $(datadir)/locale ## Various options -CFLAGS = @CFLAGS@ @CWARNS@ -g $(XCFLAGS) -DLOCALEDIR=\"$(localedir)\" +CFLAGS = @CFLAGS@ -g $(XCFLAGS) -DLOCALEDIR=\"$(localedir)\" OPTCFLAGS = @CFLAGS@ @OPTCFLAGS@ @CWARNS@ -g $(XCFLAGS) -DLOCALEDIR=\"$(localedir)\" LDFLAGS = @LDFLAGS@ $(XLDFLAGS) -LIBS = @INTLLIBS@ @LIBS@ $(XLIBS) +LIBS = @LIBS@ $(XLIBS) -CXXFLAGS = @CXXFLAGS@ @CWARNS@ -g $(XCXXFLAGS) -DLOCALEDIR=\"$(localedir)\" +CXXFLAGS = @CXXFLAGS@ -g $(XCXXFLAGS) -DLOCALEDIR=\"$(localedir)\" OPTCXXFLAGS = @CXXFLAGS @OPTCFLAGS@ @CWARNS@ -g $(XCXXFLAGS) -DLOCALEDIR=\"$(localedir)\" DEFS = -I$(top_srcdir)/include -I$(top_srcdir) -I$(srcdir) \ diff --git a/utils/configure.in b/utils/configure.in new file mode 100644 index 00000000..6bcefa0a --- /dev/null +++ b/utils/configure.in @@ -0,0 +1,23 @@ +dnl Process this file with autoconf to produce a configure script. + +AC_PREREQ([2.12]) + +AC_INIT(start-stop-daemon.c) +AM_CONFIG_HEADER(config.h) + +AC_PROG_CC +AC_CANONICAL_SYSTEM +AC_CHECK_TOOL_PREFIX + +AM_INIT_AUTOMAKE(start-stop-daemon,[`sed -n '1s/dpkg (\([0-9.]\+\)).*/\1/p' ${srcdir}/../debian/changelog`]) + +AC_PREFIX_DEFAULT(/) + +AC_PROG_INSTALL + +AC_CHECK_HEADERS(error.h hurd.h ps.h hurd/ihash.h) + +AC_CHECK_LIB(shouldbeinlibc, fmt_past_time) +AC_CHECK_LIB(ps, proc_stat_list_pid_proc_stat) + +AC_OUTPUT(Makefile) diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c index f062e1be..66dc2470 100644 --- a/utils/start-stop-daemon.c +++ b/utils/start-stop-daemon.c @@ -11,6 +11,24 @@ * changes by Klee Dienes , also placed in the Public * Domain. */ +#include "config.h" +#define _GNU_SOURCE + +#ifdef linux +#define OSLinux +#endif + +#ifdef __GNU__ +#define OSHURD +#endif + +#ifdef HAVE_HURH_H +#include +#endif +#ifdef HAVE_PS_H +#include +#endif + #include #include #include @@ -23,7 +41,12 @@ #include #include -#define VERSION "version 0.4.1, 1997-01-29" +#ifdef HAVE_ERROR_H +#include +#endif +#ifdef HURD_IHASH_H +#include +#endif static int testmode = 0; static int quietmode = 0; @@ -41,6 +64,11 @@ static const char *pidfile = NULL; static const char *progname = ""; static struct stat exec_stat; +#if defined(OSHURD) +static struct ps_context *context; +static struct proc_stat_list *procset; +#endif + struct pid_list { struct pid_list *next; @@ -54,13 +82,16 @@ static void *xmalloc(int size); static void push(struct pid_list **list, int pid); static void do_help(void); static void parse_options(int argc, char * const *argv); -static int pid_is_exec(int pid, const struct stat *esb); static int pid_is_user(int pid, int uid); static int pid_is_cmd(int pid, const char *name); static void check(int pid); static void do_pidfile(const char *name); -static void do_procfs(void); static void do_stop(void); +#if defined(OSLinux) +static int pid_is_exec(int pid, const struct stat *esb); +#endif +static void do_psinit(void); + #ifdef __GNUC__ static void fatal(const char *format, ...) @@ -284,7 +315,7 @@ parse_options(int argc, char * const *argv) badusage("--start needs --exec or --startas"); } - +#if defined(OSLinux) static int pid_is_exec(int pid, const struct stat *esb) { @@ -334,12 +365,50 @@ pid_is_cmd(int pid, const char *name) fclose(f); return (c == ')' && *name == '\0'); } +#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); +} + +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)); +} +#endif /* OSHURD */ + static void check(int pid) { +#if defined(OSLinux) if (execname && !pid_is_exec(pid, &exec_stat)) +#elif defined(OSHURD) + /* I will try this to see if it works */ + if (execname && !pid_is_cmd(pid, execname)) +#endif return; if (userspec && !pid_is_user(pid, user_id)) return; @@ -364,8 +433,9 @@ do_pidfile(const char *name) } +#if defined(OSLinux) static void -do_procfs(void) +do_procinit(void) { DIR *procdir; struct dirent *entry; @@ -386,6 +456,39 @@ do_procfs(void) if (!foundany) fatal("nothing in /proc - not mounted?"); } +#endif /* OSLinux */ + + +#if defined(OSHURD) +error_t +check_all (void *ptr) +{ + struct proc_stat *pstat = ptr; + + check (pstat->pid); + return (0); +} + +static void +do_psinit(void) + error_t err; + + 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_add_all (procset, 0, 0); + if (err) + error (1, err, "proc_stat_list_add_all"); + + /* Check all pids */ + ihash_iterate (context->procs, check_all); +} +#endif /* OSHURD */ static void @@ -454,7 +557,7 @@ main(int argc, char **argv) if (pidfile) do_pidfile(pidfile); else - do_procfs(); + do_procinit(); if (stop) { do_stop();