+/**************** INITIALISATION **********************/
+
+int af_run_init()
+{
+ char buf[2048];
+ char dir[PATH_MAX];
+ int rc;
+ uid_t me;
+ struct passwd passwd, *pw;
+
+ /* computes the 'homeappdir' */
+ me = geteuid();
+ rc = getpwuid_r(me, &passwd, buf, sizeof buf, &pw);
+ if (rc || pw == NULL) {
+ errno = rc ? errno : ENOENT;
+ ERROR("getpwuid_r failed for uid=%d: %m",(int)me);
+ return -1;
+ }
+ rc = snprintf(dir, sizeof dir, "%s/%s", passwd.pw_dir, fwk_user_app_dir);
+ if (rc >= sizeof dir) {
+ ERROR("buffer overflow in user_app_dir for uid=%d",(int)me);
+ return -1;
+ }
+ rc = create_directory(dir, 0755, 1);
+ if (rc && errno != EEXIST) {
+ ERROR("creation of directory %s failed in user_app_dir: %m", dir);
+ return -1;
+ }
+ homeappdir = strdup(dir);
+ if (homeappdir == NULL) {
+ errno = ENOMEM;
+ ERROR("out of memory in user_app_dir for %s : %m", dir);
+ return -1;
+ }
+
+ /* install signal handlers */
+
+ return 0;
+}
+