本文整理汇总了C++中path_startswith函数的典型用法代码示例。如果您正苦于以下问题:C++ path_startswith函数的具体用法?C++ path_startswith怎么用?C++ path_startswith使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了path_startswith函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: find_device
int find_device(const char *id, const char *prefix, sd_device **ret) {
_cleanup_free_ char *buf = NULL;
assert(id);
assert(ret);
if (prefix && !path_startswith(id, prefix)) {
buf = path_join(NULL, prefix, id);
if (!buf)
return -ENOMEM;
id = buf;
}
if (path_startswith(id, "/sys/"))
return sd_device_new_from_syspath(ret, id);
if (path_startswith(id, "/dev/")) {
struct stat st;
if (stat(id, &st) < 0)
return -errno;
return device_new_from_stat_rdev(ret, &st);
}
return -EINVAL;
}
开发者ID:htejun,项目名称:systemd,代码行数:27,代码来源:udevadm-util.c
示例2: assert
struct udev_device *find_device(const char *id,
const char *prefix) {
assert(id);
if (prefix && !startswith(id, prefix))
id = strjoina(prefix, id);
if (path_startswith(id, "/dev/")) {
struct stat statbuf;
char type;
if (stat(id, &statbuf) < 0)
return NULL;
if (S_ISBLK(statbuf.st_mode))
type = 'b';
else if (S_ISCHR(statbuf.st_mode))
type = 'c';
else
return NULL;
return udev_device_new_from_devnum(NULL, type, statbuf.st_rdev);
} else if (path_startswith(id, "/sys/"))
return udev_device_new_from_syspath(NULL, id);
else
return NULL;
}
开发者ID:halfline,项目名称:systemd,代码行数:28,代码来源:udevadm-util.c
示例3: mkdir_parents_internal
int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, mkdir_func_t _mkdir) {
const char *p, *e;
int r;
assert(path);
if (prefix && !path_startswith(path, prefix))
return -ENOTDIR;
/* return immediately if directory exists */
e = strrchr(path, '/');
if (!e)
return -EINVAL;
if (e == path)
return 0;
char buf[PATH_MAX + 1];
p = buf;
assert(e-path < sizeof(buf));
memcpy(buf, path, e-path);
buf[e-path] = 0;
r = is_dir(p, true);
if (r > 0)
return 0;
if (r == 0)
return -ENOTDIR;
/* create every parent directory in the path, except the last component */
p = path + strspn(path, "/");
for (;;) {
char t[strlen(path) + 1];
e = p + strcspn(p, "/");
p = e + strspn(e, "/");
/* Is this the last component? If so, then we're
* done */
if (*p == 0)
return 0;
memcpy(t, path, e - path);
t[e-path] = 0;
if (prefix && path_startswith(prefix, t))
continue;
r = _mkdir(t, mode);
if (r < 0 && errno != EEXIST)
return -errno;
}
}
开发者ID:ahills,项目名称:eudev,代码行数:53,代码来源:mkdir.c
示例4: mkdir_parents_internal
static int mkdir_parents_internal(const char *prefix, const char *path, mode_t mode, bool apply) {
const char *p, *e;
int r;
assert(path);
if (prefix && !path_startswith(path, prefix))
return -ENOTDIR;
/* return immediately if directory exists */
e = strrchr(path, '/');
if (!e)
return -EINVAL;
if (e == path)
return 0;
p = strndupa(path, e - path);
r = is_dir(p);
if (r > 0)
return 0;
if (r == 0)
return -ENOTDIR;
/* create every parent directory in the path, except the last component */
p = path + strspn(path, "/");
for (;;) {
char t[strlen(path) + 1];
e = p + strcspn(p, "/");
p = e + strspn(e, "/");
/* Is this the last component? If so, then we're
* done */
if (*p == 0)
return 0;
memcpy(t, path, e - path);
t[e-path] = 0;
if (prefix && path_startswith(prefix, t))
continue;
r = label_mkdir(t, mode, apply);
if (r < 0 && errno != EEXIST)
return -errno;
}
}
开发者ID:andymg,项目名称:android-udev,代码行数:48,代码来源:mkdir.c
示例5: drop_outside_root
static void drop_outside_root(const char *root_directory, MountEntry *m, unsigned *n) {
MountEntry *f, *t;
assert(m);
assert(n);
/* Nothing to do */
if (!root_directory)
return;
/* Drops all mounts that are outside of the root directory. */
for (f = m, t = m; f < m + *n; f++) {
if (!path_startswith(mount_entry_path(f), root_directory)) {
log_debug("%s is outside of root directory.", mount_entry_path(f));
mount_entry_done(f);
continue;
}
*t = *f;
t++;
}
*n = t - m;
}
开发者ID:heftig,项目名称:systemd,代码行数:26,代码来源:namespace.c
示例6: cg_fix_path
int cg_fix_path(const char *path, char **result) {
char *t, *c, *p;
int r;
assert(path);
assert(result);
/* First check if it already is a filesystem path */
if (path_is_absolute(path) &&
path_startswith(path, "/sys/fs/cgroup") &&
access(path, F_OK) >= 0) {
if (!(t = strdup(path)))
return -ENOMEM;
*result = t;
return 0;
}
/* Otherwise treat it as cg spec */
if ((r = cg_split_spec(path, &c, &p)) < 0)
return r;
r = cg_get_path(c ? c : SYSTEMD_CGROUP_CONTROLLER, p ? p : "/", NULL, result);
free(c);
free(p);
return r;
}
开发者ID:tizenorg,项目名称:external.systemd,代码行数:29,代码来源:cgroup-util.c
示例7: get_testdata_dir
const char* get_testdata_dir(const char *suffix) {
const char *env;
/* convenience: caller does not need to free result */
static char testdir[PATH_MAX];
/* if the env var is set, use that */
env = getenv("SYSTEMD_TEST_DATA");
testdir[sizeof(testdir) - 1] = '\0';
if (env) {
if (access(env, F_OK) < 0) {
fputs("ERROR: $SYSTEMD_TEST_DATA directory does not exist\n", stderr);
exit(1);
}
strncpy(testdir, env, sizeof(testdir) - 1);
} else {
_cleanup_free_ char *exedir = NULL;
assert_se(readlink_and_make_absolute("/proc/self/exe", &exedir) >= 0);
/* Check if we're running from the builddir. If so, use the compiled in path. */
if (path_startswith(exedir, ABS_BUILD_DIR))
assert_se(snprintf(testdir, sizeof(testdir), "%s/test", ABS_SRC_DIR) > 0);
else
/* Try relative path, according to the install-test layout */
assert_se(snprintf(testdir, sizeof(testdir), "%s/testdata", dirname(exedir)) > 0);
/* test this without the suffix, as it may contain a glob */
if (access(testdir, F_OK) < 0) {
fputs("ERROR: Cannot find testdata directory, set $SYSTEMD_TEST_DATA\n", stderr);
exit(1);
}
}
strncpy(testdir + strlen(testdir), suffix, sizeof(testdir) - strlen(testdir) - 1);
return testdir;
}
开发者ID:heftig,项目名称:systemd,代码行数:35,代码来源:tests.c
示例8: drop_inaccessible
static void drop_inaccessible(MountEntry *m, unsigned *n) {
MountEntry *f, *t;
const char *clear = NULL;
assert(m);
assert(n);
/* Drops all entries obstructed by another entry further up the tree. Expects that the array is properly
* ordered already. */
for (f = m, t = m; f < m + *n; f++) {
/* If we found a path set for INACCESSIBLE earlier, and this entry has it as prefix we should drop
* it, as inaccessible paths really should drop the entire subtree. */
if (clear && path_startswith(mount_entry_path(f), clear)) {
log_debug("%s is masked by %s.", mount_entry_path(f), clear);
mount_entry_done(f);
continue;
}
clear = f->mode == INACCESSIBLE ? mount_entry_path(f) : NULL;
*t = *f;
t++;
}
*n = t - m;
}
开发者ID:heftig,项目名称:systemd,代码行数:28,代码来源:namespace.c
示例9: mac_smack_fix
int mac_smack_fix(const char *path, bool ignore_enoent, bool ignore_erofs) {
#ifdef HAVE_SMACK
struct stat st;
#endif
int r = 0;
assert(path);
#ifdef HAVE_SMACK
if (!mac_smack_use())
return 0;
/*
* Path must be in /dev and must exist
*/
if (!path_startswith(path, "/dev"))
return 0;
r = lstat(path, &st);
if (r >= 0) {
const char *label;
/*
* Label directories and character devices "*".
* Label symlinks "_".
* Don't change anything else.
*/
if (S_ISDIR(st.st_mode))
label = SMACK_STAR_LABEL;
else if (S_ISLNK(st.st_mode))
label = SMACK_FLOOR_LABEL;
else if (S_ISCHR(st.st_mode))
label = SMACK_STAR_LABEL;
else
return 0;
r = lsetxattr(path, "security.SMACK64", label, strlen(label), 0);
/* If the FS doesn't support labels, then exit without warning */
if (r < 0 && errno == ENOTSUP)
return 0;
}
if (r < 0) {
/* Ignore ENOENT in some cases */
if (ignore_enoent && errno == ENOENT)
return 0;
if (ignore_erofs && errno == EROFS)
return 0;
r = log_debug_errno(errno, "Unable to fix SMACK label of %s: %m", path);
}
#endif
return r;
}
开发者ID:jsynacek,项目名称:systemd-rhel,代码行数:59,代码来源:smack-util.c
示例10: dkr_pull_new
int dkr_pull_new(
DkrPull **ret,
sd_event *event,
const char *index_url,
const char *image_root,
DkrPullFinished on_finished,
void *userdata) {
_cleanup_(dkr_pull_unrefp) DkrPull *i = NULL;
char *e;
int r;
assert(ret);
assert(index_url);
if (!http_url_is_valid(index_url))
return -EINVAL;
i = new0(DkrPull, 1);
if (!i)
return -ENOMEM;
i->on_finished = on_finished;
i->userdata = userdata;
i->image_root = strdup(image_root ?: "/var/lib/machines");
if (!i->image_root)
return -ENOMEM;
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
i->index_url = strdup(index_url);
if (!i->index_url)
return -ENOMEM;
e = endswith(i->index_url, "/");
if (e)
*e = 0;
if (event)
i->event = sd_event_ref(event);
else {
r = sd_event_default(&i->event);
if (r < 0)
return r;
}
r = curl_glue_new(&i->glue, i->event);
if (r < 0)
return r;
i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i;
*ret = i;
i = NULL;
return 0;
}
开发者ID:shaded-enmity,项目名称:systemd,代码行数:59,代码来源:pull-dkr.c
示例11: device_path_parse_major_minor
int device_path_parse_major_minor(const char *path, mode_t *ret_mode, dev_t *ret_devno) {
mode_t mode;
dev_t devno;
int r;
/* Tries to extract the major/minor directly from the device path if we can. Handles /dev/block/ and /dev/char/
* paths, as well out synthetic inaccessible device nodes. Never goes to disk. Returns -ENODEV if the device
* path cannot be parsed like this. */
if (path_equal(path, "/run/systemd/inaccessible/chr")) {
mode = S_IFCHR;
devno = makedev(0, 0);
} else if (path_equal(path, "/run/systemd/inaccessible/blk")) {
mode = S_IFBLK;
devno = makedev(0, 0);
} else {
const char *w;
w = path_startswith(path, "/dev/block/");
if (w)
mode = S_IFBLK;
else {
w = path_startswith(path, "/dev/char/");
if (!w)
return -ENODEV;
mode = S_IFCHR;
}
r = parse_dev(w, &devno);
if (r < 0)
return r;
}
if (ret_mode)
*ret_mode = mode;
if (ret_devno)
*ret_devno = devno;
return 0;
}
开发者ID:tblume,项目名称:systemd-testsuite-suse,代码行数:41,代码来源:stat-util.c
示例12: mount_point_is_api
bool mount_point_is_api(const char *path) {
unsigned i;
/* Checks if this mount point is considered "API", and hence
* should be ignored */
for (i = 0; i < ELEMENTSOF(mount_table); i ++)
if (path_equal(path, mount_table[i].where))
return true;
return path_startswith(path, "/sys/fs/cgroup/");
}
开发者ID:banada,项目名称:systemd,代码行数:12,代码来源:mount-setup.c
示例13: logind_wall_tty_filter
bool logind_wall_tty_filter(const char *tty, void *userdata) {
Manager *m = userdata;
const char *p;
assert(m);
if (!m->scheduled_shutdown_tty)
return true;
p = path_startswith(tty, "/dev/");
if (!p)
return true;
return !streq(p, m->scheduled_shutdown_tty);
}
开发者ID:halfline,项目名称:systemd,代码行数:15,代码来源:logind-utmp.c
示例14: tar_pull_new
int tar_pull_new(
TarPull **ret,
sd_event *event,
const char *image_root,
TarPullFinished on_finished,
void *userdata) {
_cleanup_(tar_pull_unrefp) TarPull *i = NULL;
int r;
assert(ret);
assert(event);
i = new0(TarPull, 1);
if (!i)
return -ENOMEM;
i->on_finished = on_finished;
i->userdata = userdata;
i->image_root = strdup(image_root ?: "/var/lib/machines");
if (!i->image_root)
return -ENOMEM;
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
if (event)
i->event = sd_event_ref(event);
else {
r = sd_event_default(&i->event);
if (r < 0)
return r;
}
r = curl_glue_new(&i->glue, i->event);
if (r < 0)
return r;
i->glue->on_finished = pull_job_curl_on_finished;
i->glue->userdata = i;
*ret = i;
i = NULL;
return 0;
}
开发者ID:AlexBaranosky,项目名称:systemd,代码行数:46,代码来源:pull-tar.c
示例15: tar_import_new
int tar_import_new(
TarImport **ret,
sd_event *event,
const char *image_root,
TarImportFinished on_finished,
void *userdata) {
_cleanup_(tar_import_unrefp) TarImport *i = NULL;
int r;
assert(ret);
i = new0(TarImport, 1);
if (!i)
return -ENOMEM;
i->input_fd = i->tar_fd = -1;
i->on_finished = on_finished;
i->userdata = userdata;
RATELIMIT_INIT(i->progress_rate_limit, 100 * USEC_PER_MSEC, 1);
i->last_percent = (unsigned) -1;
i->image_root = strdup(image_root ?: "/var/lib/machines");
if (!i->image_root)
return -ENOMEM;
i->grow_machine_directory = path_startswith(i->image_root, "/var/lib/machines");
if (event)
i->event = sd_event_ref(event);
else {
r = sd_event_default(&i->event);
if (r < 0)
return r;
}
*ret = i;
i = NULL;
return 0;
}
开发者ID:rachari,项目名称:systemd,代码行数:42,代码来源:import-tar.c
示例16: drop_nop
static void drop_nop(MountEntry *m, unsigned *n) {
MountEntry *f, *t;
assert(m);
assert(n);
/* Drops all entries which have an immediate parent that has the same type, as they are redundant. Assumes the
* list is ordered by prefixes. */
for (f = m, t = m; f < m + *n; f++) {
/* Only suppress such subtrees for READONLY and READWRITE entries */
if (IN_SET(f->mode, READONLY, READWRITE)) {
MountEntry *p;
bool found = false;
/* Now let's find the first parent of the entry we are looking at. */
for (p = t-1; p >= m; p--) {
if (path_startswith(mount_entry_path(f), mount_entry_path(p))) {
found = true;
break;
}
}
/* We found it, let's see if it's the same mode, if so, we can drop this entry */
if (found && p->mode == f->mode) {
log_debug("%s is redundant by %s", mount_entry_path(f), mount_entry_path(p));
mount_entry_done(f);
continue;
}
}
*t = *f;
t++;
}
*n = t - m;
}
开发者ID:heftig,项目名称:systemd,代码行数:38,代码来源:namespace.c
示例17: main
int main(int argc, char *argv[]) {
static const char virtualization_consoles[] =
"hvc0\0"
"xvc0\0"
"hvsi0\0"
"sclp_line0\0"
"ttysclp0\0"
"3270!tty1\0";
_cleanup_free_ char *active = NULL;
const char *j;
int r;
if (argc > 1 && argc != 4) {
log_error("This program takes three or no arguments.");
return EXIT_FAILURE;
}
if (argc > 1)
arg_dest = argv[1];
log_set_target(LOG_TARGET_SAFE);
log_parse_environment();
log_open();
umask(0022);
if (detect_container() > 0) {
_cleanup_free_ char *container_ttys = NULL;
log_debug("Automatically adding console shell.");
if (add_symlink("console-getty.service", "console-getty.service") < 0)
return EXIT_FAILURE;
/* When $container_ttys is set for PID 1, spawn
* gettys on all ptys named therein. Note that despite
* the variable name we only support ptys here. */
r = getenv_for_pid(1, "container_ttys", &container_ttys);
if (r > 0) {
const char *word, *state;
size_t l;
FOREACH_WORD(word, l, container_ttys, state) {
const char *t;
char tty[l + 1];
memcpy(tty, word, l);
tty[l] = 0;
/* First strip off /dev/ if it is specified */
t = path_startswith(tty, "/dev/");
if (!t)
t = tty;
/* Then, make sure it's actually a pty */
t = path_startswith(t, "pts/");
if (!t)
continue;
if (add_container_getty(t) < 0)
return EXIT_FAILURE;
}
}
/* Don't add any further magic if we are in a container */
return EXIT_SUCCESS;
}
开发者ID:nmartensen,项目名称:systemd,代码行数:70,代码来源:getty-generator.c
示例18: main
int main(int argc, char *argv[]) {
int r, output_flags;
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
if (r <= 0)
goto finish;
if (!arg_no_pager) {
r = pager_open(false);
if (r > 0 && arg_full < 0)
arg_full = true;
}
output_flags =
arg_all * OUTPUT_SHOW_ALL |
(arg_full > 0) * OUTPUT_FULL_WIDTH;
if (optind < argc) {
_cleanup_free_ char *root = NULL;
int i;
r = get_cgroup_root(&root);
if (r < 0)
goto finish;
for (i = optind; i < argc; i++) {
int q;
if (path_startswith(argv[i], "/sys/fs/cgroup")) {
printf("Directory %s:\n", argv[i]);
fflush(stdout);
q = show_cgroup_by_path(argv[i], NULL, 0, arg_kernel_threads, output_flags);
} else {
_cleanup_free_ char *c = NULL, *p = NULL, *j = NULL;
const char *controller, *path;
r = cg_split_spec(argv[i], &c, &p);
if (r < 0) {
log_error_errno(r, "Failed to split argument %s: %m", argv[i]);
goto finish;
}
controller = c ?: SYSTEMD_CGROUP_CONTROLLER;
if (p) {
j = strjoin(root, "/", p, NULL);
if (!j) {
r = log_oom();
goto finish;
}
path_kill_slashes(j);
path = j;
} else
path = root;
show_cg_info(controller, path);
q = show_cgroup(controller, path, NULL, 0, arg_kernel_threads, output_flags);
}
if (q < 0)
r = q;
}
} else {
开发者ID:michich,项目名称:systemd,代码行数:70,代码来源:cgls.c
示例19: image_make
static int image_make(
const char *pretty,
int dfd,
const char *path,
const char *filename,
Image **ret) {
struct stat st;
bool read_only;
int r;
assert(filename);
/* We explicitly *do* follow symlinks here, since we want to
* allow symlinking trees into /var/lib/machines/, and treat
* them normally. */
if (fstatat(dfd, filename, &st, 0) < 0)
return -errno;
read_only =
(path && path_startswith(path, "/usr")) ||
(faccessat(dfd, filename, W_OK, AT_EACCESS) < 0 && errno == EROFS);
if (S_ISDIR(st.st_mode)) {
_cleanup_close_ int fd = -1;
unsigned file_attr = 0;
if (!ret)
return 1;
if (!pretty)
pretty = filename;
fd = openat(dfd, filename, O_CLOEXEC|O_NOCTTY|O_DIRECTORY);
if (fd < 0)
return -errno;
/* btrfs subvolumes have inode 256 */
if (st.st_ino == 256) {
r = btrfs_is_filesystem(fd);
if (r < 0)
return r;
if (r) {
BtrfsSubvolInfo info;
/* It's a btrfs subvolume */
r = btrfs_subvol_get_info_fd(fd, 0, &info);
if (r < 0)
return r;
r = image_new(IMAGE_SUBVOLUME,
pretty,
path,
filename,
info.read_only || read_only,
info.otime,
0,
ret);
if (r < 0)
return r;
if (btrfs_quota_scan_ongoing(fd) == 0) {
BtrfsQuotaInfo quota;
r = btrfs_subvol_get_subtree_quota_fd(fd, 0, "a);
if (r >= 0) {
(*ret)->usage = quota.referenced;
(*ret)->usage_exclusive = quota.exclusive;
(*ret)->limit = quota.referenced_max;
(*ret)->limit_exclusive = quota.exclusive_max;
}
}
return 1;
}
}
/* If the IMMUTABLE bit is set, we consider the
* directory read-only. Since the ioctl is not
* supported everywhere we ignore failures. */
(void) read_attr_fd(fd, &file_attr);
/* It's just a normal directory. */
r = image_new(IMAGE_DIRECTORY,
pretty,
path,
filename,
read_only || (file_attr & FS_IMMUTABLE_FL),
0,
0,
ret);
if (r < 0)
return r;
return 1;
//.........这里部分代码省略.........
开发者ID:SimonPe,项目名称:systemd,代码行数:101,代码来源:machine-image.c
示例20: umount_recursive
int umount_recursive(const char *prefix, int flags) {
int n = 0, r;
bool again;
/* Try to umount everything recursively below a
* directory. Also, take care of stacked mounts, and keep
* unmounting them until they are gone. */
do {
_cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
again = false;
r = 0;
proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
if (!proc_self_mountinfo)
return -errno;
(void) __fsetlocking(proc_self_mountinfo, FSETLOCKING_BYCALLER);
for (;;) {
_cleanup_free_ char *path = NULL, *p = NULL;
int k;
k = fscanf(proc_self_mountinfo,
"%*s " /* (1) mount id */
"%*s " /* (2) parent id */
"%*s " /* (3) major:minor */
"%*s " /* (4) root */
"%ms " /* (5) mount point */
"%*s" /* (6) mount options */
"%*[^-]" /* (7) optional fields */
"- " /* (8) separator */
"%*s " /* (9) file system type */
"%*s" /* (10) mount source */
"%*s" /* (11) mount options 2 */
"%*[^\n]", /* some rubbish at the end */
&path);
if (k != 1) {
if (k == EOF)
break;
continue;
}
k = cunescape(path, UNESCAPE_RELAX, &p);
if (k < 0)
return k;
if (!path_startswith(p, prefix))
continue;
if (umount2(p, flags) < 0) {
r = log_debug_errno(errno, "Failed to umount %s: %m", p);
continue;
}
log_debug("Successfully unmounted %s", p);
again = true;
n++;
break;
}
} while (again);
return r < 0 ? r : n;
}
开发者ID:dm0-,项目名称:systemd,代码行数:69,代码来源:mount-util.c
注:本文中的path_startswith函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论