int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); saved_argc = argc; saved_argv = argv; if (argc > 1) { pid_t pid = 0; (void) parse_pid(argv[1], &pid); test_get_process_comm(pid); } else { TEST_REQ_RUNNING_SYSTEMD(test_get_process_comm(1)); test_get_process_comm(getpid()); } test_pid_is_unwaited(); test_pid_is_alive(); test_personality(); test_get_process_cmdline_harder(); test_rename_process(); test_getpid_cached(); test_getpid_measure(); test_safe_fork(); test_pid_to_ptr(); test_ioprio_class_from_to_string(); return 0; }
int main(int argc, char *argv[]) { bool enabled; int r; r = parse_argv(argc, argv); if (r <= 0) goto finish; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = proc_cmdline_get_bool("systemd.firstboot", &enabled); if (r < 0) { log_error_errno(r, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m"); goto finish; } if (r > 0 && !enabled) { r = 0; /* disabled */ goto finish; } r = process_locale(); if (r < 0) goto finish; r = process_keymap(); if (r < 0) goto finish; r = process_timezone(); if (r < 0) goto finish; r = process_hostname(); if (r < 0) goto finish; r = process_machine_id(); if (r < 0) goto finish; r = process_root_password(); if (r < 0) goto finish; finish: free(arg_root); free(arg_locale); free(arg_locale_messages); free(arg_keymap); free(arg_timezone); free(arg_hostname); string_erase(arg_root_password); free(arg_root_password); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { struct stat st; int r, q = 0; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); if (stat("/usr", &st) < 0) { log_error_errno(errno, "Failed to stat /usr: %m"); return EXIT_FAILURE; } r = mac_selinux_init(); if (r < 0) { log_error_errno(r, "SELinux setup failed: %m"); goto finish; } r = apply_timestamp("/etc/.updated", &st.st_mtim); q = apply_timestamp("/var/.updated", &st.st_mtim); finish: return r < 0 || q < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_strv_free_erase_ char **l = NULL; usec_t timeout; char **p; int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; if (arg_timeout > 0) timeout = now(CLOCK_MONOTONIC) + arg_timeout; else timeout = 0; r = ask_password_auto(arg_message, arg_icon, arg_id, arg_keyname, timeout, arg_flags, &l); if (r < 0) { log_error_errno(r, "Failed to query password: %m"); goto finish; } STRV_FOREACH(p, l) { puts(*p); if (!arg_multiple) break; }
int main(int argc, char* argv[]) { Hashmap *h; UnitFileList *p; Iterator i; int r; const char *const files[] = { "avahi-daemon.service", NULL }; const char *const files2[] = { "/home/lennart/test.service", NULL }; UnitFileChange *changes = NULL; unsigned n_changes = 0; UnitFileState state = 0; log_set_max_level(LOG_DEBUG); log_parse_environment(); h = hashmap_new(&string_hash_ops); r = unit_file_get_list(UNIT_FILE_SYSTEM, NULL, h, NULL, NULL); assert_se(r == 0); HASHMAP_FOREACH(p, h, i) { UnitFileState s = _UNIT_FILE_STATE_INVALID; r = unit_file_get_state(UNIT_FILE_SYSTEM, NULL, basename(p->path), &s); assert_se((r < 0 && p->state == UNIT_FILE_BAD) || (p->state == s)); fprintf(stderr, "%s (%s)\n", p->path, unit_file_state_to_string(p->state)); }
int main(int argc, char *argv[]) { _cleanup_(evcat_freep) Evcat *e = NULL; int r; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); setlocale(LC_ALL, ""); if (!is_locale_utf8()) log_warning("Locale is not set to UTF-8. Codepoints will not be printed!"); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = evcat_new(&e); if (r < 0) goto finish; r = evcat_run(e); finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int r; bool run_ambient; log_parse_environment(); log_open(); if (getuid() != 0) return EXIT_TEST_SKIP; r = setup_tests(&run_ambient); if (r < 0) return -r; show_capabilities(); test_drop_privileges(); test_update_inherited_set(); fork_test(test_have_effective_cap); if (run_ambient) fork_test(test_set_ambient_caps); return 0; }
int main(int argc, char *argv[]) { static const char* const sulogin_cmdline[] = {SULOGIN, NULL}; _cleanup_(sd_bus_flush_close_unrefp) sd_bus *bus = NULL; int r; log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); print_mode(argc > 1 ? argv[1] : ""); (void) fork_wait(sulogin_cmdline); r = bus_connect_system_systemd(&bus); if (r < 0) { log_warning_errno(r, "Failed to get D-Bus connection: %m"); r = 0; } else { (void) reload_manager(bus); r = start_default_target(bus); } return r >= 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int main(int argc, char *argv[]) { uid_t shift, range; int r; log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); if (argc != 4) { log_error("Expected PATH SHIFT RANGE parameters."); return EXIT_FAILURE; } r = parse_uid(argv[2], &shift); if (r < 0) { log_error_errno(r, "Failed to parse UID shift %s.", argv[2]); return EXIT_FAILURE; } r = parse_gid(argv[3], &range); if (r < 0) { log_error_errno(r, "Failed to parse UID range %s.", argv[3]); return EXIT_FAILURE; } r = path_patch_uid(argv[1], shift, range); if (r < 0) { log_error_errno(r, "Failed to patch directory tree: %m"); return EXIT_FAILURE; } log_info("Changed: %s", yes_no(r)); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { usec_t t; unsigned i, count; int r; bool slow; log_set_max_level(LOG_DEBUG); log_parse_environment(); r = getenv_bool("SYSTEMD_SLOW_TESTS"); slow = r >= 0 ? r : SYSTEMD_SLOW_TESTS_DEFAULT; t = slow ? 10 * USEC_PER_SEC : 1 * USEC_PER_SEC; count = slow ? 5 : 3; r = watchdog_set_timeout(&t); if (r < 0) log_warning_errno(r, "Failed to open watchdog: %m"); if (r == -EPERM) t = 0; for (i = 0; i < count; i++) { log_info("Pinging..."); r = watchdog_ping(); if (r < 0) log_warning_errno(r, "Failed to ping watchdog: %m"); usleep(t/2); } watchdog_close(true); return 0; }
int main(void) { log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); test_path_decode_unit(); test_path_get_unit(); test_path_get_user_unit(); test_path_get_session(); test_path_get_owner_uid(); test_path_get_slice(); test_path_get_user_slice(); TEST_REQ_RUNNING_SYSTEMD(test_get_paths()); test_proc(); TEST_REQ_RUNNING_SYSTEMD(test_escape()); test_controller_is_valid(); test_slice_to_path(); test_shift_path(); TEST_REQ_RUNNING_SYSTEMD(test_mask_supported()); TEST_REQ_RUNNING_SYSTEMD(test_is_cgroup_fs()); TEST_REQ_RUNNING_SYSTEMD(test_fd_is_cgroup_fs()); test_is_wanted_print(true); test_is_wanted_print(false); /* run twice to test caching */ test_is_wanted(); return 0; }
int main(int argc, char *argv[]) { int r, k; if (argc > 1 && argc != 4) { log_error("This program takes three or no arguments."); return EXIT_FAILURE; } if (argc > 1) arg_dest = argv[2]; log_set_target(LOG_TARGET_SAFE); log_parse_environment(); log_open(); umask(0022); r = generate_symlink(); if (r > 0) { k = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0); if (k < 0) log_warning_errno(k, "Failed to parse kernel command line, ignoring: %m"); } return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { struct udev *udev; static const struct option options[] = { { "debug", no_argument, NULL, 'd' }, { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'V' }, {} }; const char *command; unsigned int i; int rc = 1, c; udev = udev_new(); if (udev == NULL) goto out; log_parse_environment(); log_open(); mac_selinux_init("/dev"); while ((c = getopt_long(argc, argv, "+dhV", options, NULL)) >= 0) switch (c) { case 'd': log_set_max_level(LOG_DEBUG); break; case 'h': rc = adm_help(udev, argc, argv); goto out; case 'V': rc = adm_version(udev, argc, argv); goto out; default: goto out; } command = argv[optind]; if (command != NULL) for (i = 0; i < ELEMENTSOF(udevadm_cmds); i++) if (streq(udevadm_cmds[i]->name, command)) { argc -= optind; argv += optind; /* we need '0' here to reset the internal state */ optind = 0; rc = run_command(udev, udevadm_cmds[i], argc, argv); goto out; } fprintf(stderr, "%s: missing or unknown command\n", program_invocation_short_name); rc = 2; out: mac_selinux_finish(); udev_unref(udev); log_close(); return rc; }
int main(int argc, char **argv) { int i, N; _cleanup_globfree_ glob_t g = {}; _cleanup_strv_free_ char **globs = NULL; char **fnames; log_parse_environment(); if (argc >= 2) { N = argc - 1; fnames = argv + 1; } else { assert_se(glob(RESOLVE_TEST_DIR "/*.pkts", GLOB_NOSORT, NULL, &g) == 0); N = g.gl_pathc; fnames = g.gl_pathv; } for (i = 0; i < N; i++) { test_packet_from_file(fnames[i], false); puts(""); test_packet_from_file(fnames[i], true); if (i + 1 < N) puts(""); } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { log_set_max_level(LOG_DEBUG); log_parse_environment(); log_open(); test_dns_label_unescape(); test_dns_label_unescape_suffix(); test_dns_label_escape(); test_dns_name_normalize(); test_dns_name_equal(); test_dns_name_endswith(); test_dns_name_startswith(); test_dns_name_between(); test_dns_name_is_root(); test_dns_name_is_single_label(); test_dns_name_reverse(); test_dns_name_concat(); test_dns_name_is_valid(); test_dns_name_to_wire_format(); test_dns_service_name_is_valid(); test_dns_srv_type_is_valid(); test_dnssd_srv_type_is_valid(); test_dns_service_join(); test_dns_service_split(); test_dns_name_change_suffix(); test_dns_name_suffix(); test_dns_name_count_labels(); test_dns_name_equal_skip(); test_dns_name_compare_func(); test_dns_name_common_suffix(); test_dns_name_apply_idna(); test_dns_name_is_valid_or_address(); return 0; }
int main(int argc, char *argv[]) { _cleanup_free_ char *text = NULL; int r; setlocale(LC_ALL, "de_DE.UTF-8"); log_parse_environment(); log_open(); test_catalog_file_lang(); test_catalog_importing(); test_catalog_update(); r = catalog_list(stdout, database, true); assert_se(r >= 0); r = catalog_list(stdout, database, false); assert_se(r >= 0); assert_se(catalog_get(database, SD_MESSAGE_COREDUMP, &text) >= 0); printf(">>>%s<<<\n", text); if (database) unlink(database); return 0; }
int main(int argc, char*argv[]) { _cleanup_bus_unref_ sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = bus_open_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error("Failed to create bus connection: %s", strerror(-r)); goto finish; } r = localectl_main(bus, argc, argv); finish: pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { _cleanup_(proxy_freep) Proxy *p = NULL; int r; log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = proxy_new(&p, STDIN_FILENO, STDOUT_FILENO, arg_address); if (r < 0) goto finish; r = rename_service(p->destination_bus, p->local_bus); if (r < 0) log_debug_errno(r, "Failed to rename process: %m"); r = proxy_run(p); finish: sd_notify(false, "STOPPING=1\n" "STATUS=Shutting down."); free(arg_address); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { 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 (parse_proc_cmdline() < 0) return EXIT_FAILURE; if (!arg_enabled) return EXIT_SUCCESS; r = parse_fstab(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { sd_bus *bus = NULL; int r; setlocale(LC_ALL, ""); log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = bus_connect_transport(arg_transport, arg_host, false, &bus); if (r < 0) { log_error_errno(r, "Failed to create bus connection: %m"); goto finish; } r = timedatectl_main(bus, argc, argv); finish: /* make sure we terminate the bus connection first, and then close the * pager, see issue #3543 for the details. */ sd_bus_flush_close_unref(bus); pager_close(); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
static int run(int argc, char *argv[]) { _cleanup_close_ int fd = -1, saved_stderr = -1; int r; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) return r; fd = sd_journal_stream_fd(arg_identifier, arg_priority, arg_level_prefix); if (fd < 0) return log_error_errno(fd, "Failed to create stream fd: %m"); saved_stderr = fcntl(STDERR_FILENO, F_DUPFD_CLOEXEC, 3); r = rearrange_stdio(STDIN_FILENO, fd, fd); /* Invalidates fd on succcess + error! */ TAKE_FD(fd); if (r < 0) return log_error_errno(r, "Failed to rearrange stdout/stderr: %m"); if (argc <= optind) (void) execl("/bin/cat", "/bin/cat", NULL); else (void) execvp(argv[optind], argv + optind); r = -errno; /* Let's try to restore a working stderr, so we can print the error message */ if (saved_stderr >= 0) (void) dup3(saved_stderr, STDERR_FILENO, 0); return log_error_errno(r, "Failed to execute process: %m"); }
int main(int argc, char *argv[]) { int r = EXIT_SUCCESS; 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 (access(RC_LOCAL_SCRIPT_PATH_START, X_OK) >= 0) { log_debug("Automatically adding rc-local.service."); if (add_symlink("rc-local.service", "multi-user.target") < 0) r = EXIT_FAILURE; } if (access(RC_LOCAL_SCRIPT_PATH_STOP, X_OK) >= 0) { log_debug("Automatically adding halt-local.service."); if (add_symlink("halt-local.service", "final.target") < 0) r = EXIT_FAILURE; } return r; }
int main(int argc, char *argv[]) { int r = 0; 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); /* Don't even consider resuming outside of initramfs. */ if (!in_initrd()) return EXIT_SUCCESS; r = parse_proc_cmdline(parse_proc_cmdline_item, NULL, false); if (r < 0) log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); r = process_resume(); free(arg_resume_dev); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int r = 0; 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); r = parse_proc_cmdline(parse_proc_cmdline_item); if (r < 0) log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); /* Always honour root= and usr= in the kernel command line if we are in an initrd */ if (in_initrd()) { r = add_root_mount(); if (r == 0) r = add_usr_mount(); } /* Honour /etc/fstab only when that's enabled */ if (arg_fstab_enabled) { int k; log_debug("Parsing /etc/fstab"); /* Parse the local /etc/fstab, possibly from the initrd */ k = parse_fstab(false); if (k < 0) r = k; /* If running in the initrd also parse the /etc/fstab from the host */ if (in_initrd()) { log_debug("Parsing /sysroot/etc/fstab"); k = parse_fstab(true); if (k < 0) r = k; } } free(arg_root_what); free(arg_root_fstype); free(arg_root_options); free(arg_usr_what); free(arg_usr_fstype); free(arg_usr_options); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { Context context = {}; int r, n, fd; log_parse_environment(); log_open(); r = parse_argv(argc, argv); if (r <= 0) goto finish; r = sd_event_default(&context.event); if (r < 0) { log_error_errno(r, "Failed to allocate event loop: %m"); goto finish; } r = sd_resolve_default(&context.resolve); if (r < 0) { log_error_errno(r, "Failed to allocate resolver: %m"); goto finish; } r = sd_resolve_attach_event(context.resolve, context.event, 0); if (r < 0) { log_error_errno(r, "Failed to attach resolver: %m"); goto finish; } sd_event_set_watchdog(context.event, true); n = sd_listen_fds(1); if (n < 0) { log_error("Failed to receive sockets from parent."); r = n; goto finish; } else if (n == 0) { log_error("Didn't get any sockets passed in."); r = -EINVAL; goto finish; } for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) { r = add_listen_socket(&context, fd); if (r < 0) goto finish; } r = sd_event_loop(context.event); if (r < 0) { log_error_errno(r, "Failed to run event loop: %m"); goto finish; } finish: context_free(&context); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char* argv[]) { log_parse_environment(); log_open(); test_login(); return 0; }
int main(int argc, char* argv[]) { log_parse_environment(); log_open(); test_session_id_valid(); return 0; }
int main(int argc, char *argv[]) { test_function_t user_tests[] = { test_exec_workingdirectory, test_exec_personality, test_exec_ignoresigpipe, test_exec_privatetmp, test_exec_privatedevices, test_exec_privatenetwork, test_exec_systemcallfilter, test_exec_systemcallerrornumber, test_exec_user, test_exec_group, test_exec_environment, test_exec_environmentfile, test_exec_passenvironment, test_exec_umask, test_exec_runtimedirectory, test_exec_capabilityboundingset, test_exec_capabilityambientset, test_exec_oomscoreadjust, test_exec_ioschedulingclass, test_exec_spec_interpolation, NULL, }; test_function_t system_tests[] = { test_exec_systemcall_system_mode_with_user, NULL, }; int r; log_parse_environment(); log_open(); /* It is needed otherwise cgroup creation fails */ if (getuid() != 0) { printf("Skipping test: not root\n"); return EXIT_TEST_SKIP; } assert_se(setenv("XDG_RUNTIME_DIR", "/tmp/", 1) == 0); assert_se(set_unit_path(TEST_DIR "/test-execute/") >= 0); /* Unset VAR1, VAR2 and VAR3 which are used in the PassEnvironment test * cases, otherwise (and if they are present in the environment), * `manager_default_environment` will copy them into the default * environment which is passed to each created job, which will make the * tests that expect those not to be present to fail. */ assert_se(unsetenv("VAR1") == 0); assert_se(unsetenv("VAR2") == 0); assert_se(unsetenv("VAR3") == 0); r = run_tests(UNIT_FILE_USER, user_tests); if (r != 0) return r; return run_tests(UNIT_FILE_SYSTEM, system_tests); }
int main(int argc, char *argv[]) { static const char * const cmdline[] = { QUOTACHECK, "-anug", NULL }; pid_t pid; int r; if (argc > 1) { log_error("This program takes no arguments."); return EXIT_FAILURE; } log_set_target(LOG_TARGET_AUTO); log_parse_environment(); log_open(); umask(0022); r = proc_cmdline_parse(parse_proc_cmdline_item, NULL, 0); if (r < 0) log_warning_errno(r, "Failed to parse kernel command line, ignoring: %m"); test_files(); if (!arg_force) { if (arg_skip) return EXIT_SUCCESS; if (access("/run/systemd/quotacheck", F_OK) < 0) return EXIT_SUCCESS; } pid = fork(); if (pid < 0) { r = log_error_errno(errno, "fork(): %m"); goto finish; } if (pid == 0) { /* Child */ (void) reset_all_signal_handlers(); (void) reset_signal_mask(); assert_se(prctl(PR_SET_PDEATHSIG, SIGTERM) == 0); execv(cmdline[0], (char**) cmdline); _exit(1); /* Operational error */ } r = wait_for_terminate_and_warn("quotacheck", pid, true); finish: return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }
int main(int argc, char *argv[]) { int r, accept_fd; uid_t uid, bus_uid; gid_t gid; log_set_target(LOG_TARGET_JOURNAL_OR_KMSG); log_parse_environment(); log_open(); bus_uid = getuid(); if (geteuid() == 0) { const char *user = "******"; r = get_user_creds(&user, &uid, &gid, NULL, NULL); if (r < 0) { log_error_errno(r, "Cannot resolve user name %s: %m", user); goto finish; } r = drop_privileges(uid, gid, 1ULL << CAP_IPC_OWNER); if (r < 0) { log_error_errno(r, "Cannot drop privileges: %m"); goto finish; } } r = parse_argv(argc, argv); if (r <= 0) goto finish; r = sd_listen_fds(0); if (r != 1) { log_error("Illegal number of file descriptors passed"); goto finish; } accept_fd = SD_LISTEN_FDS_START; r = fd_nonblock(accept_fd, false); if (r < 0) { log_error_errno(r, "Cannot mark accept-fd non-blocking: %m"); goto finish; } r = loop_clients(accept_fd, bus_uid); finish: sd_notify(false, "STOPPING=1\n" "STATUS=Shutting down."); strv_free(arg_configuration); free(arg_address); return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; }