Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
swmodd
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LCM
swmodd
Commits
3bfc97cd
Commit
3bfc97cd
authored
May 26, 2020
by
Amin Ben Ramdhane
Browse files
Options
Downloads
Patches
Plain Diff
Clean up
parent
ea25f283
No related branches found
No related tags found
No related merge requests found
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
Makefile
+1
-1
1 addition, 1 deletion
Makefile
common.c
+81
-83
81 additions, 83 deletions
common.c
common.h
+27
-22
27 additions, 22 deletions
common.h
swmod.c
+131
-158
131 additions, 158 deletions
swmod.c
with
240 additions
and
264 deletions
Makefile
+
1
−
1
View file @
3bfc97cd
...
...
@@ -11,7 +11,7 @@ PROG_LDFLAGS += -luci -lubus -lubox -ljson-c -lblobmsg_json -luuid
all
:
${PROG}
${PROG}
:
$(OBJS)
$(
CC
)
$(
PROG_
LD
FLAGS
)
-o
$@
$^
$(
CC
)
$(
PROG_
C
FLAGS
)
-o
$@
$^
$(
PROG_LDFLAGS
)
clean
:
rm
-f
*
.o
$(
PROG
)
This diff is collapsed.
Click to expand it.
common.c
+
81
−
83
View file @
3bfc97cd
...
...
@@ -20,32 +20,31 @@
* 02110-1301 USA
*/
#include
"common.h"
static
struct
uci_context
*
uci_ctx_
opkg
=
NULL
;
static
struct
uci_context
*
uci_ctx_
swmod
=
NULL
;
int
opkg
_uci_init
(
void
)
int
swmod
_uci_init
(
void
)
{
uci_ctx_
opkg
=
uci_alloc_context
();
if
(
!
uci_ctx_
opkg
)
{
uci_ctx_
swmod
=
uci_alloc_context
();
if
(
!
uci_ctx_
swmod
)
{
return
-
1
;
}
uci_add_delta_path
(
uci_ctx_
opkg
,
uci_ctx_
opkg
->
savedir
);
uci_set_savedir
(
uci_ctx_
opkg
,
OPKG_SAVEDIR
_PATH
);
uci_set_confdir
(
uci_ctx_
opkg
,
OPKG_CONFDIR
_PATH
);
uci_add_delta_path
(
uci_ctx_
swmod
,
uci_ctx_
swmod
->
savedir
);
uci_set_savedir
(
uci_ctx_
swmod
,
SWMOD
_PATH
);
uci_set_confdir
(
uci_ctx_
swmod
,
SWMOD
_PATH
);
return
0
;
}
int
opkg
_uci_fini
(
void
)
int
swmod
_uci_fini
(
void
)
{
if
(
uci_ctx_
opkg
)
{
uci_free_context
(
uci_ctx_
opkg
);
if
(
uci_ctx_
swmod
)
{
uci_free_context
(
uci_ctx_
swmod
);
}
return
0
;
}
static
bool
opkg
_uci_validate_section
(
const
char
*
str
)
static
bool
swmod
_uci_validate_section
(
const
char
*
str
)
{
if
(
!*
str
)
return
false
;
...
...
@@ -61,7 +60,7 @@ static bool opkg_uci_validate_section(const char *str)
return
true
;
}
static
int
opkg
_uci_init_ptr
(
struct
uci_ptr
*
ptr
,
char
*
package
,
char
*
section
,
char
*
option
,
char
*
value
)
static
int
swmod
_uci_init_ptr
(
struct
uci_ptr
*
ptr
,
char
*
package
,
char
*
section
,
char
*
option
,
char
*
value
)
{
memset
(
ptr
,
0
,
sizeof
(
struct
uci_ptr
));
...
...
@@ -88,7 +87,7 @@ static int opkg_uci_init_ptr(struct uci_ptr *ptr, char *package, char *section,
}
lastval:
if
(
ptr
->
section
&&
!
opkg
_uci_validate_section
(
ptr
->
section
))
if
(
ptr
->
section
&&
!
swmod
_uci_validate_section
(
ptr
->
section
))
ptr
->
flags
|=
UCI_LOOKUP_EXTENDED
;
return
0
;
...
...
@@ -97,7 +96,7 @@ error:
return
-
1
;
}
struct
uci_section
*
opkg
_uci_walk_section
(
char
*
package
,
char
*
section_type
,
struct
uci_section
*
prev_section
)
struct
uci_section
*
swmod
_uci_walk_section
(
char
*
package
,
char
*
section_type
,
struct
uci_section
*
prev_section
)
{
struct
uci_ptr
ptr
;
struct
uci_element
*
e
;
...
...
@@ -113,10 +112,10 @@ struct uci_section *opkg_uci_walk_section(char *package, char *section_type, str
return
next_section
;
}
else
{
if
(
opkg
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
{
if
(
swmod
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
{
return
NULL
;
}
if
(
uci_lookup_ptr
(
uci_ctx_
opkg
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
{
if
(
uci_lookup_ptr
(
uci_ctx_
swmod
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
{
return
NULL
;
}
if
(
ptr
.
p
->
sections
.
next
==
&
ptr
.
p
->
sections
)
...
...
@@ -135,10 +134,10 @@ struct uci_section *opkg_uci_walk_section(char *package, char *section_type, str
shead
=
&
prev_section
->
package
->
sections
;
}
else
{
if
(
opkg
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
{
if
(
swmod
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
{
return
NULL
;
}
if
(
uci_lookup_ptr
(
uci_ctx_
opkg
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
{
if
(
uci_lookup_ptr
(
uci_ctx_
swmod
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
{
return
NULL
;
}
ul
=
&
ptr
.
p
->
sections
;
...
...
@@ -156,7 +155,7 @@ struct uci_section *opkg_uci_walk_section(char *package, char *section_type, str
return
NULL
;
}
void
opkg
_uci_print_list
(
struct
uci_list
*
uh
,
char
**
val
,
char
*
delimiter
)
void
swmod
_uci_print_list
(
struct
uci_list
*
uh
,
char
**
val
,
char
*
delimiter
)
{
struct
uci_element
*
e
;
static
char
buffer
[
512
];
...
...
@@ -174,7 +173,7 @@ void opkg_uci_print_list(struct uci_list *uh, char **val, char *delimiter)
*
val
=
buf
;
}
struct
uci_element
*
opkg
_uci_lookup_list
(
struct
uci_list
*
list
,
const
char
*
name
)
struct
uci_element
*
swmod
_uci_lookup_list
(
struct
uci_list
*
list
,
const
char
*
name
)
{
struct
uci_element
*
e
;
...
...
@@ -185,7 +184,7 @@ struct uci_element *opkg_uci_lookup_list(struct uci_list *list, const char *name
return
NULL
;
}
int
opkg
_uci_lookup_ptr_by_section
(
struct
uci_ptr
*
ptr
,
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
int
swmod
_uci_lookup_ptr_by_section
(
struct
uci_ptr
*
ptr
,
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
{
struct
uci_element
*
e
;
memset
(
ptr
,
0
,
sizeof
(
struct
uci_ptr
));
...
...
@@ -200,7 +199,7 @@ int opkg_uci_lookup_ptr_by_section(struct uci_ptr *ptr, struct uci_section *sect
ptr
->
s
=
section
;
if
(
ptr
->
option
)
{
e
=
opkg
_uci_lookup_list
(
&
ptr
->
s
->
options
,
ptr
->
option
);
e
=
swmod
_uci_lookup_list
(
&
ptr
->
s
->
options
,
ptr
->
option
);
if
(
!
e
)
return
UCI_OK
;
ptr
->
o
=
uci_to_option
(
e
);
...
...
@@ -217,19 +216,19 @@ int opkg_uci_lookup_ptr_by_section(struct uci_ptr *ptr, struct uci_section *sect
return
UCI_OK
;
}
char
*
opkg
_uci_get_value_by_section
(
struct
uci_section
*
section
,
char
*
option
)
char
*
swmod
_uci_get_value_by_section
(
struct
uci_section
*
section
,
char
*
option
)
{
struct
uci_ptr
ptr
;
char
*
val
=
""
;
if
(
opkg
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
NULL
)
!=
UCI_OK
)
if
(
swmod
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
NULL
)
!=
UCI_OK
)
return
val
;
if
(
!
ptr
.
o
)
return
val
;
if
(
ptr
.
o
->
type
==
UCI_TYPE_LIST
)
{
opkg
_uci_print_list
(
&
ptr
.
o
->
v
.
list
,
&
val
,
" "
);
swmod
_uci_print_list
(
&
ptr
.
o
->
v
.
list
,
&
val
,
" "
);
return
val
;
}
...
...
@@ -239,7 +238,7 @@ char *opkg_uci_get_value_by_section(struct uci_section *section, char *option)
return
val
;
}
char
*
opkg
_uci_set_value_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
char
*
swmod
_uci_set_value_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
{
struct
uci_ptr
ptr
;
int
ret
=
UCI_OK
;
...
...
@@ -247,13 +246,13 @@ char *opkg_uci_set_value_by_section(struct uci_section *section, char *option, c
if
(
section
==
NULL
)
return
""
;
if
(
opkg
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
value
)
!=
UCI_OK
)
if
(
swmod
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
value
)
!=
UCI_OK
)
return
""
;
uci_set
(
uci_ctx_
opkg
,
&
ptr
);
uci_set
(
uci_ctx_
swmod
,
&
ptr
);
if
(
ret
==
UCI_OK
)
ret
=
uci_save
(
uci_ctx_
opkg
,
ptr
.
p
);
ret
=
uci_save
(
uci_ctx_
swmod
,
ptr
.
p
);
if
(
ptr
.
o
&&
ptr
.
o
->
v
.
string
)
return
ptr
.
o
->
v
.
string
;
...
...
@@ -261,35 +260,35 @@ char *opkg_uci_set_value_by_section(struct uci_section *section, char *option, c
return
""
;
}
struct
uci_section
*
opkg
_uci_add_section
(
char
*
package
,
char
*
section_type
)
struct
uci_section
*
swmod
_uci_add_section
(
char
*
package
,
char
*
section_type
)
{
struct
uci_ptr
ptr
;
struct
uci_section
*
s
=
NULL
;
if
(
opkg
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
if
(
swmod
_uci_init_ptr
(
&
ptr
,
package
,
NULL
,
NULL
,
NULL
))
return
NULL
;
if
(
uci_lookup_ptr
(
uci_ctx_
opkg
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
if
(
uci_lookup_ptr
(
uci_ctx_
swmod
,
&
ptr
,
NULL
,
true
)
!=
UCI_OK
)
return
NULL
;
int
ret
=
uci_add_section
(
uci_ctx_
opkg
,
ptr
.
p
,
section_type
,
&
s
);
int
ret
=
uci_add_section
(
uci_ctx_
swmod
,
ptr
.
p
,
section_type
,
&
s
);
if
(
ret
!=
UCI_OK
)
return
NULL
;
return
s
;
}
int
opkg
_uci_delete_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
int
swmod
_uci_delete_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
)
{
struct
uci_ptr
ptr
=
{
0
};
if
(
section
==
NULL
)
return
-
1
;
if
(
opkg
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
value
)
!=
UCI_OK
)
if
(
swmod
_uci_lookup_ptr_by_section
(
&
ptr
,
section
,
option
,
value
)
!=
UCI_OK
)
return
-
1
;
if
(
uci_delete
(
uci_ctx_
opkg
,
&
ptr
)
!=
UCI_OK
)
if
(
uci_delete
(
uci_ctx_
swmod
,
&
ptr
)
!=
UCI_OK
)
return
-
1
;
return
0
;
...
...
@@ -306,7 +305,7 @@ void remove_newline(char *buf)
char
*
get_package_name
(
char
*
full_name
)
{
static
char
name
[
32
]
=
""
;
strncpy
(
name
,
full_name
,
sizeof
(
name
));
swmod_
strncpy
(
name
,
full_name
,
sizeof
(
name
));
char
*
dot
=
strchr
(
name
,
'.'
);
if
(
dot
)
*
dot
=
'\0'
;
...
...
@@ -323,7 +322,7 @@ int isfileexist(const char *filepath)
int
islxcrunning
(
char
*
lxc_name
)
{
char
command
[
256
],
state
[
16
];
char
command
[
256
]
=
{
0
}
,
state
[
16
]
=
{
0
}
;
FILE
*
in
;
if
(
isfileexist
(
LXC_INFO
))
{
...
...
@@ -343,7 +342,7 @@ int islxcrunning(char *lxc_name)
char
*
convert_url
(
char
*
url
,
char
*
username
,
char
*
password
)
{
static
char
buf
[
256
]
=
""
;
static
char
buf
[
256
]
=
{
0
}
;
if
(
strncmp
(
url
,
"http://"
,
7
)
==
0
)
snprintf
(
buf
,
sizeof
(
buf
),
"http://%s:%s@%s"
,
username
,
password
,
url
+
7
);
...
...
@@ -364,51 +363,50 @@ char *generate_uuid(void)
char
*
generate_duid
(
bool
sysnchronise
,
int
number
)
{
char
buf
[
36
]
=
"0123456789abcdefghijklmnopqrstuvwxyz"
,
euid
[
6
4
]
=
""
,
euid_num
[
8
]
=
""
;
char
buf
[
36
]
=
"0123456789abcdefghijklmnopqrstuvwxyz"
,
euid
[
1
6
]
=
{
0
}
,
euid_num
[
8
]
=
{
0
}
;
int
i
;
srand
(
time
(
NULL
));
if
(
sysnchronise
)
{
for
(
i
=
0
;
i
<
59
;
i
++
)
for
(
i
=
0
;
i
<
3
;
i
++
)
euid
[
i
]
=
buf
[
rand
()
%
35
];
euid
[
59
]
=
'\0'
;
sprintf
(
euid_num
,
"%04d"
,
number
);
strcat
(
euid
,
euid_num
);
str
n
cat
(
euid
,
euid_num
,
4
);
}
else
{
for
(
i
=
0
;
i
<
62
;
i
++
)
for
(
i
=
0
;
i
<
7
;
i
++
)
euid
[
i
]
=
buf
[
rand
()
%
35
];
euid
[
63
]
=
'\0'
;
}
euid
[
7
]
=
'\0'
;
return
strdup
(
euid
);
}
int
synchronize_deployment_units_with_map_du_file
(
void
)
{
struct
uci_section
*
s
=
NULL
,
*
stmp
=
NULL
;
char
path
[
256
],
line
[
256
],
name
[
64
],
version
[
64
],
command
[
256
]
;
char
path
[
256
]
=
{
0
}
,
line
[
256
]
=
{
0
}
,
name
[
64
]
=
{
0
}
,
version
[
64
]
=
{
0
}
,
command
[
512
]
=
{
0
}
;
FILE
*
log
;
DIR
*
dir
;
struct
dirent
*
ent
;
int
found
,
incr
=
0
;
opkg
_uci_foreach_section_safe
(
"map_du"
,
"deployment"
,
stmp
,
s
)
{
char
*
map_du_name
=
opkg
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_du_env
=
opkg
_uci_get_value_by_section
(
s
,
"environment"
);
swmod
_uci_foreach_section_safe
(
"map_du"
,
"deployment"
,
stmp
,
s
)
{
char
*
map_du_name
=
swmod
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_du_env
=
swmod
_uci_get_value_by_section
(
s
,
"environment"
);
if
(
strcmp
(
map_du_env
,
"OpenWRT_Linux"
)
==
0
)
snprintf
(
path
,
sizeof
(
path
),
"%s/%s.control"
,
OPKG_INFO_PATH
,
map_du_name
);
else
snprintf
(
path
,
sizeof
(
path
),
"%s/%s/rootfs/%s/%s.control"
,
LXC_PATH
,
map_du_env
,
OPKG_INFO_PATH
,
map_du_name
);
if
(
!
isfileexist
(
path
))
opkg
_uci_delete_by_section
(
s
,
NULL
,
NULL
);
swmod
_uci_delete_by_section
(
s
,
NULL
,
NULL
);
}
if
((
log
=
popen
(
"opkg list"
,
"r"
)))
{
while
(
fgets
(
line
,
sizeof
(
line
),
log
)
!=
NULL
)
{
found
=
0
;
if
(
sscanf
(
line
,
"%63s - %63s"
,
name
,
version
))
{
opkg
_uci_foreach_section
(
"map_du"
,
"deployment"
,
s
)
{
char
*
map_name
=
opkg
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_env
=
opkg
_uci_get_value_by_section
(
s
,
"environment"
);
swmod
_uci_foreach_section
(
"map_du"
,
"deployment"
,
s
)
{
char
*
map_name
=
swmod
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_env
=
swmod
_uci_get_value_by_section
(
s
,
"environment"
);
if
((
strcmp
(
map_name
,
name
)
==
0
)
&&
(
strcmp
(
map_env
,
"OpenWRT_Linux"
)
==
0
))
{
found
=
1
;
break
;
...
...
@@ -417,15 +415,15 @@ int synchronize_deployment_units_with_map_du_file(void)
if
(
found
)
continue
;
struct
uci_section
*
new_s
=
opkg
_uci_add_section
(
"map_du"
,
"deployment"
);
struct
uci_section
*
new_s
=
swmod
_uci_add_section
(
"map_du"
,
"deployment"
);
char
*
uuid
=
generate_uuid
();
char
*
duid
=
generate_duid
(
true
,
incr
);
incr
++
;
opkg
_uci_set_value_by_section
(
new_s
,
"name"
,
name
);
opkg
_uci_set_value_by_section
(
new_s
,
"version"
,
version
);
opkg
_uci_set_value_by_section
(
new_s
,
"uuid"
,
uuid
);
opkg
_uci_set_value_by_section
(
new_s
,
"duid"
,
duid
);
opkg
_uci_set_value_by_section
(
new_s
,
"environment"
,
"OpenWRT_Linux"
);
swmod
_uci_set_value_by_section
(
new_s
,
"name"
,
name
);
swmod
_uci_set_value_by_section
(
new_s
,
"version"
,
version
);
swmod
_uci_set_value_by_section
(
new_s
,
"uuid"
,
uuid
);
swmod
_uci_set_value_by_section
(
new_s
,
"duid"
,
duid
);
swmod
_uci_set_value_by_section
(
new_s
,
"environment"
,
"OpenWRT_Linux"
);
FREE
(
uuid
);
FREE
(
duid
);
}
...
...
@@ -442,9 +440,9 @@ int synchronize_deployment_units_with_map_du_file(void)
while
(
fgets
(
line
,
sizeof
(
line
),
log
)
!=
NULL
)
{
found
=
0
;
if
(
sscanf
(
line
,
"%63s - %63s"
,
name
,
version
))
{
opkg
_uci_foreach_section
(
"map_du"
,
"deployment"
,
s
)
{
char
*
map_name
=
opkg
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_env
=
opkg
_uci_get_value_by_section
(
s
,
"environment"
);
swmod
_uci_foreach_section
(
"map_du"
,
"deployment"
,
s
)
{
char
*
map_name
=
swmod
_uci_get_value_by_section
(
s
,
"name"
);
char
*
map_env
=
swmod
_uci_get_value_by_section
(
s
,
"environment"
);
if
((
strcmp
(
map_name
,
name
)
==
0
)
&&
(
strcmp
(
map_env
,
ent
->
d_name
)
==
0
))
{
found
=
1
;
break
;
...
...
@@ -453,15 +451,15 @@ int synchronize_deployment_units_with_map_du_file(void)
if
(
found
)
continue
;
struct
uci_section
*
new_s
=
opkg
_uci_add_section
(
"map_du"
,
"deployment"
);
struct
uci_section
*
new_s
=
swmod
_uci_add_section
(
"map_du"
,
"deployment"
);
char
*
uuid
=
generate_uuid
();
char
*
duid
=
generate_duid
(
true
,
incr
);
incr
++
;
opkg
_uci_set_value_by_section
(
new_s
,
"name"
,
name
);
opkg
_uci_set_value_by_section
(
new_s
,
"version"
,
version
);
opkg
_uci_set_value_by_section
(
new_s
,
"uuid"
,
uuid
);
opkg
_uci_set_value_by_section
(
new_s
,
"duid"
,
duid
);
opkg
_uci_set_value_by_section
(
new_s
,
"environment"
,
ent
->
d_name
);
swmod
_uci_set_value_by_section
(
new_s
,
"name"
,
name
);
swmod
_uci_set_value_by_section
(
new_s
,
"version"
,
version
);
swmod
_uci_set_value_by_section
(
new_s
,
"uuid"
,
uuid
);
swmod
_uci_set_value_by_section
(
new_s
,
"duid"
,
duid
);
swmod
_uci_set_value_by_section
(
new_s
,
"environment"
,
ent
->
d_name
);
FREE
(
uuid
);
FREE
(
duid
);
}
...
...
@@ -474,7 +472,7 @@ int synchronize_deployment_units_with_map_du_file(void)
return
0
;
}
void
opkg
_add_data_to_list
(
struct
list_head
*
dup_list
,
char
*
cmd
,
int
pid
,
unsigned
int
vsize
)
void
swmod
_add_data_to_list
(
struct
list_head
*
dup_list
,
char
*
cmd
,
int
pid
,
unsigned
int
vsize
)
{
struct
process_res
*
proc
;
proc
=
calloc
(
1
,
sizeof
(
struct
process_res
));
...
...
@@ -484,18 +482,18 @@ void opkg_add_data_to_list(struct list_head *dup_list, char *cmd, int pid, unsig
proc
->
vsize
=
vsize
;
}
static
void
opkg
_delete_data_from_list
(
struct
process_res
*
proc
)
static
void
swmod
_delete_data_from_list
(
struct
process_res
*
proc
)
{
list_del
(
&
proc
->
list
);
FREE
(
proc
->
cmd
);
FREE
(
proc
);
}
void
opkg
_free_data_from_list
(
struct
list_head
*
dup_list
)
void
swmod
_free_data_from_list
(
struct
list_head
*
dup_list
)
{
struct
process_res
*
proc
;
while
(
dup_list
->
next
!=
dup_list
)
{
proc
=
list_entry
(
dup_list
->
next
,
struct
process_res
,
list
);
opkg
_delete_data_from_list
(
proc
);
swmod
_delete_data_from_list
(
proc
);
}
}
This diff is collapsed.
Click to expand it.
common.h
+
27
−
22
View file @
3bfc97cd
...
...
@@ -33,9 +33,8 @@
#include
<uci.h>
#include
<libubox/list.h>
#define OPKG_SAVEDIR_PATH "/etc/swmod"
#define OPKG_CONFDIR_PATH "/etc/swmod"
#define OPKG_INFO_PATH "/usr/lib/swmod/info"
#define SWMOD_PATH "/etc/swmod"
#define OPKG_INFO_PATH "/usr/lib/opkg/info"
#define DEPLOYMENT_UNIT_PATH "/etc/swmod/map_du"
#define PROC_PATH "/proc"
#define LXC_PATH "/srv/lxc"
...
...
@@ -53,6 +52,12 @@
#define FREE(x) do { if(x) {free(x); x = NULL;} } while (0)
#endif
#define swmod_strncpy(dst, src, size) \
do { \
strncpy(dst, src, size - 1);\
dst[size-1] = '\0';\
} while(0)
struct
process_res
{
struct
list_head
list
;
...
...
@@ -61,13 +66,13 @@ struct process_res
unsigned
int
vsize
;
};
int
opkg
_uci_init
(
void
);
int
opkg
_uci_fini
(
void
);
struct
uci_section
*
opkg
_uci_walk_section
(
char
*
package
,
char
*
section_type
,
struct
uci_section
*
prev_section
);
struct
uci_section
*
opkg
_uci_add_section
(
char
*
package
,
char
*
section_type
);
int
opkg
_uci_delete_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
);
char
*
opkg
_uci_get_value_by_section
(
struct
uci_section
*
section
,
char
*
option
);
char
*
opkg
_uci_set_value_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
);
int
swmod
_uci_init
(
void
);
int
swmod
_uci_fini
(
void
);
struct
uci_section
*
swmod
_uci_walk_section
(
char
*
package
,
char
*
section_type
,
struct
uci_section
*
prev_section
);
struct
uci_section
*
swmod
_uci_add_section
(
char
*
package
,
char
*
section_type
);
int
swmod
_uci_delete_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
);
char
*
swmod
_uci_get_value_by_section
(
struct
uci_section
*
section
,
char
*
option
);
char
*
swmod
_uci_set_value_by_section
(
struct
uci_section
*
section
,
char
*
option
,
char
*
value
);
char
*
get_package_name
(
char
*
full_name
);
int
isfileexist
(
const
char
*
filepath
);
int
synchronize_deployment_units_with_map_du_file
(
void
);
...
...
@@ -76,19 +81,19 @@ char *generate_uuid(void);
char
*
generate_duid
(
bool
sysnchronise
,
int
number
);
void
remove_newline
(
char
*
buf
);
int
islxcrunning
(
char
*
lxc_name
);
void
opkg
_add_data_to_list
(
struct
list_head
*
dup_list
,
char
*
cmd
,
int
pid
,
unsigned
int
vsize
);
void
opkg
_free_data_from_list
(
struct
list_head
*
dup_list
);
void
swmod
_add_data_to_list
(
struct
list_head
*
dup_list
,
char
*
cmd
,
int
pid
,
unsigned
int
vsize
);
void
swmod
_free_data_from_list
(
struct
list_head
*
dup_list
);
#define
opkg
_uci_foreach_section(package, section_type, section) \
for (section =
opkg
_uci_walk_section(package, section_type, NULL); \
#define
swmod
_uci_foreach_section(package, section_type, section) \
for (section =
swmod
_uci_walk_section(package, section_type, NULL); \
section != NULL; \
section =
opkg
_uci_walk_section(package, section_type, section))
section =
swmod
_uci_walk_section(package, section_type, section))
#define
opkg
_uci_foreach_section_safe(package, section_type, _tmp, section) \
for(section =
opkg
_uci_walk_section(package, section_type, NULL), \
_tmp = (section) ?
opkg
_uci_walk_section(package, section_type, section) : NULL; \
#define
swmod
_uci_foreach_section_safe(package, section_type, _tmp, section) \
for(section =
swmod
_uci_walk_section(package, section_type, NULL), \
_tmp = (section) ?
swmod
_uci_walk_section(package, section_type, section) : NULL; \
section != NULL; \
section = _tmp, _tmp = (section) ?
opkg
_uci_walk_section(package, section_type, section) : NULL)
section = _tmp, _tmp = (section) ?
swmod
_uci_walk_section(package, section_type, section) : NULL)
#endif //__COMMON_H
This diff is collapsed.
Click to expand it.
swmod.c
+
131
−
158
View file @
3bfc97cd
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
sign in
to comment