aboutsummaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/_usage.h10
-rw-r--r--src/shared/misc.c91
-rw-r--r--src/shared/misc.h12
3 files changed, 97 insertions, 16 deletions
diff --git a/src/shared/_usage.h b/src/shared/_usage.h
index 91b956e0..3264ad6f 100644
--- a/src/shared/_usage.h
+++ b/src/shared/_usage.h
@@ -45,6 +45,16 @@
case 'q': case_RC_COMMON_getopt_case_q; break; \
default: case_RC_COMMON_getopt_default; break;
+#ifdef RC_USER_SERVICES
+#define case_RC_USER_SERVICES \
+ case 'U': rc_set_user(); break;
+#define getoptstring_USER_SERVICES "U"
+#define longopts_USER_SERVICES \
+ { "user", 0, NULL, 'U'},
+#define longopts_help_USER_SERVICES \
+ "use user facing services",
+#endif
+
extern const char *applet;
extern const char *extraopts;
extern const char getoptstring[];
diff --git a/src/shared/misc.c b/src/shared/misc.c
index 28f4e235..6970513f 100644
--- a/src/shared/misc.c
+++ b/src/shared/misc.c
@@ -79,6 +79,16 @@ env_filter(void)
/* Add the user defined list of vars */
env_allow = rc_stringlist_split(rc_conf_value("rc_env_allow"), " ");
+
+#ifdef RC_USER_SERVICES
+ /* Needed for local user services to be found */
+ if (rc_is_user()) {
+ rc_stringlist_addu(env_allow, "HOME");
+ rc_stringlist_addu(env_allow, "XDG_RUNTIME_DIR");
+ rc_stringlist_addu(env_allow, "XDG_CONFIG_HOME");
+ rc_stringlist_addu(env_allow, "RC_USER_SERVICES");
+ }
+#endif
/*
* If '*' is an entry in rc_env_allow, do nothing as we are to pass
* through all environment variables.
@@ -247,8 +257,22 @@ svc_lock(const char *applet, bool ignore_lock_failure)
{
char *file = NULL;
int fd;
+ char *svcdir = RC_SVCDIR;
+
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ svcdir = rc_user_svcdir();
+ }
+#endif
+
+ xasprintf(&file, "%s/exclusive/%s", svcdir, applet);
+
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ free(svcdir);
+ }
+#endif
- xasprintf(&file, RC_SVCDIR "/exclusive/%s", applet);
fd = open(file, O_WRONLY | O_CREAT | O_NONBLOCK, 0664);
free(file);
if (fd == -1)
@@ -273,8 +297,22 @@ int
svc_unlock(const char *applet, int fd)
{
char *file = NULL;
+ char *svcdir = RC_SVCDIR;
+
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ svcdir = rc_user_svcdir();
+ }
+#endif
+
+ xasprintf(&file, "%s/exclusive/%s", svcdir, applet);
+
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ free(svcdir);
+ }
+#endif
- xasprintf(&file, RC_SVCDIR "/exclusive/%s", applet);
close(fd);
unlink(file);
free(file);
@@ -385,15 +423,33 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen)
struct stat st;
struct utimbuf ut;
FILE *fp;
+ char *cache = RC_DEPTREE_CACHE;
+ char *skew = RC_DEPTREE_SKEWED;
+#ifdef RC_USER_SERVICES
+ char *user_svcdir;
+ if (rc_is_user()) {
+ user_svcdir = rc_user_svcdir();
+ xasprintf(&cache, "%s%s", user_svcdir, RC_DEPTREE_CACHE_FILE);
+ xasprintf(&skew, "%s%s", user_svcdir, RC_DEPTREE_SKEWED_FILE);
+ free(user_svcdir);
+ }
+#endif
t = 0;
if (rc_deptree_update_needed(&t, file) || force != 0) {
/* Test if we have permission to update the deptree */
- fd = open(RC_DEPTREE_CACHE, O_WRONLY);
+ fd = open(cache, O_WRONLY);
merrno = errno;
errno = serrno;
- if (fd == -1 && merrno == EACCES)
+ if (fd == -1 && merrno == EACCES) {
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ free(cache);
+ free(skew);
+ }
+#endif
return rc_deptree_load();
+ }
close(fd);
if (regen)
@@ -403,30 +459,41 @@ RC_DEPTREE * _rc_deptree_load(int force, int *regen)
eend (retval, "Failed to update the dependency tree");
if (retval == 0) {
- if (stat(RC_DEPTREE_CACHE, &st) != 0) {
- eerror("stat(%s): %s", RC_DEPTREE_CACHE, strerror(errno));
+ if (stat(cache, &st) != 0) {
+ eerror("stat(%s): %s", cache, strerror(errno));
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ free(cache);
+ free(skew);
+ }
+#endif
return NULL;
}
if (st.st_mtime < t) {
eerror("Clock skew detected with `%s'", file);
- eerrorn("Adjusting mtime of `" RC_DEPTREE_CACHE
- "' to %s", ctime(&t));
- fp = fopen(RC_DEPTREE_SKEWED, "w");
+ eerrorn("Adjusting mtime of '%s' to %s", cache, ctime(&t));
+ fp = fopen(skew, "w");
if (fp != NULL) {
fprintf(fp, "%s\n", file);
fclose(fp);
}
ut.actime = t;
ut.modtime = t;
- utime(RC_DEPTREE_CACHE, &ut);
+ utime(cache, &ut);
} else {
- if (exists(RC_DEPTREE_SKEWED))
- unlink(RC_DEPTREE_SKEWED);
+ if (exists(skew))
+ unlink(skew);
}
}
if (force == -1 && regen != NULL)
*regen = retval;
}
+#ifdef RC_USER_SERVICES
+ if (rc_is_user()) {
+ free(cache);
+ free(skew);
+ }
+#endif
return rc_deptree_load();
}
diff --git a/src/shared/misc.h b/src/shared/misc.h
index b158a786..132f4b80 100644
--- a/src/shared/misc.h
+++ b/src/shared/misc.h
@@ -33,11 +33,15 @@
#define RC_LEVEL_BOOT "boot"
#define RC_LEVEL_DEFAULT "default"
-#define RC_DEPTREE_CACHE RC_SVCDIR "/deptree"
-#define RC_DEPTREE_SKEWED RC_SVCDIR "/clock-skewed"
+#define RC_DEPTREE_CACHE_FILE "/deptree"
+#define RC_DEPTREE_CACHE RC_SVCDIR RC_DEPTREE_CACHE_FILE
+#define RC_DEPTREE_SKEWED_FILE "/clock-skewed"
+#define RC_DEPTREE_SKEWED RC_SVCDIR RC_DEPTREE_SKEWED_FILE
#define RC_KRUNLEVEL RC_SVCDIR "/krunlevel"
-#define RC_STARTING RC_SVCDIR "/rc.starting"
-#define RC_STOPPING RC_SVCDIR "/rc.stopping"
+#define RC_STARTING_FOLDER "/rc.starting"
+#define RC_STARTING RC_SVCDIR RC_STARTING_FOLDER
+#define RC_STOPPING_FOLDER "/rc.stopping"
+#define RC_STOPPING RC_SVCDIR RC_STOPPING_FOLDER
#define RC_SVCDIR_STARTING RC_SVCDIR "/starting"
#define RC_SVCDIR_INACTIVE RC_SVCDIR "/inactive"