You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.3 KiB
47 lines
1.3 KiB
5 years ago
|
+++ ./libmcount/record.c 2019-08-26 14:43:15.836981805 +0300
|
||
|
@@ -23,6 +23,44 @@
|
||
|
|
||
|
#define ARG_STR_MAX 98
|
||
|
|
||
|
+static int shm_open(const char *name, int oflag, mode_t mode) {
|
||
|
+ size_t namelen;
|
||
|
+ char *fname;
|
||
|
+ int fd;
|
||
|
+
|
||
|
+ /* Construct the filename. */
|
||
|
+ while (name[0] == '/') ++name;
|
||
|
+
|
||
|
+ if (name[0] == '\0') {
|
||
|
+ /* The name "/" is not supported. */
|
||
|
+ errno = EINVAL;
|
||
|
+ return -1;
|
||
|
+ }
|
||
|
+
|
||
|
+ namelen = strlen(name);
|
||
|
+ fname = (char *) alloca(sizeof("/data/data/com.termux/files/usr/tmp/") - 1 + namelen + 1);
|
||
|
+ memcpy(fname, "/data/data/com.termux/files/usr/tmp/", sizeof("/data/data/com.termux/files/usr/tmp/") - 1);
|
||
|
+ memcpy(fname + sizeof("/data/data/com.termux/files/usr/tmp/") - 1, name, namelen + 1);
|
||
|
+
|
||
|
+ fd = open(fname, oflag, mode);
|
||
|
+ if (fd != -1) {
|
||
|
+ /* We got a descriptor. Now set the FD_CLOEXEC bit. */
|
||
|
+ int flags = fcntl(fd, F_GETFD, 0);
|
||
|
+ flags |= FD_CLOEXEC;
|
||
|
+ flags = fcntl(fd, F_SETFD, flags);
|
||
|
+
|
||
|
+ if (flags == -1) {
|
||
|
+ /* Something went wrong. We cannot return the descriptor. */
|
||
|
+ int save_errno = errno;
|
||
|
+ close(fd);
|
||
|
+ fd = -1;
|
||
|
+ errno = save_errno;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
+ return fd;
|
||
|
+}
|
||
|
+
|
||
|
static struct mcount_shmem_buffer *allocate_shmem_buffer(char *sess_id, size_t size,
|
||
|
int tid, int idx)
|
||
|
{
|