On Fri, Sep 28, 2007 at 05:51:34PM +0200, Loïc Grenié wrote: > These are three patches for busybox. > >1) The first one adds a function xfree(ptr) to xfuncs.c which acts > as if (ptr) free(ptr) and substitute some examples of such > elements in the code. I don't remember whether such a > function is necessary or whether free() itself already checks > for null pointer.
freeing a null pointer is perfectly fine. xfree (whichever ;) not needed. http://www.opengroup.org/onlinepubs/009695399/functions/free.html all those if() can be removed instead. See further below. >2) The second one corrects a comment. > >3) The third one adds functions pgrep and pkill (this one includes > the "procps.diff" that I've sent before). > > The first patch contains some modifications to libbb.h that are > logically part of the third. Since I've hand-split the file, I've not > tried to disentangle them. It's not very difficult to do it if for > any reason you need either one and not the other. > > Loïc >Index: include/libbb.h >=================================================================== >--- include/libbb.h (r??vision 20077) >+++ include/libbb.h (copie de travail) >@@ -259,8 +259,9 @@ > char *xmalloc_readlink(const char *path); > char *xmalloc_readlink_or_warn(const char *path); > char *xrealloc_getcwd_or_warn(char *cwd); >+/* Free pointer if non NULL */ >+void xfree(void *ptr); > >- > //TODO: signal(sid, f) is the same? then why? > extern void sig_catch(int,void (*)(int)); > //#define sig_ignore(s) (sig_catch((s), SIG_IGN)) >@@ -787,6 +788,7 @@ > > int get_signum(const char *name); > const char *get_signame(int number); >+void print_signames_and_exit(void); This can be noreturn >--- /dev/null 2007-09-26 12:43:34.255962088 +0200 >+++ procps/pgrep.c 2007-09-28 14:13:18.000000000 +0200 >@@ -0,0 +1,135 @@ >+/* vi: set sw=4 ts=4: */ >+/* >+ * Mini pgrep/pkill implementation for busybox >+ * >+ * Copyright (C) 2007 There is some name missing here. >+ * >+ * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. >+ */ >+ >+#include <getopt.h> >+ >+#include "libbb.h" >+#include "xregex.h" >+ >+static char char2; >+/* Idea taken from kill.c */ >+#define pgrep (ENABLE_PGREP && char2 == 'g') >+#define pkill (ENABLE_PKILL && char2 == 'k') >+ >+static void act(unsigned pid, char *cmd, int signo, int opt) >+{ >+ if (pgrep) >+ { >+ if (opt) >+ printf("%d %s\n", pid, cmd); >+ else >+ printf("%d\n", pid); >+ } >+ else >+ kill(pid, signo); >+} >+ >+int pgrep_main(int argc, char **argv); >+int pgrep_main(int argc, char **argv) >+{ >+ char *first_arg, *cmdm = NULL; >+ procps_status_t *p = NULL; whitespace damaged. >+ regex_t re_buffer; >+ const int NMATCH = 2; >+ regmatch_t re_regs[NMATCH]; >+ int match = 0; >+ unsigned pid = getpid(); >+ int signo = SIGTERM, i; >+ uint32_t opt; >+ int scan_mask = PSSCAN_STAT, anchor, invert, last; most of these can be bool, or just use opt and remove them. That said, what's wrong about aliasing pkill to something like kill -9 $(pidof $it) same for pgrep: ps | grep $it | grep -v | awk '{print $1}' _______________________________________________ busybox mailing list [email protected] http://busybox.net/cgi-bin/mailman/listinfo/busybox
