#include "config.h"
+#include <assert.h>
+#include <dirent.h>
#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
+#include <fcntl.h>
+#include <libgen.h>
#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/vfs.h>
-#include <sys/stat.h>
+#include <unistd.h>
#include <sys/mman.h>
-#include <sys/param.h>
#include <sys/mount.h>
-#include <dirent.h>
-#include <fcntl.h>
-#include <libgen.h>
+#include <sys/param.h>
+#include <sys/prctl.h>
+#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/vfs.h>
#include <sys/wait.h>
-#include <assert.h>
-#include <sys/prctl.h>
-#include "utils.h"
#include "log.h"
#include "lxclock.h"
#include "namespace.h"
+#include "utils.h"
#ifndef PR_SET_MM
#define PR_SET_MM 35
static int _recursive_rmdir(char *dirname, dev_t pdev,
const char *exclude, int level, bool onedev)
{
- struct dirent dirent, *direntp;
+ struct dirent *direntp;
DIR *dir;
int ret, failed=0;
char pathname[MAXPATHLEN];
return -1;
}
- while (!readdir_r(dir, &dirent, &direntp)) {
+ while ((direntp = readdir(dir))) {
struct stat mystat;
int rc;
return components;
}
+bool lxc_deslashify(char *path)
+{
+ char **parts = NULL, *path2;
+
+ parts = lxc_normalize_path(path);
+ if (!parts)
+ return false;
+
+ path2 = lxc_string_join("/", (const char **) parts, *path == '/');
+ lxc_free_array((void **) parts, free);
+ if (!path2)
+ return false;
+
+ strncpy(path, path2, strlen(path));
+ free(path2);
+ return true;
+}
+
char *lxc_append_paths(const char *first, const char *second)
{
size_t len = strlen(first) + strlen(second) + 1;
if (count) {
temp = realloc(array, (count + 1) * sizeof(*array));
if (!temp) {
- int i;
+ size_t i;
for (i = 0; i < count; i++)
free(array[i]);
free(array);
* underlying file. The pages handed to us are zero filled. */
tmp = mmap(addr, length + 1, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (tmp == MAP_FAILED)
- goto out;
+ return tmp;
/* Now we establish a fixed-address mapping starting at the address we
* received from our anonymous mapping and replace all bytes excluding
* the additional \0-byte with the file. This allows us to use normal
- * string-handling function. */
+ * string-handling functions. */
overlap = mmap(tmp, length, prot, MAP_FIXED | flags, fd, offset);
if (overlap == MAP_FAILED)
- goto out;
+ munmap(tmp, length + 1);
-out:
return overlap;
}
{
return munmap(addr, length + 1);
}
+
+/* Check whether a signal is blocked by a process. */
+bool task_blocking_signal(pid_t pid, int signal)
+{
+ bool bret = false;
+ char *line = NULL;
+ long unsigned int sigblk = 0;
+ size_t n = 0;
+ int ret;
+ FILE *f;
+
+ /* The largest integer that can fit into long int is 2^64. This is a
+ * 20-digit number. */
+ size_t len = /* /proc */ 5 + /* /pid-to-str */ 21 + /* /status */ 7 + /* \0 */ 1;
+ char status[len];
+
+ ret = snprintf(status, len, "/proc/%d/status", pid);
+ if (ret < 0 || ret >= len)
+ return bret;
+
+ f = fopen(status, "r");
+ if (!f)
+ return bret;
+
+ while (getline(&line, &n, f) != -1) {
+ if (!strncmp(line, "SigBlk:\t", 8))
+ if (sscanf(line + 8, "%lx", &sigblk) != 1)
+ goto out;
+ }
+
+ if (sigblk & signal)
+ bret = true;
+
+out:
+ free(line);
+ fclose(f);
+ return bret;
+}