non-busybox dhcp clients (was: PATCH: ifupdown.c, udhcpc, and standalone shell)
Gabriel L. Somlo
somlo at cmu.edu
Thu Oct 5 18:26:50 UTC 2006
On Thu, Oct 05, 2006 at 01:08:52PM -0400, Rob Landley wrote:
> I generally just called execvp() or some such and if I got control back, that
> wasn't it.
OK, so this patch adds a do_which() function to libbb. I'll send
another email which replaces my previous ifupdown patch with one that
uses do_which(). What still needs to be done if these are accepted is
to replace debianutils/which.c with a call to do_which(), but I'll
hold on that until I get feedback on this stuff first...
Thanks,
Gabriel
diff -NarU5 busybox-svn-16294/include/libbb.h busybox-svn-16294.which/include/libbb.h
--- busybox-svn-16294/include/libbb.h 2006-10-03 13:01:09.000000000 -0400
+++ busybox-svn-16294.which/include/libbb.h 2006-10-05 14:08:25.000000000 -0400
@@ -337,10 +337,12 @@
char *concat_subpath_file(const char *path, const char *filename);
char *last_char_is(const char *s, int c);
char *fgets_str(FILE *file, const char *terminating_string);
+char *do_which(char *program);
+
extern USE_DESKTOP(long long) int uncompress(int fd_in, int fd_out);
extern int inflate(int in, int out);
extern struct hostent *xgethostbyname(const char *name);
extern struct hostent *xgethostbyname2(const char *name, int af);
diff -NarU5 busybox-svn-16294/libbb/do_which.c busybox-svn-16294.which/libbb/do_which.c
--- busybox-svn-16294/libbb/do_which.c 1969-12-31 19:00:00.000000000 -0500
+++ busybox-svn-16294.which/libbb/do_which.c 2006-10-05 14:09:14.000000000 -0400
@@ -0,0 +1,30 @@
+/* vi: set sw=4 ts=4: */
+/*
+ * Utility routines.
+ *
+ * Copyright (C) 2006 Gabriel L. Somlo
+ *
+ * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
+ */
+
+/* search PATH for executable filename; return full path if found and executable
+ * return NULL otherwise
+*/
+
+#include "libbb.h"
+
+char *do_which(char *program)
+{
+ struct stat buf;
+ char *p, *path = xstrdup(getenv("PATH"));
+ char *ret = NULL;
+ for (p = strtok(path, ":"); p; p = strtok(NULL, ":")) {
+ ret = concat_path_file(p, program);
+ if ((stat(ret, &buf) == 0) &&
+ S_ISREG(buf.st_mode) && (S_IXUSR & buf.st_mode)) break;
+ free(ret);
+ ret = NULL;
+ }
+ free(path);
+ return ret;
+}
diff -NarU5 busybox-svn-16294/libbb/Makefile.in busybox-svn-16294.which/libbb/Makefile.in
--- busybox-svn-16294/libbb/Makefile.in 2006-10-03 13:01:07.000000000 -0400
+++ busybox-svn-16294.which/libbb/Makefile.in 2006-10-05 14:08:50.000000000 -0400
@@ -31,11 +31,11 @@
xgethostbyname.c xgethostbyname2.c xreadlink.c xgetlarg.c \
fclose_nonstdin.c fflush_stdout_and_exit.c \
getopt_ulflags.c default_error_retval.c wfopen_input.c speed_table.c \
perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c bb_askpass.c \
warn_ignoring_args.c concat_subpath_file.c vfork_daemon_rexec.c \
- bb_do_delay.c
+ bb_do_delay.c do_which.c
# conditionally compiled objects:
LIBBB-$(CONFIG_FEATURE_MOUNT_LOOP)+= loop.c
LIBBB-$(CONFIG_LOSETUP)+= loop.c
LIBBB-$(CONFIG_FEATURE_MTAB_SUPPORT)+= mtab.c
More information about the busybox
mailing list