这篇教程C++ write_string_file函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中write_string_file函数的典型用法代码示例。如果您正苦于以下问题:C++ write_string_file函数的具体用法?C++ write_string_file怎么用?C++ write_string_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了write_string_file函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: test_add_dependencystatic 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: test_indirectstatic 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,
示例3: test_read_hostname_configstatic void test_read_hostname_config(void) { char path[] = "/tmp/hostname.XXXXXX"; char *hostname; int fd; fd = mkostemp_safe(path, O_RDWR|O_CLOEXEC); assert(fd > 0); close(fd); /* simple hostname */ write_string_file(path, "foo", WRITE_STRING_FILE_CREATE); assert_se(read_hostname_config(path, &hostname) == 0); assert_se(streq(hostname, "foo")); hostname = mfree(hostname); /* with comment */ write_string_file(path, "# comment/nfoo", WRITE_STRING_FILE_CREATE); assert_se(read_hostname_config(path, &hostname) == 0); assert_se(hostname); assert_se(streq(hostname, "foo")); hostname = mfree(hostname); /* with comment and extra whitespace */ write_string_file(path, "# comment/n/n foo ", WRITE_STRING_FILE_CREATE); assert_se(read_hostname_config(path, &hostname) == 0); assert_se(hostname); assert_se(streq(hostname, "foo")); hostname = mfree(hostname); /* cleans up name */ write_string_file(path, "!foo/bar.com", WRITE_STRING_FILE_CREATE); assert_se(read_hostname_config(path, &hostname) == 0); assert_se(hostname); assert_se(streq(hostname, "foobar.com")); hostname = mfree(hostname); /* no value set */ hostname = (char*) 0x1234; write_string_file(path, "# nothing here/n", WRITE_STRING_FILE_CREATE); assert_se(read_hostname_config(path, &hostname) == -ENOENT); assert_se(hostname == (char*) 0x1234); /* does not touch argument on error */ /* nonexisting file */ assert_se(read_hostname_config("/non/existing", &hostname) == -ENOENT); assert_se(hostname == (char*) 0x1234); /* does not touch argument on error */ unlink(path);}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:48,
示例4: process_machine_idstatic int process_machine_id(void) { const char *etc_machine_id; char id[SD_ID128_STRING_MAX]; int r; etc_machine_id = prefix_roota("/etc/machine-id"); if (faccessat(AT_FDCWD, etc_machine_id, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) return 0; if (!arg_root) return 0; if (sd_id128_equal(arg_machine_id, SD_ID128_NULL)) return 0; mkdir_parents(etc_machine_id, 0755); r = write_string_file(etc_machine_id, sd_id128_to_string(arg_machine_id, id)); if (r < 0) { log_error("Failed to write machine id: %s", strerror(-r)); return r; } log_info("%s written.", etc_machine_id); return 0;}
开发者ID:alan030189,项目名称:systemd,代码行数:25,
示例5: cgroup_attribute_applyint cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b) { _cleanup_free_ char *path = NULL, *v = NULL; int r; assert(a); b = cgroup_bonding_find_list(b, a->controller); if (!b) return 0; if (a->semantics && a->semantics->map_write) { r = a->semantics->map_write(a->semantics, a->value, &v); if (r < 0) return r; } r = cg_get_path(a->controller, b->path, a->name, &path); if (r < 0) return r; r = write_string_file(path, v ? v : a->value); if (r < 0) log_warning("Failed to write '%s' to %s: %s", v ? v : a->value, path, strerror(-r)); return r;}
开发者ID:kwirk,项目名称:systemd,代码行数:26,
示例6: test_copy_filestatic void test_copy_file(void) { _cleanup_free_ char *buf = NULL; char fn[] = "/tmp/test-copy_file.XXXXXX"; char fn_copy[] = "/tmp/test-copy_file.XXXXXX"; size_t sz = 0; int fd; fd = mkostemp_safe(fn, O_RDWR|O_CLOEXEC); assert_se(fd >= 0); close(fd); fd = mkostemp_safe(fn_copy, O_RDWR|O_CLOEXEC); assert_se(fd >= 0); close(fd); assert_se(write_string_file(fn, "foo bar bar bar foo") == 0); assert_se(copy_file(fn, fn_copy, 0, 0644) == 0); assert_se(read_full_file(fn_copy, &buf, &sz) == 0); assert_se(streq(buf, "foo bar bar bar foo/n")); assert_se(sz == 20); unlink(fn); unlink(fn_copy);}
开发者ID:faizalpribadi,项目名称:systemd,代码行数:26,
示例7: test_copy_file_fdstatic void test_copy_file_fd(void) { char in_fn[] = "/tmp/test-copy-file-fd-XXXXXX"; char out_fn[] = "/tmp/test-copy-file-fd-XXXXXX"; _cleanup_close_ int in_fd = -1, out_fd = -1; char text[] = "boohoo/nfoo/n/tbar/n"; char buf[64] = {0}; log_info("%s", __func__); in_fd = mkostemp_safe(in_fn); assert_se(in_fd >= 0); out_fd = mkostemp_safe(out_fn); assert_se(out_fd >= 0); assert_se(write_string_file(in_fn, text, WRITE_STRING_FILE_CREATE) == 0); assert_se(copy_file_fd("/a/file/which/does/not/exist/i/guess", out_fd, COPY_REFLINK) < 0); assert_se(copy_file_fd(in_fn, out_fd, COPY_REFLINK) >= 0); assert_se(lseek(out_fd, SEEK_SET, 0) == 0); assert_se(read(out_fd, buf, sizeof(buf)) == sizeof(text) - 1); assert_se(streq(buf, text)); unlink(in_fn); unlink(out_fn);}
开发者ID:iamyooon,项目名称:systemd,代码行数:25,
示例8: exec_liststatic int exec_list(sd_device_enumerator *e, const char *action, Set *settle_set) { sd_device *d; int r; FOREACH_DEVICE_AND_SUBSYSTEM(e, d) { _cleanup_free_ char *filename = NULL; const char *syspath; if (sd_device_get_syspath(d, &syspath) < 0) continue; if (arg_verbose) printf("%s/n", syspath); if (arg_dry_run) continue; filename = path_join(syspath, "uevent"); if (!filename) return log_oom(); r = write_string_file(filename, action, WRITE_STRING_FILE_DISABLE_BUFFER); if (r < 0) { log_debug_errno(r, "Failed to write '%s' to '%s', ignoring: %m", action, filename); continue; } if (settle_set) { r = set_put_strdup(settle_set, syspath); if (r < 0) return log_oom(); } }
开发者ID:Keruspe,项目名称:systemd,代码行数:32,
示例9: test_defaultstatic 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,
示例10: enable_utf8static int enable_utf8(int fd) { int r = 0, k; long current = 0; if (ioctl(fd, KDGKBMODE, ¤t) < 0 || current == K_XLATE) { /* * Change the current keyboard to unicode, unless it * is currently in raw or off mode anyway. We * shouldn't interfere with X11's processing of the * key events. * * http://lists.freedesktop.org/archives/systemd-devel/2013-February/008573.html * */ if (ioctl(fd, KDSKBMODE, K_UNICODE) < 0) r = -errno; } if (loop_write(fd, "/033%G", 3, false) < 0) r = -errno; k = write_string_file("/sys/module/vt/parameters/default_utf8", "1"); if (k < 0) r = k; if (r < 0) log_warning("Failed to enable UTF-8: %s", strerror(-r)); return r;}
开发者ID:Mathnerd314,项目名称:systemd,代码行数:31,
示例11: test_copy_filestatic void test_copy_file(void) { _cleanup_free_ char *buf = NULL; char fn[] = "/tmp/test-copy_file.XXXXXX"; char fn_copy[] = "/tmp/test-copy_file.XXXXXX"; size_t sz = 0; int fd; log_info("%s", __func__); fd = mkostemp_safe(fn); assert_se(fd >= 0); close(fd); fd = mkostemp_safe(fn_copy); assert_se(fd >= 0); close(fd); assert_se(write_string_file(fn, "foo bar bar bar foo", WRITE_STRING_FILE_CREATE) == 0); assert_se(copy_file(fn, fn_copy, 0, 0644, 0, COPY_REFLINK) == 0); assert_se(read_full_file(fn_copy, &buf, &sz) == 0); assert_se(streq(buf, "foo bar bar bar foo/n")); assert_se(sz == 20); unlink(fn); unlink(fn_copy);}
开发者ID:iamyooon,项目名称:systemd,代码行数:28,
示例12: process_hostnamestatic int process_hostname(void) { const char *etc_hostname; int r; etc_hostname = prefix_roota("/etc/hostname"); if (faccessat(AT_FDCWD, etc_hostname, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) return 0; r = prompt_hostname(); if (r < 0) return r; if (isempty(arg_hostname)) return 0; mkdir_parents(etc_hostname, 0755); r = write_string_file(etc_hostname, arg_hostname); if (r < 0) { log_error("Failed to write %s: %s", etc_hostname, strerror(-r)); return r; } log_info("%s written.", etc_hostname); return 0;}
开发者ID:alan030189,项目名称:systemd,代码行数:25,
示例13: block_bump_request_nrint block_bump_request_nr(const char *p) { struct stat st; uint64_t u; char *ap = NULL, *line = NULL; int r; dev_t d; assert(p); if (stat(p, &st) < 0) return -errno; if (major(st.st_dev) == 0) return 0; d = st.st_dev; block_get_whole_disk(d, &d); if (asprintf(&ap, "/sys/dev/block/%u:%u/queue/nr_requests", major(d), minor(d)) < 0) { r= -ENOMEM; goto finish; } r = read_one_line_file(ap, &line); if (r < 0) { if (r == -ENOENT) r = 0; goto finish; } r = safe_atou64(line, &u); if (r >= 0 && u >= BUMP_REQUEST_NR) { r = 0; goto finish; } free(line); line = NULL; if (asprintf(&line, "%lu", (unsigned long) BUMP_REQUEST_NR) < 0) { r = -ENOMEM; goto finish; } r = write_string_file(ap, line); if (r < 0) goto finish; log_info("Bumped block_nr parameter of %u:%u to %lu. This is a temporary hack and should be removed one day.", major(d), minor(d), (unsigned long) BUMP_REQUEST_NR); r = 1;finish: free(ap); free(line); return r;}
开发者ID:dds,项目名称:systemd,代码行数:57,
示例14: sysctl_writeint sysctl_write(const char *property, const char *value) { char *p; assert(property); assert(value); log_debug("Setting '%s' to '%s'", property, value); p = strjoina("/proc/sys/", property); return write_string_file(p, value, 0);}
开发者ID:BenjaminLefoul,项目名称:systemd,代码行数:11,
示例15: mainint main(int argc, char *argv[]) { struct stat st; const char *device; _cleanup_free_ char *major_minor = NULL; int r; if (argc != 2) { log_error("This program expects one argument."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); /* Refuse to run unless we are in an initrd() */ if (!in_initrd()) return EXIT_SUCCESS; device = argv[1]; if (stat(device, &st) < 0) { log_error_errno(errno, "Failed to stat '%s': %m", device); return EXIT_FAILURE; } if (!S_ISBLK(st.st_mode)) { log_error("Resume device '%s' is not a block device.", device); return EXIT_FAILURE; } if (asprintf(&major_minor, "%d:%d", major(st.st_rdev), minor(st.st_rdev)) < 0) { log_oom(); return EXIT_FAILURE; } r = write_string_file("/sys/power/resume", major_minor, WRITE_STRING_FILE_CREATE); if (r < 0) { log_error_errno(r, "Failed to write '%s' to /sys/power/resume: %m", major_minor); return EXIT_FAILURE; } /* * The write above shall not return. * * However, failed resume is a normal condition (may mean that there is * no hibernation image). */ log_info("Could not resume from '%s' (%s).", device, major_minor); return EXIT_SUCCESS;}
开发者ID:AOSC-Dev,项目名称:systemd,代码行数:54,
示例16: sysctl_writeint sysctl_write(const char *property, const char *value) { char *p; assert(property); assert(value); log_debug("Setting '%s' to '%s'", property, value); p = strjoina("/proc/sys/", property); return write_string_file(p, value, WRITE_STRING_FILE_DISABLE_BUFFER);}
开发者ID:heftig,项目名称:systemd,代码行数:11,
示例17: apply_rulestatic int apply_rule(const char *rule) { int r; delete_rule(rule); r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule, 0); if (r < 0) return log_error_errno(r, "Failed to add binary format: %m"); return 0;}
开发者ID:rowhit,项目名称:systemd,代码行数:11,
示例18: sync_cgroupint sync_cgroup(pid_t pid, CGroupUnified unified_requested) { _cleanup_free_ char *cgroup = NULL; char tree[] = "/tmp/unifiedXXXXXX", pid_string[DECIMAL_STR_MAX(pid) + 1]; bool undo_mount = false; const char *fn; int unified, r; unified = cg_unified(SYSTEMD_CGROUP_CONTROLLER); if (unified < 0) return log_error_errno(unified, "Failed to determine whether the unified hierarchy is used: %m"); if ((unified > 0) == (unified_requested >= CGROUP_UNIFIED_SYSTEMD)) return 0; /* When the host uses the legacy cgroup setup, but the * container shall use the unified hierarchy, let's make sure * we copy the path from the name=systemd hierarchy into the * unified hierarchy. Similar for the reverse situation. */ r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cgroup); if (r < 0) return log_error_errno(r, "Failed to get control group of " PID_FMT ": %m", pid); /* In order to access the unified hierarchy we need to mount it */ if (!mkdtemp(tree)) return log_error_errno(errno, "Failed to generate temporary mount point for unified hierarchy: %m"); if (unified) r = mount("cgroup", tree, "cgroup", MS_NOSUID|MS_NOEXEC|MS_NODEV, "none,name=systemd,xattr"); else r = mount("cgroup", tree, "cgroup2", MS_NOSUID|MS_NOEXEC|MS_NODEV, NULL); if (r < 0) { r = log_error_errno(errno, "Failed to mount unified hierarchy: %m"); goto finish; } undo_mount = true; fn = strjoina(tree, cgroup, "/cgroup.procs"); (void) mkdir_parents(fn, 0755); sprintf(pid_string, PID_FMT, pid); r = write_string_file(fn, pid_string, 0); if (r < 0) log_error_errno(r, "Failed to move process: %m");finish: if (undo_mount) (void) umount(tree); (void) rmdir(tree); return r;}
开发者ID:bkylerussell,项目名称:systemd,代码行数:53,
示例19: mainint main(int argc, char*argv[]) { if (argc != 2) { log_error("This program requires one argument."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); if (streq(argv[1], "start")) { int r = 0; if (unlink("/run/nologin") < 0 && errno != ENOENT) { log_error_errno(errno, "Failed to remove /run/nologin file: %m"); r = -errno; } if (unlink("/etc/nologin") < 0 && errno != ENOENT) { /* If the file doesn't exist and /etc simply * was read-only (in which case unlink() * returns EROFS even if the file doesn't * exist), don't complain */ if (errno != EROFS || access("/etc/nologin", F_OK) >= 0) { log_error_errno(errno, "Failed to remove /etc/nologin file: %m"); return EXIT_FAILURE; } } if (r < 0) return EXIT_FAILURE; } else if (streq(argv[1], "stop")) { int r; r = write_string_file("/run/nologin", "System is going down.", WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC); if (r < 0) { log_error_errno(r, "Failed to create /run/nologin: %m"); return EXIT_FAILURE; } } else { log_error("Unknown verb %s.", argv[1]); return EXIT_FAILURE; } return EXIT_SUCCESS;}
开发者ID:abbradar,项目名称:systemd,代码行数:52,
示例20: write_string_file_atomic_labelint write_string_file_atomic_label(const char *fn, const char *line) { int r; r = mac_selinux_create_file_prepare(fn, S_IFREG); if (r < 0) return r; r = write_string_file(fn, line, WRITE_STRING_FILE_CREATE|WRITE_STRING_FILE_ATOMIC); mac_selinux_create_file_clear(); return r;}
开发者ID:rhvgoyal,项目名称:systemd,代码行数:13,
示例21: apply_rulestatic int apply_rule(const char *rule) { int r; delete_rule(rule); r = write_string_file("/proc/sys/fs/binfmt_misc/register", rule); if (r < 0) { log_error("Failed to add binary format: %s", strerror(-r)); return r; } return 0;}
开发者ID:Mathnerd314,项目名称:systemd,代码行数:13,
示例22: mainint main(int argc, char *argv[]) { int r, k; r = parse_argv(argc, argv); if (r <= 0) return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = 0; if (argc > optind) { int i; for (i = optind; i < argc; i++) { k = apply_file(argv[i], false); if (k < 0 && r == 0) r = k; } } else { _cleanup_strv_free_ char **files = NULL; char **f; r = conf_files_list_strv(&files, ".conf", NULL, 0, (const char**) CONF_PATHS_STRV("binfmt.d")); if (r < 0) { log_error_errno(r, "Failed to enumerate binfmt.d files: %m"); goto finish; } if (arg_cat_config) { (void) pager_open(arg_no_pager, false); r = cat_files(NULL, files, 0); goto finish; } /* Flush out all rules */ write_string_file("/proc/sys/fs/binfmt_misc/status", "-1", 0); STRV_FOREACH(f, files) { k = apply_file(*f, true); if (k < 0 && r == 0) r = k; } }
开发者ID:Hariprasathganesh,项目名称:testsysd,代码行数:49,
示例23: sysctl_write_ip_propertyint sysctl_write_ip_property(int af, const char *ifname, const char *property, const char *value) { const char *p; assert(IN_SET(af, AF_INET, AF_INET6)); assert(property); assert(value); p = strjoina("/proc/sys/net/ipv", af == AF_INET ? "4" : "6", ifname ? "/conf/" : "", strempty(ifname), property[0] == '/' ? "" : "/", property); log_debug("Setting '%s' to '%s'", p, value); return write_string_file(p, value, WRITE_STRING_FILE_VERIFY_ON_FAILURE | WRITE_STRING_FILE_DISABLE_BUFFER);}
开发者ID:clemensg,项目名称:systemd,代码行数:15,
示例24: mac_smack_apply_pidint mac_smack_apply_pid(pid_t pid, const char *label) { const char *p; int r = 0; assert(label); if (!mac_smack_use()) return 0; p = procfs_file_alloca(pid, "attr/current"); r = write_string_file(p, label, 0); if (r < 0) return r; return r;}
开发者ID:lnykryn,项目名称:systemd,代码行数:16,
示例25: write_modestatic int write_mode(char **modes) { int r = 0; char **mode; STRV_FOREACH(mode, modes) { int k; k = write_string_file("/sys/power/disk", *mode, 0); if (k == 0) return 0; log_debug_errno(k, "Failed to write '%s' to /sys/power/disk: %m", *mode); if (r == 0) r = k; }
开发者ID:GuillaumeSeren,项目名称:systemd,代码行数:16,
示例26: copy_dirvoid copy_dir (disk_t disk, superblock sb, char *filename) { // Open file for reading FILE *infile = fopen(filename, "r"); if (infile == NULL) { fprintf(stderr, "%s: bad filename./n", filename); } // Determine size of file // add move pointer to beginning of file fseek(infile, 0, SEEK_END); long f_size = ftell(infile); fseek(infile, 0, SEEK_SET); // Copy contents to buffer and write to disk char *data = malloc(f_size); fread(data, 1, f_size, infile); write_string_file(disk, sb, filename, data);}
开发者ID:gwhere,项目名称:fileproj,代码行数:16,
示例27: test_copy_treestatic void test_copy_tree(void) { char original_dir[] = "/tmp/test-copy_tree/"; char copy_dir[] = "/tmp/test-copy_tree-copy/"; char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file"); char **links = STRV_MAKE("link", "file", "link2", "dir1/file"); char **p, **link; (void) rm_rf(copy_dir, REMOVE_ROOT|REMOVE_PHYSICAL); (void) rm_rf(original_dir, REMOVE_ROOT|REMOVE_PHYSICAL); STRV_FOREACH(p, files) { char *f = strjoina(original_dir, *p); assert_se(mkdir_parents(f, 0755) >= 0); assert_se(write_string_file(f, "file") == 0); }
开发者ID:iaguis,项目名称:systemd,代码行数:17,
示例28: test_copy_treestatic void test_copy_tree(void) { char original_dir[] = "/tmp/test-copy_tree/"; char copy_dir[] = "/tmp/test-copy_tree-copy/"; char **files = STRV_MAKE("file", "dir1/file", "dir1/dir2/file", "dir1/dir2/dir3/dir4/dir5/file"); char **links = STRV_MAKE("link", "file", "link2", "dir1/file"); char **p, **link; rm_rf_dangerous(copy_dir, false, true, false); rm_rf_dangerous(original_dir, false, true, false); STRV_FOREACH(p, files) { char *f = strappenda(original_dir, *p); assert_se(mkdir_parents(f, 0755) >= 0); assert_se(write_string_file(f, "file") == 0); }
开发者ID:faizalpribadi,项目名称:systemd,代码行数:17,
示例29: setup_test_dirstatic void setup_test_dir(char *tmp_dir, const char *files, ...) { va_list ap; assert_se(mkdtemp(tmp_dir)); va_start(ap, files); while (files) { _cleanup_free_ char *path; assert_se(path = strappend(tmp_dir, files)); (void) mkdir_parents(path, 0755); assert_se(write_string_file(path, "foobar", WRITE_STRING_FILE_CREATE) >= 0); files = va_arg(ap, const char *); } va_end(ap);}
开发者ID:Keruspe,项目名称:systemd,代码行数:17,
示例30: disable_utf8static int disable_utf8(int fd) { int r = 0, k; if (ioctl(fd, KDSKBMODE, K_XLATE) < 0) r = -errno; if (loop_write(fd, "/033%@", 3, false) < 0) r = -errno; k = write_string_file("/sys/module/vt/parameters/default_utf8", "0"); if (k < 0) r = k; if (r < 0) log_warning("Failed to disable UTF-8: %s", strerror(-r)); return r;}
开发者ID:Mathnerd314,项目名称:systemd,代码行数:18,
注:本文中的write_string_file函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ write_stringz函数代码示例 C++ write_string函数代码示例 |