Merge ~dirk.zimoch/epics-base:epicsEnvUnset into ~epics-core/epics-base/+git/epics-base:3.15

Proposed by Dirk Zimoch
Status: Merged
Approved by: Ralph Lange
Approved revision: 3cb72ec2091bd3e03b742ee3d8e8da426c09b210
Merge reported by: Ralph Lange
Merged at revision: 3cb72ec2091bd3e03b742ee3d8e8da426c09b210
Proposed branch: ~dirk.zimoch/epics-base:epicsEnvUnset
Merge into: ~epics-core/epics-base/+git/epics-base:3.15
Diff against target: 225 lines (+117/-0) (has conflicts)
9 files modified
documentation/RELEASE_NOTES.html (+6/-0)
src/libCom/env/envDefs.h (+1/-0)
src/libCom/iocsh/libComRegister.c (+16/-0)
src/libCom/osi/os/Darwin/osdEnv.c (+10/-0)
src/libCom/osi/os/default/osdEnv.c (+12/-0)
src/libCom/osi/os/iOS/osdEnv.c (+10/-0)
src/libCom/osi/os/vxWorks/osdEnv.c (+19/-0)
src/libCom/test/Makefile (+5/-0)
src/libCom/test/epicsEnvUnsetTest.c (+38/-0)
Conflict in documentation/RELEASE_NOTES.html
Reviewer Review Type Date Requested Status
Ralph Lange Approve
Review via email: mp+356070@code.launchpad.net

Description of the change

Allow to unset variables:
epics> echo $(ABC=default)
default
epics> epicsEnvSet ABC 123
epics> echo $(ABC=default)
123
epics> epicsEnvSet ABC ""
epics> echo $(ABC=default)

epics> epicsEnvUnset ABC
epics> echo $(ABC=default)
default

Tested on Linux and vxWorks 5.

To post a comment you must log in.
Revision history for this message
Ralph Lange (ralph-lange) wrote :

I would like to see a unit test go with that.
(For a while, the rule has been "new features must have tests - if feasible with reasonable effort".)

Also, a paragraph in the release notes would be good, and maybe a matching one in the App Developer's Guide to the Galaxy.

review: Needs Fixing
Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

After resolving the conflict in RELEASE_NOTES.html and pushing the fix, I got this email:

Launchpad encountered an internal error during the following operation: generating the diff for a merge proposal. It was logged with id OOPS-c0b008c54badfcd19623e5db4af8826d. Sorry for the inconvenience.

Should I be concerned about this?

Revision history for this message
Ralph Lange (ralph-lange) wrote :

Nah. Did you retry?

Revision history for this message
Dirk Zimoch (dirk.zimoch) wrote :

Says: Everything up-to-date
But this page still claims a conflict in RELEASE_NOTES.html.

Revision history for this message
Ralph Lange (ralph-lange) wrote :

Even if it were real: it is just an easy-to-resolve release notes thing, no worries.

Revision history for this message
Ralph Lange (ralph-lange) wrote :

Looking good now. Will merge with some trivial changes.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/documentation/RELEASE_NOTES.html b/documentation/RELEASE_NOTES.html
2index 84e8899..eecac26 100644
3--- a/documentation/RELEASE_NOTES.html
4+++ b/documentation/RELEASE_NOTES.html
5@@ -16,6 +16,7 @@
6
7 <!-- Insert new items immediately below here ... -->
8
9+<<<<<<< documentation/RELEASE_NOTES.html
10 <h3>Warning indicators in msi (and macLib) output</h3>
11
12 <p>The libCom macro expansion library has been modified so that when the
13@@ -50,6 +51,11 @@ explaining how Perl POD (Plain Old Documentation) markup can be added to
14 <tt>.dbd</tt> files to generate HTML documentation for the record types. To see
15 these instructions, run <tt>perl&nbsp;bin/&lt;host&gt;/dbdToHtml.pl&nbsp;-H</tt>
16 or <tt>perldoc&nbsp;bin/&lt;host&gt;/dbdToHtml.pl</tt>.</p>
17+=======
18+<h3>Unsetting environment variables</h3>
19+The new command <code>epicsEnvUnset <i>varname</i></code> can be used to
20+unset an environment variable.
21+>>>>>>> documentation/RELEASE_NOTES.html
22
23 <h3>Fix problem with numeric soft events</h3>
24
25diff --git a/src/libCom/env/envDefs.h b/src/libCom/env/envDefs.h
26index ac61325..20f0eb2 100644
27--- a/src/libCom/env/envDefs.h
28+++ b/src/libCom/env/envDefs.h
29@@ -95,6 +95,7 @@ epicsShareFunc long epicsShareAPI
30 envGetBoolConfigParam(const ENV_PARAM *pParam, int *pBool);
31 epicsShareFunc long epicsShareAPI epicsPrtEnvParams(void);
32 epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *value);
33+epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name);
34 epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name);
35
36 #ifdef __cplusplus
37diff --git a/src/libCom/iocsh/libComRegister.c b/src/libCom/iocsh/libComRegister.c
38index d3a5cfa..d8429fa 100644
39--- a/src/libCom/iocsh/libComRegister.c
40+++ b/src/libCom/iocsh/libComRegister.c
41@@ -110,6 +110,21 @@ static void epicsEnvSetCallFunc(const iocshArgBuf *args)
42 epicsEnvSet (name, value);
43 }
44
45+/* epicsEnvUnset */
46+static const iocshArg epicsEnvUnsetArg0 = { "name",iocshArgString};
47+static const iocshArg * const epicsEnvUnsetArgs[1] = {&epicsEnvUnsetArg0};
48+static const iocshFuncDef epicsEnvUnsetFuncDef = {"epicsEnvUnset",1,epicsEnvUnsetArgs};
49+static void epicsEnvUnsetCallFunc(const iocshArgBuf *args)
50+{
51+ char *name = args[0].sval;
52+
53+ if (name == NULL) {
54+ fprintf(stderr, "Missing environment variable name argument.\n");
55+ return;
56+ }
57+ epicsEnvUnset (name);
58+}
59+
60 /* epicsParamShow */
61 static const iocshFuncDef epicsParamShowFuncDef = {"epicsParamShow",0,NULL};
62 static void epicsParamShowCallFunc(const iocshArgBuf *args)
63@@ -367,6 +382,7 @@ void epicsShareAPI libComRegister(void)
64 iocshRegister(&pwdFuncDef, pwdCallFunc);
65
66 iocshRegister(&epicsEnvSetFuncDef, epicsEnvSetCallFunc);
67+ iocshRegister(&epicsEnvUnsetFuncDef, epicsEnvUnsetCallFunc);
68 iocshRegister(&epicsParamShowFuncDef, epicsParamShowCallFunc);
69 iocshRegister(&epicsPrtEnvParamsFuncDef, epicsPrtEnvParamsCallFunc);
70 iocshRegister(&epicsEnvShowFuncDef, epicsEnvShowCallFunc);
71diff --git a/src/libCom/osi/os/Darwin/osdEnv.c b/src/libCom/osi/os/Darwin/osdEnv.c
72index ab3f936..f7ff12c 100644
73--- a/src/libCom/osi/os/Darwin/osdEnv.c
74+++ b/src/libCom/osi/os/Darwin/osdEnv.c
75@@ -40,6 +40,16 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
76 }
77
78 /*
79+ * Unset an environment variable
80+ */
81+
82+epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
83+{
84+ iocshEnvClear(name);
85+ unsetenv(name);
86+}
87+
88+/*
89 * Show the value of the specified, or all, environment variables
90 */
91 epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name)
92diff --git a/src/libCom/osi/os/default/osdEnv.c b/src/libCom/osi/os/default/osdEnv.c
93index 682bcc9..d069f46 100644
94--- a/src/libCom/osi/os/default/osdEnv.c
95+++ b/src/libCom/osi/os/default/osdEnv.c
96@@ -56,6 +56,18 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
97 }
98
99 /*
100+ * Unset an environment variable
101+ * Using putenv with a an exsiting name but without "=..." deletes the variable.
102+ */
103+
104+epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
105+{
106+ iocshEnvClear(name);
107+ if (getenv(name) != NULL)
108+ putenv((char*)name);
109+}
110+
111+/*
112 * Show the value of the specified, or all, environment variables
113 */
114 epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name)
115diff --git a/src/libCom/osi/os/iOS/osdEnv.c b/src/libCom/osi/os/iOS/osdEnv.c
116index a32cce5..0c25672 100644
117--- a/src/libCom/osi/os/iOS/osdEnv.c
118+++ b/src/libCom/osi/os/iOS/osdEnv.c
119@@ -37,6 +37,16 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
120 }
121
122 /*
123+ * Unset an environment variable
124+ */
125+
126+epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
127+{
128+ iocshEnvClear(name);
129+ unsetenv(name);
130+}
131+
132+/*
133 * Show the value of the specified, or all, environment variables
134 */
135 epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name)
136diff --git a/src/libCom/osi/os/vxWorks/osdEnv.c b/src/libCom/osi/os/vxWorks/osdEnv.c
137index c81f493..f098976 100644
138--- a/src/libCom/osi/os/vxWorks/osdEnv.c
139+++ b/src/libCom/osi/os/vxWorks/osdEnv.c
140@@ -52,6 +52,25 @@ epicsShareFunc void epicsShareAPI epicsEnvSet (const char *name, const char *val
141 }
142
143 /*
144+ * Unset an environment variable
145+ * Basically destroy the name of that variable because vxWorks does not
146+ * support to really uset an environment variable.
147+ */
148+
149+epicsShareFunc void epicsShareAPI epicsEnvUnset (const char *name)
150+{
151+ char* var;
152+
153+ if (!name) return;
154+ iocshEnvClear(name);
155+ var = getenv(name);
156+ if (!var) return;
157+ var -= strlen(name);
158+ var --;
159+ *var = 0;
160+}
161+
162+/*
163 * Show the value of the specified, or all, environment variables
164 */
165 epicsShareFunc void epicsShareAPI epicsEnvShow (const char *name)
166diff --git a/src/libCom/test/Makefile b/src/libCom/test/Makefile
167index 89eb87f..c803393 100755
168--- a/src/libCom/test/Makefile
169+++ b/src/libCom/test/Makefile
170@@ -62,6 +62,11 @@ epicsEnvTest_SRCS += epicsEnvTest.c
171 testHarness_SRCS += epicsEnvTest.c
172 TESTS += epicsEnvTest
173
174+TESTPROD_HOST += epicsEnvUnsetTest
175+epicsEnvUnsetTest_SRCS += epicsEnvUnsetTest.c
176+testHarness_SRCS += epicsEnvUnsetTest.c
177+TESTS += epicsEnvUnsetTest
178+
179 TESTPROD_HOST += epicsErrlogTest
180 epicsErrlogTest_SRCS += epicsErrlogTest.c
181 testHarness_SRCS += epicsErrlogTest.c
182diff --git a/src/libCom/test/epicsEnvUnsetTest.c b/src/libCom/test/epicsEnvUnsetTest.c
183new file mode 100644
184index 0000000..3697a4b
185--- /dev/null
186+++ b/src/libCom/test/epicsEnvUnsetTest.c
187@@ -0,0 +1,38 @@
188+#include <stddef.h>
189+#include <stdlib.h>
190+#include <string.h>
191+#include <stdio.h>
192+
193+#include "macLib.h"
194+#include "envDefs.h"
195+#include "errlog.h"
196+#include "epicsUnitTest.h"
197+#include "testMain.h"
198+
199+static void check(const char* variable, const char* expected)
200+{
201+ const char* value;
202+
203+ value = getenv(variable);
204+ if (!testOk((!expected && !value) || (expected && value && strcmp(expected, value) == 0),
205+ "%s = \"%s\"", variable, value))
206+ {
207+ testDiag("should have been \"%s\"", expected);
208+ }
209+}
210+
211+
212+MAIN(epicsEnvUnsetTest)
213+{
214+ eltc(0);
215+ testPlan(3);
216+
217+ check("TEST_VAR_A",NULL);
218+ epicsEnvSet("TEST_VAR_A","test value");
219+ check("TEST_VAR_A","test value");
220+ epicsEnvUnset("TEST_VAR_A");
221+ check("TEST_VAR_A",NULL);
222+
223+ testDone();
224+ return 0;
225+}

Subscribers

People subscribed via source and target branches