daemon_SOURCES = \
daemon.c \
+ getprogname.h \
pidfile.c pidfile.h \
flopen.c flopen.h \
$(NULL)
man8_MANS = daemon.8
-EXTRA_DIST = $(man8_MANS)
+EXTRA_DIST = $(man8_MANS) getprogname.c
AM_CFLAGS = -Wall
AC_CHECK_FUNCS([ftruncate])
AC_CHECK_FUNCS([strtol])
AC_CHECK_FUNCS([strerror])
+AC_CHECK_FUNCS([strrchr])
+AC_REPLACE_FUNCS([getprogname])
AC_FUNC_MALLOC
AC_CONFIG_FILES([
#include "config.h"
#include "pidfile.h"
+#include "getprogname.h"
#include <sys/param.h>
const char *pidfile, *user;
pid_t otherpid;
+ setprogname(argv[0]);
+
nochdir = noclose = 1;
pidfile = user = NULL;
while ((ch = getopt(argc, argv, "-cfp:u:")) != -1) {
--- /dev/null
+#include "getprogname.h"
+#include <string.h>
+
+static const char* _progname = NULL;
+
+const char* getprogname(void) {
+ return _progname;
+}
+
+void setprogname(const char* progname) {
+ const char* last_backslash;
+
+ last_backslash = strrchr(progname, '/');
+ if (last_backslash) {
+ _progname = last_backslash + 1;
+ }
+ else {
+ _progname = progname;
+ }
+}
--- /dev/null
+#ifndef GETPROGNAME_H_INCLUDED
+#define GETPROGNAME_H_INCLUDED
+#include "config.h"
+
+#if !defined(HAVE_GETPROGNAME)
+const char* getprogname(void);
+void setprogname(const char* progname);
+#endif
+
+#endif
* SUCH DAMAGE.
*/
+#include "config.h"
+
#include "pidfile.h"
#include "flopen.h"
+#include "getprogname.h"
#include <sys/cdefs.h>
#include <sys/file.h>