您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ strjoina函数代码示例

51自学网 2021-06-03 08:31:00
  C++
这篇教程C++ strjoina函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中strjoina函数的典型用法代码示例。如果您正苦于以下问题:C++ strjoina函数的具体用法?C++ strjoina怎么用?C++ strjoina使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了strjoina函数的29个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: test_add_dependency

static void test_add_dependency(const char *root) {        UnitFileChange *changes = NULL;        unsigned n_changes = 0;        const char *p;        p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-target.target");        assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-target.target");        assert_se(symlink("real-add-dependency-test-target.target", p) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/real-add-dependency-test-service.service");        assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/add-dependency-test-service.service");        assert_se(symlink("real-add-dependency-test-service.service", p) >= 0);        assert_se(unit_file_add_dependency(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("add-dependency-test-service.service"), "add-dependency-test-target.target", UNIT_WANTS, &changes, &n_changes) >= 0);        assert_se(n_changes == 1);        assert_se(changes[0].type == UNIT_FILE_SYMLINK);        assert_se(streq(changes[0].source, "/usr/lib/systemd/system/real-add-dependency-test-service.service"));        p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/real-add-dependency-test-target.target.wants/real-add-dependency-test-service.service");        assert_se(streq(changes[0].path, p));        unit_file_changes_free(changes, n_changes);        changes = NULL; n_changes = 0;}
开发者ID:OpenDZ,项目名称:systemd,代码行数:26,


示例2: STRV_FOREACH_PAIR

        STRV_FOREACH_PAIR(link, p, links) {                char *f = strjoina(original_dir, *p);                char *l = strjoina(original_dir, *link);                assert_se(mkdir_parents(l, 0755) >= 0);                assert_se(symlink(f, l) == 0);        }
开发者ID:iaguis,项目名称:systemd,代码行数:7,


示例3: test_default

static void test_default(const char *root) {        _cleanup_free_ char *def = NULL;        UnitFileChange *changes = NULL;        unsigned n_changes = 0;        const char *p;        p = strjoina(root, "/usr/lib/systemd/system/test-default-real.target");        assert_se(write_string_file(p, "# pretty much empty", WRITE_STRING_FILE_CREATE) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/test-default.target");        assert_se(symlink("test-default-real.target", p) >= 0);        assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);        assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, 0, root, "idontexist.target", &changes, &n_changes) == -ENOENT);        assert_se(n_changes == 1);        assert_se(changes[0].type == -ENOENT);        assert_se(streq_ptr(changes[0].path, "idontexist.target"));        unit_file_changes_free(changes, n_changes);        changes = NULL; n_changes = 0;        assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) == -ENOENT);        assert_se(unit_file_set_default(UNIT_FILE_SYSTEM, 0, root, "test-default.target", &changes, &n_changes) >= 0);        assert_se(n_changes == 1);        assert_se(changes[0].type == UNIT_FILE_SYMLINK);        assert_se(streq(changes[0].source, "/usr/lib/systemd/system/test-default-real.target"));        p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH "/" SPECIAL_DEFAULT_TARGET);        assert_se(streq(changes[0].path, p));        unit_file_changes_free(changes, n_changes);        changes = NULL; n_changes = 0;        assert_se(unit_file_get_default(UNIT_FILE_SYSTEM, root, &def) >= 0);        assert_se(streq_ptr(def, "test-default-real.target"));}
开发者ID:OpenDZ,项目名称:systemd,代码行数:35,


示例4: prompt_root_password

static int prompt_root_password(void) {        const char *msg1, *msg2, *etc_shadow;        int r;        if (arg_root_password)                return 0;        if (!arg_prompt_root_password)                return 0;        etc_shadow = prefix_roota("/etc/shadow");        if (faccessat(AT_FDCWD, etc_shadow, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)                return 0;        print_welcome();        putchar('/n');        msg1 = strjoina(draw_special_char(DRAW_TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");        msg2 = strjoina(draw_special_char(DRAW_TRIANGULAR_BULLET), " Please enter new root password again: ");        for (;;) {                _cleanup_free_ char *a = NULL, *b = NULL;                r = ask_password_tty(msg1, 0, false, NULL, &a);                if (r < 0)                        return log_error_errno(r, "Failed to query root password: %m");                if (isempty(a)) {                        log_warning("No password entered, skipping.");                        break;                }                r = ask_password_tty(msg2, 0, false, NULL, &b);                if (r < 0) {                        log_error_errno(r, "Failed to query root password: %m");                        clear_string(a);                        return r;                }                if (!streq(a, b)) {                        log_error("Entered passwords did not match, please try again.");                        clear_string(a);                        clear_string(b);                        continue;                }                clear_string(b);                arg_root_password = a;                a = NULL;                break;        }        return 0;}
开发者ID:Stratoscale,项目名称:systemd,代码行数:54,


示例5: link_busnames_target

static int link_busnames_target(const char *units) {        const char *f, *t;        f = strjoina(units, "/" SPECIAL_BUSNAMES_TARGET);        t = strjoina(arg_dest, "/" SPECIAL_BASIC_TARGET ".wants/" SPECIAL_BUSNAMES_TARGET);        mkdir_parents_label(t, 0755);        if (symlink(f, t) < 0)                return log_error_errno(errno, "Failed to create symlink %s: %m", t);        return 0;}
开发者ID:michich,项目名称:systemd,代码行数:12,


示例6: create_subcgroup

int create_subcgroup(pid_t pid, bool keep_unit, CGroupUnified unified_requested) {        _cleanup_free_ char *cgroup = NULL;        CGroupMask supported;        const char *payload;        int r;        assert(pid > 1);        /* In the unified hierarchy inner nodes may only contain subgroups, but not processes. Hence, if we running in         * the unified hierarchy and the container does the same, and we did not create a scope unit for the container         * move us and the container into two separate subcgroups.         *         * Moreover, container payloads such as systemd try to manage the cgroup they run in in full (i.e. including         * its attributes), while the host systemd will only delegate cgroups for children of the cgroup created for a         * delegation unit, instead of the cgroup itself. This means, if we'd pass on the cgroup allocated from the         * host systemd directly to the payload, the host and payload systemd might fight for the cgroup         * attributes. Hence, let's insert an intermediary cgroup to cover that case too.         *         * Note that we only bother with the main hierarchy here, not with any secondary ones. On the unified setup         * that's fine because there's only one hiearchy anyway and controllers are enabled directly on it. On the         * legacy setup, this is fine too, since delegation of controllers is generally not safe there, hence we won't         * do it. */        r = cg_mask_supported(&supported);        if (r < 0)                return log_error_errno(r, "Failed to determine supported controllers: %m");        if (keep_unit)                r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, 0, &cgroup);        else                r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup);        if (r < 0)                return log_error_errno(r, "Failed to get our control group: %m");        payload = strjoina(cgroup, "/payload");        r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, payload, pid);        if (r < 0)                return log_error_errno(r, "Failed to create %s subcgroup: %m", payload);        if (keep_unit) {                const char *supervisor;                supervisor = strjoina(cgroup, "/supervisor");                r = cg_create_and_attach(SYSTEMD_CGROUP_CONTROLLER, supervisor, 0);                if (r < 0)                        return log_error_errno(r, "Failed to create %s subcgroup: %m", supervisor);        }        /* Try to enable as many controllers as possible for the new payload. */        (void) cg_enable_everywhere(supported, supported, cgroup);        return 0;}
开发者ID:halfline,项目名称:systemd,代码行数:52,


示例7: prompt_root_password

static int prompt_root_password(void) {        const char *msg1, *msg2, *etc_shadow;        int r;        if (arg_root_password)                return 0;        if (!arg_prompt_root_password)                return 0;        etc_shadow = prefix_roota(arg_root, "/etc/shadow");        if (laccess(etc_shadow, F_OK) >= 0)                return 0;        print_welcome();        putchar('/n');        msg1 = strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");        msg2 = strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET), " Please enter new root password again: ");        for (;;) {                _cleanup_strv_free_erase_ char **a = NULL, **b = NULL;                r = ask_password_tty(-1, msg1, NULL, 0, 0, NULL, &a);                if (r < 0)                        return log_error_errno(r, "Failed to query root password: %m");                if (strv_length(a) != 1) {                        log_warning("Received multiple passwords, where we expected one.");                        return -EINVAL;                }                if (isempty(*a)) {                        log_warning("No password entered, skipping.");                        break;                }                r = ask_password_tty(-1, msg2, NULL, 0, 0, NULL, &b);                if (r < 0)                        return log_error_errno(r, "Failed to query root password: %m");                if (!streq(*a, *b)) {                        log_error("Entered passwords did not match, please try again.");                        continue;                }                arg_root_password = TAKE_PTR(*a);                break;        }        return 0;}
开发者ID:Keruspe,项目名称:systemd,代码行数:51,


示例8: generator_add_symlink

int generator_add_symlink(const char *root, const char *dst, const char *dep_type, const char *src) {        /* Adds a symlink from <dst>.<dep_type>.d/ to ../<src> */        const char *from, *to;        from = strjoina("../", src);        to = strjoina(root, "/", dst, ".", dep_type, "/", src);        mkdir_parents_label(to, 0755);        if (symlink(from, to) < 0)                if (errno != EEXIST)                        return log_error_errno(errno, "Failed to create symlink /"%s/": %m", to);        return 0;}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:15,


示例9: prompt_root_password

static int prompt_root_password(void) {        const char *msg1, *msg2, *etc_shadow;        int r;        if (arg_root_password)                return 0;        if (!arg_prompt_root_password)                return 0;        etc_shadow = prefix_roota(arg_root, "/etc/shadow");        if (laccess(etc_shadow, F_OK) >= 0)                return 0;        print_welcome();        putchar('/n');        msg1 = strjoina(special_glyph(TRIANGULAR_BULLET), " Please enter a new root password (empty to skip): ");        msg2 = strjoina(special_glyph(TRIANGULAR_BULLET), " Please enter new root password again: ");        for (;;) {                _cleanup_string_free_erase_ char *a = NULL, *b = NULL;                r = ask_password_tty(msg1, NULL, 0, 0, NULL, &a);                if (r < 0)                        return log_error_errno(r, "Failed to query root password: %m");                if (isempty(a)) {                        log_warning("No password entered, skipping.");                        break;                }                r = ask_password_tty(msg2, NULL, 0, 0, NULL, &b);                if (r < 0)                        return log_error_errno(r, "Failed to query root password: %m");                if (!streq(a, b)) {                        log_error("Entered passwords did not match, please try again.");                        continue;                }                arg_root_password = a;                a = NULL;                break;        }        return 0;}
开发者ID:OpenDZ,项目名称:systemd,代码行数:48,


示例10: test_indirect

static void test_indirect(const char *root) {        UnitFileChange *changes = NULL;        unsigned n_changes = 0;        UnitFileState state;        const char *p;        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) == -ENOENT);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) == -ENOENT);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) == -ENOENT);        p = strjoina(root, "/usr/lib/systemd/system/indirecta.service");        assert_se(write_string_file(p,                                    "[Install]/n"                                    "Also=indirectb.service/n", WRITE_STRING_FILE_CREATE) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/indirectb.service");        assert_se(write_string_file(p,                                    "[Install]/n"                                    "WantedBy=multi-user.target/n", WRITE_STRING_FILE_CREATE) >= 0);        p = strjoina(root, "/usr/lib/systemd/system/indirectc.service");        assert_se(symlink("indirecta.service", p) >= 0);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_DISABLED);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);        assert_se(unit_file_enable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);        assert_se(n_changes == 1);        assert_se(changes[0].type == UNIT_FILE_SYMLINK);        assert_se(streq(changes[0].source, "/usr/lib/systemd/system/indirectb.service"));        p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");        assert_se(streq(changes[0].path, p));        unit_file_changes_free(changes, n_changes);        changes = NULL; n_changes = 0;        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirecta.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectb.service", &state) >= 0 && state == UNIT_FILE_ENABLED);        assert_se(unit_file_get_state(UNIT_FILE_SYSTEM, root, "indirectc.service", &state) >= 0 && state == UNIT_FILE_INDIRECT);        assert_se(unit_file_disable(UNIT_FILE_SYSTEM, 0, root, STRV_MAKE("indirectc.service"), &changes, &n_changes) >= 0);        assert_se(n_changes == 1);        assert_se(changes[0].type == UNIT_FILE_UNLINK);        p = strjoina(root, SYSTEM_CONFIG_UNIT_PATH"/multi-user.target.wants/indirectb.service");        assert_se(streq(changes[0].path, p));        unit_file_changes_free(changes, n_changes);        changes = NULL; n_changes = 0;}
开发者ID:OpenDZ,项目名称:systemd,代码行数:48,


示例11: main

int main(int argc, char** argv) {        _cleanup_free_ char *cmd = NULL, *cmd2 = NULL, *ans = NULL, *ans2 = NULL, *d = NULL, *tmp = NULL, *line = NULL;        _cleanup_close_ int fd = -1, fd2 = -1;        const char *p = argv[1] ?: "/tmp";        char *pattern;        log_set_max_level(LOG_DEBUG);        log_parse_environment();        pattern = strjoina(p, "/systemd-test-XXXXXX");        fd = open_tmpfile_unlinkable(p, O_RDWR|O_CLOEXEC);        assert_se(fd >= 0);        assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd) > 0);        (void) system(cmd);        assert_se(readlink_malloc(cmd + 6, &ans) >= 0);        log_debug("link1: %s", ans);        assert_se(endswith(ans, " (deleted)"));        fd2 = mkostemp_safe(pattern);        assert_se(fd >= 0);        assert_se(unlink(pattern) == 0);        assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid_cached(), fd2) > 0);        (void) system(cmd2);        assert_se(readlink_malloc(cmd2 + 6, &ans2) >= 0);        log_debug("link2: %s", ans2);        assert_se(endswith(ans2, " (deleted)"));        pattern = strjoina(p, "/tmpfiles-test");        assert_se(tempfn_random(pattern, NULL, &d) >= 0);        fd = open_tmpfile_linkable(d, O_RDWR|O_CLOEXEC, &tmp);        assert_se(fd >= 0);        assert_se(write(fd, "foobar/n", 7) == 7);        assert_se(touch(d) >= 0);        assert_se(link_tmpfile(fd, tmp, d) == -EEXIST);        assert_se(unlink(d) >= 0);        assert_se(link_tmpfile(fd, tmp, d) >= 0);        assert_se(read_one_line_file(d, &line) >= 0);        assert_se(streq(line, "foobar"));        assert_se(unlink(d) >= 0);        return 0;}
开发者ID:Werkov,项目名称:systemd,代码行数:48,


示例12: button_open

int button_open(Button *b) {        char *p, name[256];        int r;        assert(b);        b->fd = safe_close(b->fd);        p = strjoina("/dev/input/", b->name);        b->fd = open(p, O_RDWR|O_CLOEXEC|O_NOCTTY|O_NONBLOCK);        if (b->fd < 0)                return log_warning_errno(errno, "Failed to open %s: %m", b->name);        if (ioctl(b->fd, EVIOCGNAME(sizeof(name)), name) < 0) {                r = log_error_errno(errno, "Failed to get input name: %m");                goto fail;        }        r = sd_event_add_io(b->manager->event, &b->io_event_source, b->fd, EPOLLIN, button_dispatch, b);        if (r < 0) {                log_error_errno(r, "Failed to add button event: %m");                goto fail;        }        log_info("Watching system buttons on /dev/input/%s (%s)", b->name, name);        return 0;fail:        b->fd = safe_close(b->fd);        return r;}
开发者ID:nazgul77,项目名称:systemd,代码行数:33,


示例13: add_root_mount

static int add_root_mount(void) {        _cleanup_free_ char *what = NULL;        const char *opts;        if (isempty(arg_root_what)) {                log_debug("Could not find a root= entry on the kernel command line.");                return 0;        }        what = fstab_node_to_udev_node(arg_root_what);        if (!path_is_absolute(what)) {                log_debug("Skipping entry what=%s where=/sysroot type=%s", what, strna(arg_root_fstype));                return 0;        }        if (!arg_root_options)                opts = arg_root_rw > 0 ? "rw" : "ro";        else if (arg_root_rw >= 0 ||                 !fstab_test_option(arg_root_options, "ro/0" "rw/0"))                opts = strjoina(arg_root_options, ",", arg_root_rw > 0 ? "rw" : "ro");        else                opts = arg_root_options;        log_debug("Found entry what=%s where=/sysroot type=%s", what, strna(arg_root_fstype));        return add_mount(what,                         "/sysroot",                         arg_root_fstype,                         opts,                         1,                         false,                         false,                         false,                         SPECIAL_INITRD_ROOT_FS_TARGET,                         "/proc/cmdline");}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:35,


示例14: main

int main(int argc, char** argv) {        const char *p = argv[1] ?: "/tmp";        char *pattern = strjoina(p, "/systemd-test-XXXXXX");        _cleanup_close_ int fd, fd2;        _cleanup_free_ char *cmd, *cmd2, *ans, *ans2;        log_set_max_level(LOG_DEBUG);        log_parse_environment();        fd = open_tmpfile(p, O_RDWR|O_CLOEXEC);        assert_se(fd >= 0);        assert_se(asprintf(&cmd, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd) > 0);        (void) system(cmd);        assert_se(readlink_malloc(cmd + 6, &ans) >= 0);        log_debug("link1: %s", ans);        assert_se(endswith(ans, " (deleted)"));        fd2 = mkostemp_safe(pattern, O_RDWR|O_CLOEXEC);        assert_se(fd >= 0);        assert_se(unlink(pattern) == 0);        assert_se(asprintf(&cmd2, "ls -l /proc/"PID_FMT"/fd/%d", getpid(), fd2) > 0);        (void) system(cmd2);        assert_se(readlink_malloc(cmd2 + 6, &ans2) >= 0);        log_debug("link2: %s", ans2);        assert_se(endswith(ans2, " (deleted)"));        return 0;}
开发者ID:nmartensen,项目名称:systemd,代码行数:30,


示例15: install_loader_config

static int install_loader_config(const char *esp_path) {        char *p;        char line[64];        char *machine = NULL;        _cleanup_fclose_ FILE *f = NULL, *g = NULL;        f = fopen("/etc/machine-id", "re");        if (!f)                return errno == ENOENT ? 0 : -errno;        if (fgets(line, sizeof(line), f) != NULL) {                char *s;                s = strchr(line, '/n');                if (s)                        s[0] = '/0';                if (strlen(line) == 32)                        machine = line;        }        if (!machine)                return -ESRCH;        p = strjoina(esp_path, "/loader/loader.conf");        g = fopen(p, "wxe");        if (g) {                fprintf(g, "#timeout 3/n");                fprintf(g, "default %s-*/n", machine);                if (ferror(g))                        return log_error_errno(EIO, "Failed to write /"%s/": %m", p);        }        return 0;}
开发者ID:Rydoo42,项目名称:systemd,代码行数:34,


示例16: unit_file_find_dirs

static int unit_file_find_dirs(                const char *original_root,                Set *unit_path_cache,                const char *unit_path,                const char *name,                const char *suffix,                char ***dirs) {        _cleanup_free_ char *prefix = NULL, *instance = NULL, *built = NULL;        bool is_instance, chopped;        const char *dash;        UnitType type;        char *path;        size_t n;        int r;        assert(unit_path);        assert(name);        assert(suffix);        path = strjoina(unit_path, "/", name, suffix);        if (!unit_path_cache || set_get(unit_path_cache, path)) {                r = unit_file_find_dir(original_root, path, dirs);                if (r < 0)                        return r;        }        is_instance = unit_name_is_valid(name, UNIT_NAME_INSTANCE);        if (is_instance) { /* Also try the template dir */                _cleanup_free_ char *template = NULL;
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:30,


示例17: add_match

static int add_match(sd_journal *j, const char *match) {        _cleanup_free_ char *p = NULL;        const char* prefix, *pattern;        pid_t pid;        int r;        if (strchr(match, '='))                prefix = "";        else if (strchr(match, '/')) {                r = path_make_absolute_cwd(match, &p);                if (r < 0)                        return log_error_errno(r, "path_make_absolute_cwd(/"%s/"): %m", match);                match = p;                prefix = "COREDUMP_EXE=";        } else if (parse_pid(match, &pid) >= 0)                prefix = "COREDUMP_PID=";        else                prefix = "COREDUMP_COMM=";        pattern = strjoina(prefix, match);        log_debug("Adding match: %s", pattern);        r = sd_journal_add_match(j, pattern, 0);        if (r < 0)                return log_error_errno(r, "Failed to add match /"%s/": %m", match);        return 0;}
开发者ID:dankor,项目名称:systemd,代码行数:28,


示例18: generator_open_unit_file

int generator_open_unit_file(                const char *dest,                const char *source,                const char *name,                FILE **file) {        const char *unit;        FILE *f;        unit = strjoina(dest, "/", name);        f = fopen(unit, "wxe");        if (!f) {                if (source && errno == EEXIST)                        return log_error_errno(errno,                                               "Failed to create unit file %s, as it already exists. Duplicate entry in %s?",                                               unit, source);                else                        return log_error_errno(errno,                                               "Failed to create unit file %s: %m",                                               unit);        }        (void) __fsetlocking(f, FSETLOCKING_BYCALLER);        fprintf(f,                "# Automatically generated by %s/n/n",                program_invocation_short_name);        *file = f;        return 0;}
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:32,


示例19: test_execute_directory

static void test_execute_directory(bool gather_stdout) {        char template_lo[] = "/tmp/test-exec-util.XXXXXXX";        char template_hi[] = "/tmp/test-exec-util.XXXXXXX";        const char * dirs[] = {template_hi, template_lo, NULL};        const char *name, *name2, *name3, *overridden, *override, *masked, *mask;        log_info("/* %s (%s) */", __func__, gather_stdout ? "gathering stdout" : "asynchronous");        assert_se(mkdtemp(template_lo));        assert_se(mkdtemp(template_hi));        name = strjoina(template_lo, "/script");        name2 = strjoina(template_hi, "/script2");        name3 = strjoina(template_lo, "/useless");        overridden = strjoina(template_lo, "/overridden");        override = strjoina(template_hi, "/overridden");
开发者ID:GuillaumeSeren,项目名称:systemd,代码行数:16,


示例20: 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,


示例21: condition_test_needs_update

static int condition_test_needs_update(Condition *c) {        const char *p;        struct stat usr, other;        assert(c);        assert(c->parameter);        assert(c->type == CONDITION_NEEDS_UPDATE);        /* If the file system is read-only we shouldn't suggest an update */        if (path_is_read_only_fs(c->parameter) > 0)                return false;        /* Any other failure means we should allow the condition to be true,         * so that we rather invoke too many update tools then too         * few. */        if (!path_is_absolute(c->parameter))                return true;        p = strjoina(c->parameter, "/.updated");        if (lstat(p, &other) < 0)                return true;        if (lstat("/usr/", &usr) < 0)                return true;        return usr.st_mtim.tv_sec > other.st_mtim.tv_sec ||                (usr.st_mtim.tv_sec == other.st_mtim.tv_sec && usr.st_mtim.tv_nsec > other.st_mtim.tv_nsec);}
开发者ID:blaskovic,项目名称:systemd-rhel,代码行数:29,


示例22: raw_pull_copy_auxiliary_file

static int raw_pull_copy_auxiliary_file(                RawPull *i,                const char *suffix,                char **path) {        const char *local;        int r;        assert(i);        assert(suffix);        assert(path);        r = raw_pull_determine_path(i, suffix, path);        if (r < 0)                return r;        local = strjoina(i->image_root, "/", i->local, suffix);        r = copy_file_atomic(*path, local, 0644, 0, COPY_REFLINK | (i->force_local ? COPY_REPLACE : 0));        if (r == -EEXIST)                log_warning_errno(r, "File %s already exists, not replacing.", local);        else if (r == -ENOENT)                log_debug_errno(r, "Skipping creation of auxiliary file, since none was found.");        else if (r < 0)                log_warning_errno(r, "Failed to copy file %s, ignoring: %m", local);        else                log_info("Created new file %s.", local);        return 0;}
开发者ID:dankor,项目名称:systemd,代码行数:30,


示例23: dkr_pull_pull_layer

static int dkr_pull_pull_layer(DkrPull *i) {        _cleanup_free_ char *path = NULL;        const char *url, *layer = NULL;        int r;        assert(i);        assert(!i->layer_job);        assert(!i->temp_path);        assert(!i->final_path);        for (;;) {                layer = dkr_pull_current_layer(i);                if (!layer)                        return 0; /* no more layers */                path = strjoin(i->image_root, "/.dkr-", layer, NULL);                if (!path)                        return log_oom();                if (laccess(path, F_OK) < 0) {                        if (errno == ENOENT)                                break;                        return log_error_errno(errno, "Failed to check for container: %m");                }                log_info("Layer %s already exists, skipping.", layer);                i->current_ancestry++;                free(path);                path = NULL;        }        log_info("Pulling layer %s...", layer);        i->final_path = path;        path = NULL;        url = strjoina(PROTOCOL_PREFIX, i->response_registries[0], "/v1/images/", layer, "/layer");        r = pull_job_new(&i->layer_job, url, i->glue, i);        if (r < 0)                return log_error_errno(r, "Failed to allocate layer job: %m");        r = dkr_pull_add_token(i, i->layer_job);        if (r < 0)                return log_oom();        i->layer_job->on_finished = dkr_pull_job_on_finished;        i->layer_job->on_open_disk = dkr_pull_job_on_open_disk;        i->layer_job->on_progress = dkr_pull_job_on_progress;        i->layer_job->grow_machine_directory = i->grow_machine_directory;        r = pull_job_begin(i->layer_job);        if (r < 0)                return log_error_errno(r, "Failed to start layer job: %m");        return 0;}
开发者ID:shaded-enmity,项目名称:systemd,代码行数:59,


示例24: process_locale

static int process_locale(void) {        const char *etc_localeconf;        char* locales[3];        unsigned i = 0;        int r;        etc_localeconf = prefix_roota(arg_root, "/etc/locale.conf");        if (faccessat(AT_FDCWD, etc_localeconf, F_OK, AT_SYMLINK_NOFOLLOW) >= 0)                return 0;        if (arg_copy_locale && arg_root) {                mkdir_parents(etc_localeconf, 0755);                r = copy_file("/etc/locale.conf", etc_localeconf, 0, 0644, 0);                if (r != -ENOENT) {                        if (r < 0)                                return log_error_errno(r, "Failed to copy %s: %m", etc_localeconf);                        log_info("%s copied.", etc_localeconf);                        return 0;                }        }        r = prompt_locale();        if (r < 0)                return r;        if (!isempty(arg_locale))                locales[i++] = strjoina("LANG=", arg_locale);        if (!isempty(arg_locale_messages) && !streq(arg_locale_messages, arg_locale))                locales[i++] = strjoina("LC_MESSAGES=", arg_locale_messages);        if (i == 0)                return 0;        locales[i] = NULL;        mkdir_parents(etc_localeconf, 0755);        r = write_env_file(etc_localeconf, locales);        if (r < 0)                return log_error_errno(r, "Failed to write %s: %m", etc_localeconf);        log_info("%s written.", etc_localeconf);        return 0;}
开发者ID:eidoscode,项目名称:systemd,代码行数:45,


示例25: assert_return

idev_device *idev_find_keyboard(idev_session *s, const char *name) {        char *kname;        assert_return(s, NULL);        assert_return(name, NULL);        kname = strjoina("keyboard/", name);        return hashmap_get(s->device_map, kname);}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:9,


示例26: sysctl_read

int sysctl_read(const char *property, char **content) {        char *p;        assert(property);        assert(content);        p = strjoina("/proc/sys/", property);        return read_full_file(p, content, NULL);}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:9,


示例27: assert

static char *image_roothash_path(Image *image) {        const char *fn;        assert(image);        fn = strjoina(image->name, ".roothash");        return file_in_same_dir(image->path, fn);}
开发者ID:Keruspe,项目名称:systemd,代码行数:9,


示例28: STRV_FOREACH

        STRV_FOREACH(p, files) {                _cleanup_free_ char *buf = NULL;                size_t sz = 0;                char *f = strjoina(copy_dir, *p);                assert_se(access(f, F_OK) == 0);                assert_se(read_full_file(f, &buf, &sz) == 0);                assert_se(streq(buf, "file/n"));        }
开发者ID:iaguis,项目名称:systemd,代码行数:9,


示例29: add_usr_mount

static int add_usr_mount(void) {        _cleanup_free_ char *what = NULL;        const char *opts;        if (!arg_usr_what && !arg_usr_fstype && !arg_usr_options)                return 0;        if (arg_root_what && !arg_usr_what) {                arg_usr_what = strdup(arg_root_what);                if (!arg_usr_what)                        return log_oom();        }        if (arg_root_fstype && !arg_usr_fstype) {                arg_usr_fstype = strdup(arg_root_fstype);                if (!arg_usr_fstype)                        return log_oom();        }        if (arg_root_options && !arg_usr_options) {                arg_usr_options = strdup(arg_root_options);                if (!arg_usr_options)                        return log_oom();        }        if (!arg_usr_what)                return 0;        what = fstab_node_to_udev_node(arg_usr_what);        if (!path_is_absolute(what)) {                log_debug("Skipping entry what=%s where=/sysroot/usr type=%s", what, strna(arg_usr_fstype));                return -1;        }        if (!arg_usr_options)                opts = arg_root_rw > 0 ? "rw" : "ro";        else if (!fstab_test_option(arg_usr_options, "ro/0" "rw/0"))                opts = strjoina(arg_usr_options, ",", arg_root_rw > 0 ? "rw" : "ro");        else                opts = arg_usr_options;        log_debug("Found entry what=%s where=/sysroot/usr type=%s", what, strna(arg_usr_fstype));        return add_mount(what,                         "/sysroot/usr",                         arg_usr_fstype,                         opts,                         1,                         false,                         false,                         false,                         SPECIAL_INITRD_ROOT_FS_TARGET,                         "/proc/cmdline");}
开发者ID:RaghavanSanthanam,项目名称:systemd,代码行数:56,



注:本文中的strjoina函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ strlcat函数代码示例
C++ stripspace函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。