/[gentoo-alt]/trunk/baselayout-prefix/src/start-stop-daemon.c
Gentoo

Diff of /trunk/baselayout-prefix/src/start-stop-daemon.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1687 Revision 1688
54# define OSFreeBSD 54# define OSFreeBSD
55#elif defined(__NetBSD__) 55#elif defined(__NetBSD__)
56# define OSNetBSD 56# define OSNetBSD
57#elif defined(__APPLE__) 57#elif defined(__APPLE__)
58# define OSDarwin 58# define OSDarwin
59#elif defined(_AIX)
60# define OSaix
59#else 61#else
60# error Unknown architecture - cannot build start-stop-daemon 62# error Unknown architecture - cannot build start-stop-daemon
61#endif 63#endif
62 64
63#define MIN_POLL_INTERVAL 20000 /*us*/ 65#define MIN_POLL_INTERVAL 20000 /*us*/
81#endif 83#endif
82 84
83#if defined(OShpux) 85#if defined(OShpux)
84#include <sys/param.h> 86#include <sys/param.h>
85#include <sys/pstat.h> 87#include <sys/pstat.h>
88#endif
89
90#if defined(OSaix)
91#include <sys/procfs.h>
86#endif 92#endif
87 93
88#include <errno.h> 94#include <errno.h>
89#include <stdio.h> 95#include <stdio.h>
90#include <stdlib.h> 96#include <stdlib.h>
176static int pid_is_cmd(pid_t pid, const char *name); 182static int pid_is_cmd(pid_t pid, const char *name);
177static void check(pid_t pid); 183static void check(pid_t pid);
178static void do_pidfile(const char *name); 184static void do_pidfile(const char *name);
179static void do_stop(int signal_nr, int quietmode, 185static void do_stop(int signal_nr, int quietmode,
180 int *n_killed, int *n_notkilled, int retry_nr); 186 int *n_killed, int *n_notkilled, int retry_nr);
181#if defined(OSLinux) || defined(OShpux) 187#if defined(OSLinux) || defined(OShpux) || defined(OSaix)
182static int pid_is_exec(pid_t pid, const struct stat *esb); 188static int pid_is_exec(pid_t pid, const struct stat *esb);
183#endif 189#endif
184 190
185#ifdef __GNUC__ 191#ifdef __GNUC__
186static void fatal(const char *format, ...) 192static void fatal(const char *format, ...)
753#endif /* OSHURD */ 759#endif /* OSHURD */
754 760
755static void 761static void
756check(pid_t pid) 762check(pid_t pid)
757{ 763{
758#if defined(OSLinux) || defined(OShpux) 764#if defined(OSLinux) || defined(OShpux) || defined(OSaix)
759 if (execname && !pid_is_exec(pid, &exec_stat)) 765 if (execname && !pid_is_exec(pid, &exec_stat))
760 return; 766 return;
761#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin) 767#elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)
762 /* I will try this to see if it works */ 768 /* I will try this to see if it works */
763 if (execname && !pid_is_cmd(pid, execname)) 769 if (execname && !pid_is_cmd(pid, execname))
789} 795}
790 796
791/* WTA: this needs to be an autoconf check for /proc/pid existance. 797/* WTA: this needs to be an autoconf check for /proc/pid existance.
792 */ 798 */
793 799
794#if defined(OSLinux) || defined (OSsunos) || defined(OSfreebsd) 800#if defined(OSLinux) || defined (OSsunos) || defined(OSfreebsd) || defined(OSaix)
795static void 801static void
796do_procinit(void) 802do_procinit(void)
797{ 803{
798 DIR *procdir; 804 DIR *procdir;
799 struct dirent *entry; 805 struct dirent *entry;
1056 check(pst[i].pst_pid); 1062 check(pst[i].pst_pid);
1057 idx = pst[count - 1].pst_idx + 1; 1063 idx = pst[count - 1].pst_idx + 1;
1058 } 1064 }
1059} 1065}
1060#endif /* OShpux */ 1066#endif /* OShpux */
1067
1068#if defined(OSaix)
1069/* max possible pid (signed long) in theory:
1070 * 32bit: 2147483647 (10 digits)
1071 * 64bit: 9223372036854775807 (19 digits)
1072 */
1073static int
1074pid_is_exec(pid_t pid, const struct stat *esb)
1075{
1076 struct stat sb;
1077 char buf[40];
1078
1079 sprintf(buf, "/proc/%ld/object/a.out", pid);
1080 if (stat(buf, &sb) != 0)
1081 return 0;
1082 return (sb.st_dev == esb->st_dev && sb.st_ino == esb->st_ino);
1083}
1084
1085
1086static int
1087pid_is_user(pid_t pid, uid_t uid)
1088{
1089 struct stat sb;
1090 char buf[32];
1091
1092 sprintf(buf, "/proc/%ld", pid);
1093 if (stat(buf, &sb) != 0)
1094 return 0;
1095 return (sb.st_uid == uid);
1096}
1097
1098
1099static int
1100pid_is_cmd(pid_t pid, const char *name)
1101{
1102 char buf[40];
1103 FILE *f;
1104 struct psinfo psi;
1105 int r;
1106
1107 sprintf(buf, "/proc/%ld/psinfo", pid);
1108 f = fopen(buf, "r");
1109 if (!f)
1110 return 0;
1111 r = fread(&psi, sizeof(psi), 1, f);
1112 fclose(f);
1113 if (r != 1) {
1114 return 0;
1115 }
1116 return strcmp(name, psi.pr_fname) == 0;
1117}
1118#endif /* OSaix */
1061 1119
1062 1120
1063static void 1121static void
1064do_findprocs(void) 1122do_findprocs(void)
1065{ 1123{

Legend:
Removed from v.1687  
changed lines
  Added in v.1688

  ViewVC Help
Powered by ViewVC 1.1.20