Просмотр исходного кода

Add support for HURD to start-stop-daemon
Move start-stop-daemon to a new utils/ subdirectory

Wichert Akkerman лет назад: 27
Родитель
Сommit
ddaff1f222
8 измененных файлов с 172 добавлено и 10 удалено
  1. 6 0
      ChangeLog
  2. 20 0
      autogen.sh
  3. 2 1
      configure.in
  4. 5 0
      debian/rules
  5. 4 0
      utils/.cvsignore
  6. 3 3
      utils/Makefile.am
  7. 23 0
      utils/configure.in
  8. 109 6
      utils/start-stop-daemon.c

+ 6 - 0
ChangeLog

@@ -1,3 +1,9 @@
+Mon Oct 11 17:37:47 CEST 1999 Wichert Akkerman <wakkerma@debian.org>
+
+  * 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 <wakkerma@debian.org>
 
   * Preparation to move start-stop-daemon from scripts to utils

+ 20 - 0
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 ..
+

+ 2 - 1
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])

+ 5 - 0
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)

+ 4 - 0
utils/.cvsignore

@@ -1 +1,5 @@
 Makefile.in
+configure
+aclocal.m4
+Makefile.in
+stamp-h.in

+ 3 - 3
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) \

+ 23 - 0
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)

+ 109 - 6
utils/start-stop-daemon.c

@@ -11,6 +11,24 @@
  * changes by Klee Dienes <klee@debian.org>, 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 <hurd.h>
+#endif
+#ifdef HAVE_PS_H
+#include <ps.h>
+#endif
+
 #include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -23,7 +41,12 @@
 #include <getopt.h>
 #include <pwd.h>
 
-#define VERSION "version 0.4.1, 1997-01-29"
+#ifdef HAVE_ERROR_H
+#include <error.h>
+#endif
+#ifdef HURD_IHASH_H
+#include <hurd/ihash.h>
+#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();