Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
6
66
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Vidal
66
Commits
0a6ef7dc
Commit
0a6ef7dc
authored
5 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
add build_env,env_get_from_src function
parent
e0baa14b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/66/environ.h
+3
-1
3 additions, 1 deletion
src/include/66/environ.h
src/lib66/environ.c
+117
-0
117 additions, 0 deletions
src/lib66/environ.c
with
120 additions
and
1 deletion
src/include/66/environ.h
+
3
−
1
View file @
0a6ef7dc
...
...
@@ -20,7 +20,7 @@
#define MAXVAR 50
#define MAXFILE 500
#define MAXENV 409
6
#define MAXENV 409
5
typedef
struct
exlsn_s
exlsn_t
,
*
exlsn_t_ref
;
struct
exlsn_s
...
...
@@ -41,4 +41,6 @@ extern int env_parsenclean(stralloc *modifs,stralloc *src) ;
extern
int
make_env_from_line
(
char
const
**
v
,
stralloc
*
sa
)
;
extern
int
env_substitute
(
char
const
*
key
,
char
const
*
val
,
exlsn_t
*
info
,
char
const
*
const
*
envp
,
int
unexport
)
;
extern
int
env_addkv
(
const
char
*
key
,
const
char
*
val
,
exlsn_t
*
info
)
;
extern
size_t
build_env
(
char
const
*
src
,
char
const
*
const
*
envp
,
char
const
**
newenv
,
char
*
tmpenv
)
;
extern
int
env_get_from_src
(
stralloc
*
modifs
,
char
const
*
src
)
;
#endif
This diff is collapsed.
Click to expand it.
src/lib66/environ.c
+
117
−
0
View file @
0a6ef7dc
...
...
@@ -17,15 +17,21 @@
#include
<oblibs/string.h>
#include
<oblibs/stralist.h>
#include
<oblibs/directory.h>
#include
<oblibs/files.h>
#include
<oblibs/types.h>
#include
<skalibs/stralloc.h>
#include
<skalibs/genalloc.h>
#include
<skalibs/diuint32.h>
#include
<skalibs/env.h>
#include
<skalibs/strerr2.h>
#include
<skalibs/djbunix.h>
#include
<skalibs/bytestr.h>
#include
<66/parser.h>
#include
<66/environ.h>
#include
<66/utils.h>
#include
<execline/execline.h>
/* @Return 1 on success
...
...
@@ -270,3 +276,114 @@ int env_addkv (const char *key, const char *val, exlsn_t *info)
info
->
values
.
len
=
blah
.
value
;
return
0
;
}
int
env_get_from_src
(
stralloc
*
modifs
,
char
const
*
src
)
{
int
r
;
size_t
filesize
;
unsigned
int
i
;
stralloc
sa
=
STRALLOC_ZERO
;
genalloc
toparse
=
GENALLOC_ZERO
;
r
=
scan_mode
(
src
,
S_IFDIR
)
;
if
(
r
<
0
)
{
r
=
scan_mode
(
src
,
S_IFREG
)
;
if
(
!
r
||
r
<
0
)
{
VERBO3
strerr_warnw2sys
(
"invalid environment: "
,
src
)
;
goto
err
;
}
filesize
=
file_get_size
(
src
)
;
if
(
filesize
>
MAXENV
)
{
VERBO3
strerr_warnw2x
(
"environment too long: "
,
src
)
;
goto
err
;
}
if
(
!
openreadfileclose
(
src
,
&
sa
,
filesize
))
{
VERBO3
strerr_warnwu2sys
(
"open: "
,
src
)
;
goto
err
;
}
if
(
!
env_parsenclean
(
modifs
,
&
sa
))
{
VERBO3
strerr_warnwu2x
(
"parse and clean environment of: "
,
sa
.
s
)
;
goto
err
;
}
}
else
if
(
!
r
)
{
VERBO3
strerr_warnw2sys
(
"invalid environment: "
,
src
)
;
goto
err
;
}
/** we parse all file of the directory*/
else
{
r
=
dir_get
(
&
toparse
,
src
,
""
,
S_IFREG
)
;
if
(
!
r
)
{
VERBO3
strerr_warnwu2sys
(
"get file from: "
,
src
)
;
goto
err
;
}
for
(
i
=
0
;
i
<
genalloc_len
(
stralist
,
&
toparse
)
;
i
++
)
{
sa
.
len
=
0
;
if
(
i
>
MAXFILE
)
{
VERBO3
strerr_warnw2x
(
"to many file to parse in: "
,
src
)
;
goto
err
;
}
if
(
!
file_readputsa
(
&
sa
,
src
,
gaistr
(
&
toparse
,
i
)))
{
VERBO3
strerr_warnw4x
(
"read file: "
,
src
,
"/"
,
gaistr
(
&
toparse
,
i
))
;
goto
err
;
}
if
(
!
env_parsenclean
(
modifs
,
&
sa
))
{
VERBO3
strerr_warnw4x
(
"parse and clean environment of: "
,
src
,
"/"
,
gaistr
(
&
toparse
,
i
))
;
goto
err
;
}
}
}
genalloc_deepfree
(
stralist
,
&
toparse
,
stra_free
)
;
stralloc_free
(
&
sa
)
;
return
1
;
err:
genalloc_deepfree
(
stralist
,
&
toparse
,
stra_free
)
;
stralloc_free
(
&
sa
)
;
return
0
;
}
size_t
build_env
(
char
const
*
src
,
char
const
*
const
*
envp
,
char
const
**
newenv
,
char
*
tmpenv
)
{
stralloc
modifs
=
STRALLOC_ZERO
;
size_t
envlen
=
env_len
(
envp
)
;
if
(
!
env_get_from_src
(
&
modifs
,
src
))
{
VERBO3
strerr_warnw2x
(
"get environment file from: "
,
src
)
;
goto
err
;
}
size_t
n
=
env_len
(
envp
)
+
1
+
byte_count
(
modifs
.
s
,
modifs
.
len
,
'\0'
)
;
size_t
mlen
=
modifs
.
len
;
if
(
mlen
>
MAXENV
)
{
VERBO3
strerr_warnw2x
(
"environment too long: "
,
src
)
;
goto
err
;
}
memcpy
(
tmpenv
,
modifs
.
s
,
mlen
)
;
tmpenv
[
mlen
]
=
0
;
if
(
!
env_merge
(
newenv
,
n
,
envp
,
envlen
,
tmpenv
,
mlen
))
{
VERBO3
strerr_warnwu2x
(
"merge environment from: "
,
src
)
;
goto
err
;
}
stralloc_free
(
&
modifs
)
;
return
1
;
err:
stralloc_free
(
&
modifs
)
;
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment