#include <sys/xattr.h>
#include <errno.h>
#include <fcntl.h>
+#include <ctype.h>
#include <tzplatform_config.h>
#include <glib.h>
#include <vconf.h>
return 0;
}
+static int __create_socket_dir(int pid, uid_t uid)
+{
+ char path[PATH_MAX];
+
+ if (uid < REGULAR_UID_MIN)
+ snprintf(path, sizeof(path), "/run/aul/daemons/%d", uid);
+ else
+ snprintf(path, sizeof(path), "/run/aul/apps/%d/%d", uid, pid);
+
+ if (mkdir(path, 0700) != 0) {
+ if (errno == EEXIST) {
+ if (access(path, R_OK) != 0) {
+ _E("Failed to acess %s directory", path);
+ return -1;
+ }
+ } else {
+ _E("Failed to create %s directory", path);
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
static void __create_socket_path(char *path_buf, int size, int pid, uid_t uid)
{
if (uid < REGULAR_UID_MIN) {
}
}
+static void __create_socket_link(const char *socket_path, int pid, uid_t uid)
+{
+ char path[PATH_MAX];
+
+ if (__create_socket_dir(pid, uid) < 0)
+ return;
+
+ __create_socket_path(path, sizeof(path), pid, uid);
+ if (link(socket_path, path) < 0) {
+ if (errno == EEXIST)
+ _D("path(%s) - already exists", path);
+ else
+ _E("path(%s) - unknown create error", path);
+ }
+}
+
API int aul_sock_create_server(int pid, uid_t uid)
{
struct sockaddr_un saddr;
- struct sockaddr_un p_saddr;
int fd;
- int ret;
- int pgid;
+ int env_pid = -1;
+ char *env_str;
fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC | SOCK_NONBLOCK, 0);
/* support above version 2.6.27*/
memset(&saddr, 0, sizeof(saddr));
saddr.sun_family = AF_UNIX;
- if (uid < REGULAR_UID_MIN) {
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "/run/aul/daemons/%d", uid);
-
- } else {
- snprintf(saddr.sun_path, sizeof(saddr.sun_path),
- "/run/aul/apps/%d/%d", uid, pid);
- }
-
- ret = mkdir(saddr.sun_path, 0700);
- if (ret != 0) {
- if (errno == EEXIST) {
- if (access(saddr.sun_path, R_OK) != 0) {
- _E("Failed to access %s directory",
- saddr.sun_path);
- close(fd);
- return -1;
- }
- } else {
- _E("Failed to create %s directory", saddr.sun_path);
- close(fd);
- return -1;
- }
+ if (__create_socket_dir(pid, uid) < 0) {
+ close(fd);
+ return -1;
}
__create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pid, uid);
return -1;
}
- /* support app launched by shell script */
+ /* Create socket link */
if (pid > 0) {
- pgid = getpgid(pid);
- if (pgid > 1) {
- __create_socket_path(saddr.sun_path, sizeof(saddr.sun_path), pgid, uid);
- if (link(saddr.sun_path, p_saddr.sun_path) < 0) {
- if (errno == EEXIST)
- _D("pg path - already exists");
- else
- _E("pg path - unknown create error");
- }
- }
+ env_str = getenv("AUL_PID");
+ if (env_str && isdigit(env_str[0]))
+ env_pid = atoi(env_str);
+
+ if (env_pid > 1 && pid != env_pid)
+ __create_socket_link(saddr.sun_path, env_pid, uid);
}
return fd;