Explorar el Código

Merge branch 'maint'

* maint:
  Fix short userfile storage
  Remove dirname(3) compat - it is in POSIX.1-2001
Bryan Drewery hace 6 años
padre
commit
9686ee67e5
Se han modificado 13 ficheros con 14 adiciones y 77 borrados
  1. 1 0
      doc/UPDATES.md
  2. 0 1
      src/Makefile.in
  3. 1 1
      src/chanprog.cc
  4. 1 0
      src/common.h
  5. 0 1
      src/compat/compat.h
  6. 0 48
      src/compat/dirname.c
  7. 0 18
      src/compat/dirname.h
  8. 1 1
      src/conf.cc
  9. 4 1
      src/main.cc
  10. 1 1
      src/main.h
  11. 1 1
      src/misc_file.cc
  12. 3 3
      src/mod/update.mod/update.cc
  13. 1 1
      src/users.cc

+ 1 - 0
doc/UPDATES.md

@@ -25,6 +25,7 @@
   * Don't crash when looking up a missing response.
   * Fix cmd_slowjoin still adding the channel on parsing error.
   * Fix -Wwritable-strings warnings
+  * Fix dirname(3) support on FreeBSD (#89).
 
 # 1.4.9
   * Fix various compile warnings and spam

+ 0 - 1
src/Makefile.in

@@ -71,7 +71,6 @@ OBJS = auth.So \
 	mod/share.mod/share.So \
 	mod/transfer.mod/transfer.So \
 	mod/update.mod/update.So \
-	compat/dirname.o \
 	compat/dn_expand.o \
 	compat/snprintf.o \
 	compat/memmem.o \

+ 1 - 1
src/chanprog.cc

@@ -599,7 +599,7 @@ void chanprog()
   channel_add(NULL, "default", def_chanset, 1);
 
   if (conf.bot->hub) {
-    simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
+    simple_snprintf(userfile, PATH_MAX, "%s/.u", bindir);
     loading = 1;
     checkchans(0);
     readuserfile(userfile, &userlist);

+ 1 - 0
src/common.h

@@ -24,6 +24,7 @@
 #include "compat/compat.h"
 
 #include <sys/param.h>
+#include <libgen.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>

+ 0 - 1
src/compat/compat.h

@@ -11,7 +11,6 @@
 #  include "config.h"
 #endif
 
-#include "dirname.h"
 #include "dn_expand.h"
 #include "snprintf.h"
 #include "memutil.h"

+ 0 - 48
src/compat/dirname.c

@@ -1,48 +0,0 @@
-#include "dirname.h"
-
-#include <errno.h>
-#include <string.h>
-#include <sys/param.h>
-#include "strlcpy.h"
-
-
-char *
-dirname(const char *path)
-{
-        static char bname[MAXPATHLEN] = "";
-        const char *endp = NULL;
-
-        /* Empty or NULL string gets treated as "." */
-        if (path == NULL || *path == '\0') {
-                strlcpy(bname, ".", sizeof bname);
-                return(bname);
-        }
-
-        /* Strip trailing slashes */
-        endp = path + strlen(path) - 1;
-        while (endp > path && *endp == '/')
-                endp--;
-
-        /* Find the start of the dir */
-        while (endp > path && *endp != '/')
-                endp--;
-
-        /* Either the dir is "/" or there are no slashes */
-        if (endp == path) {
-                strlcpy(bname, *endp == '/' ? "/" : ".", sizeof bname);
-                return(bname);
-        } else {
-                do {
-                        endp--;
-                } while (endp > path && *endp == '/');
-        }
-
-        if (endp - path + 2 > (signed) sizeof(bname)) {
-                errno = ENAMETOOLONG;
-                return(NULL);
-        }
-        strlcpy(bname, path, endp - path + 2);
-        return(bname);
-}
-
-/* vim: set sts=2 sw=2 ts=8 et: */

+ 0 - 18
src/compat/dirname.h

@@ -1,18 +0,0 @@
-#ifndef _DIRNAME_H
-#define _DIRNAME_H
-
-#ifdef HAVE_CONFIG_H
-#  include "config.h"
-#endif
-
-#define dirname my_dirname
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-char *dirname(const char *);
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* !_DIRNAME_H */

+ 1 - 1
src/conf.cc

@@ -1019,7 +1019,7 @@ bin_to_conf(bool error)
   if (!mkdir_p(conf.datadir) && error)
     werr(ERR_DATADIR);
 
-  str_redup(&conf.datadir, replace(datadir, dirname(binname), "."));
+  str_redup(&conf.datadir, replace(datadir, bindir, "."));
 
   if (Tempfile::FindDir() == ERROR)
     werr(ERR_TMPSTAT);

+ 4 - 1
src/main.cc

@@ -108,6 +108,7 @@ bool	term_z = 0;		/* Foreground: use the terminal as a party line? */
 int 	updating = 0; 		/* this is set when the binary is called from itself. */
 char 	tempdir[PATH_MAX] = "";
 char 	*binname = NULL;
+char    *bindir = NULL;
 time_t	online_since;		/* Unix-time that the bot loaded up */
 time_t  restart_time;
 bool	restart_was_update = 0;
@@ -729,7 +730,9 @@ int main(int argc, char **argv)
   }
 
   binname = getfullbinname(argv[0]);
-  if (chdir(dirname(binname)))
+  char *binname_tmp = strdup(binname);
+  bindir = dirname(binname_tmp);
+  if (chdir(bindir))
     werr(ERR_BINSTAT);
 
   /* Find a temporary tempdir until we load binary data */

+ 1 - 1
src/main.h

@@ -17,7 +17,7 @@ enum {
 extern int		default_flags, default_uflags, do_confedit,
 			updating, do_restart, do_write_userfile;
 extern bool		use_stderr, backgrd, used_B, term_z, loading, have_linked_to_hub, restart_was_update, restarting, safe_to_log;
-extern char		tempdir[], *binname, owner[121], version[151], ver[101], quit_msg[], *socksfile;
+extern char		tempdir[], *binname, *bindir, owner[121], version[151], ver[101], quit_msg[], *socksfile;
 extern time_t		online_since, now, restart_time;
 extern egg_timeval_t	egg_timeval_now;
 extern uid_t		myuid;

+ 1 - 1
src/misc_file.cc

@@ -292,7 +292,7 @@ bool Tempfile::FindDir() noexcept
 
   /* If this is a hub, use, "./tmp/" */
   if (conf.bots && conf.bots->nick && conf.bots->hub) {
-    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", dirname(binname));
+    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", bindir);
     if (check_tempdir(0)) {
       looking = 0;
       return OK;

+ 3 - 3
src/mod/update.mod/update.cc

@@ -274,7 +274,7 @@ void finish_update_stream(int idx, bd::Stream& stream)
 
   char rand[7] = "";
   make_rand_str(rand, sizeof(rand) - 1, 0);
-  simple_snprintf(buf, sizeof(buf), "%s/.update-%s", dirname(binname), rand);
+  simple_snprintf(buf, sizeof(buf), "%s/.update-%s", bindir, rand);
 
   stream.writeFile(buf);
   fixmod(buf);
@@ -331,9 +331,9 @@ static void start_sending_binary(int idx, bool streamable)
 
   simple_snprintf(update_file, sizeof update_file, "wraith.%s-%s", sysname, egg_version);
 
-  simple_snprintf(update_fpath, sizeof update_fpath, "%s/bins/%s", dirname(binname), update_file);
+  simple_snprintf(update_fpath, sizeof update_fpath, "%s/bins/%s", bindir, update_file);
 //  if (!can_stat(update_fpath))
-//    simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", dirname(binname), update_file);
+//    simple_snprintf(update_fpath, sizeof update_fpath, "%s/%s", bindir, update_file);
 
   if (!can_stat(update_fpath)) {
     putlog(LOG_MISC, "*", "Need to update \002%s\002 with %s but there was an error: %s", dcc[idx].nick, update_fpath,

+ 1 - 1
src/users.cc

@@ -56,7 +56,7 @@
 #include "misc_file.h"
 #include "EncryptedStream.h"
 
-char userfile[121] = "";	/* where the user records are stored */
+char userfile[PATH_MAX] = "";	/* where the user records are stored */
 char autolink_failed[HANDLEN + 1] = "";
 interval_t ignore_time = 10;		/* how many minutes will ignores last? */
 bool	dont_restructure = 0;		/* set when we botlink() to a hub with +U, only stops bot from restructuring */