chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
41f9172
)
unit-printf: before resolving exec context specifiers check whether the object actual...
author
Lennart Poettering
<lennart@poettering.net>
Tue, 18 Sep 2012 09:40:01 +0000
(11:40 +0200)
committer
Lennart Poettering
<lennart@poettering.net>
Tue, 18 Sep 2012 09:40:01 +0000
(11:40 +0200)
src/core/mount.c
patch
|
blob
|
history
src/core/service.c
patch
|
blob
|
history
src/core/socket.c
patch
|
blob
|
history
src/core/swap.c
patch
|
blob
|
history
src/core/unit-printf.c
patch
|
blob
|
history
src/core/unit.c
patch
|
blob
|
history
src/core/unit.h
patch
|
blob
|
history
diff --git
a/src/core/mount.c
b/src/core/mount.c
index
fc981c7
..
92e2f73
100644
(file)
--- a/
src/core/mount.c
+++ b/
src/core/mount.c
@@
-1797,6
+1797,8
@@
DEFINE_STRING_TABLE_LOOKUP(mount_result, MountResult);
const UnitVTable mount_vtable = {
.object_size = sizeof(Mount),
const UnitVTable mount_vtable = {
.object_size = sizeof(Mount),
+ .exec_context_offset = offsetof(Mount, exec_context),
+
.sections =
"Unit\0"
"Mount\0"
.sections =
"Unit\0"
"Mount\0"
diff --git
a/src/core/service.c
b/src/core/service.c
index
1e3e875
..
39e1ab5
100644
(file)
--- a/
src/core/service.c
+++ b/
src/core/service.c
@@
-3837,6
+3837,8
@@
DEFINE_STRING_TABLE_LOOKUP(start_limit_action, StartLimitAction);
const UnitVTable service_vtable = {
.object_size = sizeof(Service),
const UnitVTable service_vtable = {
.object_size = sizeof(Service),
+ .exec_context_offset = offsetof(Service, exec_context),
+
.sections =
"Unit\0"
"Service\0"
.sections =
"Unit\0"
"Service\0"
diff --git
a/src/core/socket.c
b/src/core/socket.c
index
63e6ed2
..
3614045
100644
(file)
--- a/
src/core/socket.c
+++ b/
src/core/socket.c
@@
-2196,6
+2196,8
@@
DEFINE_STRING_TABLE_LOOKUP(socket_result, SocketResult);
const UnitVTable socket_vtable = {
.object_size = sizeof(Socket),
const UnitVTable socket_vtable = {
.object_size = sizeof(Socket),
+ .exec_context_offset = offsetof(Socket, exec_context),
+
.sections =
"Unit\0"
"Socket\0"
.sections =
"Unit\0"
"Socket\0"
diff --git
a/src/core/swap.c
b/src/core/swap.c
index
8ba6055
..
d5bf153
100644
(file)
--- a/
src/core/swap.c
+++ b/
src/core/swap.c
@@
-1355,6
+1355,8
@@
DEFINE_STRING_TABLE_LOOKUP(swap_result, SwapResult);
const UnitVTable swap_vtable = {
.object_size = sizeof(Swap),
const UnitVTable swap_vtable = {
.object_size = sizeof(Swap),
+ .exec_context_offset = offsetof(Swap, exec_context),
+
.sections =
"Unit\0"
"Swap\0"
.sections =
"Unit\0"
"Swap\0"
diff --git
a/src/core/unit-printf.c
b/src/core/unit-printf.c
index
cd49206
..
35da29a
100644
(file)
--- a/
src/core/unit-printf.c
+++ b/
src/core/unit-printf.c
@@
-119,16
+119,21
@@
static char *specifier_runtime(char specifier, void *data, void *userdata) {
}
static char *specifier_user_name(char specifier, void *data, void *userdata) {
}
static char *specifier_user_name(char specifier, void *data, void *userdata) {
- Service *s = userdata;
+ Unit *u = userdata;
+ ExecContext *c;
int r;
const char *username;
int r;
const char *username;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* get USER env from our own env if set */
/* get USER env from our own env if set */
- if (!
s->exec_context.
user)
+ if (!
c->
user)
return getusername_malloc();
/* fish username from passwd */
return getusername_malloc();
/* fish username from passwd */
- username =
s->exec_context.
user;
+ username =
c->
user;
r = get_user_creds(&username, NULL, NULL, NULL, NULL);
if (r < 0)
return NULL;
r = get_user_creds(&username, NULL, NULL, NULL, NULL);
if (r < 0)
return NULL;
@@
-137,12
+142,17
@@
static char *specifier_user_name(char specifier, void *data, void *userdata) {
}
static char *specifier_user_home(char specifier, void *data, void *userdata) {
}
static char *specifier_user_home(char specifier, void *data, void *userdata) {
- Service *s = userdata;
+ Unit *u = userdata;
+ ExecContext *c;
int r;
const char *username, *home;
int r;
const char *username, *home;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* return HOME if set, otherwise from passwd */
/* return HOME if set, otherwise from passwd */
- if (!
s->exec_context.
user) {
+ if (!
c->
user) {
char *h;
r = get_home_dir(&h);
char *h;
r = get_home_dir(&h);
@@
-152,7
+162,7
@@
static char *specifier_user_home(char specifier, void *data, void *userdata) {
return h;
}
return h;
}
- username =
s->exec_context.
user;
+ username =
c->
user;
r = get_user_creds(&username, NULL, NULL, &home, NULL);
if (r < 0)
return NULL;
r = get_user_creds(&username, NULL, NULL, &home, NULL);
if (r < 0)
return NULL;
@@
-161,12
+171,17
@@
static char *specifier_user_home(char specifier, void *data, void *userdata) {
}
static char *specifier_user_shell(char specifier, void *data, void *userdata) {
}
static char *specifier_user_shell(char specifier, void *data, void *userdata) {
- Service *s = userdata;
+ Unit *u = userdata;
+ ExecContext *c;
int r;
const char *username, *shell;
int r;
const char *username, *shell;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* return HOME if set, otherwise from passwd */
/* return HOME if set, otherwise from passwd */
- if (!
s->exec_context.
user) {
+ if (!
c->
user) {
char *sh;
r = get_shell(&sh);
char *sh;
r = get_shell(&sh);
@@
-176,7
+191,7
@@
static char *specifier_user_shell(char specifier, void *data, void *userdata) {
return sh;
}
return sh;
}
- username =
s->exec_context.
user;
+ username =
c->
user;
r = get_user_creds(&username, NULL, NULL, NULL, &shell);
if (r < 0)
return strdup("/bin/sh");
r = get_user_creds(&username, NULL, NULL, NULL, &shell);
if (r < 0)
return strdup("/bin/sh");
diff --git
a/src/core/unit.c
b/src/core/unit.c
index
4eea5b5
..
1e33936
100644
(file)
--- a/
src/core/unit.c
+++ b/
src/core/unit.c
@@
-2684,6
+2684,17
@@
int unit_exec_context_defaults(Unit *u, ExecContext *c) {
return 0;
}
return 0;
}
+ExecContext *unit_get_exec_context(Unit *u) {
+ size_t offset;
+ assert(u);
+
+ offset = UNIT_VTABLE(u)->exec_context_offset;
+ if (offset <= 0)
+ return NULL;
+
+ return (ExecContext*) ((uint8_t*) u + offset);
+}
+
static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
[UNIT_ACTIVE] = "active",
[UNIT_RELOADING] = "reloading",
static const char* const unit_active_state_table[_UNIT_ACTIVE_STATE_MAX] = {
[UNIT_ACTIVE] = "active",
[UNIT_RELOADING] = "reloading",
diff --git
a/src/core/unit.h
b/src/core/unit.h
index
da715dc
..
bf961c2
100644
(file)
--- a/
src/core/unit.h
+++ b/
src/core/unit.h
@@
-266,6
+266,10
@@
struct UnitVTable {
/* How much memory does an object of this unit type need */
size_t object_size;
/* How much memory does an object of this unit type need */
size_t object_size;
+ /* If greater than 0, the offset into the object where
+ * ExecContext is found, if the unit type has that */
+ size_t exec_context_offset;
+
/* Config file sections this unit type understands, separated
* by NUL chars */
const char *sections;
/* Config file sections this unit type understands, separated
* by NUL chars */
const char *sections;
@@
-538,6
+542,8
@@
int unit_add_mount_links(Unit *u);
int unit_exec_context_defaults(Unit *u, ExecContext *c);
int unit_exec_context_defaults(Unit *u, ExecContext *c);
+ExecContext *unit_get_exec_context(Unit *u);
+
const char *unit_active_state_to_string(UnitActiveState i);
UnitActiveState unit_active_state_from_string(const char *s);
const char *unit_active_state_to_string(UnitActiveState i);
UnitActiveState unit_active_state_from_string(const char *s);