#include <getopt.h>
#include <sys/resource.h>
+/* Override ENABLE_FEATURE_PIDFILE */
+#define WANT_PIDFILE 1
#include "libbb.h"
static int signal_nr = 15;
n = strcmp(execbuf, name);
if (ENABLE_FEATURE_CLEAN_UP)
free(execbuf);
- return ~n; /* nonzero (true) if execbuf == name */
+ return !n; /* nonzero (true) if execbuf == name */
}
static int pid_is_user(int pid, int uid)
pid_t pid = vfork();
if (pid < 0) /* error */
bb_perror_msg_and_die("vfork");
- if (pid == 0) /* parent */
- return 0;
+ if (pid != 0) {
+ /* parent */
+ /* why _exit? the child may have changed the stack,
+ * so "return 0" may do bad things */
+ _exit(0);
}
/* child */
+ setsid(); /* detach from controlling tty */
/* Redirect stdio to /dev/null, close extra FDs.
* We do not actually daemonize because of DAEMON_ONLY_SANITIZE */
bb_daemonize_or_rexec(
}
if (opt & OPT_MAKEPID) {
/* user wants _us_ to make the pidfile */
- FILE *pidf = xfopen(pidfile, "w");
-
- pid_t pidt = getpid();
- fprintf(pidf, "%d\n", pidt);
- fclose(pidf);
+ write_pidfile(pidfile);
}
if (opt & OPT_c) {
struct bb_uidgid_t ugid;
* llist_t *llist_add_to(llist_t *old_head, void *data)
* etc does not result in smaller code... */
-
-#if ENABLE_FEATURE_PIDFILE
+/* start_stop_daemon and (udhcpc with ifupdown) are special - they want to
+ * create pidfiles regardless of FEATURE_PIDFILE. */
+#if ENABLE_FEATURE_PIDFILE || defined(WANT_PIDFILE)
int write_pidfile(const char *path);
#define remove_pidfile(f) ((void)unlink(f))
#else
*
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+
+/* Override ENABLE_FEATURE_PIDFILE */
+#define WANT_PIDFILE 1
#include "libbb.h"
-#if ENABLE_FEATURE_PIDFILE
int write_pidfile(const char *path)
{
int pid_fd;
close(pid_fd);
return 1;
}
-#endif
static int bootp_up(struct interface_defn_t *ifd, execfn *exec)
{
return execute("bootpc[[ --bootfile %bootfile%]] --dev %iface%"
- "[[ --server %server%]][[ --hwaddr %hwaddr%]] "
- "--returniffail --serverbcast", ifd, exec);
+ "[[ --server %server%]][[ --hwaddr %hwaddr%]]"
+ " --returniffail --serverbcast", ifd, exec);
}
static int ppp_up(struct interface_defn_t *ifd, execfn *exec)
#include <getopt.h>
#include <syslog.h>
+/* Override ENABLE_FEATURE_PIDFILE - ifupdown needs our pidfile to always exist */
+#define WANT_PIDFILE 1
#include "common.h"
#include "dhcpd.h"
#include "dhcpc.h"