In order to maintain compatibility with older trees, we now have minadbd.old and minui.old. I had to use a TARGET_GLOBAL_CFLAG to handle ifdef issues in minui/minui.d because healthd includes minui/minui.h and there was no other alternative to make minui.h compatible with older trees without having to modify healthd rules which is outside of TWRP. Note that the new minui does not currently have support for qcom overlay graphics. Support for this graphics mode will likely be added in a later patch set. If you are building in a 6.0 tree and have a device that needs qcom overlay graphics, be warned, as off mode charging may not work properly. A dead battery in this case could potentially brick your device if it is unable to charge as healthd handles charging duties. Update rules for building toolbox and add rules for making toybox Use permissive.sh in init.rc which will follow symlinks so we do not have to worry about what binary is supplying the setenforce functionality (toolbox, toybox, or busybox). Fix a few warnings in the main recovery binary source code. Fix a few includes that were missing that prevented compiling in 6.0 Change-Id: Ia67aa2107d260883da5e365475a19bea538e8b97
140 lines
2.3 KiB
C
140 lines
2.3 KiB
C
/*
|
|
* Copyright (C) 2012 Sami Kerola <kerolasa@iki.fi>
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <paths.h>
|
|
#include <sys/stat.h>
|
|
#include <unistd.h>
|
|
#include <sys/time.h>
|
|
#include <sys/resource.h>
|
|
|
|
#include "c.h"
|
|
#include "fileutils.h"
|
|
#include "pathnames.h"
|
|
|
|
#ifndef _PATH_TMP
|
|
#define _PATH_TMP "/tmp/"
|
|
#endif
|
|
|
|
/* Create open temporary file in safe way. Please notice that the
|
|
* file permissions are -rw------- by default. */
|
|
int xmkstemp(char **tmpname, char *dir)
|
|
{
|
|
char *localtmp;
|
|
char *tmpenv;
|
|
mode_t old_mode;
|
|
int fd, rc;
|
|
|
|
/* Some use cases must be capable of being moved atomically
|
|
* with rename(2), which is the reason why dir is here. */
|
|
if (dir != NULL)
|
|
tmpenv = dir;
|
|
else
|
|
tmpenv = getenv("TMPDIR");
|
|
|
|
if (tmpenv)
|
|
rc = asprintf(&localtmp, "%s/%s.XXXXXX", tmpenv,
|
|
program_invocation_short_name);
|
|
else
|
|
rc = asprintf(&localtmp, "%s/%s.XXXXXX", _PATH_TMP,
|
|
program_invocation_short_name);
|
|
|
|
if (rc < 0)
|
|
return -1;
|
|
|
|
old_mode = umask(077);
|
|
fd = mkstemp(localtmp);
|
|
umask(old_mode);
|
|
if (fd == -1) {
|
|
free(localtmp);
|
|
localtmp = NULL;
|
|
}
|
|
*tmpname = localtmp;
|
|
return fd;
|
|
}
|
|
|
|
/*
|
|
* portable getdtablesize()
|
|
*/
|
|
int get_fd_tabsize(void)
|
|
{
|
|
int m;
|
|
|
|
#if defined(HAVE_GETDTABLESIZE)
|
|
m = getdtablesize();
|
|
#elif defined(HAVE_GETRLIMIT) && defined(RLIMIT_NOFILE)
|
|
struct rlimit rl;
|
|
|
|
getrlimit(RLIMIT_NOFILE, &rl);
|
|
m = rl.rlim_cur;
|
|
#elif defined(HAVE_SYSCONF) && defined(_SC_OPEN_MAX)
|
|
m = sysconf(_SC_OPEN_MAX);
|
|
#else
|
|
m = OPEN_MAX;
|
|
#endif
|
|
return m;
|
|
}
|
|
|
|
#ifdef TEST_PROGRAM
|
|
int main(void)
|
|
{
|
|
FILE *f;
|
|
char *tmpname;
|
|
f = xfmkstemp(&tmpname, NULL);
|
|
unlink(tmpname);
|
|
free(tmpname);
|
|
fclose(f);
|
|
return EXIT_FAILURE;
|
|
}
|
|
#endif
|
|
|
|
|
|
int mkdir_p(const char *path, mode_t mode)
|
|
{
|
|
char *p, *dir;
|
|
int rc = 0;
|
|
|
|
if (!path || !*path)
|
|
return -EINVAL;
|
|
|
|
dir = p = strdup(path);
|
|
if (!dir)
|
|
return -ENOMEM;
|
|
|
|
if (*p == '/')
|
|
p++;
|
|
|
|
while (p && *p) {
|
|
char *e = strchr(p, '/');
|
|
if (e)
|
|
*e = '\0';
|
|
if (*p) {
|
|
rc = mkdir(dir, mode);
|
|
if (rc && errno != EEXIST)
|
|
break;
|
|
rc = 0;
|
|
}
|
|
if (!e)
|
|
break;
|
|
*e = '/';
|
|
p = e + 1;
|
|
}
|
|
|
|
free(dir);
|
|
return rc;
|
|
}
|
|
|
|
/* returns basename and keeps dirname in the @path, if @path is "/" (root)
|
|
* then returns empty string */
|
|
char *stripoff_last_component(char *path)
|
|
{
|
|
char *p = path ? strrchr(path, '/') : NULL;
|
|
|
|
if (!p)
|
|
return NULL;
|
|
*p = '\0';
|
|
return p + 1;
|
|
}
|