#include <glib.h>
#include <sys/utsname.h>
+/* For multi-user support */
+#include <tzplatform_config.h>
+
#include "heynoti-internal.h"
#define AU_PREFIX_SYSNOTI "SYS"
#ifndef NOTI_ROOT
-# define NOTI_ROOT "/tmp/noti"
+#define NOTI_ROOT tzplatform_mkpath(TZ_SYS_SHARE, "noti")
#endif
static int __make_noti_file(const char *p);
static inline int __make_noti_path(char *path, int size, const char *name);
static int __read_proc(const char *path, char *buf, int size);
-static int __get_kern_ver();
static void __clear_nslot_list(GList *g_ns);
static struct noti_cont *__get_noti_cont(int fd);
static int __handle_callback(struct noti_cont *nc, int wd, uint32_t mask);
};
typedef struct noti_cont ncont;
-static const char *noti_root = NOTI_ROOT;
static GList *g_nc;
static int __make_noti_root(const char *p)
{
int fd;
- if ((fd = open(p, O_RDONLY)) == -1) {
- if (mkdir(p, 0777) == -1)
- return -1;
- } else {
- fchmod(fd, 0777);
- close(fd);
- }
+ if ((fd = open(p, O_RDONLY)) == -1 )
+ return -1;
+
+ close(fd);
+
return 0;
}
{
int fd;
-#ifdef NODAC_PERMISSION
- if ((fd = open(p, O_RDONLY)) == -1) {
- if ((fd = open(p, O_CREAT, 0666)) < 0) {
- return -1;
- }
- fchmod(fd, 0666);
- close(fd);
- } else {
- fchmod(fd, 0666);
- close(fd);
- }
-#else
- if ((fd = open(p, O_RDONLY)) == -1) {
- if ((fd = open(p, O_CREAT, 0644)) < 0) {
- return -1;
- }
- close(fd);
- } else {
- fchmod(fd, 0644);
- close(fd);
- }
-#endif
+ if ((fd = open(p, O_RDONLY)) == -1)
+ return -1;
+
+ close(fd);
+
return 0;
}
static inline int __make_noti_path(char *path, int size, const char *name)
{
- return snprintf(path, size, "%s/%s", noti_root, name);
+ return snprintf(path, size, "%s/%s", NOTI_ROOT, name);
}
static int __read_proc(const char *path, char *buf, int size)
return ret;
}
-static int kern_ver; /* Kernel version */
#define PROC_VERSION "/proc/version"
-static int __get_kern_ver()
+static int __check_kern_ver()
{
struct utsname nm;
int ret;
int v2;
int v3;
- util_retv_if(kern_ver != 0, kern_ver);
-
ret = uname(&nm);
if (ret == 0) {
strncpy(buf, nm.release, sizeof(buf));
}
if (ret == 3) {
- kern_ver = KERNEL_VERSION(v1, v2, v3);
- return kern_ver;
+ if(KERNEL_VERSION(v1, v2, v3) < KERNEL_VERSION(2, 6, 13)) {
+ return -1;
+ } else {
+ return 0;
+ }
}
return -1;
{
int r;
struct inotify_event ie;
- char name[FILENAME_MAX];
+ char name[FILENAME_MAX] = {0, };
struct noti_cont *nc;
if (nc)
__handle_callback(nc, ie.wd, ie.mask);
- if (ie.len > 0)
- read(fd, name, ie.len);
+ if(ie.len > SSIZE_MAX)
+ return -1;
+
+ if (ie.len > 0u) {
+ r = read(fd, name, (ie.len > FILENAME_MAX) ? (size_t)FILENAME_MAX : (size_t) ie.len);
+ }
- r = read(fd, &ie, sizeof(ie));
+ if(r > 0) {
+ r = read(fd, &ie, sizeof(ie));
+ }
}
return 0;
return -1;
}
- __make_noti_file(notipath);
-
wd = __get_wd(fd, notipath);
util_retvm_if(wd == -1, -1, "Error: add noti: %s", strerror(errno));
return 0;
}
-API int heynoti_subscribe_file(int fd, const char *path, void (*cb) (void *),
- void *data, uint32_t mask)
-{
- if (path == NULL || cb == NULL) {
- UTIL_DBG("Error: add noti: Invalid input");
- errno = EINVAL;
- return -1;
- }
-
- return __add_noti(fd, path, cb, data, mask);
-}
-
API int heynoti_subscribe(int fd, const char *noti, void (*cb) (void *),
void *data)
{
return r;
}
-API int heynoti_unsubscribe_file(int fd, const char *path, void (*cb) (void *))
-{
- int r;
-
- if (fd < 0 || path == NULL) {
- errno = EINVAL;
- return -1;
- }
-
- r = del_noti(fd, path, cb);
- util_warn_if(r == -1, "Error: del [%s]: %s", path, strerror(errno));
-
- return r;
-}
-
API int heynoti_publish(const char *noti)
{
int fd;
}
UTIL_DBG("send noti: [%s]", notipath);
-#ifdef NODAC_PERMISSION
- fd = open(notipath, O_CREAT | O_TRUNC | O_RDWR, 0666);
-#else
- fd = open(notipath, O_CREAT | O_TRUNC | O_RDWR, 0644);
-#endif
+ fd = open(notipath, O_TRUNC | O_WRONLY);
+
util_retvm_if(fd == -1, -1, "Error: send noti: %s", strerror(errno));
/*
if(sb.st_mode & 0033)
fchmod(fd, 0644);
*/
-#ifdef NODAC_PERMISSION
- fchmod(fd, 0666);
-#endif
close(fd);
return 0;
struct noti_cont *nc;
- if (__get_kern_ver() < KERNEL_VERSION(2, 6, 13)) {
+ if(__check_kern_ver() < 0) {
UTIL_ERR("inotify requires kernel version >= 2.6.13 ");
errno = EPERM;
return -1;
fd = inotify_init();
util_retvm_if(fd == -1, -1, "inotify init: %s", strerror(errno));
- fcntl(fd, F_SETFD, FD_CLOEXEC);
- fcntl(fd, F_SETFL, O_NONBLOCK);
+ r = fcntl(fd, F_SETFD, FD_CLOEXEC);
+ util_retvm_if(r < 0, -1, "fcntl error : %s", strerror(errno));
+ r = fcntl(fd, F_SETFL, O_NONBLOCK);
+ util_retvm_if(r < 0, -1, "fcntl error : %s", strerror(errno));
- r = __make_noti_root(noti_root);
+ r = __make_noti_root(NOTI_ROOT);
if (r == -1) {
- UTIL_ERR("make noti root: %s : %s", noti_root, strerror(errno));
+ UTIL_ERR("make noti root: %s : %s", NOTI_ROOT, strerror(errno));
close(fd);
return -1;
}