}
static char *specifier_user_name(char specifier, void *data, void *userdata) {
- Service *s = userdata;
+ Unit *u = userdata;
+ ExecContext *c;
int r;
const char *username;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* get USER env from our own env if set */
- if (!s->exec_context.user)
+ if (!c->user)
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;
}
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;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* return HOME if set, otherwise from passwd */
- if (!s->exec_context.user) {
+ if (!c->user) {
char *h;
r = get_home_dir(&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;
}
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;
+ c = unit_get_exec_context(u);
+ if (!c)
+ return NULL;
+
/* return HOME if set, otherwise from passwd */
- if (!s->exec_context.user) {
+ if (!c->user) {
char *sh;
r = get_shell(&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");
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",
/* 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;
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);