Select the types of activity you want to include in your feed.
Implement _set_user_dir_suffix
Please, please, *please* take a look at my comments in _libcoreservices_fork_child! If there are ever any issues with threading and forking, remember to take a look at this code
···22#include <stddef.h>
33#include <stdlib.h>
44#include <stdio.h>
55+#include <pthread.h>
66+#include "dirhelper_priv.h"
77+88+static const char* dir_suffix = NULL;
99+static pthread_mutex_t dir_suffix_lock = PTHREAD_MUTEX_INITIALIZER;
510611void _dirhelper_fork_child(void)
712{
···9141015void _libcoreservices_fork_child(void)
1116{
1717+ /**
1818+ * my god, threading is *incredibly* tricky when mixed with `fork()`!
1919+ * and the POSIX spec is so unclear about the behavior of mutexes when `fork()`ing
2020+ * and the macOS docs are no help
2121+ *
2222+ * the *only* viable resources i found was this commit in jemalloc:
2323+ * https://github.com/jemalloc/jemalloc/commit/0a4f5a7eea5e42292cea95fd30a88201c8d4a1ca
2424+ *
2525+ * basically, it *seems* that it's fine to reinitialize mutexes in the child---on macOS at least
2626+ * but i really wish the POSIX spec or macOS docs mentioned this kind of stuff!
2727+ *
2828+ * undefined behavior is really the **worst** behavior
2929+ */
3030+ dir_suffix_lock = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
3131+3232+ /**
3333+ * i checked on a real macOS system and confirmed this behavior:
3434+ * `fork()` does NOT reset the directory suffix
3535+ */
3636+ //dir_suffix = NULL;
1237}
13381414-enum {
1515- DIRHELPER_USER_LOCAL = 0,
1616- DIRHELPER_USER_LOCAL_TEMP,
1717- DIRHELPER_USER_LOCAL_CACHE
1818-};
1919-2039char* _dirhelper(int which, char* p, size_t limit)
2140{
4141+ pthread_mutex_lock(&dir_suffix_lock);
2242 switch (which)
2343 {
2444 case DIRHELPER_USER_LOCAL:
···27472848 home = getenv("HOME");
2949 if (home == NULL)
3030- home = "/";
5050+ home = "";
31513232- strlcpy(p, home, limit);
5252+ snprintf(p, limit, "%s/%s%s", home, dir_suffix ? dir_suffix : "", dir_suffix ? "/" : "");
3353 return p;
3454 }
3555 case DIRHELPER_USER_LOCAL_TEMP:
···4060 if (tmp == NULL)
4161 tmp = "/tmp";
42624343- strlcpy(p, tmp, limit);
6363+ snprintf(p, limit, "%s/%s%s", tmp, dir_suffix ? dir_suffix : "", dir_suffix ? "/" : "");
4464 return p;
4565 }
4666 case DIRHELPER_USER_LOCAL_CACHE:
···49695070 home = getenv("HOME");
5171 if (home != NULL)
5252- snprintf(p, limit, "%s/.cache", home);
7272+ snprintf(p, limit, "%s/.cache/%s%s", home, dir_suffix ? dir_suffix : "", dir_suffix ? "/" : "");
5373 else
5454- strlcpy(p, "/tmp", limit);
7474+ snprintf(p, limit, "/tmp/%s%s", dir_suffix ? dir_suffix : "", dir_suffix ? "/" : "");
55755676 return p;
5777 }
5878 default:
5959- return NULL;
7979+ p = NULL;
6080 }
8181+ pthread_mutex_unlock(&dir_suffix_lock);
8282+ return p;
6183}
62848585+int _set_user_dir_suffix(const char* suffix) {
8686+ pthread_mutex_lock(&dir_suffix_lock);
8787+ dir_suffix = suffix;
8888+ pthread_mutex_unlock(&dir_suffix_lock);
8989+ return 0;
9090+};
9191+
+63
src/libsystem_coreservices/dirhelper_priv.h
···11+/*
22+ * Copyright (c) 2006, 2007, 2010 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. Please obtain a copy of the License at
1010+ * http://www.opensource.apple.com/apsl/ and read it before using this
1111+ * file.
1212+ *
1313+ * The Original Code and all software distributed under the License are
1414+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1515+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
1616+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
1717+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
1818+ * Please see the License for the specific language governing rights and
1919+ * limitations under the License.
2020+ *
2121+ * @APPLE_LICENSE_HEADER_END@
2222+ */
2323+/**
2424+ *
2525+ * Modified for Darling
2626+ *
2727+ */
2828+2929+#ifndef _DIRHELPER_PRIV_H_
3030+#define _DIRHELPER_PRIV_H_
3131+3232+#include <sys/cdefs.h>
3333+#include <sys/types.h>
3434+3535+#define VAR_FOLDERS_PATH "/var/folders/"
3636+3737+#define DIRHELPER_BOOTSTRAP_NAME "com.apple.bsd.dirhelper"
3838+#define DIRHELPER_CACHE_STR "C/"
3939+#define DIRHELPER_TEMP_STR "T/"
4040+#define DIRHELPER_TOP_STR "0/"
4141+#define DIRHELPER_ENV_USER_DIR_SUFFIX "DIRHELPER_USER_DIR_SUFFIX"
4242+4343+typedef enum {
4444+ DIRHELPER_USER_LOCAL = 0,
4545+ DIRHELPER_USER_LOCAL_TEMP,
4646+ DIRHELPER_USER_LOCAL_CACHE,
4747+ DIRHELPER_USER_LOCAL_LAST = DIRHELPER_USER_LOCAL_CACHE
4848+} dirhelper_which_t;
4949+5050+__BEGIN_DECLS
5151+char *__user_local_dirname(uid_t uid, dirhelper_which_t which, char *path,
5252+ size_t pathlen);
5353+char *__user_local_mkdir_p(char *path);
5454+5555+__attribute__((visibility("hidden"), __format__(__printf__,1,2)))
5656+void _setcrashlogmessage(const char *fmt, ...);
5757+#define setcrashlogmessage(fmt, ...) _setcrashlogmessage("%s: %u: " fmt, __func__, __LINE__, ##__VA_ARGS__)
5858+5959+int _set_user_dir_suffix(const char* suffix);
6060+6161+__END_DECLS
6262+6363+#endif /* _DIRHELPER_PRIV_H_ */