Explorar o código

Use string literals instead of macros for environment variable names

The environment variable names are part of the exposed API, and as such
would need a transition plan in case of name change. Inline the macro
values to ease code reading.
Guillem Jover %!s(int64=15) %!d(string=hai) anos
pai
achega
76ed5f9ff4
Modificáronse 6 ficheiros con 8 adicións e 15 borrados
  1. 1 1
      lib/dpkg/command.c
  2. 0 7
      lib/dpkg/dpkg.h
  3. 1 1
      src/configure.c
  4. 1 1
      src/divertcmd.c
  5. 4 4
      src/help.c
  6. 1 1
      src/trigcmd.c

+ 1 - 1
lib/dpkg/command.c

@@ -195,7 +195,7 @@ command_shell(const char *cmd, const char *name)
 	const char *shell;
 	const char *mode;
 
-	shell = getenv(SHELLENV);
+	shell = getenv("SHELL");
 	if (shell == NULL || shell[0] == '\0')
 		shell = DEFAULTSHELL;
 

+ 0 - 7
lib/dpkg/dpkg.h

@@ -76,14 +76,7 @@ DPKG_BEGIN_DECLS
 #define IMPORTANTFMT      "%04d"
 #define MAXUPDATES         250
 
-#define MAINTSCRIPTPKGENVVAR "DPKG_MAINTSCRIPT_PACKAGE"
-#define MAINTSCRIPTARCHENVVAR "DPKG_MAINTSCRIPT_ARCH"
-#define MAINTSCRIPTNAMEENVVAR "DPKG_MAINTSCRIPT_NAME"
-#define MAINTSCRIPTDPKGENVVAR "DPKG_RUNNING_VERSION"
-
-#define SHELLENV            "SHELL"
 #define DEFAULTSHELL        "sh"
-#define PAGERENV            "PAGER"
 #define DEFAULTPAGER        "pager"
 
 #define MD5HASHLEN           32

+ 1 - 1
src/configure.c

@@ -505,7 +505,7 @@ showdiff(const char *old, const char *new)
 		const char *pager;
 		char cmdbuf[1024];
 
-		pager = getenv(PAGERENV);
+		pager = getenv("PAGER");
 		if (!pager || !*pager)
 			pager = DEFAULTPAGER;
 

+ 1 - 1
src/divertcmd.c

@@ -713,7 +713,7 @@ main(int argc, const char * const *argv)
 	standard_startup();
 	myopt(&argv, cmdinfos);
 
-	env_pkgname = getenv(MAINTSCRIPTPKGENVVAR);
+	env_pkgname = getenv("DPKG_MAINTSCRIPT_PACKAGE");
 	if (!opt_pkgname && env_pkgname)
 		setpackage(NULL, env_pkgname);
 

+ 4 - 4
src/help.c

@@ -263,10 +263,10 @@ do_script(struct pkginfo *pkg, struct pkgbin *pif,
 
   c1 = subproc_fork();
   if (!c1) {
-    if (setenv(MAINTSCRIPTPKGENVVAR, pkg->name, 1) ||
-        setenv(MAINTSCRIPTARCHENVVAR, pif->architecture, 1) ||
-        setenv(MAINTSCRIPTNAMEENVVAR, cmd->argv[0], 1) ||
-        setenv(MAINTSCRIPTDPKGENVVAR, PACKAGE_VERSION, 1))
+    if (setenv("DPKG_MAINTSCRIPT_PACKAGE", pkg->name, 1) ||
+        setenv("DPKG_MAINTSCRIPT_ARCH", pif->architecture, 1) ||
+        setenv("DPKG_MAINTSCRIPT_NAME", cmd->argv[0], 1) ||
+        setenv("DPKG_RUNNING_VERSION", PACKAGE_VERSION, 1))
       ohshite(_("unable to setenv for maintainer script"));
 
     cmd->filename = cmd->argv[0] = preexecscript(cmd);

+ 1 - 1
src/trigcmd.c

@@ -204,7 +204,7 @@ main(int argc, const char *const *argv)
 		badusage(_("takes one argument, the trigger name"));
 
 	if (!bypackage) {
-		bypackage = getenv(MAINTSCRIPTPKGENVVAR);
+		bypackage = getenv("DPKG_MAINTSCRIPT_PACKAGE");
 		if (!bypackage)
 			ohshit(_("must be called from a maintainer script"
 			         " (or with a --by-package option)"));