Magellan Linux

Diff of /trunk/mkinitrd-magellan/busybox/procps/kill.c

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

revision 983 by niro, Fri Apr 24 18:33:46 2009 UTC revision 984 by niro, Sun May 30 11:32:42 2010 UTC
# Line 92  int kill_main(int argc, char **argv) Line 92  int kill_main(int argc, char **argv)
92   quiet = 1;   quiet = 1;
93   arg = *++argv;   arg = *++argv;
94   argc--;   argc--;
95   if (argc < 1) bb_show_usage();   if (argc < 1)
96   if (arg[0] != '-') goto do_it_now;   bb_show_usage();
97     if (arg[0] != '-')
98     goto do_it_now;
99   }   }
100    
101   arg++; /* skip '-' */   arg++; /* skip '-' */
102    
103     /* -o PID? (if present, it always is at the end of command line) */
104     if (killall5 && arg[0] == 'o')
105     goto do_it_now;
106    
107   if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */   if (argc > 1 && arg[0] == 's' && arg[1] == '\0') { /* -s SIG? */
108   argc--;   argc--;
109   arg = *++argv;   arg = *++argv;
# Line 109  int kill_main(int argc, char **argv) Line 116  int kill_main(int argc, char **argv)
116   arg = *++argv;   arg = *++argv;
117   argc--;   argc--;
118    
119  do_it_now:   do_it_now:
120   pid = getpid();   pid = getpid();
121    
122   if (killall5) {   if (killall5) {
123   pid_t sid;   pid_t sid;
124   procps_status_t* p = NULL;   procps_status_t* p = NULL;
125     int ret = 0;
126    
127   /* Find out our own session id */   /* Find out our session id */
128   sid = getsid(pid);   sid = getsid(pid);
129   /* Now stop all processes */   /* Stop all processes */
130   kill(-1, SIGSTOP);   kill(-1, SIGSTOP);
131   /* Now kill all processes except our session */   /* Signal all processes except those in our session */
132   while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) {   while ((p = procps_scan(p, PSSCAN_PID|PSSCAN_SID))) {
133   if (p->sid != (unsigned)sid && p->pid != (unsigned)pid && p->pid != 1)   int i;
134   kill(p->pid, signo);  
135     if (p->sid == (unsigned)sid
136     || p->pid == (unsigned)pid
137     || p->pid == 1)
138     continue;
139    
140     /* All remaining args must be -o PID options.
141     * Check p->pid against them. */
142     for (i = 0; i < argc; i++) {
143     pid_t omit;
144    
145     arg = argv[i];
146     if (arg[0] != '-' || arg[1] != 'o') {
147     bb_error_msg("bad option '%s'", arg);
148     ret = 1;
149     goto resume;
150     }
151     arg += 2;
152     if (!arg[0] && argv[++i])
153     arg = argv[i];
154     omit = bb_strtoi(arg, NULL, 10);
155     if (errno) {
156     bb_error_msg("bad pid '%s'", arg);
157     ret = 1;
158     goto resume;
159     }
160     if (p->pid == omit)
161     goto dont_kill;
162     }
163     kill(p->pid, signo);
164     dont_kill: ;
165   }   }
166     resume:
167   /* And let them continue */   /* And let them continue */
168   kill(-1, SIGCONT);   kill(-1, SIGCONT);
169   return 0;   return ret;
170   }   }
171    
172   /* Pid or name is required for kill/killall */   /* Pid or name is required for kill/killall */
# Line 156  do_it_now: Line 195  do_it_now:
195   continue;   continue;
196   errors++;   errors++;
197   if (!quiet)   if (!quiet)
198   bb_perror_msg("cannot kill pid %u", (unsigned)*pl);   bb_perror_msg("can't kill pid %u", (unsigned)*pl);
199   }   }
200   }   }
201   free(pidList);   free(pidList);
# Line 175  do_it_now: Line 214  do_it_now:
214   bb_error_msg("bad pid '%s'", arg);   bb_error_msg("bad pid '%s'", arg);
215   errors++;   errors++;
216   } else if (kill(pid, signo) != 0) {   } else if (kill(pid, signo) != 0) {
217   bb_perror_msg("cannot kill pid %d", (int)pid);   bb_perror_msg("can't kill pid %d", (int)pid);
218   errors++;   errors++;
219   }   }
220   arg = *++argv;   arg = *++argv;

Legend:
Removed from v.983  
changed lines
  Added in v.984