Esempio n. 1
0
/* If a pidfile has been configured, creates it and stores the running
 * process's pid in it.  Ensures that the pidfile will be deleted when the
 * process exits. */
static void
make_pidfile(void)
{
    int error;

    error = GetFileAttributes(pidfile);
    if (error != INVALID_FILE_ATTRIBUTES) {
        /* pidfile exists. Try to unlink() it. */
        error = unlink(pidfile);
        if (error) {
            VLOG_FATAL("Failed to delete existing pidfile %s (%s)", pidfile,
                       ovs_strerror(errno));
        }
    }

    filep_pidfile = fopen(pidfile, "w");
    if (filep_pidfile == NULL) {
        VLOG_FATAL("failed to open %s (%s)", pidfile, ovs_strerror(errno));
    }

    fatal_signal_add_hook(unlink_pidfile, NULL, NULL, true);

    fprintf(filep_pidfile, "%d\n", _getpid());
    if (fflush(filep_pidfile) == EOF) {
        VLOG_FATAL("Failed to write into the pidfile %s", pidfile);
    }

    /* Don't close the pidfile till the process exits. */
}
Esempio n. 2
0
/* Registers 'file' to be unlinked when the program terminates via exit() or a
 * fatal signal. */
void
fatal_signal_add_file_to_unlink(const char *file)
{
    static bool added_hook = false;
    if (!added_hook) {
        added_hook = true;
        fatal_signal_add_hook(unlink_files, NULL, true);
        fatal_signal_add_hook(destroy_pipeline, NULL, true);
    }

    fatal_signal_block();
    if (n_files >= max_files) {
        files = x2nrealloc(files, &max_files, sizeof *files);
    }
    files[n_files++] = xstrdup(file);
    fatal_signal_unblock();
}
Esempio n. 3
0
/* Registers 'file' to be unlinked when the program terminates via exit() or a
 * fatal signal. */
void
fatal_signal_add_file_to_unlink(const char *file)
{
    if (!added_hook) {
        added_hook = true;
        fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
    }

    sset_add(&files, file);
}
Esempio n. 4
0
/* Registers 'file' to be unlinked when the program terminates via exit() or a
 * fatal signal. */
void
fatal_signal_add_file_to_unlink(const char *file)
{
    fatal_signal_init();

    ovs_mutex_lock(&mutex);
    if (!added_hook) {
        added_hook = true;
        fatal_signal_add_hook(unlink_files, cancel_files, NULL, true);
    }

    sset_add(&files, file);
    ovs_mutex_unlock(&mutex);
}
int
main(int argc, char *argv[])
{
    struct dhclient *cli;
    int error;

    set_program_name(argv[0]);
    register_fault_handlers();
    vlog_init();
    parse_options(argc, argv);

    argc -= optind;
    argv += optind;
    if (argc != 1) {
        ofp_fatal(0, "exactly one non-option argument required; "
                  "use --help for help");
    }

    error = dhclient_create(argv[0], modify_dhcp_request, NULL, NULL, &cli);
    if (error) {
        ofp_fatal(error, "dhclient_create failed");
    }
    dhclient_init(cli, request_ip.s_addr);
    fatal_signal_add_hook(release, cli, true);

    for (;;) {
        fatal_signal_block();
        dhclient_run(cli);
        if (dhclient_changed(cli)) {
            dhclient_configure_netdev(cli);
            if (update_resolv_conf) {
                dhclient_update_resolv_conf(cli);
            }
        }
        dhclient_wait(cli);
        fatal_signal_unblock();
        poll_block();
    }
}