| … | |
… | |
| 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> |
| … | |
… | |
| 176 | static int pid_is_cmd(pid_t pid, const char *name); |
182 | static int pid_is_cmd(pid_t pid, const char *name); |
| 177 | static void check(pid_t pid); |
183 | static void check(pid_t pid); |
| 178 | static void do_pidfile(const char *name); |
184 | static void do_pidfile(const char *name); |
| 179 | static void do_stop(int signal_nr, int quietmode, |
185 | static 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) |
| 182 | static int pid_is_exec(pid_t pid, const struct stat *esb); |
188 | static int pid_is_exec(pid_t pid, const struct stat *esb); |
| 183 | #endif |
189 | #endif |
| 184 | |
190 | |
| 185 | #ifdef __GNUC__ |
191 | #ifdef __GNUC__ |
| 186 | static void fatal(const char *format, ...) |
192 | static void fatal(const char *format, ...) |
| … | |
… | |
| 753 | #endif /* OSHURD */ |
759 | #endif /* OSHURD */ |
| 754 | |
760 | |
| 755 | static void |
761 | static void |
| 756 | check(pid_t pid) |
762 | check(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) |
| 795 | static void |
801 | static void |
| 796 | do_procinit(void) |
802 | do_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 | */ |
|
|
1073 | static int |
|
|
1074 | pid_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 | |
|
|
1086 | static int |
|
|
1087 | pid_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 | |
|
|
1099 | static int |
|
|
1100 | pid_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 | |
| 1063 | static void |
1121 | static void |
| 1064 | do_findprocs(void) |
1122 | do_findprocs(void) |
| 1065 | { |
1123 | { |