diff --git a/Changes b/Changes index 01a0c64c8..2a1915e4b 100644 --- a/Changes +++ b/Changes @@ -1355,3 +1355,5 @@ - Fixed set::allowed-nickchars causing a segfault for some unknown charsets, reported by avb (#0003069). - Cutoff webtv whois at MAXTARGETS (#0003004). +- loadmodule now reports proper errors when the actual file can't be found, instead of blaming + it on the temp file, reported in #3015. diff --git a/src/modules.c b/src/modules.c index fb76e513c..255cf1d46 100644 --- a/src/modules.c +++ b/src/modules.c @@ -331,14 +331,25 @@ char *Module_Create(char *path_) strcpy(path, "./"); strcat(path, path_); } + + if (!file_exists(path)) + { + snprintf(errorbuf, sizeof(errorbuf), "Cannot open module file: %s", strerror(errno)); + return errorbuf; + } #ifdef __OpenBSD__ /* For OpenBSD, do not do a hardlinkink attempt first because it checks inode * numbers to see if a certain module is already loaded. -- Syzop */ - unreal_copyfileex(path, tmppath, 0); + ret = unreal_copyfileex(path, tmppath, 0); #else - unreal_copyfileex(path, tmppath, 1); + ret = unreal_copyfileex(path, tmppath, 1); #endif + if (!ret) + { + snprintf(errorbuf, sizeof(errorbuf), "Failed to copy module file."); + return errorbuf; + } if ((Mod = irc_dlopen(tmppath, RTLD_NOW))) { /* We have engaged the borg cube. Scan for lifesigns. */ diff --git a/src/support.c b/src/support.c index 5e684f232..f4bcba14b 100644 --- a/src/support.c +++ b/src/support.c @@ -1675,6 +1675,17 @@ void *MyMallocEx(size_t size) return (p); } +int file_exists(char* file) +{ + FILE *fd; + fd = fopen(file, "r"); + if (!fd) + { + return 0; + } + return 1; +} + /* Returns a unique filename in the specified directory * using the specified suffix. The returned value will * be of the form /. @@ -1766,7 +1777,10 @@ int unreal_copyfile(char *src, char *dest) #endif if (srcfd < 0) + { + config_error("Unable to open file '%s': %s", src, strerror(errno)); return 0; + } #ifndef _WIN32 destfd = open(dest, O_WRONLY|O_CREAT, DEFAULT_PERMISSIONS); @@ -1814,7 +1828,7 @@ int unreal_copyfileex(char *src, char *dest, int tryhardlink) #ifndef _WIN32 /* Try a hardlink first... */ if (tryhardlink && !link(src, dest)) - return 0; /* success */ + return 1; /* success */ #endif return unreal_copyfile(src, dest); }