diff --git a/bin/named/main.c b/bin/named/main.c index 652c9f52bf..e77a415dc8 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: main.c,v 1.108 2001/05/08 03:42:28 gson Exp $ */ +/* $Id: main.c,v 1.109 2001/05/08 19:47:53 gson Exp $ */ #include @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -62,7 +63,7 @@ /* #include "xxdb.h" */ static isc_boolean_t want_stats = ISC_FALSE; -static const char * program_name = "named"; +static char program_name[256] = "named"; static char saved_command_line[512]; void @@ -264,21 +265,9 @@ static void parse_command_line(int argc, char *argv[]) { int ch; int port; - char *s; save_command_line(argc, argv); - /* - * See if we should run as lwresd. - */ - s = strrchr(argv[0], '/'); - if (s == NULL) - s = argv[0]; - else - s++; - if (strcmp(s, "lwresd") == 0) - ns_g_lwresdonly = ISC_TRUE; - isc_commandline_errprint = ISC_FALSE; while ((ch = isc_commandline_parse(argc, argv, "c:C:d:fgi:ln:N:p:P:st:u:vx:")) != @@ -517,7 +506,13 @@ int main(int argc, char *argv[]) { isc_result_t result; - program_name = argv[0]; + result = isc_file_progname(argv[0], program_name, sizeof(program_name)); + if (result != ISC_R_SUCCESS) + ns_main_earlyfatal("program name too long"); + + if (strcmp(program_name, "lwresd") == 0) + ns_g_lwresdonly = ISC_TRUE; + isc_assertion_setcallback(assertion_failed); isc_error_setfatal(library_fatal_error); isc_error_setunexpected(library_unexpected_error); diff --git a/lib/isc/include/isc/file.h b/lib/isc/include/isc/file.h index 26b7bdbb8b..dae858f453 100644 --- a/lib/isc/include/isc/file.h +++ b/lib/isc/include/isc/file.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: file.h,v 1.17 2001/05/05 02:47:19 bwelling Exp $ */ +/* $Id: file.h,v 1.18 2001/05/08 19:47:54 gson Exp $ */ #ifndef ISC_FILE_H #define ISC_FILE_H 1 @@ -183,6 +183,22 @@ isc_file_basename(const char *filename); * Return the final component of the path in the file name. */ +isc_result_t +isc_file_progname(const char *filename, char *buf, size_t buflen); +/* + * Given an operating system specific file name "filename" + * referring to a program, return the canonical program name. + * Any directory prefix or executable file name extension (if + * used on the OS in case) is stripped. On systems where program + * names are case insensitive, the name is canonicalized to all + * lower case. The name is written to 'buf', an array of 'buflen' + * chars, and null terminated. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOSPACE The name did not fit in 'buf'. + */ + isc_result_t isc_file_template(const char *path, const char *templet, char *buf, size_t buflen); diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index bf9fe934e3..6970dbf447 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: file.c,v 1.32 2001/05/05 02:47:21 bwelling Exp $ */ +/* $Id: file.c,v 1.33 2001/05/08 19:47:55 gson Exp $ */ #include @@ -244,3 +244,13 @@ isc_file_basename(const char *filename) { return (filename); return (s + 1); } + +isc_result_t +isc_file_progname(const char *filename, char *buf, size_t buflen) { + const char *base = isc_file_basename(filename); + size_t len = strlen(base) + 1; + if (len > buflen) + return (ISC_R_NOSPACE); + memcpy(buf, base, len); + return (ISC_R_SUCCESS); +}