#include <sys/un.h>
#include <errno.h>
#include <dirent.h>
+#include <unistd.h>
#include <bundle.h>
#include <bundle_internal.h>
#ifdef _APPFW_FEATURE_SOCKET_ACTIVATION
{
struct sockaddr_un saddr;
int fd;
+ int ret;
if (is_app)
fd = socket(AF_UNIX, SOCK_STREAM, 0);
snprintf(saddr.sun_path, sizeof(saddr.sun_path),
"%s/apps/%d/%d",
SOCKET_PATH, getuid(), getpid());
+ 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 - %d",
+ saddr.sun_path, errno);
+ close(fd);
+ return -1;
+ }
+ } else {
+ _E("Failed to create %s directory - %d",
+ saddr.sun_path, errno);
+ close(fd);
+ return -1;
+ }
+ }
+ snprintf(saddr.sun_path, sizeof(saddr.sun_path),
+ "%s/apps/%d/%d/.app-sock",
+ SOCKET_PATH, getuid(), getpid());
} else {
snprintf(saddr.sun_path, sizeof(saddr.sun_path),
"%s/daemons/%d/.debug-launchpad-sock",
setenv("AUL_LISTEN_SOCK", buf, 1);
}
+static int __delete_dir(const char *path)
+{
+ DIR *dp;
+ struct dirent dentry;
+ struct dirent *result = NULL;
+ char buf[PATH_MAX];
+ struct stat statbuf;
+ int ret;
+
+ if (path == NULL)
+ return -1;
+
+ dp = opendir(path);
+ if (dp == NULL)
+ return -1;
+
+ while (readdir_r(dp, &dentry, &result) == 0 && result) {
+ if (!strcmp(dentry.d_name, ".") || !strcmp(dentry.d_name, ".."))
+ continue;
+
+ snprintf(buf, sizeof(buf), "%s/%s", path, dentry.d_name);
+ ret = stat(buf, &statbuf);
+ if (ret == 0) {
+ if (S_ISDIR(statbuf.st_mode))
+ __delete_dir(buf);
+ else
+ unlink(buf);
+ }
+ }
+
+ rmdir(path);
+ closedir(dp);
+
+ return 0;
+}
+
+int _delete_sock_path(int pid, uid_t uid)
+{
+ char path[PATH_MAX];
+
+ snprintf(path, sizeof(path), "/run/aul/apps/%d/%d", uid, pid);
+ if (access(path, F_OK) == 0)
+ __delete_dir(path);
+
+ if (access(path, F_OK) == 0)
+ return -1;
+
+ return 0;
+}
+
*/
#include <stdio.h>
+#include <stdlib.h>
#include <signal.h>
#include <sys/smack.h>
#include <sys/types.h>
snprintf(path, sizeof(path), "/proc/%s", dentry->d_name);
if (access(path, F_OK) != 0) { /* Flawfinder: ignore */
- snprintf(path, sizeof(path), "%s/apps/%d/%s",
- SOCKET_PATH, getuid(), dentry->d_name);
- unlink(path);
+ _delete_sock_path(atoi(dentry->d_name), getuid());
continue;
}
}
_send_app_dead_signal(dead_pid);
- snprintf(buf, MAX_LOCAL_BUFSZ, "%s/apps/%d/%d",
- SOCKET_PATH, getuid(), dead_pid);
- unlink(buf);
+ _delete_sock_path(dead_pid, getuid());
__socket_garbage_collector();