*
* Connection Manager
*
- * Copyright (C) 2007-2010 Intel Corporation. All rights reserved.
+ * Copyright (C) 2007-2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
#include <config.h>
#endif
+#define _GNU_SOURCE
#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
off_t ptrlen, keylen;
int fd;
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return NULL;
void *dst_map;
int fd, result;
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -1;
subpath, d->d_name);
if (compare_file(src_map, src_st, pathname) == 0) {
- closedir(dir);
- return g_strdup_printf("%s/%s",
+ str = g_strdup_printf("%s/%s",
subpath, d->d_name);
+ closedir(dir);
+ return str;
}
break;
case DT_DIR:
DBG("sysconfig zone %s", zone);
- fd = open(ETC_LOCALTIME, O_RDONLY);
+ fd = open(ETC_LOCALTIME, O_RDONLY | O_CLOEXEC);
if (fd < 0) {
g_free(zone);
return NULL;
static int write_file(void *src_map, struct stat *src_st, const char *pathname)
{
+ struct stat st;
int fd;
ssize_t written;
DBG("pathname %s", pathname);
- fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (lstat(pathname, &st) == 0) {
+ if (S_ISLNK(st.st_mode))
+ unlink(pathname);
+ }
+
+ fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
if (fd < 0)
return -EIO;
snprintf(pathname, PATH_MAX, "%s/%s", USR_SHARE_ZONEINFO, zone);
- fd = open(pathname, O_RDONLY);
+ fd = open(pathname, O_RDONLY | O_CLOEXEC);
if (fd < 0)
return -EINVAL;
dirname = g_path_get_dirname(ETC_LOCALTIME);
wd = inotify_add_watch(fd, dirname, IN_DONT_FOLLOW |
- IN_MODIFY | IN_MOVED_TO);
+ IN_CLOSE_WRITE | IN_MOVED_TO);
g_free(dirname);