diff options
author | Aaron Plattner <aplattner@nvidia.com> | 2011-01-24 07:42:56 -0800 |
---|---|---|
committer | Aaron Plattner <aplattner@nvidia.com> | 2011-01-24 07:42:56 -0800 |
commit | 918a0b644654267e5d4d82a18232c91c68693209 (patch) | |
tree | dc1f2c48773bb5aa9b456e69926c3730fa197fe0 | |
parent | 302afbef422649dad0dad2111c73261255922b55 (diff) |
270.18270.18
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | alloc-utils.c | 90 | ||||
-rw-r--r-- | backup.c | 14 | ||||
-rw-r--r-- | common-utils/common-utils.c | 257 | ||||
-rw-r--r-- | common-utils/common-utils.h (renamed from alloc-utils.h) | 33 | ||||
-rw-r--r-- | common-utils/src.mk | 2 | ||||
-rw-r--r-- | dist-files.mk | 4 | ||||
-rw-r--r-- | help-args.c | 2 | ||||
-rw-r--r-- | misc.h | 3 | ||||
-rw-r--r-- | nvidia-installer.h | 12 | ||||
-rw-r--r-- | snarf-http.c | 15 | ||||
-rw-r--r-- | string-utils.c | 122 | ||||
-rw-r--r-- | string-utils.h | 48 | ||||
-rw-r--r-- | utils.mk | 6 | ||||
-rw-r--r-- | version.mk | 2 |
15 files changed, 318 insertions, 301 deletions
@@ -132,11 +132,10 @@ LDFLAGS += -L. -ldl MKPRECOMPILED_SRC = crc.c mkprecompiled.c MKPRECOMPILED_OBJS = $(call BUILD_OBJECT_LIST,$(MKPRECOMPILED_SRC)) -MAKESELF_HELP_SCRIPT_SRC = makeself-help-script.c \ - help-args.c \ - format.c \ - string-utils.c \ - alloc-utils.c +MAKESELF_HELP_SCRIPT_SRC = makeself-help-script.c +MAKESELF_HELP_SCRIPT_SRC += help-args.c +MAKESELF_HELP_SCRIPT_SRC += format.c +MAKESELF_HELP_SCRIPT_SRC += $(COMMON_UTILS_DIR)/common-utils.c BUILD_MAKESELF_OBJECT_LIST = \ $(patsubst %.o,%.makeself.o,$(call BUILD_OBJECT_LIST,$(1))) diff --git a/alloc-utils.c b/alloc-utils.c deleted file mode 100644 index 3a4b9ab..0000000 --- a/alloc-utils.c +++ /dev/null @@ -1,90 +0,0 @@ -/* - * nvidia-installer: A tool for installing NVIDIA software packages on - * Unix and Linux systems. - * - * Copyright (C) 2003-2009 NVIDIA Corporation - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307, USA - * - * - * alloc-utils.c: this file contains heap management helper functions. - */ - -#include <string.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> - -#include "alloc-utils.h" - -/* - * nvalloc() - malloc wrapper that checks for errors, and zeros - * out the memory; if an error occurs, an error is printed - * to stderr and exit is called. This function will only return - * on success. - */ - -void *nvalloc(size_t size) -{ - void *m = malloc(size); - - if (!m) { - fprintf(stderr, "%s: memory allocation failure (%s)! \n", - PROGRAM_NAME, strerror(errno)); - exit(1); - } - memset((char *) m, 0, size); - return m; - -} /* nvalloc() */ - - - -/* - * nvrealloc() - realloc wrapper that checks for errors; if an - * error occurs, an error is printed to stderr and exit - * is called. This function will only return on success. - */ - -void *nvrealloc(void *ptr, size_t size) -{ - void *m; - - if (ptr == NULL) return nvalloc(size); - - m = realloc(ptr, size); - if (!m) { - fprintf(stderr, "%s: memory re-allocation failure (%s)! \n", - PROGRAM_NAME, strerror(errno)); - exit(1); - } - return m; - -} /* nvrealloc() */ - - - -/* - * nvfree() - frees memory allocated with nvalloc(), provided - * a non-NULL pointer is provided. - */ -void nvfree(char *s) -{ - if (s) free(s); - -} /* nvfree() */ @@ -49,6 +49,8 @@ #define BACKUP_DIRECTORY "/var/lib/nvidia" #define BACKUP_LOG (BACKUP_DIRECTORY "/log") +#define RMMOD_MODULE_NAME "nvidia" + /* * XXX when uninstalling should we remove directories that were * created by our installation? @@ -117,7 +119,6 @@ typedef struct { } BackupInfo; - static BackupInfo *read_backup_log_file(Options *op); static void free_backup_info(BackupInfo *b); @@ -500,7 +501,7 @@ static int do_uninstall(Options *op) BackupLogEntry *e; BackupInfo *b; int i, len, ok; - char *tmpstr; + char *tmpstr, *cmd; float percent; static const char existing_installation_is_borked[] = @@ -658,6 +659,15 @@ static int do_uninstall(Options *op) /* XXX what to do if this fails?... nothing */ } + /* + * attempt to unload the kernel module, but don't abort if this fails: the + * kernel may not have been configured with support for module unloading + * (Linux 2.6) or the user might have unloaded it themselves. + */ + cmd = nvstrcat(op->utils[RMMOD], " ", RMMOD_MODULE_NAME, NULL); + run_command(op, cmd, NULL, FALSE, 0, TRUE); + nvfree(cmd); + run_distro_hook(op, "post-uninstall"); free_backup_info(b); diff --git a/common-utils/common-utils.c b/common-utils/common-utils.c new file mode 100644 index 0000000..31f790f --- /dev/null +++ b/common-utils/common-utils.c @@ -0,0 +1,257 @@ +/* + * Copyright (C) 2010 NVIDIA Corporation + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the: + * + * Free Software Foundation, Inc. + * 59 Temple Place - Suite 330 + * Boston, MA 02111-1307, USA + */ + + +#include <stdio.h> +#include <stdarg.h> + +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <fcntl.h> +#include <ctype.h> +#include <pwd.h> + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/mman.h> +#include <sys/ioctl.h> +#include <sys/termios.h> + +#include "common-utils.h" + + +/****************************************************************************/ +/* Memory allocation helper functions */ +/****************************************************************************/ + +/* + * nvalloc() - calloc wrapper that checks for errors; if an error + * occurs, an error is printed to stderr and exit is called -- this + * function will only return on success. + */ + +void *nvalloc(size_t size) +{ + void *m = calloc(1, size); + + if (!m) { + fprintf(stderr, "%s: memory allocation failure (%s)! \n", + PROGRAM_NAME, strerror(errno)); + exit(1); + } + return m; + +} /* nvalloc() */ + + + +/* + * nvstrcat() - allocate a new string, copying all given strings + * into it. taken from glib + */ + +char *nvstrcat(const char *str, ...) +{ + unsigned int l; + va_list args; + char *s; + char *concat; + + l = 1 + strlen(str); + va_start(args, str); + s = va_arg(args, char *); + + while (s) { + l += strlen(s); + s = va_arg(args, char *); + } + va_end(args); + + concat = nvalloc(l); + concat[0] = 0; + + strcat(concat, str); + va_start(args, str); + s = va_arg(args, char *); + while (s) { + strcat(concat, s); + s = va_arg(args, char *); + } + va_end(args); + + return concat; + +} /* nvstrcat() */ + + + +/* + * nvrealloc() - realloc wrapper that checks for errors; if an error + * occurs, an error is printed to stderr and exit is called -- this + * function will only return on success. + */ + +void *nvrealloc(void *ptr, size_t size) +{ + void *m; + + if (ptr == NULL) return nvalloc(size); + + m = realloc(ptr, size); + if (!m) { + fprintf(stderr, "%s: memory re-allocation failure (%s)! \n", + PROGRAM_NAME, strerror(errno)); + exit(1); + } + return m; + +} /* nvrealloc() */ + + + +/* + * nvstrdup() - wrapper for strdup() that checks the return value; if + * an error occurs, an error is printed to stderr and exit is called + * -- this function will only return on success. + */ + +char *nvstrdup(const char *s) +{ + char *m; + + if (!s) return NULL; + + m = strdup(s); + + if (!m) { + fprintf(stderr, "%s: memory allocation failure during strdup (%s)! \n", + PROGRAM_NAME, strerror(errno)); + exit(1); + } + return m; + +} /* nvstrdup() */ + + + +/* + * nvstrtolower() - convert the given string to lowercase. + */ + +char *nvstrtolower(char *s) +{ + char *start = s; + + if (s == NULL) return NULL; + + while (*s) { + *s = tolower(*s); + s++; + } + + return start; + +} /* nvstrtolower() */ + + + +/* + * nvfree() - frees memory allocated with nvalloc(), provided + * a non-NULL pointer is provided. + */ +void nvfree(void *s) +{ + if (s) free(s); + +} /* nvfree() */ + + + +/****************************************************************************/ +/* misc */ +/****************************************************************************/ + +/* + * tilde_expansion() - do tilde expansion on the given path name; + * based loosely on code snippets found in the comp.unix.programmer + * FAQ. The tilde expansion rule is: if a tilde ('~') is alone or + * followed by a '/', then substitute the current user's home + * directory; if followed by the name of a user, then substitute that + * user's home directory. + * + * Returns NULL if its argument is NULL; otherwise, returns a malloced + * and tilde-expanded string. + */ + +char *tilde_expansion(const char *str) +{ + char *prefix = NULL; + const char *replace; + char *user, *ret; + struct passwd *pw; + int len; + + if (!str) return NULL; + + if (str[0] != '~') return strdup(str); + + if ((str[1] == '/') || (str[1] == '\0')) { + + /* expand to the current user's home directory */ + + prefix = getenv("HOME"); + if (!prefix) { + + /* $HOME isn't set; get the home directory from /etc/passwd */ + + pw = getpwuid(getuid()); + if (pw) prefix = pw->pw_dir; + } + + replace = str + 1; + + } else { + + /* expand to the specified user's home directory */ + + replace = strchr(str, '/'); + if (!replace) replace = str + strlen(str); + + len = replace - str; + user = malloc(len + 1); + strncpy(user, str+1, len-1); + user[len] = '\0'; + pw = getpwnam(user); + if (pw) prefix = pw->pw_dir; + free (user); + } + + if (!prefix) return strdup(str); + + ret = malloc(strlen(prefix) + strlen(replace) + 1); + strcpy(ret, prefix); + strcat(ret, replace); + + return ret; + +} /* tilde_expansion() */ diff --git a/alloc-utils.h b/common-utils/common-utils.h index a7f3310..f1b0d4e 100644 --- a/alloc-utils.h +++ b/common-utils/common-utils.h @@ -1,35 +1,42 @@ /* - * nvidia-installer: A tool for installing NVIDIA software packages on - * Unix and Linux systems. - * - * Copyright (C) 2003-2009 NVIDIA Corporation + * Copyright (C) 2010 NVIDIA Corporation * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the: * * Free Software Foundation, Inc. * 59 Temple Place - Suite 330 * Boston, MA 02111-1307, USA - * - * - * alloc-utils.h */ -#ifndef __ALLOC_UTILS_H__ -#define __ALLOC_UTILS_H__ +#ifndef __COMMON_UTILS_H__ +#define __COMMON_UTILS_H__ + +#if !defined(TRUE) +#define TRUE 1 +#endif + +#if !defined(FALSE) +#define FALSE 0 +#endif void *nvalloc(size_t size); +char *nvstrcat(const char *str, ...); void *nvrealloc(void *ptr, size_t size); -void nvfree(char *s); +char *nvstrdup(const char *s); +char *nvstrtolower(char *s); +void nvfree(void *s); + +char *tilde_expansion(const char *str); -#endif /* __ALLOC_UTILS_H__ */ +#endif /* __COMMON_UTILS_H__ */ diff --git a/common-utils/src.mk b/common-utils/src.mk index b93479e..14e4131 100644 --- a/common-utils/src.mk +++ b/common-utils/src.mk @@ -1,7 +1,9 @@ # makefile fragment included by nvidia-xconfig, nvidia-settings, and nvidia-installer COMMON_UTILS_SRC += nvgetopt.c +COMMON_UTILS_SRC += common-utils.c COMMON_UTILS_EXTRA_DIST += nvgetopt.h +COMMON_UTILS_EXTRA_DIST += common-utils.h COMMON_UTILS_EXTRA_DIST += src.mk diff --git a/dist-files.mk b/dist-files.mk index 26c92df..b961392 100644 --- a/dist-files.mk +++ b/dist-files.mk @@ -49,8 +49,6 @@ SRC += update.c SRC += user-interface.c SRC += sanity.c SRC += help-args.c -SRC += string-utils.c -SRC += alloc-utils.c DIST_FILES := $(SRC) @@ -71,8 +69,6 @@ DIST_FILES += snarf.h DIST_FILES += update.h DIST_FILES += user-interface.h DIST_FILES += help-args.h -DIST_FILES += string-utils.h -DIST_FILES += alloc-utils.h DIST_FILES += COPYING DIST_FILES += README diff --git a/help-args.c b/help-args.c index 08db884..a74d213 100644 --- a/help-args.c +++ b/help-args.c @@ -30,8 +30,6 @@ #include <string.h> #include <stdio.h> -#include "string-utils.h" -#include "alloc-utils.h" #include "nvidia-installer.h" #include "format.h" @@ -35,9 +35,6 @@ #include "nvidia-installer.h" #include "command-list.h" -#include "alloc-utils.h" -#include "string-utils.h" - /* * NV_VSNPRINTF() - takes a fmt string, and uses vsnprintf to build * the resulting string whic it assigns to buf. The caller of this diff --git a/nvidia-installer.h b/nvidia-installer.h index 91fe5c8..05e6276 100644 --- a/nvidia-installer.h +++ b/nvidia-installer.h @@ -31,6 +31,7 @@ #include <sys/types.h> #include <stdint.h> +#include "common-utils.h" /* * Enumerated type, listing each of the system utilities we'll need. @@ -273,17 +274,6 @@ typedef struct { -/* define boolean values TRUE and FALSE */ - -#ifndef TRUE -#define TRUE 1 -#endif /* TRUE */ - -#ifndef FALSE -#define FALSE 0 -#endif /* FALSE */ - - /* flags for passing into install_from_cwd() */ #define ADJUST_CWD 0x01 diff --git a/snarf-http.c b/snarf-http.c index 7a089f0..8a2f067 100644 --- a/snarf-http.c +++ b/snarf-http.c @@ -42,6 +42,21 @@ #include "misc.h" +/* + * NV_STRCAT() - takes a dynamically allocated string followed by a + * NULL-terminated list of arbitrary strings and concatenates the + * strings with nvstrcat(); the newly allocated string replaces the + * original one, which is freed. + */ +#define NV_STRCAT(str, args...) \ +do { \ + char *__tmp_str = (str); \ + (str) = nvstrcat(__tmp_str, ##args); \ + nvfree(__tmp_str); \ +} while (0) + + + extern int default_opts; int redirect_count = 0; diff --git a/string-utils.c b/string-utils.c deleted file mode 100644 index 01ddebc..0000000 --- a/string-utils.c +++ /dev/null @@ -1,122 +0,0 @@ -/* - * nvidia-installer: A tool for installing NVIDIA software packages on - * Unix and Linux systems. - * - * Copyright (C) 2003-2009 NVIDIA Corporation - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307, USA - * - * - * string-utils.c: this file contains various helper function used for - * string manipulation in nvidia-installer. - */ - -#include <ctype.h> -#include <string.h> -#include <errno.h> -#include <stdarg.h> -#include <stdio.h> -#include <stdlib.h> - -#include "string-utils.h" -#include "alloc-utils.h" - -/* - * nvstrdup() - wrapper for strdup() that checks the return - * value; if an error occurs, an error is printed to - * stderr and exit is called. This function will only return - * on success. - */ - -char *nvstrdup(const char *s) -{ - char *m; - - if (!s) return NULL; - - m = strdup(s); - - if (!m) { - fprintf(stderr, "%s: memory allocation failure during strdup (%s)! \n", - PROGRAM_NAME, strerror(errno)); - exit(1); - } - return m; - -} /* nvstrdup() */ - - - -/* - * nvstrtolower() - convert the given string to lowercase. - */ - -char *nvstrtolower(char *s) -{ - char *start = s; - - if (s == NULL) return NULL; - - while (*s) { - *s = tolower(*s); - s++; - } - - return start; - -} /* nvstrtolower() */ - - - -/* - * nvstrcat() - allocate a new string, copying all given strings - * into it. taken from glib - */ - -char *nvstrcat(const char *str, ...) -{ - unsigned int l; - va_list args; - char *s; - char *concat; - - l = 1 + strlen(str); - va_start(args, str); - s = va_arg(args, char *); - - while (s) { - l += strlen(s); - s = va_arg(args, char *); - } - va_end(args); - - concat = nvalloc(l); - concat[0] = 0; - - strcat(concat, str); - va_start(args, str); - s = va_arg(args, char *); - while (s) { - strcat(concat, s); - s = va_arg(args, char *); - } - va_end(args); - - return concat; - -} /* nvstrcat() */ diff --git a/string-utils.h b/string-utils.h deleted file mode 100644 index 1dcf500..0000000 --- a/string-utils.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * nvidia-installer: A tool for installing NVIDIA software packages on - * Unix and Linux systems. - * - * Copyright (C) 2003-2009 NVIDIA Corporation - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the: - * - * Free Software Foundation, Inc. - * 59 Temple Place - Suite 330 - * Boston, MA 02111-1307, USA - * - * - * string-utils.h - */ - -#ifndef __STRING_UTILS_H__ -#define __STRING_UTILS_H__ - -/* - * NV_STRCAT() - takes a dynamically allocated string followed by a - * NULL-terminated list of arbitrary strings and concatenates the - * strings with nvstrcat(); the newly allocated string replaces the - * original one, which is freed. - */ -#define NV_STRCAT(str, args...) \ -do { \ - char *__tmp_str = (str); \ - (str) = nvstrcat(__tmp_str, ##args); \ - nvfree(__tmp_str); \ -} while (0) - -char *nvstrdup(const char *s); -char *nvstrtolower(char *s); -char *nvstrcat(const char *str, ...); - -#endif /* __STRING_UTILS_H__ */ @@ -97,6 +97,12 @@ ifndef TARGET_ARCH TARGET_ARCH := $(subst i686,x86,$(TARGET_ARCH)) endif +ifeq ($(TARGET_OS),Linux) + LIBDL_LDFLAGS = -ldl +else + LIBDL_LDFLAGS = +endif + OUTPUTDIR ?= _out/$(TARGET_OS)_$(TARGET_ARCH) NV_QUIET_COMMAND_REMOVED_TARGET_PREFIX ?= @@ -1 +1 @@ -NVIDIA_VERSION = 260.19.36 +NVIDIA_VERSION = 270.18 |