Ticket #39018: start-stop-daemon.c.rej

File start-stop-daemon.c.rej, 2.8 KB (added by cooljeanius (Eric Gallager), 11 years ago)

failed patch for start-stop-daemon.c

Line 
1***************
2*** 809,815 ****
3  #if defined(OSLinux) || defined(OShpux)
4        if (execname && !pid_is_exec(pid, &exec_stat))
5                return;
6- #elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD)
7        /* Let's try this to see if it works */
8        if (execname && !pid_is_cmd(pid, execname))
9                return;
10--- 812,818 ----
11  #if defined(OSLinux) || defined(OShpux)
12        if (execname && !pid_is_exec(pid, &exec_stat))
13                return;
14+ #elif defined(OSHURD) || defined(OSFreeBSD) || defined(OSNetBSD) || defined(OSDarwin)
15        /* Let's try this to see if it works */
16        if (execname && !pid_is_cmd(pid, execname))
17                return;
18***************
19*** 153,158 ****
20  {
21        /* Nothing to do */
22  }
23  #endif /* OSOpenBSD */
24 
25  #if defined(OShpux)
26--- 154,160 ----
27  {
28        /* Nothing to do */
29  }
30+ #endif
31  #endif /* OSOpenBSD */
32 
33  #if defined(OShpux)
34***************
35*** 154,159 ****
36        /* Nothing to do */
37  }
38  #endif /* OSOpenBSD */
39 
40  #if defined(OShpux)
41  static int
42--- 133,212 ----
43        /* Nothing to do */
44  }
45  #endif /* OSOpenBSD */
46+
47+ #if defined(OSDarwin)
48+ #include <sys/sysctl.h>
49+ int
50+ pid_is_user(pid_t pid, uid_t uid)
51+ {
52+       int mib[4];
53+       size_t size;
54+       struct kinfo_proc ki;
55+
56+       size = sizeof(ki);
57+       mib[0] = CTL_KERN;
58+       mib[1] = KERN_PROC;
59+       mib[2] = KERN_PROC_PID;
60+       mib[3] = pid;
61+       if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
62+               errx(1, "%s", "Failure calling sysctl");
63+       return (uid == ki.kp_eproc.e_pcred.p_ruid);
64+ }
65+
66+ static int
67+ pid_is_cmd(pid_t pid, const char *name)
68+ {
69+       int mib[4];
70+       size_t size;
71+       struct kinfo_proc ki;
72+
73+       size = sizeof(ki);
74+       mib[0] = CTL_KERN;
75+       mib[1] = KERN_PROC;
76+       mib[2] = KERN_PROC_PID;
77+       mib[3] = pid;
78+       if (sysctl(mib, 4, &ki, &size, NULL, 0) < 0)
79+               errx(1, "%s", "Failure calling sysctl");
80+       return (!strncmp(name, ki.kp_proc.p_comm, MAXCOMLEN));
81+ }
82+
83+ static void
84+ do_procinit(void)
85+ {
86+       int mib[3];
87+       size_t size;
88+       int nprocs, ret, i;
89+       struct kinfo_proc *procs = NULL, *newprocs;
90+       
91+       mib[0] = CTL_KERN;
92+       mib[1] = KERN_PROC;
93+       mib[2] = KERN_PROC_ALL;
94+       ret = sysctl(mib, 3, NULL, &size, NULL, 0);
95+       /* Allocate enough memory for entire process table */
96+       do {
97+               size += size / 10;
98+               newprocs = realloc(procs, size);
99+               if (newprocs == NULL) {
100+                       if (procs)
101+                               free(procs);
102+                       errx(1, "%s", "Could not reallocate memory");
103+               }
104+               procs = newprocs;
105+               ret = sysctl(mib, 3, procs, &size, NULL, 0);
106+       } while (ret >= 0 && errno == ENOMEM);
107+
108+       if (ret < 0)
109+               errx(1, "%s", "Failure calling sysctl");
110+
111+       /* Verify size of proc structure */
112+       if (size % sizeof(struct kinfo_proc) != 0)
113+               errx(1, "%s", "proc size mismatch, userland out of sync with kernel");
114+       nprocs = size / sizeof(struct kinfo_proc);
115+       for (i = 0; i < nprocs; i++) {
116+               check(procs[i].kp_proc.p_pid);
117+       }
118+ }
119+ #endif /* OSDarwin */
120 
121  #if defined(OShpux)
122  static int